Fixed issue #3304: Double click on stash list item does nothing, show log instead
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob7fe3bdf684acc02d8c6fe704a04f767711bcd0f1
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2014 - TortoiseSVN
4 // Copyright (C) 2008-2018 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "CommitDlg.h"
23 #include "MessageBox.h"
24 #include "AppUtils.h"
25 #include "PathUtils.h"
26 #include "Git.h"
27 #include "HistoryDlg.h"
28 #include "Hooks.h"
29 #include "UnicodeUtils.h"
30 #include "../TGitCache/CacheInterface.h"
31 #include "ProgressDlg.h"
32 #include "ShellUpdater.h"
33 #include "Commands/PushCommand.h"
34 #include "COMError.h"
35 #include "Globals.h"
36 #include "SysProgressDlg.h"
37 #include "MassiveGitTask.h"
38 #include "LogDlg.h"
39 #include "BstrSafeVector.h"
40 #include "StringUtils.h"
41 #include "FileTextLines.h"
42 #include "DPIAware.h"
44 #ifdef _DEBUG
45 #define new DEBUG_NEW
46 #undef THIS_FILE
47 static char THIS_FILE[] = __FILE__;
48 #endif
50 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(L"TORTOISEGIT_AUTOLISTREADY_MSG");
51 UINT CCommitDlg::WM_UPDATEOKBUTTON = RegisterWindowMessage(L"TORTOISEGIT_COMMIT_UPDATEOKBUTTON");
52 UINT CCommitDlg::WM_UPDATEDATAFALSE = RegisterWindowMessage(L"TORTOISEGIT_COMMIT_UPDATEDATAFALSE");
54 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)
55 CCommitDlg::CCommitDlg(CWnd* pParent /*=nullptr*/)
56 : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)
57 , m_bShowUnversioned(FALSE)
58 , m_bBlock(FALSE)
59 , m_bThreadRunning(FALSE)
60 , m_bRunThread(FALSE)
61 , m_pThread(nullptr)
62 , m_bWholeProject(FALSE)
63 , m_bWholeProject2(FALSE)
64 , m_bKeepChangeList(TRUE)
65 , m_bDoNotAutoselectSubmodules(FALSE)
66 , m_itemsCount(0)
67 , m_bSelectFilesForCommit(TRUE)
68 , m_bNoPostActions(FALSE)
69 , m_bAutoClose(false)
70 , m_bSetCommitDateTime(FALSE)
71 , m_bCreateNewBranch(FALSE)
72 , m_bForceCommitAmend(false)
73 , m_bCommitMessageOnly(FALSE)
74 , m_bSetAuthor(FALSE)
75 , m_bCancelled(false)
76 , m_PostCmd(GIT_POSTCOMMIT_CMD_NOTHING)
77 , m_bAmendDiffToLastCommit(FALSE)
78 , m_nPopupPasteListCmd(0)
79 , m_nPopupPasteLastMessage(0)
80 , m_nPopupRecentMessage(0)
81 , m_nPopupPickCommitHash(0)
82 , m_nPopupPickCommitMessage(0)
83 , m_hAccel(nullptr)
84 , m_bWarnDetachedHead(true)
85 , m_hAccelOkButton(nullptr)
86 , m_bDoNotStoreLastSelectedLine(true)
87 , m_bCommitAmend(FALSE)
91 CCommitDlg::~CCommitDlg()
93 if (m_hAccelOkButton)
94 DestroyAcceleratorTable(m_hAccelOkButton);
95 delete m_pThread;
98 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
100 CResizableStandAloneDialog::DoDataExchange(pDX);
101 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
102 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
103 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
104 DDX_Check(pDX, IDC_COMMIT_SETDATETIME, m_bSetCommitDateTime);
105 DDX_Check(pDX, IDC_CHECK_NEWBRANCH, m_bCreateNewBranch);
106 DDX_Text(pDX, IDC_NEWBRANCH, m_sCreateNewBranch);
107 DDX_Text(pDX, IDC_BUGID, m_sBugID);
108 DDX_Text(pDX, IDC_COMMIT_AUTHORDATA, m_sAuthor);
109 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
110 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
111 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
112 DDX_Check(pDX, IDC_NOAUTOSELECTSUBMODULES, m_bDoNotAutoselectSubmodules);
113 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
114 DDX_Check(pDX, IDC_COMMIT_MESSAGEONLY, m_bCommitMessageOnly);
115 DDX_Check(pDX,IDC_COMMIT_AMENDDIFF,m_bAmendDiffToLastCommit);
116 DDX_Check(pDX, IDC_COMMIT_SETAUTHOR, m_bSetAuthor);
117 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
118 DDX_Control(pDX, IDC_COMMIT_DATEPICKER, m_CommitDate);
119 DDX_Control(pDX, IDC_COMMIT_TIMEPICKER, m_CommitTime);
120 DDX_Control(pDX, IDC_COMMIT_AS_COMMIT_DATE, m_AsCommitDateCtrl);
121 DDX_Control(pDX, IDC_CHECKALL, m_CheckAll);
122 DDX_Control(pDX, IDC_CHECKNONE, m_CheckNone);
123 DDX_Control(pDX, IDC_CHECKUNVERSIONED, m_CheckUnversioned);
124 DDX_Control(pDX, IDC_CHECKVERSIONED, m_CheckVersioned);
125 DDX_Control(pDX, IDC_CHECKADDED, m_CheckAdded);
126 DDX_Control(pDX, IDC_CHECKDELETED, m_CheckDeleted);
127 DDX_Control(pDX, IDC_CHECKMODIFIED, m_CheckModified);
128 DDX_Control(pDX, IDC_CHECKFILES, m_CheckFiles);
129 DDX_Control(pDX, IDC_CHECKSUBMODULES, m_CheckSubmodules);
130 DDX_Control(pDX, IDOK, m_ctrlOkButton);
133 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
134 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
135 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
136 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
137 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
138 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
139 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
140 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
141 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE, OnFileDropped)
142 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
143 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
145 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED, &CCommitDlg::OnCheck)
146 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
147 ON_REGISTERED_MESSAGE(WM_UPDATEOKBUTTON, OnUpdateOKButton)
148 ON_REGISTERED_MESSAGE(WM_UPDATEDATAFALSE, OnUpdateDataFalse)
149 ON_WM_TIMER()
150 ON_WM_SIZE()
151 ON_WM_SYSCOLORCHANGE()
152 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
153 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
154 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
155 ON_BN_CLICKED(IDC_COMMIT_MESSAGEONLY, &CCommitDlg::OnBnClickedCommitMessageOnly)
156 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
157 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
158 ON_COMMAND(ID_FOCUS_FILELIST, OnFocusFileList)
159 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
160 ON_WM_MOVE()
161 ON_WM_MOVING()
162 ON_WM_SIZING()
163 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
164 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF, &CCommitDlg::OnBnClickedCommitAmenddiff)
165 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES, &CCommitDlg::OnBnClickedNoautoselectsubmodules)
166 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME, &CCommitDlg::OnBnClickedCommitSetDateTime)
167 ON_BN_CLICKED(IDC_COMMIT_AS_COMMIT_DATE, &CCommitDlg::OnBnClickedCommitAsCommitDate)
168 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH, &CCommitDlg::OnBnClickedCheckNewBranch)
169 ON_BN_CLICKED(IDC_COMMIT_SETAUTHOR, &CCommitDlg::OnBnClickedCommitSetauthor)
170 END_MESSAGE_MAP()
172 int GetCommitTemplate(CString &msg)
174 CString tplFilename = g_Git.GetConfigValue(L"commit.template");
175 if (tplFilename.IsEmpty())
176 return -1;
178 if (tplFilename[0] == L'/')
180 if (tplFilename.GetLength() >= 3)
182 // handle "/d/TortoiseGit/tpl.txt" -> "d:/TortoiseGit/tpl.txt"
183 if (tplFilename[2] == L'/')
185 LPWSTR buf = tplFilename.GetBuffer();
186 buf[0] = buf[1];
187 buf[1] = L':';
188 tplFilename.ReleaseBuffer();
192 else if (CStringUtils::StartsWith(tplFilename, L"~/"))
193 tplFilename = g_Git.GetHomeDirectory() + tplFilename.Mid((int)wcslen(L"~"));
195 tplFilename.Replace(L'/', L'\\');
197 if (!CGit::LoadTextFile(tplFilename, msg))
198 return -1;
199 return 0;
202 BOOL CCommitDlg::OnInitDialog()
204 CResizableStandAloneDialog::OnInitDialog();
205 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
207 if (m_sLogMessage.IsEmpty())
209 if (!m_bForceCommitAmend)
210 GetCommitTemplate(m_sLogMessage);
212 CString dotGitPath;
213 GitAdminDir::GetWorktreeAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
214 CGit::LoadTextFile(dotGitPath + L"SQUASH_MSG", m_sLogMessage);
215 CGit::LoadTextFile(dotGitPath + L"MERGE_MSG", m_sLogMessage);
217 if (!RunStartCommitHook())
219 EndDialog(IDCANCEL);
220 return FALSE;
223 m_regAddBeforeCommit = CRegDWORD(L"Software\\TortoiseGit\\AddBeforeCommit", TRUE);
224 m_bShowUnversioned = m_regAddBeforeCommit;
226 CString regPath(g_Git.m_CurrentDir);
227 regPath.Replace(L':', L'_');
228 m_regShowWholeProject = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\ShowWholeProject\\" + regPath, FALSE);
229 m_bWholeProject = m_regShowWholeProject;
231 m_History.SetMaxHistoryItems((LONG)CRegDWORD(L"Software\\TortoiseGit\\MaxHistoryItems", 25));
233 m_regKeepChangelists = CRegDWORD(L"Software\\TortoiseGit\\KeepChangeLists", FALSE);
234 m_bKeepChangeList = m_regKeepChangelists;
236 m_regDoNotAutoselectSubmodules = CRegDWORD(L"Software\\TortoiseGit\\DoNotAutoselectSubmodules", FALSE);
237 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
239 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
241 if (m_pathList.IsEmpty())
242 m_bWholeProject2 = true;
244 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
245 m_bWholeProject2 = true;
247 SetDlgTitle();
249 if (m_bSetAuthor)
250 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_SHOW);
252 if (m_bSetCommitDateTime)
254 m_CommitDate.SetTime(&m_wantCommitTime);
255 m_CommitTime.SetTime(&m_wantCommitTime);
256 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
257 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
260 UpdateData(FALSE);
262 m_ListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD | GITSLC_COLDEL, L"CommitDlg", (GITSLC_POPALL ^ (GITSLC_POPCOMMIT | GITSLC_POPSAVEAS | GITSLC_POPPREPAREDIFF)), true, true);
263 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
264 m_ListCtrl.SetCancelBool(&m_bCancelled);
265 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
266 m_ListCtrl.EnableFileDrop();
267 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
269 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
270 m_ProjectProperties.ReadProps();
272 m_cLogMessage.Init(m_ProjectProperties);
273 m_cLogMessage.SetFont(CAppUtils::GetLogFontName(), CAppUtils::GetLogFontSize());
274 m_cLogMessage.RegisterContextMenuHandler(this);
275 std::map<int, UINT> icons;
276 icons[AUTOCOMPLETE_SPELLING] = IDI_SPELL;
277 icons[AUTOCOMPLETE_FILENAME] = IDI_FILE;
278 icons[AUTOCOMPLETE_PROGRAMCODE] = IDI_CODE;
279 icons[AUTOCOMPLETE_SNIPPET] = IDI_SNIPPET;
280 m_cLogMessage.SetIcon(icons);
282 OnEnChangeLogmessage();
284 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
285 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
286 m_tooltips.AddTool(IDC_MERGEACTIVE, IDC_MERGEACTIVE_TT);
287 m_tooltips.AddTool(IDC_COMMIT_MESSAGEONLY, IDS_COMMIT_MESSAGEONLY_TT);
288 m_tooltips.AddTool(IDC_COMMIT_AS_COMMIT_DATE, IDS_COMMIT_AS_COMMIT_DATE_TT);
290 CBugTraqAssociations bugtraq_associations;
291 bugtraq_associations.Load(m_ProjectProperties.GetProviderUUID(), m_ProjectProperties.sProviderParams);
293 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
295 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
296 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
298 CComPtr<IBugTraqProvider> pProvider;
299 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
300 if (SUCCEEDED(hr))
302 m_BugTraqProvider = pProvider;
303 ATL::CComBSTR temp;
304 ATL::CComBSTR parameters(m_bugtraq_association.GetParameters());
305 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), parameters, &temp)))
307 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
308 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
309 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
313 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
315 else if (!m_ProjectProperties.sMessage.IsEmpty())
317 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
318 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
319 if (!m_ProjectProperties.sLabel.IsEmpty())
320 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
321 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
322 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
323 GetDlgItem(IDC_BUGID)->SetFocus();
324 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
325 if (!sBugID.IsEmpty())
327 SetDlgItemText(IDC_BUGID, sBugID);
330 else
332 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
333 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
334 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
335 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
336 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
339 if (!m_sLogMessage.IsEmpty())
341 m_cLogMessage.SetText(m_sLogMessage);
342 m_cLogMessage.Call(SCI_SETCURRENTPOS, 0);
343 m_cLogMessage.Call(SCI_SETSEL, 0, 0);
346 GetWindowText(m_sWindowTitle);
348 AdjustControlSize(IDC_SHOWUNVERSIONED);
349 AdjustControlSize(IDC_WHOLE_PROJECT);
350 AdjustControlSize(IDC_CHECK_NEWBRANCH);
351 AdjustControlSize(IDC_COMMIT_AMEND);
352 AdjustControlSize(IDC_COMMIT_MESSAGEONLY);
353 AdjustControlSize(IDC_COMMIT_AMENDDIFF);
354 AdjustControlSize(IDC_COMMIT_SETDATETIME);
355 AdjustControlSize(IDC_COMMIT_SETAUTHOR);
356 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES);
357 AdjustControlSize(IDC_KEEPLISTS);
358 AdjustControlSize(IDC_COMMIT_AS_COMMIT_DATE);
360 // line up all controls and adjust their sizes.
361 #define LINKSPACING 9
362 RECT rc = AdjustControlSize(IDC_SELECTLABEL);
363 rc.right -= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
364 rc = AdjustStaticSize(IDC_CHECKALL, rc, LINKSPACING);
365 rc = AdjustStaticSize(IDC_CHECKNONE, rc, LINKSPACING);
366 rc = AdjustStaticSize(IDC_CHECKUNVERSIONED, rc, LINKSPACING);
367 rc = AdjustStaticSize(IDC_CHECKVERSIONED, rc, LINKSPACING);
368 rc = AdjustStaticSize(IDC_CHECKADDED, rc, LINKSPACING);
369 rc = AdjustStaticSize(IDC_CHECKDELETED, rc, LINKSPACING);
370 rc = AdjustStaticSize(IDC_CHECKMODIFIED, rc, LINKSPACING);
371 rc = AdjustStaticSize(IDC_CHECKFILES, rc, LINKSPACING);
372 rc = AdjustStaticSize(IDC_CHECKSUBMODULES, rc, LINKSPACING);
374 GetClientRect(m_DlgOrigRect);
375 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
377 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
378 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
379 AddAnchor(IDC_BUGID, TOP_RIGHT);
380 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
381 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
382 AddAnchor(IDC_CHECK_NEWBRANCH, TOP_RIGHT);
383 AddAnchor(IDC_NEWBRANCH, TOP_LEFT, TOP_RIGHT);
384 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
385 // AddAnchor(IDC_HISTORY, TOP_LEFT);
386 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
387 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
388 AddAnchor(IDC_VIEW_PATCH, BOTTOM_RIGHT);
389 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
390 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
391 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
392 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
393 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
394 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
395 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
396 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
397 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
398 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
399 AddAnchor(IDOK, BOTTOM_RIGHT);
400 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
401 AddAnchor(IDHELP, BOTTOM_RIGHT);
402 AddAnchor(IDC_MERGEACTIVE, BOTTOM_RIGHT);
403 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
404 AddAnchor(IDC_COMMIT_MESSAGEONLY, BOTTOM_LEFT);
405 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
406 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
407 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
408 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
409 AddAnchor(IDC_COMMIT_AS_COMMIT_DATE, TOP_LEFT);
410 AddAnchor(IDC_COMMIT_SETAUTHOR, TOP_LEFT);
411 AddAnchor(IDC_COMMIT_AUTHORDATA, TOP_LEFT, TOP_RIGHT);
413 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
414 AddAnchor(IDC_CHECKALL, TOP_LEFT);
415 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
416 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
417 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
418 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
419 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
420 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
421 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
422 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
424 if (GetExplorerHWND())
425 CenterWindow(CWnd::FromHandle(GetExplorerHWND()));
426 EnableSaveRestore(L"CommitDlg");
427 DWORD yPos = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer");
428 RECT rcDlg, rcLogMsg, rcFileList;
429 GetClientRect(&rcDlg);
430 m_cLogMessage.GetWindowRect(&rcLogMsg);
431 ScreenToClient(&rcLogMsg);
432 m_ListCtrl.GetWindowRect(&rcFileList);
433 ScreenToClient(&rcFileList);
434 if (yPos)
436 RECT rectSplitter;
437 m_wndSplitter.GetWindowRect(&rectSplitter);
438 ScreenToClient(&rectSplitter);
439 int delta = yPos - rectSplitter.top;
440 if ((rcLogMsg.bottom + delta > rcLogMsg.top) && (rcLogMsg.bottom + delta < rcFileList.bottom - CDPIAware::Instance().ScaleY(30)))
442 m_wndSplitter.SetWindowPos(nullptr, rectSplitter.left, yPos, 0, 0, SWP_NOSIZE);
443 DoSize(delta);
444 Invalidate();
448 SetSplitterRange();
450 if (m_bForceCommitAmend || m_bCommitAmend)
451 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
453 // add all directories to the watcher
455 for (int i=0; i<m_pathList.GetCount(); ++i)
457 if (m_pathList[i].IsDirectory())
458 m_pathwatcher.AddPath(m_pathList[i]);
461 StartStatusThread();
462 CRegDWORD err = CRegDWORD(L"Software\\TortoiseGit\\ErrorOccurred", FALSE);
463 CRegDWORD historyhint = CRegDWORD(L"Software\\TortoiseGit\\HistoryHintShown", FALSE);
464 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
466 historyhint = TRUE;
467 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
469 err = FALSE;
471 this->m_ctrlShowPatch.SetURL(CString());
473 if (g_Git.GetConfigValueBool(L"tgit.commitshowpatch"))
474 OnStnClickedViewPatch();
476 if (CTGitPath(g_Git.m_CurrentDir).IsMergeActive())
478 DialogEnableWindow(IDC_CHECK_NEWBRANCH, FALSE);
479 m_bCreateNewBranch = FALSE;
480 GetDlgItem(IDC_MERGEACTIVE)->ShowWindow(SW_SHOW);
481 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_COMMIT_MERGE_HINT, IDS_APPNAME, MB_ICONINFORMATION, L"CommitMergeHint", IDS_MSGBOX_DONOTSHOWAGAIN);
484 PrepareOkButton();
486 return FALSE; // return TRUE unless you set the focus to a control
487 // EXCEPTION: OCX Property Pages should return FALSE
490 void CCommitDlg::PrepareOkButton()
492 if (m_bNoPostActions)
493 return;
494 m_regLastAction = CRegDWORD(L"Software\\TortoiseGit\\CommitLastAction", 0);
495 int i = 0;
496 for (auto labelId : { IDS_COMMIT_COMMIT, IDS_COMMIT_RECOMMIT, IDS_COMMIT_COMMITPUSH })
498 ++i;
499 CString label;
500 label.LoadString(labelId);
501 m_ctrlOkButton.AddEntry(label);
502 TCHAR accellerator = CStringUtils::GetAccellerator(label);
503 if (accellerator == L'\0')
504 continue;
505 ++m_accellerators[accellerator].cnt;
506 if (m_accellerators[accellerator].cnt > 1)
507 m_accellerators[accellerator].id = -1;
508 else
509 m_accellerators[accellerator].id = i - 1;
511 m_ctrlOkButton.SetCurrentEntry(m_regLastAction);
512 if (m_accellerators.size())
514 LPACCEL lpaccelNew = (LPACCEL)LocalAlloc(LPTR, m_accellerators.size() * sizeof(ACCEL));
515 if (!lpaccelNew)
516 return;
517 SCOPE_EXIT{ LocalFree(lpaccelNew); };
518 i = 0;
519 for (auto& entry : m_accellerators)
521 lpaccelNew[i].cmd = (WORD)(WM_USER + 1 + entry.second.id);
522 lpaccelNew[i].fVirt = FVIRTKEY | FALT;
523 lpaccelNew[i].key = entry.first;
524 entry.second.wmid = lpaccelNew[i].cmd;
525 ++i;
527 m_hAccelOkButton = CreateAcceleratorTable(lpaccelNew, (int)m_accellerators.size());
531 static bool UpdateIndex(CMassiveGitTask &mgt, CSysProgressDlg &sysProgressDlg, int progress, int maxProgress)
533 if (mgt.IsListEmpty())
534 return true;
536 if (sysProgressDlg.HasUserCancelled())
537 return false;
539 if (sysProgressDlg.IsVisible())
541 sysProgressDlg.SetTitle(IDS_APPNAME);
542 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
543 sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
544 sysProgressDlg.SetProgress(progress, maxProgress);
545 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing
548 BOOL cancel = FALSE;
549 return mgt.Execute(cancel);
552 static void DoPush(HWND hWnd)
554 CString head;
555 if (g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir, head))
556 return;
557 CString remote, remotebranch;
558 g_Git.GetRemotePushBranch(head, remote, remotebranch);
559 if (remote.IsEmpty() || remotebranch.IsEmpty())
561 CAppUtils::Push(hWnd);
562 return;
565 CAppUtils::DoPush(hWnd, CAppUtils::IsSSHPutty(), false, false, false, false, false, false, head, remote, remotebranch, false, 0);
568 void CCommitDlg::OnOK()
570 if (m_bBlock)
571 return;
572 if (m_bThreadRunning)
574 m_bCancelled = true;
575 StopStatusThread();
577 this->UpdateData();
579 auto locker(m_ListCtrl.AcquireReadLock());
581 if (m_ListCtrl.GetConflictedCount() != 0 && CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROGRS_CONFLICTSOCCURRED, IDS_APPNAME, 1, IDI_EXCLAMATION, IDS_OKBUTTON, IDS_IGNOREBUTTON, 0, L"CommitWarnOnUnresolved") == 1)
583 auto pos = m_ListCtrl.GetFirstSelectedItemPosition();
584 while (pos)
585 m_ListCtrl.SetItemState(m_ListCtrl.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
586 int nListItems = m_ListCtrl.GetItemCount();
587 for (int i = 0; i < nListItems; ++i)
589 auto entry = m_ListCtrl.GetListEntry(i);
590 if (entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
592 m_ListCtrl.EnsureVisible(i, FALSE);
593 m_ListCtrl.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
594 m_ListCtrl.SetFocus();
595 return;
598 return;
601 if (m_bCreateNewBranch)
603 if (!g_Git.IsBranchNameValid(m_sCreateNewBranch))
605 ShowEditBalloon(IDC_NEWBRANCH, IDS_B_T_NOTEMPTY, IDS_ERR_ERROR, TTI_ERROR);
606 return;
608 if (g_Git.BranchTagExists(m_sCreateNewBranch))
610 // branch already exists
611 CString msg;
612 msg.LoadString(IDS_B_EXISTS);
613 msg += L' ' + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME));
614 ShowEditBalloon(IDC_NEWBRANCH, msg, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
615 return;
617 if (g_Git.BranchTagExists(m_sCreateNewBranch, false))
619 // tag with the same name exists -> shortref is ambiguous
620 if (CMessageBox::Show(m_hWnd, IDS_B_SAMETAGNAMEEXISTS, IDS_APPNAME, 2, IDI_EXCLAMATION, IDS_CONTINUEBUTTON, IDS_ABORTBUTTON) == 2)
621 return;
625 CString id;
626 GetDlgItemText(IDC_BUGID, id);
627 if (!m_ProjectProperties.CheckBugID(id))
629 ShowEditBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDS_ERR_ERROR, TTI_ERROR);
630 return;
632 m_sLogMessage = m_cLogMessage.GetText();
633 if ( m_sLogMessage.IsEmpty() )
635 // no message entered, go round again
636 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
637 return;
639 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
641 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
642 return;
645 if (m_ProjectProperties.bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
647 UINT retval = CMessageBox::Show(this->m_hWnd, IDS_PROC_COMMIT_NOSIGNOFFLINE, IDS_APPNAME, 1, IDI_WARNING, IDS_PROC_COMMIT_ADDSIGNOFFBUTTON, IDS_PROC_COMMIT_NOADDSIGNOFFBUTTON, IDS_ABORTBUTTON);
648 if (retval == 1)
650 OnBnClickedSignOff();
651 m_sLogMessage = m_cLogMessage.GetText();
653 else if (retval == 3)
654 return;
657 if (CAppUtils::MessageContainsConflictHints(GetSafeHwnd(), m_sLogMessage))
658 return;
660 CHooks::Instance().SetProjectProperties(g_Git.m_CurrentDir, m_ProjectProperties);
661 if (CHooks::Instance().IsHookPresent(pre_commit_hook, g_Git.m_CurrentDir)) {
662 DWORD exitcode = 0xFFFFFFFF;
663 CString error;
664 CTGitPathList list;
665 m_ListCtrl.WriteCheckedNamesToPathList(list);
666 if (CHooks::Instance().PreCommit(GetSafeHwnd(), g_Git.m_CurrentDir, list, m_sLogMessage, exitcode, error))
668 if (exitcode)
670 CString temp;
671 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
672 MessageBox(temp, L"TortoiseGit", MB_ICONERROR);
673 return;
678 int nListItems = m_ListCtrl.GetItemCount();
679 for (int i = 0; i < nListItems && !m_bCommitMessageOnly; ++i)
681 auto entry = m_ListCtrl.GetListEntry(i);
682 if (!entry->m_Checked || !entry->IsDirectory())
683 continue;
685 bool dirty = false;
686 if (entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
688 CGit subgit;
689 subgit.m_CurrentDir = g_Git.CombinePath(entry);
690 CString subcmdout;
691 subgit.Run(L"git.exe status --porcelain", &subcmdout, CP_UTF8);
692 dirty = !subcmdout.IsEmpty();
694 else
696 CString cmd, cmdout;
697 cmd.Format(L"git.exe diff -- \"%s\"", entry->GetWinPath());
698 g_Git.Run(cmd, &cmdout, CP_UTF8);
699 dirty = CStringUtils::EndsWith(cmdout, L"-dirty\n");
702 if (dirty)
704 CString message;
705 message.Format(IDS_COMMITDLG_SUBMODULEDIRTY, (LPCTSTR)entry->GetGitPathString());
706 int result = CMessageBox::Show(m_hWnd, message, L"TortoiseGit", 1, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_COMMIT)), CString(MAKEINTRESOURCE(IDS_MSGBOX_IGNORE)), CString(MAKEINTRESOURCE(IDS_MSGBOX_CANCEL)));
707 if (result == 1)
709 CString cmdCommit;
710 cmdCommit.Format(L"/command:commit /path:\"%s\\%s\"", (LPCTSTR)g_Git.m_CurrentDir, entry->GetWinPath());
711 CAppUtils::RunTortoiseGitProc(cmdCommit);
712 return;
714 else if (result == 2)
715 continue;
716 else
717 return;
721 if (!m_bCommitMessageOnly)
722 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
723 m_pathwatcher.Stop();
724 InterlockedExchange(&m_bBlock, TRUE);
725 //first add all the unversioned files the user selected
726 //and check if all versioned files are selected
727 int nchecked = 0;
729 CMassiveGitTask mgtReAddAfterCommit(L"add --ignore-errors -f");
730 CMassiveGitTask mgtReDelAfterCommit(L"rm --cached --ignore-unmatch");
732 CString cmd;
733 CString out;
735 bool bAddSuccess=true;
736 bool bCloseCommitDlg=false;
738 CSysProgressDlg sysProgressDlg;
739 if (nListItems >= 25)
741 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
742 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
743 sysProgressDlg.SetTime(true);
744 sysProgressDlg.SetShowProgressBar(true);
745 sysProgressDlg.ShowModal(this, true);
748 CBlockCacheForPath cacheBlock(g_Git.m_CurrentDir);
749 ULONGLONG currentTicks = GetTickCount64();
751 if (g_Git.UsingLibGit2(CGit::GIT_CMD_COMMIT_UPDATE_INDEX))
753 bAddSuccess = false;
756 CAutoRepository repository(g_Git.GetGitRepository());
757 if (!repository)
759 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not open repository."), L"TortoiseGit", MB_OK | MB_ICONERROR);
760 break;
763 CGitHash revHash;
764 CString revRef = L"HEAD";
765 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
766 revRef = L"HEAD~1";
767 if (CGit::GetHash(repository, revHash, revRef))
769 MessageBox(g_Git.GetLibGit2LastErr(L"Could not get HEAD hash after committing."), L"TortoiseGit", MB_ICONERROR);
770 break;
773 CAutoCommit commit;
774 if (!revHash.IsEmpty() && git_commit_lookup(commit.GetPointer(), repository, revHash))
776 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not get last commit."), L"TortoiseGit", MB_OK | MB_ICONERROR);
777 break;
780 CAutoTree tree;
781 if (!revHash.IsEmpty() && git_commit_tree(tree.GetPointer(), commit))
783 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not read tree of commit."), L"TortoiseGit", MB_OK | MB_ICONERROR);
784 break;
787 CAutoIndex index;
788 if (git_repository_index(index.GetPointer(), repository))
790 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not get the repository index."), L"TortoiseGit", MB_OK | MB_ICONERROR);
791 break;
794 CAutoIndex indexOld;
795 if (!revHash.IsEmpty() && (git_index_new(indexOld.GetPointer()) || git_index_read_tree(indexOld, tree)))
797 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not read the tree into the index."), L"TortoiseGit", MB_OK | MB_ICONERROR);
798 break;
801 bAddSuccess = true;
803 for (int j = 0; j < nListItems; ++j)
805 auto entry = m_ListCtrl.GetListEntry(j);
807 if (sysProgressDlg.IsVisible())
809 if (GetTickCount64() - currentTicks > 1000UL || j == nListItems - 1 || j == 0)
811 sysProgressDlg.SetLine(2, entry->GetGitPathString(), true);
812 sysProgressDlg.SetProgress(j, nListItems);
813 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too often: this takes time!
814 currentTicks = GetTickCount64();
818 CStringA filePathA = CUnicodeUtils::GetMulti(entry->GetGitPathString(), CP_UTF8).TrimRight(L'/');
820 if (entry->m_Checked && !m_bCommitMessageOnly)
822 if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
823 git_index_remove_bypath(index, filePathA); // ignore error
824 else
826 if (git_index_add_bypath(index, filePathA))
828 bAddSuccess = false;
829 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not add \"" + entry->GetGitPathString() + L"\" to index."), L"TortoiseGit", MB_OK | MB_ICONERROR);
830 break;
834 if ((entry->m_Action & CTGitPath::LOGACTIONS_REPLACED) && !entry->GetGitOldPathString().IsEmpty())
835 git_index_remove_bypath(index, CUnicodeUtils::GetUTF8(entry->GetGitOldPathString())); // ignore error
837 ++nchecked;
839 else
841 if (entry->m_Action & CTGitPath::LOGACTIONS_ADDED || entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
843 git_index_remove_bypath(index, filePathA); // ignore error
844 mgtReAddAfterCommit.AddFile(*entry);
846 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED && !entry->GetGitOldPathString().IsEmpty())
848 const git_index_entry* oldIndexEntry = nullptr;
849 if ((oldIndexEntry = git_index_get_bypath(indexOld, CUnicodeUtils::GetUTF8(entry->GetGitOldPathString()), 0)) == nullptr || git_index_add(index, oldIndexEntry))
851 bAddSuccess = false;
852 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not reset \"" + entry->GetGitOldPathString() + L"\" to old index entry."), L"TortoiseGit", MB_OK | MB_ICONERROR);
853 break;
855 mgtReDelAfterCommit.AddFile(entry->GetGitOldPathString());
858 else if (!(entry->m_Action & CTGitPath::LOGACTIONS_UNVER))
860 const git_index_entry* oldIndexEntry = nullptr;
861 if ((oldIndexEntry = git_index_get_bypath(indexOld, filePathA, 0)) == nullptr || git_index_add(index, oldIndexEntry))
863 bAddSuccess = false;
864 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not reset \"" + entry->GetGitPathString() + L"\" to old index entry."), L"TortoiseGit", MB_OK | MB_ICONERROR);
865 break;
867 if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED && !(entry->m_Action & CTGitPath::LOGACTIONS_MISSING))
868 mgtReDelAfterCommit.AddFile(entry->GetGitPathString());
872 if (sysProgressDlg.HasUserCancelled())
874 bAddSuccess = false;
875 break;
878 if (bAddSuccess && git_index_write(index))
879 bAddSuccess = false;
881 for (int j = 0; bAddSuccess && j < nListItems; ++j)
882 CShellUpdater::Instance().AddPathForUpdate(*m_ListCtrl.GetListEntry(j));
883 } while (0);
885 else
887 // ***************************************************
888 // ATTENTION: Similar code in RebaseDlg.cpp!!!
889 // ***************************************************
890 CMassiveGitTask mgtAdd(L"add -f");
891 CMassiveGitTask mgtUpdateIndexForceRemove(L"update-index --force-remove");
892 CMassiveGitTask mgtUpdateIndex(L"update-index");
893 CMassiveGitTask mgtRm(L"rm --ignore-unmatch");
894 CMassiveGitTask mgtRmFCache(L"rm -f --cache");
895 CString resetCmd = L"reset";
896 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
897 resetCmd += L" HEAD~1";;
898 CMassiveGitTask mgtReset(resetCmd, TRUE, true);
899 for (int j = 0; j < nListItems; ++j)
901 auto entry = m_ListCtrl.GetListEntry(j);
903 if (entry->m_Checked && !m_bCommitMessageOnly)
905 if ((entry->m_Action & CTGitPath::LOGACTIONS_UNVER) || (entry->IsDirectory() && !(entry->m_Action & CTGitPath::LOGACTIONS_DELETED)))
906 mgtAdd.AddFile(entry->GetGitPathString());
907 else if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
908 mgtUpdateIndexForceRemove.AddFile(entry->GetGitPathString());
909 else
910 mgtUpdateIndex.AddFile(entry->GetGitPathString());
912 if ((entry->m_Action & CTGitPath::LOGACTIONS_REPLACED) && !entry->GetGitOldPathString().IsEmpty())
913 mgtRm.AddFile(entry->GetGitOldPathString());
915 ++nchecked;
917 else
919 if (entry->m_Action & CTGitPath::LOGACTIONS_ADDED || entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
920 { //To init git repository, there are not HEAD, so we can use git reset command
921 mgtRmFCache.AddFile(entry->GetGitPathString());
922 mgtReAddAfterCommit.AddFile(*entry);
924 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED && !entry->GetGitOldPathString().IsEmpty())
926 mgtReset.AddFile(entry->GetGitOldPathString());
927 mgtReDelAfterCommit.AddFile(entry->GetGitOldPathString());
930 else if (!(entry->m_Action & CTGitPath::LOGACTIONS_UNVER))
932 mgtReset.AddFile(entry->GetGitPathString());
933 if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED && !(entry->m_Action & CTGitPath::LOGACTIONS_MISSING))
934 mgtReDelAfterCommit.AddFile(entry->GetGitPathString());
938 if (sysProgressDlg.HasUserCancelled())
940 bAddSuccess = false;
941 break;
945 CMassiveGitTask tasks[] = { mgtAdd, mgtUpdateIndexForceRemove, mgtUpdateIndex, mgtRm, mgtRmFCache, mgtReset };
946 int progress = 0, maxProgress = 0;
947 for (int j = 0; j < _countof(tasks); ++j)
948 maxProgress += tasks[j].GetListCount();
949 for (int j = 0; j < _countof(tasks); ++j)
950 bAddSuccess = bAddSuccess && UpdateIndex(tasks[j], sysProgressDlg, progress += tasks[j].GetListCount(), maxProgress);
952 if (sysProgressDlg.HasUserCancelled())
953 bAddSuccess = false;
955 for (int j = 0; bAddSuccess && j < nListItems; ++j)
956 CShellUpdater::Instance().AddPathForUpdate(*m_ListCtrl.GetListEntry(j));
959 if (sysProgressDlg.HasUserCancelled())
960 bAddSuccess = false;
962 sysProgressDlg.Stop();
964 if (bAddSuccess && m_bCreateNewBranch)
966 if (g_Git.Run(L"git.exe branch " + m_sCreateNewBranch, &out, CP_UTF8))
968 MessageBox(L"Creating new branch failed:\n" + out, L"TortoiseGit", MB_OK | MB_ICONERROR);
969 bAddSuccess = false;
971 if (g_Git.Run(L"git.exe checkout " + m_sCreateNewBranch + L" --", &out, CP_UTF8))
973 MessageBox(L"Switching to new branch failed:\n" + out, L"TortoiseGit", MB_OK | MB_ICONERROR);
974 bAddSuccess = false;
978 if (bAddSuccess && m_bWarnDetachedHead && CheckHeadDetach())
979 bAddSuccess = false;
981 m_sBugID.Trim();
982 CString sExistingBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
983 sExistingBugID.Trim();
984 if (!m_sBugID.IsEmpty() && m_sBugID.Compare(sExistingBugID))
986 m_sBugID.Replace(L", ", L",");
987 m_sBugID.Replace(L" ,", L",");
988 CString sBugID = m_ProjectProperties.sMessage;
989 sBugID.Replace(L"%BUGID%", m_sBugID);
990 if (m_ProjectProperties.bAppend)
991 m_sLogMessage += L'\n' + sBugID + L'\n';
992 else
993 m_sLogMessage = sBugID + L'\n' + m_sLogMessage;
996 // now let the bugtraq plugin check the commit message
997 CComPtr<IBugTraqProvider2> pProvider2;
998 if (m_BugTraqProvider)
1000 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1001 if (SUCCEEDED(hr))
1003 ATL::CComBSTR temp;
1004 ATL::CComBSTR repositoryRoot(g_Git.m_CurrentDir);
1005 ATL::CComBSTR parameters(m_bugtraq_association.GetParameters());
1006 ATL::CComBSTR commonRoot(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
1007 ATL::CComBSTR commitMessage(m_sLogMessage);
1008 CBstrSafeVector pathList(m_selectedPathList.GetCount());
1010 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
1011 pathList.PutElement(index, m_selectedPathList[index].GetGitPathString());
1013 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
1015 COMError ce(hr);
1016 CString sErr;
1017 sErr.FormatMessage(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
1018 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
1020 else
1022 CString sError = temp;
1023 if (!sError.IsEmpty())
1025 CMessageBox::Show(GetSafeHwnd(), sError, L"TortoiseGit", MB_ICONERROR);
1026 InterlockedExchange(&m_bBlock, FALSE);
1027 return;
1033 if (m_bCommitMessageOnly || bAddSuccess && (nchecked || m_bCommitAmend || CTGitPath(g_Git.m_CurrentDir).IsMergeActive()))
1035 bCloseCommitDlg = true;
1037 CString tempfile=::GetTempFile();
1039 if (CAppUtils::SaveCommitUnicodeFile(tempfile, m_sLogMessage))
1041 CMessageBox::Show(GetSafeHwnd(), L"Could not save commit message", L"TortoiseGit", MB_OK | MB_ICONERROR);
1042 InterlockedExchange(&m_bBlock, FALSE);
1043 return;
1046 CTGitPath path=g_Git.m_CurrentDir;
1048 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
1050 out.Empty();
1051 CString amend;
1052 if(this->m_bCommitAmend)
1053 amend = L"--amend";
1055 CString dateTime;
1056 if (m_bSetCommitDateTime)
1058 CTime date, time;
1059 m_CommitDate.GetTime(date);
1060 m_CommitTime.GetTime(time);
1061 if (m_bCommitAmend && m_AsCommitDateCtrl.GetCheck())
1062 dateTime = L"--date=\"now\"";
1063 else
1064 dateTime.Format(L"--date=%sT%s", (LPCTSTR)date.Format(L"%Y-%m-%d"), (LPCTSTR)time.Format(L"%H:%M:%S"));
1066 CString author;
1067 if (m_bSetAuthor)
1068 author.Format(L"--author=\"%s\"", (LPCTSTR)m_sAuthor);
1069 CString allowEmpty = m_bCommitMessageOnly ? L"--allow-empty" : L"";
1070 // TODO: make sure notes.amend.rewrite does still work when switching to libgit2
1071 cmd.Format(L"git.exe commit %s %s %s %s -F \"%s\"", (LPCTSTR)author, (LPCTSTR)dateTime, (LPCTSTR)amend, (LPCTSTR)allowEmpty, (LPCTSTR)tempfile);
1073 CCommitProgressDlg progress;
1074 progress.m_bBufferAll=true; // improve show speed when there are many file added.
1075 progress.m_GitCmd=cmd;
1076 progress.m_bShowCommand = FALSE; // don't show the commit command
1077 progress.m_PreText = out; // show any output already generated in log window
1078 if (m_ctrlOkButton.GetCurrentEntry() > 0)
1079 progress.m_AutoClose = GitProgressAutoClose::AUTOCLOSE_IF_NO_ERRORS;
1081 progress.m_PostCmdCallback = [&](DWORD status, PostCmdList& postCmdList)
1083 if (status || m_bNoPostActions || m_bAutoClose)
1084 return;
1086 if (IsGitSVN)
1087 postCmdList.emplace_back(IDI_COMMIT, IDS_MENUSVNDCOMMIT, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_DCOMMIT; });
1089 postCmdList.emplace_back(IDI_PUSH, IDS_MENUPUSH, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_PUSH; });
1090 postCmdList.emplace_back(IDI_PULL, IDS_MENUPULL, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_PULL; });
1091 postCmdList.emplace_back(IDI_COMMIT, IDS_PROC_COMMIT_RECOMMIT, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_RECOMMIT; });
1092 postCmdList.emplace_back(IDI_TAG, IDS_MENUTAG, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_CREATETAG; });
1095 m_PostCmd = GIT_POSTCOMMIT_CMD_NOTHING;
1096 progress.DoModal();
1098 if (!m_bNoPostActions)
1099 m_regLastAction = (int)m_ctrlOkButton.GetCurrentEntry();
1100 if (m_ctrlOkButton.GetCurrentEntry() == 1)
1101 m_PostCmd = GIT_POSTCOMMIT_CMD_RECOMMIT;
1103 ::DeleteFile(tempfile);
1105 if (m_BugTraqProvider && progress.m_GitStatus == 0)
1107 CComPtr<IBugTraqProvider2> pProvider;
1108 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
1109 if (SUCCEEDED(hr))
1111 ATL::CComBSTR commonRoot(g_Git.m_CurrentDir);
1112 CBstrSafeVector pathList(m_selectedPathList.GetCount());
1114 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
1115 pathList.PutElement(index, m_selectedPathList[index].GetGitPathString());
1117 ATL::CComBSTR logMessage(m_sLogMessage);
1119 CGitHash hash;
1120 if (g_Git.GetHash(hash, L"HEAD"))
1121 MessageBox(g_Git.GetGitLastErr(L"Could not get HEAD hash after committing."), L"TortoiseGit", MB_ICONERROR);
1122 LONG version = g_Git.Hash2int(hash);
1124 ATL::CComBSTR temp;
1125 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
1126 commonRoot,
1127 pathList,
1128 logMessage,
1129 (LONG)version,
1130 &temp)))
1132 CString sErr = temp;
1133 if (!sErr.IsEmpty())
1134 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_OK | MB_ICONERROR);
1135 else
1137 COMError ce(hr);
1138 sErr.FormatMessage(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
1139 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_OK | MB_ICONERROR);
1144 RestoreFiles(progress.m_GitStatus == 0, false);
1145 if (((DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit", TRUE)) == TRUE)
1147 BOOL cancel = FALSE;
1148 mgtReAddAfterCommit.Execute(cancel);
1149 mgtReDelAfterCommit.Execute(cancel);
1152 if (!progress.m_GitStatus)
1154 DWORD exitcode = 0xFFFFFFFF;
1155 CString error;
1156 CHooks::Instance().SetProjectProperties(g_Git.m_CurrentDir, m_ProjectProperties);
1157 if (CHooks::Instance().PostCommit(GetSafeHwnd(), g_Git.m_CurrentDir, amend.IsEmpty(), exitcode, error))
1159 if (exitcode)
1161 CString temp;
1162 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
1163 MessageBox(temp, L"TortoiseGit", MB_ICONERROR);
1164 bCloseCommitDlg = false;
1169 if (progress.m_GitStatus || m_PostCmd == GIT_POSTCOMMIT_CMD_RECOMMIT)
1171 bCloseCommitDlg = false;
1172 if (m_PostCmd == GIT_POSTCOMMIT_CMD_RECOMMIT)
1174 if (!m_sLogMessage.IsEmpty())
1176 ReloadHistoryEntries();
1177 m_History.AddEntry(m_sLogMessage);
1178 m_History.Save();
1181 this->m_sLogMessage.Empty();
1182 GetCommitTemplate(m_sLogMessage);
1183 m_cLogMessage.SetText(m_sLogMessage);
1184 if (m_bCreateNewBranch)
1186 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);
1187 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
1189 m_bCreateNewBranch = FALSE;
1190 m_ListCtrl.Clear();
1191 if (!RunStartCommitHook())
1192 bCloseCommitDlg = true;
1195 if (!progress.m_GitStatus)
1197 m_AmendStr.Empty();
1198 m_bCommitAmend = FALSE;
1199 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
1200 m_bSetCommitDateTime = FALSE;
1201 m_AsCommitDateCtrl.ShowWindow(SW_HIDE);
1202 m_AsCommitDateCtrl.SetCheck(FALSE);
1203 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_HIDE);
1204 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_HIDE);
1205 m_bSetAuthor = FALSE;
1206 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_HIDE);
1209 UpdateData(FALSE);
1212 else if(bAddSuccess)
1214 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
1215 bCloseCommitDlg=false;
1218 UpdateData();
1219 m_regAddBeforeCommit = m_bShowUnversioned;
1220 m_regKeepChangelists = m_bKeepChangeList;
1221 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
1222 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
1223 m_bKeepChangeList = FALSE;
1224 InterlockedExchange(&m_bBlock, FALSE);
1226 if (!m_sLogMessage.IsEmpty())
1228 ReloadHistoryEntries();
1229 m_History.AddEntry(m_sLogMessage);
1230 m_History.Save();
1233 SaveSplitterPos();
1235 if (bCloseCommitDlg)
1237 if (m_ctrlOkButton.GetCurrentEntry() == 2)
1238 DoPush(GetSafeHwnd());
1239 CResizableStandAloneDialog::OnOK();
1241 else if (m_PostCmd == GIT_POSTCOMMIT_CMD_RECOMMIT)
1243 m_bDoNotStoreLastSelectedLine = true;
1244 this->Refresh();
1245 this->BringWindowToTop();
1248 CShellUpdater::Instance().Flush();
1251 void CCommitDlg::SaveSplitterPos()
1253 if (!IsIconic())
1255 CRegDWORD regPos(L"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer");
1256 RECT rectSplitter;
1257 m_wndSplitter.GetWindowRect(&rectSplitter);
1258 ScreenToClient(&rectSplitter);
1259 regPos = rectSplitter.top;
1263 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
1265 return ((CCommitDlg*)pVoid)->StatusThread();
1268 void CCommitDlg::ReloadHistoryEntries()
1270 CString reg;
1271 reg.Format(L"Software\\TortoiseGit\\History\\commit%s", (LPCTSTR)m_ListCtrl.m_sUUID);
1272 reg.Replace(L':', L'_');
1273 m_History.Load(reg, L"logmsgs");
1276 UINT CCommitDlg::StatusThread()
1278 //get the status of all selected file/folders recursively
1279 //and show the ones which have to be committed to the user
1280 //in a list control.
1281 m_pathwatcher.Stop();
1283 m_bCancelled = false;
1285 DialogEnableWindow(IDOK, false);
1286 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
1287 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
1288 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
1289 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
1290 DialogEnableWindow(IDC_EXTERNALWARNING, false);
1291 DialogEnableWindow(IDC_COMMIT_AMEND, FALSE);
1292 DialogEnableWindow(IDC_COMMIT_AMENDDIFF, FALSE);
1293 // read the list of recent log entries before querying the WC for status
1294 // -> the user may select one and modify / update it while we are crawling the WC
1296 DialogEnableWindow(IDC_CHECKALL, false);
1297 DialogEnableWindow(IDC_CHECKNONE, false);
1298 DialogEnableWindow(IDC_CHECKUNVERSIONED, false);
1299 DialogEnableWindow(IDC_CHECKVERSIONED, false);
1300 DialogEnableWindow(IDC_CHECKADDED, false);
1301 DialogEnableWindow(IDC_CHECKDELETED, false);
1302 DialogEnableWindow(IDC_CHECKMODIFIED, false);
1303 DialogEnableWindow(IDC_CHECKFILES, false);
1304 DialogEnableWindow(IDC_CHECKSUBMODULES, false);
1306 g_Git.RefreshGitIndex();
1308 CString dotGitPath;
1309 GitAdminDir::GetWorktreeAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
1310 if (PathFileExists(dotGitPath + L"CHERRY_PICK_HEAD"))
1312 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
1313 m_bCommitAmend = FALSE;
1314 SendMessage(WM_UPDATEDATAFALSE);
1317 if (!m_bDoNotStoreLastSelectedLine)
1318 m_ListCtrl.StoreScrollPos();
1319 // Initialise the list control with the status of the files/folders below us
1320 m_ListCtrl.Clear();
1321 BOOL success;
1322 CTGitPathList *pList;
1323 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE || m_bForceCommitAmend) && (m_bAmendDiffToLastCommit==FALSE);
1324 m_ListCtrl.m_bIncludedStaged = true;
1325 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
1327 if(m_bWholeProject || m_bWholeProject2)
1328 pList = nullptr;
1329 else
1330 pList = &m_pathList;
1332 success=m_ListCtrl.GetStatus(pList);
1334 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1335 if(this->m_bShowUnversioned)
1336 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
1338 m_ListCtrl.CheckIfChangelistsArePresent(false);
1340 DWORD dwShow = GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWINCHANGELIST | GITSLC_SHOWDIRECTFILES;
1341 dwShow |= DWORD(m_regAddBeforeCommit) ? GITSLC_SHOWUNVERSIONED : 0;
1342 if (success)
1344 /*if (!m_checkedPathList.IsEmpty())
1345 m_ListCtrl.Show(dwShow, m_checkedPathList);
1346 else*/
1348 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
1349 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
1350 m_ListCtrl.Show(dwShow, dwCheck);
1353 if (m_ListCtrl.HasExternalsFromDifferentRepos())
1355 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
1356 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
1359 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
1360 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
1361 if (m_ListCtrl.GetItemCount() != 0 && m_ListCtrl.GetTopIndex() == 0 && (m_bDoNotStoreLastSelectedLine || CRegDWORD(L"Software\\TortoiseGit\\RememberFileListPosition", TRUE) != TRUE))
1362 m_ListCtrl.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
1364 if (!success)
1366 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
1367 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
1368 m_ListCtrl.Show(dwShow);
1370 m_bDoNotStoreLastSelectedLine = false;
1372 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
1373 && !PathFileExists(dotGitPath + L"MERGE_HEAD"))
1375 CString temp;
1376 temp.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED);
1377 if (CMessageBox::ShowCheck(GetSafeHwnd(), temp, L"TortoiseGit", MB_ICONINFORMATION | MB_YESNO, L"NothingToCommitShowUnversioned", nullptr) == IDYES)
1379 m_bShowUnversioned = TRUE;
1380 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
1381 dwShow = (DWORD)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWUNVERSIONED);
1382 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
1383 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
1387 SetDlgTitle();
1389 // we don't have to block the commit dialog while we fetch the
1390 // auto completion list.
1391 m_pathwatcher.ClearChangedPaths();
1392 InterlockedExchange(&m_bBlock, FALSE);
1393 std::map<CString, int> autolist;
1394 if ((DWORD)CRegDWORD(L"Software\\TortoiseGit\\Autocompletion", TRUE) == TRUE)
1396 m_ListCtrl.BusyCursor(true);
1397 GetAutocompletionList(autolist);
1398 m_ListCtrl.BusyCursor(false);
1400 SendMessage(WM_UPDATEOKBUTTON);
1401 m_ListCtrl.Invalidate();
1402 if (m_bRunThread)
1404 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1405 DialogEnableWindow(IDC_WHOLE_PROJECT, !m_bWholeProject2);
1406 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1407 if (m_ListCtrl.HasChangeLists())
1408 DialogEnableWindow(IDC_KEEPLISTS, true);
1410 // activate amend checkbox (if necessary)
1411 if (g_Git.IsInitRepos())
1413 m_bCommitAmend = FALSE;
1414 SendMessage(WM_UPDATEDATAFALSE);
1416 else
1418 if (m_bForceCommitAmend)
1420 m_bCommitAmend = TRUE;
1421 SendMessage(WM_UPDATEDATAFALSE);
1423 else
1424 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(!PathFileExists(dotGitPath + L"CHERRY_PICK_HEAD"));
1426 CGitHash hash;
1427 if (g_Git.GetHash(hash, L"HEAD"))
1429 MessageBox(g_Git.GetGitLastErr(L"Could not get HEAD hash."), L"TortoiseGit", MB_ICONERROR);
1431 if (!hash.IsEmpty())
1433 GitRev headRevision;
1434 if (headRevision.GetParentFromHash(hash))
1435 MessageBox(headRevision.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
1436 // do not allow to show diff to "last" revision if it has more that one parent
1437 if (headRevision.ParentsCount() != 1)
1439 m_bAmendDiffToLastCommit = TRUE;
1440 SendMessage(WM_UPDATEDATAFALSE);
1442 else
1443 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(TRUE);
1447 UpdateCheckLinks();
1449 // we have the list, now signal the main thread about it
1450 SendMessage(WM_AUTOLISTREADY, 0, (LPARAM)&autolist); // only send the message if the thread wasn't told to quit!
1453 InterlockedExchange(&m_bRunThread, FALSE);
1454 InterlockedExchange(&m_bThreadRunning, FALSE);
1455 // force the cursor to normal
1456 RefreshCursor();
1458 return 0;
1461 void CCommitDlg::SetDlgTitle()
1463 if (m_sTitle.IsEmpty())
1464 GetWindowText(m_sTitle);
1466 if (m_bWholeProject || m_bWholeProject2)
1467 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
1468 else
1470 if (m_pathList.GetCount() == 1)
1471 CAppUtils::SetWindowTitle(m_hWnd, g_Git.CombinePath(m_pathList[0].GetUIPathString()), m_sTitle);
1472 else
1473 CAppUtils::SetWindowTitle(m_hWnd, g_Git.CombinePath(m_ListCtrl.GetCommonDirectory(false)), m_sTitle);
1477 void CCommitDlg::OnCancel()
1479 UpdateData();
1480 m_sBugID.Trim();
1481 m_sLogMessage = m_cLogMessage.GetText();
1482 if (!m_sBugID.IsEmpty())
1484 m_sBugID.Replace(L", ", L",");
1485 m_sBugID.Replace(L" ,", L",");
1486 CString sBugID = m_ProjectProperties.sMessage;
1487 sBugID.Replace(L"%BUGID%", m_sBugID);
1488 if (m_ProjectProperties.bAppend)
1489 m_sLogMessage += L'\n' + sBugID + L'\n';
1490 else
1491 m_sLogMessage = sBugID + L'\n' + m_sLogMessage;
1494 bool hasChangedMessage = (m_sLogTemplate.Compare(m_sLogMessage) != 0) && !m_sLogMessage.IsEmpty();
1496 CString tmp;
1497 tmp.LoadString(IDS_REALLYCANCEL);
1498 tmp.AppendChar(L'\n');
1499 tmp.AppendChar(L'\n');
1500 tmp.Append(CString(MAKEINTRESOURCE(IDS_HINTLASTMESSAGES)));
1501 CString dontaskagain;
1502 dontaskagain.LoadString(IDS_MSGBOX_DONOTSHOWAGAIN);
1503 BOOL dontaskagainchecked = FALSE;
1504 if ((hasChangedMessage || m_ListCtrl.GetItemCount() > 0) && CMessageBox::ShowCheck(GetSafeHwnd(), tmp, L"TortoiseGit", MB_ICONQUESTION | MB_DEFBUTTON2 | MB_YESNO, L"CommitAskBeforeCancel", dontaskagain, &dontaskagainchecked) == IDNO)
1506 if (dontaskagainchecked)
1507 CMessageBox::SetRegistryValue(L"CommitAskBeforeCancel", IDYES);
1508 return;
1511 m_bCancelled = true;
1512 m_pathwatcher.Stop();
1514 if (m_bThreadRunning)
1515 StopStatusThread();
1516 if (!RestoreFiles())
1517 return;
1518 if (hasChangedMessage)
1520 ReloadHistoryEntries();
1521 m_History.AddEntry(m_sLogMessage);
1522 m_History.Save();
1524 SaveSplitterPos();
1525 CResizableStandAloneDialog::OnCancel();
1528 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1530 if (m_hAccel)
1532 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1533 if (ret)
1534 return TRUE;
1536 if (m_hAccelOkButton && GetDlgItem(IDOK)->IsWindowEnabled() && TranslateAccelerator(m_hWnd, m_hAccelOkButton, pMsg))
1537 return TRUE;
1539 if (pMsg->message == WM_KEYDOWN)
1541 switch (pMsg->wParam)
1543 case VK_F5:
1545 if (m_bBlock)
1546 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1547 Refresh();
1549 break;
1550 case VK_RETURN:
1552 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1554 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1555 PostMessage(WM_COMMAND, IDOK);
1556 return TRUE;
1558 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1560 // Pressing RETURN in the bug id control
1561 // moves the focus to the message
1562 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1563 return TRUE;
1566 break;
1570 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1573 void CCommitDlg::Refresh()
1575 if (m_bThreadRunning)
1576 return;
1578 StartStatusThread();
1581 void CCommitDlg::StartStatusThread()
1583 if (InterlockedExchange(&m_bBlock, TRUE) != FALSE)
1584 return;
1586 delete m_pThread;
1587 m_pThread = nullptr;
1589 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
1590 if (!m_pThread)
1592 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1593 InterlockedExchange(&m_bBlock, FALSE);
1594 return;
1596 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
1597 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
1598 m_pThread->m_bAutoDelete = FALSE;
1599 m_pThread->ResumeThread();
1602 void CCommitDlg::StopStatusThread()
1604 InterlockedExchange(&m_bRunThread, FALSE);
1605 WaitForSingleObject(m_pThread->m_hThread, 5000);
1606 if (!m_bThreadRunning)
1607 return;
1609 // we gave the thread a chance to quit. Since the thread didn't
1610 // listen to us we have to kill it.
1611 g_Git.KillRelatedThreads(m_pThread);
1612 InterlockedExchange(&m_bThreadRunning, FALSE);
1615 void CCommitDlg::OnBnClickedShowunversioned()
1617 m_tooltips.Pop(); // hide the tooltips
1618 UpdateData();
1619 m_regAddBeforeCommit = m_bShowUnversioned;
1620 if (!m_bBlock)
1622 DWORD dwShow = m_ListCtrl.GetShowFlags();
1623 if (DWORD(m_regAddBeforeCommit))
1624 dwShow |= GITSLC_SHOWUNVERSIONED;
1625 else
1626 dwShow &= ~GITSLC_SHOWUNVERSIONED;
1627 if(dwShow & GITSLC_SHOWUNVERSIONED)
1629 if (m_bWholeProject || m_bWholeProject2)
1630 m_ListCtrl.GetStatus(nullptr, false, false, true);
1631 else
1632 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1634 m_ListCtrl.StoreScrollPos();
1635 m_ListCtrl.Show(dwShow, 0, true, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
1636 UpdateCheckLinks();
1640 void CCommitDlg::OnStnClickedExternalwarning()
1642 m_tooltips.Popup();
1645 void CCommitDlg::OnEnChangeLogmessage()
1647 SendMessage(WM_UPDATEOKBUTTON);
1650 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1652 #if 0
1653 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1655 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1657 m_bShowUnversioned = TRUE;
1658 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED;
1659 m_ListCtrl.Show(dwShow);
1660 UpdateData(FALSE);
1663 #endif
1664 return 0;
1667 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1669 Refresh();
1670 return 0;
1673 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM lParam)
1675 BringWindowToTop();
1676 SetForegroundWindow();
1677 SetActiveWindow();
1678 // if multiple files/folders are dropped
1679 // this handler is called for every single item
1680 // separately.
1681 // To avoid creating multiple refresh threads and
1682 // causing crashes, we only add the items to the
1683 // list control and start a timer.
1684 // When the timer expires, we start the refresh thread,
1685 // but only if it isn't already running - otherwise we
1686 // restart the timer.
1687 CTGitPath path;
1688 path.SetFromWin((LPCTSTR)lParam);
1690 // check whether the dropped file belongs to the very same repository
1691 CString projectDir;
1692 if (!path.HasAdminDir(&projectDir) || !CPathUtils::ArePathStringsEqual(g_Git.m_CurrentDir, projectDir))
1693 return 0;
1695 // just add all the items we get here.
1696 // if the item is versioned, the add will fail but nothing
1697 // more will happen.
1698 CString cmd;
1699 cmd.Format(L"git.exe add -- \"%s\"", (LPCTSTR)path.GetWinPathString());
1700 g_Git.Run(cmd, nullptr, CP_UTF8);
1702 if (!m_ListCtrl.HasPath(path))
1704 if (m_pathList.AreAllPathsFiles())
1706 m_pathList.AddPath(path);
1707 m_pathList.RemoveDuplicates();
1709 else
1711 // if the path list contains folders, we have to check whether
1712 // our just (maybe) added path is a child of one of those. If it is
1713 // a child of a folder already in the list, we must not add it. Otherwise
1714 // that path could show up twice in the list.
1715 bool bHasParentInList = false;
1716 for (int i=0; i<m_pathList.GetCount(); ++i)
1718 if (m_pathList[i].IsAncestorOf(path))
1720 bHasParentInList = true;
1721 break;
1724 if (!bHasParentInList)
1726 m_pathList.AddPath(path);
1727 m_pathList.RemoveDuplicates();
1731 m_ListCtrl.ResetChecked(path);
1733 // Always start the timer, since the status of an existing item might have changed
1734 SetTimer(REFRESHTIMER, 200, nullptr);
1735 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Item %s dropped, timer started\n", path.GetWinPath());
1736 return 0;
1739 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM lparam)
1741 m_cLogMessage.SetAutoCompletionList(std::move(*reinterpret_cast<std::map<CString, int>*>(lparam)), '*');
1742 return 0;
1745 //////////////////////////////////////////////////////////////////////////
1746 // functions which run in the status thread
1747 //////////////////////////////////////////////////////////////////////////
1749 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1751 CString strLine;
1754 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1755 while (m_bRunThread && file.ReadString(strLine))
1757 if (strLine.IsEmpty())
1758 continue;
1759 if (strLine[0] == L'#')
1760 continue;
1761 int eqpos = strLine.Find('=');
1762 CString rgx;
1763 rgx = strLine.Mid(eqpos+1).Trim();
1765 int pos = -1;
1766 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1768 mapRegex[strLine.Left(pos)] = rgx;
1769 strLine = strLine.Mid(pos+1).Trim();
1771 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1773 file.Close();
1775 catch (CFileException* pE)
1777 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException loading auto list regex file\n");
1778 pE->Delete();
1782 void CCommitDlg::ParseSnippetFile(const CString& sFile, std::map<CString, CString>& mapSnippet)
1784 CString strLine;
1787 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1788 while (m_bRunThread && file.ReadString(strLine))
1790 if (strLine.IsEmpty())
1791 continue;
1792 if (strLine[0] == L'#') // comment char
1793 continue;
1794 int eqpos = strLine.Find(L'=');
1795 if (eqpos <= 0)
1796 continue;
1797 CString key = strLine.Left(eqpos);
1798 auto rawvalue = strLine.GetBuffer() + eqpos + 1;
1799 CString value;
1800 bool isEscaped = false;
1801 for (int i = 0, len = strLine.GetLength() - eqpos - 1; i < len; ++i)
1803 wchar_t c = rawvalue[i];
1804 if (isEscaped)
1806 switch (c)
1808 case L't': c = L'\t'; break;
1809 case L'n': c = L'\n'; break;
1810 case L'r': c = L'\r'; break;
1811 case L'\\': c = L'\\'; break;
1812 default: value += rawvalue[i - 1]; break; // i is known to be > 0
1814 value += c;
1815 isEscaped = false;
1817 else if (c == L'\\')
1818 isEscaped = true;
1819 else
1820 value += c;
1822 mapSnippet[key] = value;
1824 file.Close();
1826 catch (CFileException* pE)
1828 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException loading auto list regex file\n");
1829 pE->Delete();
1833 void CCommitDlg::GetAutocompletionList(std::map<CString, int>& autolist)
1835 // the auto completion list is made of strings from each selected files.
1836 // the strings used are extracted from the files with regexes found
1837 // in the file "autolist.txt".
1838 // the format of that file is:
1839 // file extensions separated with commas '=' regular expression to use
1840 // example:
1841 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1842 // .cpp = (?<=[^\s]::)\b\w+\b
1844 std::map<CString, CString> mapRegex;
1845 CString sRegexFile = CPathUtils::GetAppDirectory();
1846 CRegDWORD regtimeout = CRegDWORD(L"Software\\TortoiseGit\\AutocompleteParseTimeout", 5);
1847 ULONGLONG timeoutvalue = ULONGLONG(DWORD(regtimeout)) * 1000UL;;
1848 sRegexFile += L"autolist.txt";
1849 if (!m_bRunThread)
1850 return;
1851 ParseRegexFile(sRegexFile, mapRegex);
1852 sRegexFile = CPathUtils::GetAppDataDirectory();
1853 sRegexFile += L"autolist.txt";
1854 if (PathFileExists(sRegexFile))
1855 ParseRegexFile(sRegexFile, mapRegex);
1857 m_snippet.clear();
1858 CString sSnippetFile = CPathUtils::GetAppDirectory();
1859 sSnippetFile += L"snippet.txt";
1860 ParseSnippetFile(sSnippetFile, m_snippet);
1861 sSnippetFile = CPathUtils::GetAppDataDirectory();
1862 sSnippetFile += L"snippet.txt";
1863 if (PathFileExists(sSnippetFile))
1864 ParseSnippetFile(sSnippetFile, m_snippet);
1865 for (const auto& snip : m_snippet)
1866 autolist.emplace(snip.first, AUTOCOMPLETE_SNIPPET);
1868 ULONGLONG starttime = GetTickCount64();
1870 // now we have two arrays of strings, where the first array contains all
1871 // file extensions we can use and the second the corresponding regex strings
1872 // to apply to those files.
1874 // the next step is to go over all files shown in the commit dialog
1875 // and scan them for strings we can use
1876 int nListItems = m_ListCtrl.GetItemCount();
1878 for (int i=0; i<nListItems && m_bRunThread; ++i)
1880 // stop parsing after timeout
1881 if ((!m_bRunThread) || (GetTickCount64() - starttime > timeoutvalue))
1882 return;
1884 CString sWinPath;
1885 CString sPartPath;
1886 CString sExt;
1887 int action;
1889 auto locker(m_ListCtrl.AcquireReadLock());
1890 auto path = m_ListCtrl.GetListEntry(i);
1892 if (!path)
1893 continue;
1895 sWinPath = path->GetWinPathString();
1896 sPartPath = path->GetGitPathString();
1897 sExt = path->GetFileExtension();
1898 action = path->m_Action;
1900 autolist.emplace(sPartPath, AUTOCOMPLETE_FILENAME);
1902 int pos = 0;
1903 int lastPos = 0;
1904 while ((pos = sPartPath.Find('/', pos)) >= 0)
1906 ++pos;
1907 lastPos = pos;
1908 autolist.emplace(sPartPath.Mid(pos), AUTOCOMPLETE_FILENAME);
1911 // Last inserted entry is a file name.
1912 // Some users prefer to also list file name without extension.
1913 if (CRegDWORD(L"Software\\TortoiseGit\\AutocompleteRemovesExtensions", FALSE))
1915 int dotPos = sPartPath.ReverseFind('.');
1916 if ((dotPos >= 0) && (dotPos > lastPos))
1917 autolist.emplace(sPartPath.Mid(lastPos, dotPos - lastPos), AUTOCOMPLETE_FILENAME);
1920 if (action == CTGitPath::LOGACTIONS_UNVER && !CRegDWORD(L"Software\\TortoiseGit\\AutocompleteParseUnversioned", FALSE))
1921 continue;
1922 if (action == CTGitPath::LOGACTIONS_IGNORE)
1923 continue;
1925 sExt.MakeLower();
1926 // find the regex string which corresponds to the file extension
1927 CString rdata = mapRegex[sExt];
1928 if (rdata.IsEmpty())
1929 continue;
1931 ScanFile(autolist, sWinPath, rdata, sExt);
1933 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Auto completion list loaded in %I64u msec\n", GetTickCount64() - starttime);
1936 void CCommitDlg::ScanFile(std::map<CString, int>& autolist, const CString& sFilePath, const CString& sRegex, const CString& sExt)
1938 static std::map<CString, std::wregex> regexmap;
1940 std::wstring sFileContent;
1941 CAutoFile hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
1942 if (hFile)
1944 DWORD size = GetFileSize(hFile, nullptr);
1945 if (size > CRegDWORD(L"Software\\TortoiseGit\\AutocompleteParseMaxSize", 300000L))
1947 // no files bigger than 300k
1948 return;
1950 // allocate memory to hold file contents
1951 CBuffer oFile;
1954 oFile.SetLength(size);
1956 catch (CMemoryException*)
1958 return;
1960 DWORD readbytes;
1961 if (!ReadFile(hFile, oFile, size, &readbytes, nullptr))
1962 return;
1963 oFile.SetLength(readbytes);
1964 CFileTextLines filetextlines;
1965 CFileTextLines::UnicodeType type = filetextlines.CheckUnicodeType(oFile, readbytes);
1968 CBaseFilter* pFilter = nullptr;
1969 switch (type)
1971 case CFileTextLines::BINARY:
1972 return;
1973 case CFileTextLines::UTF8:
1974 case CFileTextLines::UTF8BOM:
1975 pFilter = new CUtf8Filter(NULL);
1976 break;
1977 default:
1978 case CFileTextLines::ASCII:
1979 pFilter = new CAsciiFilter(NULL);
1980 break;
1981 case CFileTextLines::UTF16_BE:
1982 case CFileTextLines::UTF16_BEBOM:
1983 pFilter = new CUtf16beFilter(NULL);
1984 break;
1985 case CFileTextLines::UTF16_LE:
1986 case CFileTextLines::UTF16_LEBOM:
1987 pFilter = new CUtf16leFilter(NULL);
1988 break;
1989 case CFileTextLines::UTF32_BE:
1990 pFilter = new CUtf32beFilter(NULL);
1991 break;
1992 case CFileTextLines::UTF32_LE:
1993 pFilter = new CUtf32leFilter(NULL);
1994 break;
1996 pFilter->Decode(oFile);
1997 delete pFilter;
1999 catch (CMemoryException*)
2001 return;
2003 sFileContent = std::wstring((wchar_t*)oFile, oFile.GetLength() / sizeof(wchar_t));
2005 if (sFileContent.empty() || !m_bRunThread)
2006 return;
2010 std::wregex regCheck;
2011 std::map<CString, std::wregex>::const_iterator regIt;
2012 if ((regIt = regexmap.find(sExt)) != regexmap.end())
2013 regCheck = regIt->second;
2014 else
2016 regCheck = std::wregex(sRegex, std::regex_constants::icase | std::regex_constants::ECMAScript);
2017 regexmap[sExt] = regCheck;
2019 const std::wsregex_iterator end;
2020 for (std::wsregex_iterator it(sFileContent.cbegin(), sFileContent.cend(), regCheck); it != end; ++it)
2022 const std::wsmatch match = *it;
2023 for (size_t i = 1; i < match.size(); ++i)
2025 if (match[i].second-match[i].first)
2026 autolist.emplace(std::wstring(match[i]).c_str(), AUTOCOMPLETE_PROGRAMCODE);
2030 catch (std::exception&) {}
2033 // CSciEditContextMenuInterface
2034 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
2036 CString sMenuItemText;
2037 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITHASH);
2038 m_nPopupPickCommitHash = nCmd++;
2039 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPickCommitHash, sMenuItemText);
2041 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITMESSAGE);
2042 m_nPopupPickCommitMessage = nCmd++;
2043 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPickCommitMessage, sMenuItemText);
2045 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTEFILELIST);
2046 m_nPopupPasteListCmd = nCmd++;
2047 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
2049 ReloadHistoryEntries();
2050 if (!m_History.IsEmpty())
2052 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
2053 m_nPopupPasteLastMessage = nCmd++;
2054 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
2056 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
2057 m_nPopupRecentMessage = nCmd++;
2058 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
2062 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
2064 if (cmd == m_nPopupPickCommitHash)
2066 // use the git log to allow selection of a version
2067 CLogDlg dlg;
2068 // tell the dialog to use mode for selecting revisions
2069 dlg.SetSelect(true);
2070 // only one revision must be selected however
2071 dlg.SingleSelection(true);
2072 dlg.ShowWorkingTreeChanges(false);
2073 if (dlg.DoModal() == IDOK && !dlg.GetSelectedHash().empty())
2074 pSciEdit->InsertText(dlg.GetSelectedHash().at(0).ToString());
2075 return true;
2078 if (cmd == m_nPopupPickCommitMessage)
2080 // use the git log to allow selection of a version
2081 CLogDlg dlg;
2082 // tell the dialog to use mode for selecting revisions
2083 dlg.SetSelect(true);
2084 // only one revision must be selected however
2085 dlg.SingleSelection(true);
2086 dlg.ShowWorkingTreeChanges(false);
2087 if (dlg.DoModal() == IDOK && !dlg.GetSelectedHash().empty())
2089 GitRev rev;
2090 if (rev.GetCommit(dlg.GetSelectedHash().at(0).ToString()))
2092 MessageBox(rev.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2093 return false;
2095 CString message = rev.GetSubject() + L"\r\n" + rev.GetBody();
2096 pSciEdit->InsertText(message);
2098 return true;
2101 if (cmd == m_nPopupPasteListCmd)
2103 CString logmsg;
2104 auto locker(m_ListCtrl.AcquireReadLock());
2105 int nListItems = m_ListCtrl.GetItemCount();
2106 for (int i=0; i<nListItems; ++i)
2108 auto entry = m_ListCtrl.GetListEntry(i);
2109 if (entry&&entry->m_Checked)
2111 CString status = entry->GetActionName();
2112 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
2113 status = L"Add"; // I18N TODO
2115 //git_wc_status_kind status = entry->status;
2116 WORD langID = (WORD)CRegStdDWORD(L"Software\\TortoiseGit\\LanguageID", GetUserDefaultLangID());
2117 if (m_ProjectProperties.bFileListInEnglish)
2118 langID = 1033;
2120 logmsg.AppendFormat(L"%-10s %s\r\n", (LPCTSTR)status, (LPCTSTR)m_ListCtrl.GetItemText(i, 0));
2123 pSciEdit->InsertText(logmsg);
2124 return true;
2127 if(cmd == m_nPopupPasteLastMessage)
2129 if (m_History.IsEmpty())
2130 return false;
2132 CString logmsg;
2133 logmsg +=m_History.GetEntry(0);
2134 pSciEdit->InsertText(logmsg);
2135 return true;
2138 if(cmd == m_nPopupRecentMessage )
2140 OnBnClickedHistory();
2141 return true;
2143 return false;
2146 void CCommitDlg::HandleSnippet(int type, const CString &text, CSciEdit *pSciEdit)
2148 if (type == AUTOCOMPLETE_SNIPPET)
2150 CString target = m_snippet[text];
2151 pSciEdit->GetWordUnderCursor(true);
2152 pSciEdit->InsertText(target, false);
2156 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
2158 switch (nIDEvent)
2160 case ENDDIALOGTIMER:
2161 KillTimer(ENDDIALOGTIMER);
2162 EndDialog(0);
2163 break;
2164 case REFRESHTIMER:
2165 if (m_bThreadRunning)
2167 SetTimer(REFRESHTIMER, 200, nullptr);
2168 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Wait some more before refreshing\n");
2170 else
2172 KillTimer(REFRESHTIMER);
2173 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Refreshing after items dropped\n");
2174 Refresh();
2176 break;
2177 case FILLPATCHVTIMER:
2178 FillPatchView();
2179 break;
2181 __super::OnTimer(nIDEvent);
2184 void CCommitDlg::OnBnClickedHistory()
2186 m_tooltips.Pop(); // hide the tooltips
2187 if (m_pathList.IsEmpty())
2188 return;
2190 CHistoryDlg historyDlg;
2191 ReloadHistoryEntries();
2192 historyDlg.SetHistory(m_History);
2193 if (historyDlg.DoModal() != IDOK)
2194 return;
2196 CString sMsg = historyDlg.GetSelectedText();
2197 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
2199 CString sBugID = m_ProjectProperties.FindBugID(sMsg);
2200 if ((!sBugID.IsEmpty()) && ((GetDlgItem(IDC_BUGID)->IsWindowVisible())))
2201 SetDlgItemText(IDC_BUGID, sBugID);
2202 if (m_sLogTemplate.Compare(m_cLogMessage.GetText()) != 0)
2203 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
2204 else
2205 m_cLogMessage.SetText(sMsg);
2208 SendMessage(WM_UPDATEOKBUTTON);
2209 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2212 void CCommitDlg::OnBnClickedBugtraqbutton()
2214 m_tooltips.Pop(); // hide the tooltips
2215 CString sMsg = m_cLogMessage.GetText();
2217 if (!m_BugTraqProvider)
2218 return;
2220 ATL::CComBSTR parameters(m_bugtraq_association.GetParameters());
2221 ATL::CComBSTR commonRoot(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
2222 CBstrSafeVector pathList(m_pathList.GetCount());
2224 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
2225 pathList.PutElement(index, m_pathList[index].GetGitPathString());
2227 ATL::CComBSTR originalMessage(sMsg);
2228 ATL::CComBSTR temp;
2230 // first try the IBugTraqProvider2 interface
2231 CComPtr<IBugTraqProvider2> pProvider2;
2232 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
2233 bool bugIdOutSet = false;
2234 if (SUCCEEDED(hr))
2236 ATL::CComBSTR repositoryRoot(g_Git.m_CurrentDir);
2237 ATL::CComBSTR bugIDOut;
2238 GetDlgItemText(IDC_BUGID, m_sBugID);
2239 ATL::CComBSTR bugID(m_sBugID);
2240 CBstrSafeVector revPropNames;
2241 CBstrSafeVector revPropValues;
2242 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
2244 CString sErr;
2245 sErr.FormatMessage(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2246 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
2248 else
2250 if (bugIDOut)
2252 bugIdOutSet = true;
2253 m_sBugID = bugIDOut;
2254 SetDlgItemText(IDC_BUGID, m_sBugID);
2256 m_cLogMessage.SetText((LPCTSTR)temp);
2259 else
2261 // if IBugTraqProvider2 failed, try IBugTraqProvider
2262 CComPtr<IBugTraqProvider> pProvider;
2263 hr = m_BugTraqProvider.QueryInterface(&pProvider);
2264 if (FAILED(hr))
2266 CString sErr;
2267 sErr.FormatMessage(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2268 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
2269 return;
2272 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
2274 CString sErr;
2275 sErr.FormatMessage(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2276 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
2278 else
2279 m_cLogMessage.SetText((LPCTSTR)temp);
2281 m_sLogMessage = m_cLogMessage.GetText();
2282 if (!m_ProjectProperties.sMessage.IsEmpty())
2284 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
2285 if (!sBugID.IsEmpty() && !bugIdOutSet)
2286 SetDlgItemText(IDC_BUGID, sBugID);
2289 m_cLogMessage.SetFocus();
2292 void CCommitDlg::FillPatchView(bool onlySetTimer)
2294 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2296 KillTimer(FILLPATCHVTIMER);
2297 if (onlySetTimer)
2299 SetTimer(FILLPATCHVTIMER, 100, nullptr);
2300 return;
2303 auto locker(m_ListCtrl.AcquireReadWeakLock(50));
2304 if (!locker.IsAcquired())
2306 SetTimer(FILLPATCHVTIMER, 100, nullptr);
2307 return;
2309 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
2310 CString cmd,out;
2312 while(pos)
2314 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
2315 auto p = m_ListCtrl.GetListEntry(nSelect);
2316 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
2318 CString head = L"HEAD";
2319 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
2320 head = L"HEAD~1";
2321 cmd.Format(L"git.exe diff %s -- \"%s\"", (LPCTSTR)head, (LPCTSTR)p->GetGitPathString());
2322 g_Git.Run(cmd, &out, CP_UTF8);
2326 m_patchViewdlg.SetText(out);
2329 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
2331 this->FillPatchView(true);
2332 return 0;
2336 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
2338 SendMessage(WM_UPDATEOKBUTTON);
2339 return 0;
2342 LRESULT CCommitDlg::OnCheck(WPARAM wnd, LPARAM)
2344 HWND hwnd = (HWND)wnd;
2345 bool check = !(GetAsyncKeyState(VK_SHIFT) & 0x8000);
2346 if (hwnd == GetDlgItem(IDC_CHECKALL)->GetSafeHwnd())
2347 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, check);
2348 else if (hwnd == GetDlgItem(IDC_CHECKNONE)->GetSafeHwnd())
2349 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, !check);
2350 else if (hwnd == GetDlgItem(IDC_CHECKUNVERSIONED)->GetSafeHwnd())
2351 m_ListCtrl.Check(GITSLC_SHOWUNVERSIONED, check);
2352 else if (hwnd == GetDlgItem(IDC_CHECKVERSIONED)->GetSafeHwnd())
2353 m_ListCtrl.Check(GITSLC_SHOWVERSIONED, check);
2354 else if (hwnd == GetDlgItem(IDC_CHECKADDED)->GetSafeHwnd())
2355 m_ListCtrl.Check(GITSLC_SHOWADDED, check);
2356 else if (hwnd == GetDlgItem(IDC_CHECKDELETED)->GetSafeHwnd())
2357 m_ListCtrl.Check(GITSLC_SHOWREMOVED, check);
2358 else if (hwnd == GetDlgItem(IDC_CHECKMODIFIED)->GetSafeHwnd())
2359 m_ListCtrl.Check(GITSLC_SHOWMODIFIED, check);
2360 else if (hwnd == GetDlgItem(IDC_CHECKFILES)->GetSafeHwnd())
2361 m_ListCtrl.Check(GITSLC_SHOWFILES, check);
2362 else if (hwnd == GetDlgItem(IDC_CHECKSUBMODULES)->GetSafeHwnd())
2363 m_ListCtrl.Check(GITSLC_SHOWSUBMODULES, check);
2365 return 0;
2368 LRESULT CCommitDlg::OnUpdateOKButton(WPARAM, LPARAM)
2370 if (m_bBlock)
2371 return 0;
2373 CString text = m_cLogMessage.GetText().Trim();
2374 bool bValidLogSize = !text.IsEmpty() && text.GetLength() >= m_ProjectProperties.nMinLogSize;
2375 bool bAmendOrSelectFilesOrMerge = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit) || CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
2377 DialogEnableWindow(IDOK, bValidLogSize && (m_bCommitMessageOnly || bAmendOrSelectFilesOrMerge));
2379 return 0;
2382 LRESULT CCommitDlg::OnUpdateDataFalse(WPARAM, LPARAM)
2384 UpdateData(FALSE);
2385 return 0;
2388 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
2390 switch (message) {
2391 case WM_NOTIFY:
2392 if (wParam == IDC_SPLITTER)
2394 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2395 DoSize(pHdr->delta);
2397 break;
2398 case WM_COMMAND:
2399 if (m_hAccelOkButton && LOWORD(wParam) >= WM_USER && LOWORD(wParam) <= WM_USER + m_accellerators.size())
2401 for (const auto& entry : m_accellerators)
2403 if (entry.second.wmid != LOWORD(wParam))
2404 continue;
2405 if (entry.second.id == -1)
2406 m_ctrlOkButton.PostMessage(WM_KEYDOWN, VK_F4, NULL);
2407 else
2409 m_ctrlOkButton.SetCurrentEntry(entry.second.id);
2410 OnOK();
2412 return 0;
2415 break;
2418 return __super::DefWindowProc(message, wParam, lParam);
2421 void CCommitDlg::SetSplitterRange()
2423 if ((m_ListCtrl)&&(m_cLogMessage))
2425 CRect rcTop;
2426 m_cLogMessage.GetWindowRect(rcTop);
2427 ScreenToClient(rcTop);
2428 CRect rcMiddle;
2429 m_ListCtrl.GetWindowRect(rcMiddle);
2430 ScreenToClient(rcMiddle);
2431 if (rcMiddle.Height() && rcMiddle.Width())
2432 m_wndSplitter.SetRange(rcTop.top + CDPIAware::Instance().ScaleY(120), rcMiddle.bottom - CDPIAware::Instance().ScaleY(80));
2436 void CCommitDlg::DoSize(int delta)
2438 RemoveAnchor(IDC_MESSAGEGROUP);
2439 RemoveAnchor(IDC_LOGMESSAGE);
2440 RemoveAnchor(IDC_SPLITTER);
2441 RemoveAnchor(IDC_SIGNOFF);
2442 RemoveAnchor(IDC_COMMIT_AMEND);
2443 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
2444 RemoveAnchor(IDC_COMMIT_SETDATETIME);
2445 RemoveAnchor(IDC_COMMIT_DATEPICKER);
2446 RemoveAnchor(IDC_COMMIT_TIMEPICKER);
2447 RemoveAnchor(IDC_COMMIT_AS_COMMIT_DATE);
2448 RemoveAnchor(IDC_COMMIT_SETAUTHOR);
2449 RemoveAnchor(IDC_COMMIT_AUTHORDATA);
2450 RemoveAnchor(IDC_LISTGROUP);
2451 RemoveAnchor(IDC_FILELIST);
2452 RemoveAnchor(IDC_TEXT_INFO);
2453 RemoveAnchor(IDC_SELECTLABEL);
2454 RemoveAnchor(IDC_CHECKALL);
2455 RemoveAnchor(IDC_CHECKNONE);
2456 RemoveAnchor(IDC_CHECKUNVERSIONED);
2457 RemoveAnchor(IDC_CHECKVERSIONED);
2458 RemoveAnchor(IDC_CHECKADDED);
2459 RemoveAnchor(IDC_CHECKDELETED);
2460 RemoveAnchor(IDC_CHECKMODIFIED);
2461 RemoveAnchor(IDC_CHECKFILES);
2462 RemoveAnchor(IDC_CHECKSUBMODULES);
2464 auto hdwp = BeginDeferWindowPos(24);
2465 CSplitterControl::ChangeRect(hdwp, &m_cLogMessage, 0, 0, 0, delta);
2466 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_MESSAGEGROUP), 0, 0, 0, delta);
2467 CSplitterControl::ChangeRect(hdwp, &m_ListCtrl, 0, delta, 0, 0);
2468 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_LISTGROUP), 0, delta, 0, 0);
2469 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_SIGNOFF), 0, delta, 0, delta);
2470 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_AMEND), 0, delta, 0, delta);
2471 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_AMENDDIFF), 0, delta, 0, delta);
2472 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_SETDATETIME), 0, delta, 0, delta);
2473 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_DATEPICKER), 0, delta, 0, delta);
2474 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_TIMEPICKER), 0, delta, 0, delta);
2475 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_AS_COMMIT_DATE), 0, delta, 0, delta);
2476 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_SETAUTHOR), 0, delta, 0, delta);
2477 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_AUTHORDATA), 0, delta, 0, delta);
2478 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_TEXT_INFO), 0, delta, 0, delta);
2479 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_SELECTLABEL), 0, delta, 0, delta);
2480 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKALL), 0, delta, 0, delta);
2481 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKNONE), 0, delta, 0, delta);
2482 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKUNVERSIONED), 0, delta, 0, delta);
2483 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKVERSIONED), 0, delta, 0, delta);
2484 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKADDED), 0, delta, 0, delta);
2485 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKDELETED), 0, delta, 0, delta);
2486 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKMODIFIED), 0, delta, 0, delta);
2487 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKFILES), 0, delta, 0, delta);
2488 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKSUBMODULES), 0, delta, 0, delta);
2489 EndDeferWindowPos(hdwp);
2491 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
2492 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
2493 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
2494 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
2495 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
2496 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
2497 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
2498 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
2499 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
2500 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
2501 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
2502 AddAnchor(IDC_COMMIT_AS_COMMIT_DATE, TOP_LEFT);
2503 AddAnchor(IDC_COMMIT_SETAUTHOR, TOP_LEFT);
2504 AddAnchor(IDC_COMMIT_AUTHORDATA, TOP_LEFT, TOP_RIGHT);
2505 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
2506 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
2507 AddAnchor(IDC_CHECKALL, TOP_LEFT);
2508 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
2509 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
2510 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
2511 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
2512 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
2513 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
2514 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
2515 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
2516 ArrangeLayout();
2517 // adjust the minimum size of the dialog to prevent the resizing from
2518 // moving the list control too far down.
2519 CRect rcLogMsg;
2520 m_cLogMessage.GetClientRect(rcLogMsg);
2521 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
2523 SetSplitterRange();
2524 m_cLogMessage.Invalidate();
2525 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
2528 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
2530 // first, let the resizing take place
2531 __super::OnSize(nType, cx, cy);
2533 //set range
2534 SetSplitterRange();
2537 CString CCommitDlg::GetSignedOffByLine()
2539 CString str;
2541 CString username = g_Git.GetUserName();
2542 CString email = g_Git.GetUserEmail();
2543 username.Remove(L'\n');
2544 email.Remove(L'\n');
2546 str.Format(L"Signed-off-by: %s <%s>", (LPCTSTR)username, (LPCTSTR)email);
2548 return str;
2551 void CCommitDlg::OnBnClickedSignOff()
2553 CString str = GetSignedOffByLine();
2555 if (m_cLogMessage.GetText().Find(str) == -1) {
2556 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
2557 int lastNewline = m_cLogMessage.GetText().ReverseFind(L'\n');
2558 int foundByLine = -1;
2559 if (lastNewline > 0)
2560 foundByLine = m_cLogMessage.GetText().Find(L"-by: ", lastNewline);
2562 if (foundByLine == -1 || foundByLine < lastNewline)
2563 str = L"\r\n" + str;
2565 m_cLogMessage.SetText(m_cLogMessage.GetText() + L"\r\n" + str + L"\r\n");
2569 void CCommitDlg::OnBnClickedCommitAmend()
2571 this->UpdateData();
2572 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
2574 GitRev rev;
2575 if (rev.GetCommit(L"HEAD"))
2576 MessageBox(rev.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2577 m_AmendStr = rev.GetSubject() + L'\n' + rev.GetBody();
2580 if(this->m_bCommitAmend)
2582 this->m_NoAmendStr=this->m_cLogMessage.GetText();
2583 m_cLogMessage.SetText(m_AmendStr);
2584 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
2585 if (m_bSetCommitDateTime)
2586 m_AsCommitDateCtrl.ShowWindow(SW_SHOW);
2588 else
2590 this->m_AmendStr=this->m_cLogMessage.GetText();
2591 m_cLogMessage.SetText(m_NoAmendStr);
2592 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
2593 m_AsCommitDateCtrl.ShowWindow(SW_HIDE);
2594 m_AsCommitDateCtrl.SetCheck(FALSE);
2595 OnBnClickedCommitAsCommitDate();
2598 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2599 OnBnClickedCommitSetauthor(); // to update the commit author
2601 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2602 Refresh();
2605 void CCommitDlg::OnBnClickedCommitMessageOnly()
2607 this->UpdateData();
2608 this->m_ListCtrl.EnableWindow(m_bCommitMessageOnly ? FALSE : TRUE);
2609 SendMessage(WM_UPDATEOKBUTTON);
2612 void CCommitDlg::OnBnClickedWholeProject()
2614 m_tooltips.Pop(); // hide the tooltips
2615 UpdateData();
2616 m_ListCtrl.Clear();
2617 if (!m_bBlock)
2619 if (m_bWholeProject || m_bWholeProject2)
2620 m_ListCtrl.GetStatus(nullptr, true, false, true);
2621 else
2622 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
2624 m_regShowWholeProject = m_bWholeProject;
2626 DWORD dwShow = m_ListCtrl.GetShowFlags();
2627 if (DWORD(m_regAddBeforeCommit))
2628 dwShow |= GITSLC_SHOWUNVERSIONED;
2629 else
2630 dwShow &= ~GITSLC_SHOWUNVERSIONED;
2632 m_ListCtrl.StoreScrollPos();
2633 m_ListCtrl.Show(dwShow, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
2634 UpdateCheckLinks();
2637 SetDlgTitle();
2640 void CCommitDlg::OnFocusMessage()
2642 m_cLogMessage.SetFocus();
2645 void CCommitDlg::OnFocusFileList()
2647 m_ListCtrl.SetFocus();
2650 void CCommitDlg::OnScnUpdateUI(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2652 auto pos = (Sci_Position)m_cLogMessage.Call(SCI_GETCURRENTPOS);
2653 auto line = (int)m_cLogMessage.Call(SCI_LINEFROMPOSITION, pos);
2654 auto column = (int)m_cLogMessage.Call(SCI_GETCOLUMN, pos);
2656 CString str;
2657 str.Format(L"%d/%d", line + 1, column + 1);
2658 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
2660 if(*pResult)
2661 *pResult=0;
2664 void CCommitDlg::TogglePatchView()
2666 OnStnClickedViewPatch();
2669 void CCommitDlg::OnStnClickedViewPatch()
2671 m_patchViewdlg.m_ParentDlg = this;
2672 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
2674 BOOL viewPatchEnabled = FALSE;
2675 viewPatchEnabled = g_Git.GetConfigValueBool(L"tgit.commitshowpatch");
2676 if (viewPatchEnabled == FALSE)
2677 g_Git.SetConfigValue(L"tgit.commitshowpatch", L"true");
2678 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
2679 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2680 CRect rect;
2681 this->GetWindowRect(&rect);
2683 m_patchViewdlg.ShowWindow(SW_SHOW);
2685 m_patchViewdlg.SetWindowPos(nullptr, rect.right, rect.top, (DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\TortoiseProc\\PatchDlgWidth", rect.Width()), rect.Height(),
2686 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
2688 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2690 ShowViewPatchText(false);
2691 FillPatchView();
2693 else
2695 g_Git.SetConfigValue(L"tgit.commitshowpatch", L"false");
2696 m_patchViewdlg.ShowWindow(SW_HIDE);
2697 m_patchViewdlg.DestroyWindow();
2698 ShowViewPatchText(true);
2700 this->m_ctrlShowPatch.Invalidate();
2703 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
2705 __super::OnMoving(fwSide, pRect);
2707 if (::IsWindow(m_patchViewdlg.m_hWnd))
2709 RECT patchrect;
2710 m_patchViewdlg.GetWindowRect(&patchrect);
2711 if (::IsWindow(m_hWnd))
2713 RECT thisrect;
2714 GetWindowRect(&thisrect);
2715 if (patchrect.left == thisrect.right)
2717 m_patchViewdlg.SetWindowPos(nullptr, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2718 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2724 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2726 __super::OnSizing(fwSide, pRect);
2728 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2730 CRect thisrect, patchrect;
2731 this->GetWindowRect(thisrect);
2732 this->m_patchViewdlg.GetWindowRect(patchrect);
2733 if(thisrect.right==patchrect.left)
2735 patchrect.left -= (thisrect.right - pRect->right);
2736 patchrect.right-= (thisrect.right - pRect->right);
2738 if( patchrect.bottom == thisrect.bottom)
2739 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2740 if( patchrect.top == thisrect.top)
2741 patchrect.top -= thisrect.top-pRect->top;
2742 m_patchViewdlg.MoveWindow(patchrect);
2747 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2749 *pResult = 0;
2750 TRACE("Item Changed\r\n");
2753 int CCommitDlg::CheckHeadDetach()
2755 CString output;
2756 if (CGit::GetCurrentBranchFromFile(g_Git.m_CurrentDir, output))
2758 int retval = CMessageBox::Show(GetSafeHwnd(), IDS_PROC_COMMIT_DETACHEDWARNING, IDS_APPNAME, MB_YESNOCANCEL | MB_ICONWARNING);
2759 if(retval == IDYES)
2761 if (CAppUtils::CreateBranchTag(GetSafeHwnd(), FALSE, nullptr, true) == FALSE)
2762 return 1;
2764 else if (retval == IDCANCEL)
2765 return 1;
2767 return 0;
2770 void CCommitDlg::OnBnClickedCommitAmenddiff()
2772 UpdateData();
2773 Refresh();
2776 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2778 UpdateData();
2779 Refresh();
2782 void CCommitDlg::OnBnClickedCommitSetDateTime()
2784 UpdateData();
2786 if (m_bSetCommitDateTime)
2788 CTime authordate = CTime::GetCurrentTime();
2789 if (m_bCommitAmend)
2791 GitRev headRevision;
2792 if (headRevision.GetCommit(L"HEAD"))
2793 MessageBox(headRevision.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2794 authordate = headRevision.GetAuthorDate();
2795 m_AsCommitDateCtrl.ShowWindow(SW_SHOW);
2798 m_CommitDate.SetTime(&authordate);
2799 m_CommitTime.SetTime(&authordate);
2801 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
2802 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
2804 else
2806 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_HIDE);
2807 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_HIDE);
2808 m_AsCommitDateCtrl.ShowWindow(SW_HIDE);
2809 m_AsCommitDateCtrl.SetCheck(FALSE);
2810 OnBnClickedCommitAsCommitDate();
2814 void CCommitDlg::OnBnClickedCommitAsCommitDate()
2816 GetDlgItem(IDC_COMMIT_DATEPICKER)->EnableWindow(!m_AsCommitDateCtrl.GetCheck());
2817 GetDlgItem(IDC_COMMIT_TIMEPICKER)->EnableWindow(!m_AsCommitDateCtrl.GetCheck());
2820 void CCommitDlg::OnBnClickedCheckNewBranch()
2822 UpdateData();
2823 if (m_bCreateNewBranch)
2825 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_HIDE);
2826 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_SHOW);
2828 else
2830 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
2831 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);
2835 bool CCommitDlg::RestoreFiles(bool doNotAsk, bool allowCancel)
2837 if (m_ListCtrl.m_restorepaths.empty())
2838 return true;
2840 if (!doNotAsk)
2842 auto ret = CMessageBox::Show(m_hWnd, IDS_PROC_COMMIT_RESTOREFILES, IDS_APPNAME, 2, IDI_QUESTION, IDS_PROC_COMMIT_RESTOREFILES_RESTORE, IDS_PROC_COMMIT_RESTOREFILES_KEEP, allowCancel ? IDS_MSGBOX_CANCEL : 0);
2843 if (ret == 3)
2844 return false;
2845 if (ret == 2)
2846 return true;
2849 for (const auto& item : m_ListCtrl.m_restorepaths)
2851 CString dest = g_Git.CombinePath(item.first);
2852 CopyFile(item.second, dest, FALSE);
2853 CPathUtils::Touch(dest);
2855 m_ListCtrl.m_restorepaths.clear();
2857 return true;
2860 void CCommitDlg::UpdateCheckLinks()
2862 DialogEnableWindow(IDC_CHECKALL, true);
2863 DialogEnableWindow(IDC_CHECKNONE, true);
2864 DialogEnableWindow(IDC_CHECKUNVERSIONED, m_ListCtrl.GetUnversionedCount() > 0);
2865 DialogEnableWindow(IDC_CHECKVERSIONED, m_ListCtrl.GetItemCount() > m_ListCtrl.GetUnversionedCount());
2866 DialogEnableWindow(IDC_CHECKADDED, m_ListCtrl.GetAddedCount() > 0);
2867 DialogEnableWindow(IDC_CHECKDELETED, m_ListCtrl.GetDeletedCount() > 0);
2868 DialogEnableWindow(IDC_CHECKMODIFIED, m_ListCtrl.GetModifiedCount() > 0);
2869 DialogEnableWindow(IDC_CHECKFILES, m_ListCtrl.GetFileCount() > 0);
2870 DialogEnableWindow(IDC_CHECKSUBMODULES, m_ListCtrl.GetSubmoduleCount() > 0);
2873 void CCommitDlg::OnBnClickedCommitSetauthor()
2875 UpdateData();
2877 if (m_bSetAuthor)
2879 m_sAuthor.Format(L"%s <%s>", (LPCTSTR)g_Git.GetUserName(), (LPCTSTR)g_Git.GetUserEmail());
2880 if (m_bCommitAmend)
2882 GitRev headRevision;
2883 if (headRevision.GetCommit(L"HEAD"))
2884 MessageBox(headRevision.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2885 m_sAuthor.Format(L"%s <%s>", (LPCTSTR)headRevision.GetAuthorName(), (LPCTSTR)headRevision.GetAuthorEmail());
2888 UpdateData(FALSE);
2890 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_SHOW);
2892 else
2893 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_HIDE);
2896 bool CCommitDlg::RunStartCommitHook()
2898 DWORD exitcode = 0xFFFFFFFF;
2899 CString error;
2900 CHooks::Instance().SetProjectProperties(g_Git.m_CurrentDir, m_ProjectProperties);
2901 if (CHooks::Instance().StartCommit(GetSafeHwnd(), g_Git.m_CurrentDir, m_pathList, m_sLogMessage, exitcode, error))
2903 if (exitcode)
2905 CString temp;
2906 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2907 MessageBox(temp, L"TortoiseGit", MB_ICONERROR);
2908 return false;
2911 return true;
2914 void CCommitDlg::OnSysColorChange()
2916 __super::OnSysColorChange();
2917 m_cLogMessage.SetColors(true);
2918 m_cLogMessage.SetFont(CAppUtils::GetLogFontName(), CAppUtils::GetLogFontSize());