Fix possible deadlock
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob832448a2f770cbf306668b33face4fc895498fd9
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"
43 #ifdef _DEBUG
44 #define new DEBUG_NEW
45 #undef THIS_FILE
46 static char THIS_FILE[] = __FILE__;
47 #endif
49 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(L"TORTOISEGIT_AUTOLISTREADY_MSG");
50 UINT CCommitDlg::WM_UPDATEOKBUTTON = RegisterWindowMessage(L"TORTOISEGIT_COMMIT_UPDATEOKBUTTON");
51 UINT CCommitDlg::WM_UPDATEDATAFALSE = RegisterWindowMessage(L"TORTOISEGIT_COMMIT_UPDATEDATAFALSE");
53 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)
54 CCommitDlg::CCommitDlg(CWnd* pParent /*=nullptr*/)
55 : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)
56 , m_bShowUnversioned(FALSE)
57 , m_bBlock(FALSE)
58 , m_bThreadRunning(FALSE)
59 , m_bRunThread(FALSE)
60 , m_pThread(nullptr)
61 , m_bWholeProject(FALSE)
62 , m_bWholeProject2(FALSE)
63 , m_bKeepChangeList(TRUE)
64 , m_bDoNotAutoselectSubmodules(FALSE)
65 , m_itemsCount(0)
66 , m_bSelectFilesForCommit(TRUE)
67 , m_bNoPostActions(FALSE)
68 , m_bAutoClose(false)
69 , m_bSetCommitDateTime(FALSE)
70 , m_bCreateNewBranch(FALSE)
71 , m_bForceCommitAmend(false)
72 , m_bCommitMessageOnly(FALSE)
73 , m_bSetAuthor(FALSE)
74 , m_bCancelled(false)
75 , m_PostCmd(GIT_POSTCOMMIT_CMD_NOTHING)
76 , m_bAmendDiffToLastCommit(FALSE)
77 , m_nPopupPasteListCmd(0)
78 , m_nPopupPasteLastMessage(0)
79 , m_nPopupRecentMessage(0)
80 , m_nPopupPickCommitHash(0)
81 , m_nPopupPickCommitMessage(0)
82 , m_hAccel(nullptr)
83 , m_bWarnDetachedHead(true)
84 , m_hAccelOkButton(nullptr)
85 , m_bDoNotStoreLastSelectedLine(true)
86 , m_bCommitAmend(FALSE)
90 CCommitDlg::~CCommitDlg()
92 if (m_hAccelOkButton)
93 DestroyAcceleratorTable(m_hAccelOkButton);
94 delete m_pThread;
97 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
99 CResizableStandAloneDialog::DoDataExchange(pDX);
100 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
101 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
102 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
103 DDX_Check(pDX, IDC_COMMIT_SETDATETIME, m_bSetCommitDateTime);
104 DDX_Check(pDX, IDC_CHECK_NEWBRANCH, m_bCreateNewBranch);
105 DDX_Text(pDX, IDC_NEWBRANCH, m_sCreateNewBranch);
106 DDX_Text(pDX, IDC_BUGID, m_sBugID);
107 DDX_Text(pDX, IDC_COMMIT_AUTHORDATA, m_sAuthor);
108 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
109 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
110 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
111 DDX_Check(pDX, IDC_NOAUTOSELECTSUBMODULES, m_bDoNotAutoselectSubmodules);
112 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
113 DDX_Check(pDX, IDC_COMMIT_MESSAGEONLY, m_bCommitMessageOnly);
114 DDX_Check(pDX,IDC_COMMIT_AMENDDIFF,m_bAmendDiffToLastCommit);
115 DDX_Check(pDX, IDC_COMMIT_SETAUTHOR, m_bSetAuthor);
116 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
117 DDX_Control(pDX, IDC_COMMIT_DATEPICKER, m_CommitDate);
118 DDX_Control(pDX, IDC_COMMIT_TIMEPICKER, m_CommitTime);
119 DDX_Control(pDX, IDC_COMMIT_AS_COMMIT_DATE, m_AsCommitDateCtrl);
120 DDX_Control(pDX, IDC_CHECKALL, m_CheckAll);
121 DDX_Control(pDX, IDC_CHECKNONE, m_CheckNone);
122 DDX_Control(pDX, IDC_CHECKUNVERSIONED, m_CheckUnversioned);
123 DDX_Control(pDX, IDC_CHECKVERSIONED, m_CheckVersioned);
124 DDX_Control(pDX, IDC_CHECKADDED, m_CheckAdded);
125 DDX_Control(pDX, IDC_CHECKDELETED, m_CheckDeleted);
126 DDX_Control(pDX, IDC_CHECKMODIFIED, m_CheckModified);
127 DDX_Control(pDX, IDC_CHECKFILES, m_CheckFiles);
128 DDX_Control(pDX, IDC_CHECKSUBMODULES, m_CheckSubmodules);
129 DDX_Control(pDX, IDOK, m_ctrlOkButton);
132 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
133 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
134 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
135 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
136 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
137 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
138 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
139 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
140 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE, OnFileDropped)
141 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
142 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
144 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED, &CCommitDlg::OnCheck)
145 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
146 ON_REGISTERED_MESSAGE(WM_UPDATEOKBUTTON, OnUpdateOKButton)
147 ON_REGISTERED_MESSAGE(WM_UPDATEDATAFALSE, OnUpdateDataFalse)
148 ON_WM_TIMER()
149 ON_WM_SIZE()
150 ON_WM_SYSCOLORCHANGE()
151 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
152 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
153 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
154 ON_BN_CLICKED(IDC_COMMIT_MESSAGEONLY, &CCommitDlg::OnBnClickedCommitMessageOnly)
155 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
156 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
157 ON_COMMAND(ID_FOCUS_FILELIST, OnFocusFileList)
158 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
159 ON_WM_MOVE()
160 ON_WM_MOVING()
161 ON_WM_SIZING()
162 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
163 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF, &CCommitDlg::OnBnClickedCommitAmenddiff)
164 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES, &CCommitDlg::OnBnClickedNoautoselectsubmodules)
165 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME, &CCommitDlg::OnBnClickedCommitSetDateTime)
166 ON_BN_CLICKED(IDC_COMMIT_AS_COMMIT_DATE, &CCommitDlg::OnBnClickedCommitAsCommitDate)
167 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH, &CCommitDlg::OnBnClickedCheckNewBranch)
168 ON_BN_CLICKED(IDC_COMMIT_SETAUTHOR, &CCommitDlg::OnBnClickedCommitSetauthor)
169 END_MESSAGE_MAP()
171 int GetCommitTemplate(CString &msg)
173 CString tplFilename = g_Git.GetConfigValue(L"commit.template");
174 if (tplFilename.IsEmpty())
175 return -1;
177 if (tplFilename[0] == L'/')
179 if (tplFilename.GetLength() >= 3)
181 // handle "/d/TortoiseGit/tpl.txt" -> "d:/TortoiseGit/tpl.txt"
182 if (tplFilename[2] == L'/')
184 LPWSTR buf = tplFilename.GetBuffer();
185 buf[0] = buf[1];
186 buf[1] = L':';
187 tplFilename.ReleaseBuffer();
192 tplFilename.Replace(L'/', L'\\');
194 if (!CGit::LoadTextFile(tplFilename, msg))
195 return -1;
196 return 0;
199 BOOL CCommitDlg::OnInitDialog()
201 CResizableStandAloneDialog::OnInitDialog();
202 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
204 if (m_sLogMessage.IsEmpty())
206 if (!m_bForceCommitAmend)
207 GetCommitTemplate(m_sLogMessage);
209 CString dotGitPath;
210 GitAdminDir::GetWorktreeAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
211 CGit::LoadTextFile(dotGitPath + L"SQUASH_MSG", m_sLogMessage);
212 CGit::LoadTextFile(dotGitPath + L"MERGE_MSG", m_sLogMessage);
214 if (!RunStartCommitHook())
216 EndDialog(IDCANCEL);
217 return FALSE;
220 m_regAddBeforeCommit = CRegDWORD(L"Software\\TortoiseGit\\AddBeforeCommit", TRUE);
221 m_bShowUnversioned = m_regAddBeforeCommit;
223 CString regPath(g_Git.m_CurrentDir);
224 regPath.Replace(L':', L'_');
225 m_regShowWholeProject = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\ShowWholeProject\\" + regPath, FALSE);
226 m_bWholeProject = m_regShowWholeProject;
228 m_History.SetMaxHistoryItems((LONG)CRegDWORD(L"Software\\TortoiseGit\\MaxHistoryItems", 25));
230 m_regKeepChangelists = CRegDWORD(L"Software\\TortoiseGit\\KeepChangeLists", FALSE);
231 m_bKeepChangeList = m_regKeepChangelists;
233 m_regDoNotAutoselectSubmodules = CRegDWORD(L"Software\\TortoiseGit\\DoNotAutoselectSubmodules", FALSE);
234 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
236 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
238 if (m_pathList.IsEmpty())
239 m_bWholeProject2 = true;
241 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
242 m_bWholeProject2 = true;
244 SetDlgTitle();
246 if (m_bSetAuthor)
247 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_SHOW);
249 if (m_bSetCommitDateTime)
251 m_CommitDate.SetTime(&m_wantCommitTime);
252 m_CommitTime.SetTime(&m_wantCommitTime);
253 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
254 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
257 UpdateData(FALSE);
259 m_ListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD | GITSLC_COLDEL, L"CommitDlg", (GITSLC_POPALL ^ (GITSLC_POPCOMMIT | GITSLC_POPSAVEAS | GITSLC_PREPAREDIFF)), true, true);
260 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
261 m_ListCtrl.SetCancelBool(&m_bCancelled);
262 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
263 m_ListCtrl.EnableFileDrop();
264 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
266 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
267 m_ProjectProperties.ReadProps();
269 m_cLogMessage.Init(m_ProjectProperties);
270 m_cLogMessage.SetFont(CAppUtils::GetLogFontName(), CAppUtils::GetLogFontSize());
271 m_cLogMessage.RegisterContextMenuHandler(this);
272 std::map<int, UINT> icons;
273 icons[AUTOCOMPLETE_SPELLING] = IDI_SPELL;
274 icons[AUTOCOMPLETE_FILENAME] = IDI_FILE;
275 icons[AUTOCOMPLETE_PROGRAMCODE] = IDI_CODE;
276 icons[AUTOCOMPLETE_SNIPPET] = IDI_SNIPPET;
277 m_cLogMessage.SetIcon(icons);
279 OnEnChangeLogmessage();
281 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
282 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
283 m_tooltips.AddTool(IDC_MERGEACTIVE, IDC_MERGEACTIVE_TT);
284 m_tooltips.AddTool(IDC_COMMIT_MESSAGEONLY, IDS_COMMIT_MESSAGEONLY_TT);
285 m_tooltips.AddTool(IDC_COMMIT_AS_COMMIT_DATE, IDS_COMMIT_AS_COMMIT_DATE_TT);
287 CBugTraqAssociations bugtraq_associations;
288 bugtraq_associations.Load(m_ProjectProperties.GetProviderUUID(), m_ProjectProperties.sProviderParams);
290 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
292 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
293 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
295 CComPtr<IBugTraqProvider> pProvider;
296 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
297 if (SUCCEEDED(hr))
299 m_BugTraqProvider = pProvider;
300 ATL::CComBSTR temp;
301 ATL::CComBSTR parameters(m_bugtraq_association.GetParameters());
302 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), parameters, &temp)))
304 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
305 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
306 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
310 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
312 else if (!m_ProjectProperties.sMessage.IsEmpty())
314 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
315 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
316 if (!m_ProjectProperties.sLabel.IsEmpty())
317 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
318 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
319 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
320 GetDlgItem(IDC_BUGID)->SetFocus();
321 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
322 if (!sBugID.IsEmpty())
324 SetDlgItemText(IDC_BUGID, sBugID);
327 else
329 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
330 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
331 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
332 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
333 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
336 if (!m_sLogMessage.IsEmpty())
338 m_cLogMessage.SetText(m_sLogMessage);
339 m_cLogMessage.Call(SCI_SETCURRENTPOS, 0);
340 m_cLogMessage.Call(SCI_SETSEL, 0, 0);
343 GetWindowText(m_sWindowTitle);
345 AdjustControlSize(IDC_SHOWUNVERSIONED);
346 AdjustControlSize(IDC_WHOLE_PROJECT);
347 AdjustControlSize(IDC_CHECK_NEWBRANCH);
348 AdjustControlSize(IDC_COMMIT_AMEND);
349 AdjustControlSize(IDC_COMMIT_MESSAGEONLY);
350 AdjustControlSize(IDC_COMMIT_AMENDDIFF);
351 AdjustControlSize(IDC_COMMIT_SETDATETIME);
352 AdjustControlSize(IDC_COMMIT_SETAUTHOR);
353 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES);
354 AdjustControlSize(IDC_KEEPLISTS);
355 AdjustControlSize(IDC_COMMIT_AS_COMMIT_DATE);
357 // line up all controls and adjust their sizes.
358 #define LINKSPACING 9
359 RECT rc = AdjustControlSize(IDC_SELECTLABEL);
360 rc.right -= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
361 rc = AdjustStaticSize(IDC_CHECKALL, rc, LINKSPACING);
362 rc = AdjustStaticSize(IDC_CHECKNONE, rc, LINKSPACING);
363 rc = AdjustStaticSize(IDC_CHECKUNVERSIONED, rc, LINKSPACING);
364 rc = AdjustStaticSize(IDC_CHECKVERSIONED, rc, LINKSPACING);
365 rc = AdjustStaticSize(IDC_CHECKADDED, rc, LINKSPACING);
366 rc = AdjustStaticSize(IDC_CHECKDELETED, rc, LINKSPACING);
367 rc = AdjustStaticSize(IDC_CHECKMODIFIED, rc, LINKSPACING);
368 rc = AdjustStaticSize(IDC_CHECKFILES, rc, LINKSPACING);
369 rc = AdjustStaticSize(IDC_CHECKSUBMODULES, rc, LINKSPACING);
371 GetClientRect(m_DlgOrigRect);
372 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
374 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
375 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
376 AddAnchor(IDC_BUGID, TOP_RIGHT);
377 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
378 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
379 AddAnchor(IDC_CHECK_NEWBRANCH, TOP_RIGHT);
380 AddAnchor(IDC_NEWBRANCH, TOP_LEFT, TOP_RIGHT);
381 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
382 // AddAnchor(IDC_HISTORY, TOP_LEFT);
383 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
384 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
385 AddAnchor(IDC_VIEW_PATCH, BOTTOM_RIGHT);
386 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
387 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
388 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
389 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
390 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
391 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
392 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
393 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
394 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
395 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
396 AddAnchor(IDOK, BOTTOM_RIGHT);
397 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
398 AddAnchor(IDHELP, BOTTOM_RIGHT);
399 AddAnchor(IDC_MERGEACTIVE, BOTTOM_RIGHT);
400 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
401 AddAnchor(IDC_COMMIT_MESSAGEONLY, BOTTOM_LEFT);
402 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
403 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
404 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
405 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
406 AddAnchor(IDC_COMMIT_AS_COMMIT_DATE, TOP_LEFT);
407 AddAnchor(IDC_COMMIT_SETAUTHOR, TOP_LEFT);
408 AddAnchor(IDC_COMMIT_AUTHORDATA, TOP_LEFT, TOP_RIGHT);
410 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
411 AddAnchor(IDC_CHECKALL, TOP_LEFT);
412 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
413 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
414 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
415 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
416 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
417 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
418 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
419 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
421 if (hWndExplorer)
422 CenterWindow(CWnd::FromHandle(hWndExplorer));
423 EnableSaveRestore(L"CommitDlg");
424 DWORD yPos = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer");
425 RECT rcDlg, rcLogMsg, rcFileList;
426 GetClientRect(&rcDlg);
427 m_cLogMessage.GetWindowRect(&rcLogMsg);
428 ScreenToClient(&rcLogMsg);
429 m_ListCtrl.GetWindowRect(&rcFileList);
430 ScreenToClient(&rcFileList);
431 if (yPos)
433 RECT rectSplitter;
434 m_wndSplitter.GetWindowRect(&rectSplitter);
435 ScreenToClient(&rectSplitter);
436 int delta = yPos - rectSplitter.top;
437 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
439 m_wndSplitter.SetWindowPos(nullptr, rectSplitter.left, yPos, 0, 0, SWP_NOSIZE);
440 DoSize(delta);
441 Invalidate();
445 SetSplitterRange();
447 if (m_bForceCommitAmend || m_bCommitAmend)
448 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
450 // add all directories to the watcher
452 for (int i=0; i<m_pathList.GetCount(); ++i)
454 if (m_pathList[i].IsDirectory())
455 m_pathwatcher.AddPath(m_pathList[i]);
458 m_updatedPathList = m_pathList;
460 StartStatusThread();
461 CRegDWORD err = CRegDWORD(L"Software\\TortoiseGit\\ErrorOccurred", FALSE);
462 CRegDWORD historyhint = CRegDWORD(L"Software\\TortoiseGit\\HistoryHintShown", FALSE);
463 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
465 historyhint = TRUE;
466 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
468 err = FALSE;
470 this->m_ctrlShowPatch.SetURL(CString());
472 if (g_Git.GetConfigValueBool(L"tgit.commitshowpatch"))
473 OnStnClickedViewPatch();
475 if (CTGitPath(g_Git.m_CurrentDir).IsMergeActive())
477 DialogEnableWindow(IDC_CHECK_NEWBRANCH, FALSE);
478 m_bCreateNewBranch = FALSE;
479 GetDlgItem(IDC_MERGEACTIVE)->ShowWindow(SW_SHOW);
480 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_COMMIT_MERGE_HINT, IDS_APPNAME, MB_ICONINFORMATION, L"CommitMergeHint", IDS_MSGBOX_DONOTSHOWAGAIN);
483 PrepareOkButton();
485 return FALSE; // return TRUE unless you set the focus to a control
486 // EXCEPTION: OCX Property Pages should return FALSE
489 void CCommitDlg::PrepareOkButton()
491 if (m_bNoPostActions)
492 return;
493 m_regLastAction = CRegDWORD(L"Software\\TortoiseGit\\CommitLastAction", 0);
494 int i = 0;
495 for (auto labelId : { IDS_COMMIT_COMMIT, IDS_COMMIT_RECOMMIT, IDS_COMMIT_COMMITPUSH })
497 ++i;
498 CString label;
499 label.LoadString(labelId);
500 m_ctrlOkButton.AddEntry(label);
501 TCHAR accellerator = CStringUtils::GetAccellerator(label);
502 if (accellerator == L'\0')
503 continue;
504 ++m_accellerators[accellerator].cnt;
505 if (m_accellerators[accellerator].cnt > 1)
506 m_accellerators[accellerator].id = -1;
507 else
508 m_accellerators[accellerator].id = i - 1;
510 m_ctrlOkButton.SetCurrentEntry(m_regLastAction);
511 if (m_accellerators.size())
513 LPACCEL lpaccelNew = (LPACCEL)LocalAlloc(LPTR, m_accellerators.size() * sizeof(ACCEL));
514 if (!lpaccelNew)
515 return;
516 SCOPE_EXIT{ LocalFree(lpaccelNew); };
517 i = 0;
518 for (auto& entry : m_accellerators)
520 lpaccelNew[i].cmd = (WORD)(WM_USER + 1 + entry.second.id);
521 lpaccelNew[i].fVirt = FVIRTKEY | FALT;
522 lpaccelNew[i].key = entry.first;
523 entry.second.wmid = lpaccelNew[i].cmd;
524 ++i;
526 m_hAccelOkButton = CreateAcceleratorTable(lpaccelNew, (int)m_accellerators.size());
530 static bool UpdateIndex(CMassiveGitTask &mgt, CSysProgressDlg &sysProgressDlg, int progress, int maxProgress)
532 if (mgt.IsListEmpty())
533 return true;
535 if (sysProgressDlg.HasUserCancelled())
536 return false;
538 if (sysProgressDlg.IsVisible())
540 sysProgressDlg.SetTitle(IDS_APPNAME);
541 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
542 sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
543 sysProgressDlg.SetProgress(progress, maxProgress);
544 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing
547 BOOL cancel = FALSE;
548 return mgt.Execute(cancel);
551 static void DoPush()
553 CString head;
554 if (g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir, head))
555 return;
556 CString remote, remotebranch;
557 g_Git.GetRemotePushBranch(head, remote, remotebranch);
558 if (remote.IsEmpty() || remotebranch.IsEmpty())
560 CAppUtils::Push();
561 return;
564 CAppUtils::DoPush(CAppUtils::IsSSHPutty(), false, false, false, false, false, false, head, remote, remotebranch, false, 0);
567 void CCommitDlg::OnOK()
569 if (m_bBlock)
570 return;
571 if (m_bThreadRunning)
573 m_bCancelled = true;
574 StopStatusThread();
576 this->UpdateData();
578 auto locker(m_ListCtrl.AcquireReadLock());
580 if (m_ListCtrl.GetConflictedCount() != 0 && CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROGRS_CONFLICTSOCCURRED, IDS_APPNAME, 1, IDI_EXCLAMATION, IDS_OKBUTTON, IDS_IGNOREBUTTON, 0, L"CommitWarnOnUnresolved") == 1)
582 auto pos = m_ListCtrl.GetFirstSelectedItemPosition();
583 while (pos)
584 m_ListCtrl.SetItemState(m_ListCtrl.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
585 int nListItems = m_ListCtrl.GetItemCount();
586 for (int i = 0; i < nListItems; ++i)
588 auto entry = m_ListCtrl.GetListEntry(i);
589 if (entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
591 m_ListCtrl.EnsureVisible(i, FALSE);
592 m_ListCtrl.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
593 m_ListCtrl.SetFocus();
594 return;
597 return;
600 if (m_bCreateNewBranch)
602 if (!g_Git.IsBranchNameValid(m_sCreateNewBranch))
604 ShowEditBalloon(IDC_NEWBRANCH, IDS_B_T_NOTEMPTY, IDS_ERR_ERROR, TTI_ERROR);
605 return;
607 if (g_Git.BranchTagExists(m_sCreateNewBranch))
609 // branch already exists
610 CString msg;
611 msg.LoadString(IDS_B_EXISTS);
612 msg += L' ' + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME));
613 ShowEditBalloon(IDC_NEWBRANCH, msg, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
614 return;
616 if (g_Git.BranchTagExists(m_sCreateNewBranch, false))
618 // tag with the same name exists -> shortref is ambiguous
619 if (CMessageBox::Show(m_hWnd, IDS_B_SAMETAGNAMEEXISTS, IDS_APPNAME, 2, IDI_EXCLAMATION, IDS_CONTINUEBUTTON, IDS_ABORTBUTTON) == 2)
620 return;
624 CString id;
625 GetDlgItemText(IDC_BUGID, id);
626 if (!m_ProjectProperties.CheckBugID(id))
628 ShowEditBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDS_ERR_ERROR, TTI_ERROR);
629 return;
631 m_sLogMessage = m_cLogMessage.GetText();
632 if ( m_sLogMessage.IsEmpty() )
634 // no message entered, go round again
635 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
636 return;
638 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
640 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
641 return;
644 if (m_ProjectProperties.bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
646 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);
647 if (retval == 1)
649 OnBnClickedSignOff();
650 m_sLogMessage = m_cLogMessage.GetText();
652 else if (retval == 3)
653 return;
656 if (CAppUtils::MessageContainsConflictHints(GetSafeHwnd(), m_sLogMessage))
657 return;
659 if (CHooks::Instance().IsHookPresent(pre_commit_hook, g_Git.m_CurrentDir)) {
660 DWORD exitcode = 0xFFFFFFFF;
661 CString error;
662 CTGitPathList list;
663 m_ListCtrl.WriteCheckedNamesToPathList(list);
664 if (CHooks::Instance().PreCommit(g_Git.m_CurrentDir, list, m_sLogMessage, exitcode, error))
666 if (exitcode)
668 CString temp;
669 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
670 MessageBox(temp, L"TortoiseGit", MB_ICONERROR);
671 return;
676 int nListItems = m_ListCtrl.GetItemCount();
677 for (int i = 0; i < nListItems && !m_bCommitMessageOnly; ++i)
679 auto entry = m_ListCtrl.GetListEntry(i);
680 if (!entry->m_Checked || !entry->IsDirectory())
681 continue;
683 bool dirty = false;
684 if (entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
686 CGit subgit;
687 subgit.m_CurrentDir = g_Git.CombinePath(entry);
688 CString subcmdout;
689 subgit.Run(L"git.exe status --porcelain", &subcmdout, CP_UTF8);
690 dirty = !subcmdout.IsEmpty();
692 else
694 CString cmd, cmdout;
695 cmd.Format(L"git.exe diff -- \"%s\"", entry->GetWinPath());
696 g_Git.Run(cmd, &cmdout, CP_UTF8);
697 dirty = CStringUtils::EndsWith(cmdout, L"-dirty\n");
700 if (dirty)
702 CString message;
703 message.Format(IDS_COMMITDLG_SUBMODULEDIRTY, (LPCTSTR)entry->GetGitPathString());
704 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)));
705 if (result == 1)
707 CString cmdCommit;
708 cmdCommit.Format(L"/command:commit /path:\"%s\\%s\"", (LPCTSTR)g_Git.m_CurrentDir, entry->GetWinPath());
709 CAppUtils::RunTortoiseGitProc(cmdCommit);
710 return;
712 else if (result == 2)
713 continue;
714 else
715 return;
719 if (!m_bCommitMessageOnly)
720 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
721 m_pathwatcher.Stop();
722 InterlockedExchange(&m_bBlock, TRUE);
723 //first add all the unversioned files the user selected
724 //and check if all versioned files are selected
725 int nchecked = 0;
727 CMassiveGitTask mgtReAddAfterCommit(L"add --ignore-errors -f");
728 CMassiveGitTask mgtReDelAfterCommit(L"rm --cached --ignore-unmatch");
730 CString cmd;
731 CString out;
733 bool bAddSuccess=true;
734 bool bCloseCommitDlg=false;
736 CSysProgressDlg sysProgressDlg;
737 if (nListItems >= 25)
739 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
740 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
741 sysProgressDlg.SetTime(true);
742 sysProgressDlg.SetShowProgressBar(true);
743 sysProgressDlg.ShowModal(this, true);
746 CBlockCacheForPath cacheBlock(g_Git.m_CurrentDir);
747 ULONGLONG currentTicks = GetTickCount64();
749 if (g_Git.UsingLibGit2(CGit::GIT_CMD_COMMIT_UPDATE_INDEX))
751 bAddSuccess = false;
754 CAutoRepository repository(g_Git.GetGitRepository());
755 if (!repository)
757 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not open repository."), L"TortoiseGit", MB_OK | MB_ICONERROR);
758 break;
761 CGitHash revHash;
762 CString revRef = L"HEAD";
763 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
764 revRef = L"HEAD~1";
765 if (CGit::GetHash(repository, revHash, revRef))
767 MessageBox(g_Git.GetLibGit2LastErr(L"Could not get HEAD hash after committing."), L"TortoiseGit", MB_ICONERROR);
768 break;
771 CAutoCommit commit;
772 if (!revHash.IsEmpty() && git_commit_lookup(commit.GetPointer(), repository, (const git_oid*)revHash.m_hash))
774 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not get last commit."), L"TortoiseGit", MB_OK | MB_ICONERROR);
775 break;
778 CAutoTree tree;
779 if (!revHash.IsEmpty() && git_commit_tree(tree.GetPointer(), commit))
781 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not read tree of commit."), L"TortoiseGit", MB_OK | MB_ICONERROR);
782 break;
785 CAutoIndex index;
786 if (git_repository_index(index.GetPointer(), repository))
788 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not get the repository index."), L"TortoiseGit", MB_OK | MB_ICONERROR);
789 break;
792 CAutoIndex indexOld;
793 if (!revHash.IsEmpty() && (git_index_new(indexOld.GetPointer()) || git_index_read_tree(indexOld, tree)))
795 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not read the tree into the index."), L"TortoiseGit", MB_OK | MB_ICONERROR);
796 break;
799 bAddSuccess = true;
801 for (int j = 0; j < nListItems; ++j)
803 auto entry = m_ListCtrl.GetListEntry(j);
805 if (sysProgressDlg.IsVisible())
807 if (GetTickCount64() - currentTicks > 1000UL || j == nListItems - 1 || j == 0)
809 sysProgressDlg.SetLine(2, entry->GetGitPathString(), true);
810 sysProgressDlg.SetProgress(j, nListItems);
811 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too often: this takes time!
812 currentTicks = GetTickCount64();
816 CStringA filePathA = CUnicodeUtils::GetMulti(entry->GetGitPathString(), CP_UTF8).TrimRight(L'/');
818 if (entry->m_Checked && !m_bCommitMessageOnly)
820 if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
821 git_index_remove_bypath(index, filePathA); // ignore error
822 else
824 if (git_index_add_bypath(index, filePathA))
826 bAddSuccess = false;
827 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not add \"" + entry->GetGitPathString() + L"\" to index."), L"TortoiseGit", MB_OK | MB_ICONERROR);
828 break;
832 if ((entry->m_Action & CTGitPath::LOGACTIONS_REPLACED) && !entry->GetGitOldPathString().IsEmpty())
833 git_index_remove_bypath(index, CUnicodeUtils::GetUTF8(entry->GetGitOldPathString())); // ignore error
835 ++nchecked;
837 else
839 if (entry->m_Action & CTGitPath::LOGACTIONS_ADDED || entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
841 git_index_remove_bypath(index, filePathA); // ignore error
842 mgtReAddAfterCommit.AddFile(*entry);
844 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED && !entry->GetGitOldPathString().IsEmpty())
846 const git_index_entry* oldIndexEntry = nullptr;
847 if ((oldIndexEntry = git_index_get_bypath(indexOld, CUnicodeUtils::GetUTF8(entry->GetGitOldPathString()), 0)) == nullptr || git_index_add(index, oldIndexEntry))
849 bAddSuccess = false;
850 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not reset \"" + entry->GetGitOldPathString() + L"\" to old index entry."), L"TortoiseGit", MB_OK | MB_ICONERROR);
851 break;
853 mgtReDelAfterCommit.AddFile(entry->GetGitOldPathString());
856 else if (!(entry->m_Action & CTGitPath::LOGACTIONS_UNVER))
858 const git_index_entry* oldIndexEntry = nullptr;
859 if ((oldIndexEntry = git_index_get_bypath(indexOld, filePathA, 0)) == nullptr || git_index_add(index, oldIndexEntry))
861 bAddSuccess = false;
862 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not reset \"" + entry->GetGitPathString() + L"\" to old index entry."), L"TortoiseGit", MB_OK | MB_ICONERROR);
863 break;
865 if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED && !(entry->m_Action & CTGitPath::LOGACTIONS_MISSING))
866 mgtReDelAfterCommit.AddFile(entry->GetGitPathString());
870 if (sysProgressDlg.HasUserCancelled())
872 bAddSuccess = false;
873 break;
876 if (bAddSuccess && git_index_write(index))
877 bAddSuccess = false;
879 for (int j = 0; bAddSuccess && j < nListItems; ++j)
880 CShellUpdater::Instance().AddPathForUpdate(*m_ListCtrl.GetListEntry(j));
881 } while (0);
883 else
885 // ***************************************************
886 // ATTENTION: Similar code in RebaseDlg.cpp!!!
887 // ***************************************************
888 CMassiveGitTask mgtAdd(L"add -f");
889 CMassiveGitTask mgtUpdateIndexForceRemove(L"update-index --force-remove");
890 CMassiveGitTask mgtUpdateIndex(L"update-index");
891 CMassiveGitTask mgtRm(L"rm --ignore-unmatch");
892 CMassiveGitTask mgtRmFCache(L"rm -f --cache");
893 CString resetCmd = L"reset";
894 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
895 resetCmd += L" HEAD~1";;
896 CMassiveGitTask mgtReset(resetCmd, TRUE, true);
897 for (int j = 0; j < nListItems; ++j)
899 auto entry = m_ListCtrl.GetListEntry(j);
901 if (entry->m_Checked && !m_bCommitMessageOnly)
903 if ((entry->m_Action & CTGitPath::LOGACTIONS_UNVER) || (entry->IsDirectory() && !(entry->m_Action & CTGitPath::LOGACTIONS_DELETED)))
904 mgtAdd.AddFile(entry->GetGitPathString());
905 else if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
906 mgtUpdateIndexForceRemove.AddFile(entry->GetGitPathString());
907 else
908 mgtUpdateIndex.AddFile(entry->GetGitPathString());
910 if ((entry->m_Action & CTGitPath::LOGACTIONS_REPLACED) && !entry->GetGitOldPathString().IsEmpty())
911 mgtRm.AddFile(entry->GetGitOldPathString());
913 ++nchecked;
915 else
917 if (entry->m_Action & CTGitPath::LOGACTIONS_ADDED || entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
918 { //To init git repository, there are not HEAD, so we can use git reset command
919 mgtRmFCache.AddFile(entry->GetGitPathString());
920 mgtReAddAfterCommit.AddFile(*entry);
922 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED && !entry->GetGitOldPathString().IsEmpty())
924 mgtReset.AddFile(entry->GetGitOldPathString());
925 mgtReDelAfterCommit.AddFile(entry->GetGitOldPathString());
928 else if (!(entry->m_Action & CTGitPath::LOGACTIONS_UNVER))
930 mgtReset.AddFile(entry->GetGitPathString());
931 if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED && !(entry->m_Action & CTGitPath::LOGACTIONS_MISSING))
932 mgtReDelAfterCommit.AddFile(entry->GetGitPathString());
936 if (sysProgressDlg.HasUserCancelled())
938 bAddSuccess = false;
939 break;
943 CMassiveGitTask tasks[] = { mgtAdd, mgtUpdateIndexForceRemove, mgtUpdateIndex, mgtRm, mgtRmFCache, mgtReset };
944 int progress = 0, maxProgress = 0;
945 for (int j = 0; j < _countof(tasks); ++j)
946 maxProgress += tasks[j].GetListCount();
947 for (int j = 0; j < _countof(tasks); ++j)
948 bAddSuccess = bAddSuccess && UpdateIndex(tasks[j], sysProgressDlg, progress += tasks[j].GetListCount(), maxProgress);
950 if (sysProgressDlg.HasUserCancelled())
951 bAddSuccess = false;
953 for (int j = 0; bAddSuccess && j < nListItems; ++j)
954 CShellUpdater::Instance().AddPathForUpdate(*m_ListCtrl.GetListEntry(j));
957 if (sysProgressDlg.HasUserCancelled())
958 bAddSuccess = false;
960 sysProgressDlg.Stop();
962 if (bAddSuccess && m_bCreateNewBranch)
964 if (g_Git.Run(L"git.exe branch " + m_sCreateNewBranch, &out, CP_UTF8))
966 MessageBox(L"Creating new branch failed:\n" + out, L"TortoiseGit", MB_OK | MB_ICONERROR);
967 bAddSuccess = false;
969 if (g_Git.Run(L"git.exe checkout " + m_sCreateNewBranch + L" --", &out, CP_UTF8))
971 MessageBox(L"Switching to new branch failed:\n" + out, L"TortoiseGit", MB_OK | MB_ICONERROR);
972 bAddSuccess = false;
976 if (bAddSuccess && m_bWarnDetachedHead && CheckHeadDetach())
977 bAddSuccess = false;
979 m_sBugID.Trim();
980 CString sExistingBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
981 sExistingBugID.Trim();
982 if (!m_sBugID.IsEmpty() && m_sBugID.Compare(sExistingBugID))
984 m_sBugID.Replace(L", ", L",");
985 m_sBugID.Replace(L" ,", L",");
986 CString sBugID = m_ProjectProperties.sMessage;
987 sBugID.Replace(L"%BUGID%", m_sBugID);
988 if (m_ProjectProperties.bAppend)
989 m_sLogMessage += L'\n' + sBugID + L'\n';
990 else
991 m_sLogMessage = sBugID + L'\n' + m_sLogMessage;
994 // now let the bugtraq plugin check the commit message
995 CComPtr<IBugTraqProvider2> pProvider2;
996 if (m_BugTraqProvider)
998 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
999 if (SUCCEEDED(hr))
1001 ATL::CComBSTR temp;
1002 ATL::CComBSTR repositoryRoot(g_Git.m_CurrentDir);
1003 ATL::CComBSTR parameters(m_bugtraq_association.GetParameters());
1004 ATL::CComBSTR commonRoot(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
1005 ATL::CComBSTR commitMessage(m_sLogMessage);
1006 CBstrSafeVector pathList(m_selectedPathList.GetCount());
1008 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
1009 pathList.PutElement(index, m_selectedPathList[index].GetGitPathString());
1011 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
1013 COMError ce(hr);
1014 CString sErr;
1015 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
1016 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
1018 else
1020 CString sError = temp;
1021 if (!sError.IsEmpty())
1023 CMessageBox::Show(GetSafeHwnd(), sError, L"TortoiseGit", MB_ICONERROR);
1024 InterlockedExchange(&m_bBlock, FALSE);
1025 return;
1031 if (m_bCommitMessageOnly || bAddSuccess && (nchecked || m_bCommitAmend || CTGitPath(g_Git.m_CurrentDir).IsMergeActive()))
1033 bCloseCommitDlg = true;
1035 CString tempfile=::GetTempFile();
1037 if (CAppUtils::SaveCommitUnicodeFile(tempfile, m_sLogMessage))
1039 CMessageBox::Show(GetSafeHwnd(), L"Could not save commit message", L"TortoiseGit", MB_OK | MB_ICONERROR);
1040 InterlockedExchange(&m_bBlock, FALSE);
1041 return;
1044 CTGitPath path=g_Git.m_CurrentDir;
1046 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
1048 out.Empty();
1049 CString amend;
1050 if(this->m_bCommitAmend)
1051 amend = L"--amend";
1053 CString dateTime;
1054 if (m_bSetCommitDateTime)
1056 CTime date, time;
1057 m_CommitDate.GetTime(date);
1058 m_CommitTime.GetTime(time);
1059 if (m_bCommitAmend && m_AsCommitDateCtrl.GetCheck())
1060 dateTime = CAppUtils::IsGitVersionNewerOrEqual(2, 1) ? L"--date=\"now\"" : L"--date=\"\"" ;
1061 else
1062 dateTime.Format(L"--date=%sT%s", (LPCTSTR)date.Format(L"%Y-%m-%d"), (LPCTSTR)time.Format(L"%H:%M:%S"));
1064 CString author;
1065 if (m_bSetAuthor)
1066 author.Format(L"--author=\"%s\"", (LPCTSTR)m_sAuthor);
1067 CString allowEmpty = m_bCommitMessageOnly ? L"--allow-empty" : L"";
1068 // TODO: make sure notes.amend.rewrite does still work when switching to libgit2
1069 cmd.Format(L"git.exe commit %s %s %s %s -F \"%s\"", (LPCTSTR)author, (LPCTSTR)dateTime, (LPCTSTR)amend, (LPCTSTR)allowEmpty, (LPCTSTR)tempfile);
1071 CCommitProgressDlg progress;
1072 progress.m_bBufferAll=true; // improve show speed when there are many file added.
1073 progress.m_GitCmd=cmd;
1074 progress.m_bShowCommand = FALSE; // don't show the commit command
1075 progress.m_PreText = out; // show any output already generated in log window
1076 if (m_ctrlOkButton.GetCurrentEntry() > 0)
1077 progress.m_AutoClose = GitProgressAutoClose::AUTOCLOSE_IF_NO_ERRORS;
1079 progress.m_PostCmdCallback = [&](DWORD status, PostCmdList& postCmdList)
1081 if (status || m_bNoPostActions || m_bAutoClose)
1082 return;
1084 if (IsGitSVN)
1085 postCmdList.emplace_back(IDI_COMMIT, IDS_MENUSVNDCOMMIT, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_DCOMMIT; });
1087 postCmdList.emplace_back(IDI_PUSH, IDS_MENUPUSH, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_PUSH; });
1088 postCmdList.emplace_back(IDI_PULL, IDS_MENUPULL, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_PULL; });
1089 postCmdList.emplace_back(IDI_COMMIT, IDS_PROC_COMMIT_RECOMMIT, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_RECOMMIT; });
1090 postCmdList.emplace_back(IDI_TAG, IDS_MENUTAG, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_CREATETAG; });
1093 m_PostCmd = GIT_POSTCOMMIT_CMD_NOTHING;
1094 progress.DoModal();
1096 if (!m_bNoPostActions)
1097 m_regLastAction = (int)m_ctrlOkButton.GetCurrentEntry();
1098 if (m_ctrlOkButton.GetCurrentEntry() == 1)
1099 m_PostCmd = GIT_POSTCOMMIT_CMD_RECOMMIT;
1101 ::DeleteFile(tempfile);
1103 if (m_BugTraqProvider && progress.m_GitStatus == 0)
1105 CComPtr<IBugTraqProvider2> pProvider;
1106 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
1107 if (SUCCEEDED(hr))
1109 ATL::CComBSTR commonRoot(g_Git.m_CurrentDir);
1110 CBstrSafeVector pathList(m_selectedPathList.GetCount());
1112 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
1113 pathList.PutElement(index, m_selectedPathList[index].GetGitPathString());
1115 ATL::CComBSTR logMessage(m_sLogMessage);
1117 CGitHash hash;
1118 if (g_Git.GetHash(hash, L"HEAD"))
1119 MessageBox(g_Git.GetGitLastErr(L"Could not get HEAD hash after committing."), L"TortoiseGit", MB_ICONERROR);
1120 LONG version = g_Git.Hash2int(hash);
1122 ATL::CComBSTR temp;
1123 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
1124 commonRoot,
1125 pathList,
1126 logMessage,
1127 (LONG)version,
1128 &temp)))
1130 CString sErr = temp;
1131 if (!sErr.IsEmpty())
1132 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_OK | MB_ICONERROR);
1133 else
1135 COMError ce(hr);
1136 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
1137 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_OK | MB_ICONERROR);
1142 RestoreFiles(progress.m_GitStatus == 0, false);
1143 if (((DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit", TRUE)) == TRUE)
1145 BOOL cancel = FALSE;
1146 mgtReAddAfterCommit.Execute(cancel);
1147 mgtReDelAfterCommit.Execute(cancel);
1150 if (!progress.m_GitStatus)
1152 DWORD exitcode = 0xFFFFFFFF;
1153 CString error;
1154 if (CHooks::Instance().PostCommit(g_Git.m_CurrentDir, amend.IsEmpty(), exitcode, error))
1156 if (exitcode)
1158 CString temp;
1159 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
1160 MessageBox(temp, L"TortoiseGit", MB_ICONERROR);
1161 bCloseCommitDlg = false;
1166 if (progress.m_GitStatus || m_PostCmd == GIT_POSTCOMMIT_CMD_RECOMMIT)
1168 bCloseCommitDlg = false;
1169 if (m_PostCmd == GIT_POSTCOMMIT_CMD_RECOMMIT)
1171 if (!m_sLogMessage.IsEmpty())
1173 ReloadHistoryEntries();
1174 m_History.AddEntry(m_sLogMessage);
1175 m_History.Save();
1178 this->m_sLogMessage.Empty();
1179 GetCommitTemplate(m_sLogMessage);
1180 m_cLogMessage.SetText(m_sLogMessage);
1181 if (m_bCreateNewBranch)
1183 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);
1184 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
1186 m_bCreateNewBranch = FALSE;
1187 m_ListCtrl.Clear();
1188 if (!RunStartCommitHook())
1189 bCloseCommitDlg = true;
1192 if (!progress.m_GitStatus)
1194 m_AmendStr.Empty();
1195 m_bCommitAmend = FALSE;
1198 UpdateData(FALSE);
1201 else if(bAddSuccess)
1203 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
1204 bCloseCommitDlg=false;
1207 UpdateData();
1208 m_regAddBeforeCommit = m_bShowUnversioned;
1209 m_regKeepChangelists = m_bKeepChangeList;
1210 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
1211 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
1212 m_bKeepChangeList = FALSE;
1213 InterlockedExchange(&m_bBlock, FALSE);
1215 if (!m_sLogMessage.IsEmpty())
1217 ReloadHistoryEntries();
1218 m_History.AddEntry(m_sLogMessage);
1219 m_History.Save();
1222 SaveSplitterPos();
1224 if (bCloseCommitDlg)
1226 if (m_ctrlOkButton.GetCurrentEntry() == 2)
1227 DoPush();
1228 CResizableStandAloneDialog::OnOK();
1230 else if (m_PostCmd == GIT_POSTCOMMIT_CMD_RECOMMIT)
1232 m_bDoNotStoreLastSelectedLine = true;
1233 this->Refresh();
1234 this->BringWindowToTop();
1237 CShellUpdater::Instance().Flush();
1240 void CCommitDlg::SaveSplitterPos()
1242 if (!IsIconic())
1244 CRegDWORD regPos(L"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer");
1245 RECT rectSplitter;
1246 m_wndSplitter.GetWindowRect(&rectSplitter);
1247 ScreenToClient(&rectSplitter);
1248 regPos = rectSplitter.top;
1252 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
1254 return ((CCommitDlg*)pVoid)->StatusThread();
1257 void CCommitDlg::ReloadHistoryEntries()
1259 CString reg;
1260 reg.Format(L"Software\\TortoiseGit\\History\\commit%s", (LPCTSTR)m_ListCtrl.m_sUUID);
1261 reg.Replace(L':', L'_');
1262 m_History.Load(reg, L"logmsgs");
1265 UINT CCommitDlg::StatusThread()
1267 //get the status of all selected file/folders recursively
1268 //and show the ones which have to be committed to the user
1269 //in a list control.
1270 m_pathwatcher.Stop();
1272 g_Git.RefreshGitIndex();
1274 m_bCancelled = false;
1276 DialogEnableWindow(IDOK, false);
1277 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
1278 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
1279 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
1280 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
1281 DialogEnableWindow(IDC_EXTERNALWARNING, false);
1282 DialogEnableWindow(IDC_COMMIT_AMEND, FALSE);
1283 DialogEnableWindow(IDC_COMMIT_AMENDDIFF, FALSE);
1284 // read the list of recent log entries before querying the WC for status
1285 // -> the user may select one and modify / update it while we are crawling the WC
1287 DialogEnableWindow(IDC_CHECKALL, false);
1288 DialogEnableWindow(IDC_CHECKNONE, false);
1289 DialogEnableWindow(IDC_CHECKUNVERSIONED, false);
1290 DialogEnableWindow(IDC_CHECKVERSIONED, false);
1291 DialogEnableWindow(IDC_CHECKADDED, false);
1292 DialogEnableWindow(IDC_CHECKDELETED, false);
1293 DialogEnableWindow(IDC_CHECKMODIFIED, false);
1294 DialogEnableWindow(IDC_CHECKFILES, false);
1295 DialogEnableWindow(IDC_CHECKSUBMODULES, false);
1297 CString dotGitPath;
1298 GitAdminDir::GetWorktreeAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
1299 if (PathFileExists(dotGitPath + L"CHERRY_PICK_HEAD"))
1301 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
1302 m_bCommitAmend = FALSE;
1303 SendMessage(WM_UPDATEDATAFALSE);
1306 if (!m_bDoNotStoreLastSelectedLine)
1307 m_ListCtrl.StoreScrollPos();
1308 // Initialise the list control with the status of the files/folders below us
1309 m_ListCtrl.Clear();
1310 BOOL success;
1311 CTGitPathList *pList;
1312 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE || m_bForceCommitAmend) && (m_bAmendDiffToLastCommit==FALSE);
1313 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
1315 if(m_bWholeProject || m_bWholeProject2)
1316 pList = nullptr;
1317 else
1318 pList = &m_pathList;
1320 success=m_ListCtrl.GetStatus(pList);
1322 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1323 if(this->m_bShowUnversioned)
1324 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
1326 m_ListCtrl.CheckIfChangelistsArePresent(false);
1328 DWORD dwShow = GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWINCHANGELIST | GITSLC_SHOWDIRECTFILES;
1329 dwShow |= DWORD(m_regAddBeforeCommit) ? GITSLC_SHOWUNVERSIONED : 0;
1330 if (success)
1332 /*if (!m_checkedPathList.IsEmpty())
1333 m_ListCtrl.Show(dwShow, m_checkedPathList);
1334 else*/
1336 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
1337 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
1338 m_ListCtrl.Show(dwShow, dwCheck);
1341 if (m_ListCtrl.HasExternalsFromDifferentRepos())
1343 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
1344 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
1347 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
1348 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
1349 if (m_ListCtrl.GetItemCount() != 0 && m_ListCtrl.GetTopIndex() == 0 && (m_bDoNotStoreLastSelectedLine || CRegDWORD(L"Software\\TortoiseGit\\RememberFileListPosition", TRUE) != TRUE))
1350 m_ListCtrl.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
1352 if (!success)
1354 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
1355 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
1356 m_ListCtrl.Show(dwShow);
1358 m_bDoNotStoreLastSelectedLine = false;
1360 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
1361 && !PathFileExists(dotGitPath + L"MERGE_HEAD"))
1363 CString temp;
1364 temp.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED);
1365 if (CMessageBox::ShowCheck(GetSafeHwnd(), temp, L"TortoiseGit", MB_ICONINFORMATION | MB_YESNO, L"NothingToCommitShowUnversioned", nullptr) == IDYES)
1367 m_bShowUnversioned = TRUE;
1368 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
1369 dwShow = (DWORD)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWUNVERSIONED);
1370 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
1371 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
1375 SetDlgTitle();
1377 // we don't have to block the commit dialog while we fetch the
1378 // auto completion list.
1379 m_pathwatcher.ClearChangedPaths();
1380 InterlockedExchange(&m_bBlock, FALSE);
1381 std::map<CString, int> autolist;
1382 if ((DWORD)CRegDWORD(L"Software\\TortoiseGit\\Autocompletion", TRUE) == TRUE)
1384 m_ListCtrl.BusyCursor(true);
1385 GetAutocompletionList(autolist);
1386 m_ListCtrl.BusyCursor(false);
1388 SendMessage(WM_UPDATEOKBUTTON);
1389 m_ListCtrl.Invalidate();
1390 if (m_bRunThread)
1392 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1393 DialogEnableWindow(IDC_WHOLE_PROJECT, !m_bWholeProject2);
1394 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1395 if (m_ListCtrl.HasChangeLists())
1396 DialogEnableWindow(IDC_KEEPLISTS, true);
1398 // activate amend checkbox (if necessary)
1399 if (g_Git.IsInitRepos())
1401 m_bCommitAmend = FALSE;
1402 SendMessage(WM_UPDATEDATAFALSE);
1404 else
1406 if (m_bForceCommitAmend)
1408 m_bCommitAmend = TRUE;
1409 SendMessage(WM_UPDATEDATAFALSE);
1411 else
1412 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(!PathFileExists(dotGitPath + L"CHERRY_PICK_HEAD"));
1414 CGitHash hash;
1415 if (g_Git.GetHash(hash, L"HEAD"))
1417 MessageBox(g_Git.GetGitLastErr(L"Could not get HEAD hash."), L"TortoiseGit", MB_ICONERROR);
1419 if (!hash.IsEmpty())
1421 GitRev headRevision;
1422 if (headRevision.GetParentFromHash(hash))
1423 MessageBox(headRevision.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
1424 // do not allow to show diff to "last" revision if it has more that one parent
1425 if (headRevision.ParentsCount() != 1)
1427 m_bAmendDiffToLastCommit = TRUE;
1428 SendMessage(WM_UPDATEDATAFALSE);
1430 else
1431 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(TRUE);
1435 UpdateCheckLinks();
1437 // we have the list, now signal the main thread about it
1438 SendMessage(WM_AUTOLISTREADY, 0, (LPARAM)&autolist); // only send the message if the thread wasn't told to quit!
1441 InterlockedExchange(&m_bRunThread, FALSE);
1442 InterlockedExchange(&m_bThreadRunning, FALSE);
1443 // force the cursor to normal
1444 RefreshCursor();
1446 return 0;
1449 void CCommitDlg::SetDlgTitle()
1451 if (m_sTitle.IsEmpty())
1452 GetWindowText(m_sTitle);
1454 if (m_bWholeProject || m_bWholeProject2)
1455 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
1456 else
1458 if (m_pathList.GetCount() == 1)
1459 CAppUtils::SetWindowTitle(m_hWnd, g_Git.CombinePath(m_pathList[0].GetUIPathString()), m_sTitle);
1460 else
1461 CAppUtils::SetWindowTitle(m_hWnd, g_Git.CombinePath(m_ListCtrl.GetCommonDirectory(false)), m_sTitle);
1465 void CCommitDlg::OnCancel()
1467 UpdateData();
1468 m_sBugID.Trim();
1469 m_sLogMessage = m_cLogMessage.GetText();
1470 if (!m_sBugID.IsEmpty())
1472 m_sBugID.Replace(L", ", L",");
1473 m_sBugID.Replace(L" ,", L",");
1474 CString sBugID = m_ProjectProperties.sMessage;
1475 sBugID.Replace(L"%BUGID%", m_sBugID);
1476 if (m_ProjectProperties.bAppend)
1477 m_sLogMessage += L'\n' + sBugID + L'\n';
1478 else
1479 m_sLogMessage = sBugID + L'\n' + m_sLogMessage;
1482 bool hasChangedMessage = (m_sLogTemplate.Compare(m_sLogMessage) != 0) && !m_sLogMessage.IsEmpty();
1484 CString tmp;
1485 tmp.LoadString(IDS_REALLYCANCEL);
1486 tmp.AppendChar(L'\n');
1487 tmp.AppendChar(L'\n');
1488 tmp.Append(CString(MAKEINTRESOURCE(IDS_HINTLASTMESSAGES)));
1489 CString dontaskagain;
1490 dontaskagain.LoadString(IDS_MSGBOX_DONOTSHOWAGAIN);
1491 BOOL dontaskagainchecked = FALSE;
1492 if ((hasChangedMessage || m_ListCtrl.GetItemCount() > 0) && CMessageBox::ShowCheck(GetSafeHwnd(), tmp, L"TortoiseGit", MB_ICONQUESTION | MB_DEFBUTTON2 | MB_YESNO, L"CommitAskBeforeCancel", dontaskagain, &dontaskagainchecked) == IDNO)
1494 if (dontaskagainchecked)
1495 CMessageBox::SetRegistryValue(L"CommitAskBeforeCancel", IDYES);
1496 return;
1499 m_bCancelled = true;
1500 m_pathwatcher.Stop();
1502 if (m_bThreadRunning)
1503 StopStatusThread();
1504 if (!RestoreFiles())
1505 return;
1506 if (hasChangedMessage)
1508 ReloadHistoryEntries();
1509 m_History.AddEntry(m_sLogMessage);
1510 m_History.Save();
1512 SaveSplitterPos();
1513 CResizableStandAloneDialog::OnCancel();
1516 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1518 if (m_hAccel)
1520 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1521 if (ret)
1522 return TRUE;
1524 if (m_hAccelOkButton && GetDlgItem(IDOK)->IsWindowEnabled() && TranslateAccelerator(m_hWnd, m_hAccelOkButton, pMsg))
1525 return TRUE;
1527 if (pMsg->message == WM_KEYDOWN)
1529 switch (pMsg->wParam)
1531 case VK_F5:
1533 if (m_bBlock)
1534 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1535 Refresh();
1537 break;
1538 case VK_RETURN:
1540 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1542 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1543 PostMessage(WM_COMMAND, IDOK);
1544 return TRUE;
1546 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1548 // Pressing RETURN in the bug id control
1549 // moves the focus to the message
1550 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1551 return TRUE;
1554 break;
1558 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1561 void CCommitDlg::Refresh()
1563 if (m_bThreadRunning)
1564 return;
1566 StartStatusThread();
1569 void CCommitDlg::StartStatusThread()
1571 if (InterlockedExchange(&m_bBlock, TRUE) != FALSE)
1572 return;
1574 delete m_pThread;
1575 m_pThread = nullptr;
1577 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
1578 if (!m_pThread)
1580 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1581 InterlockedExchange(&m_bBlock, FALSE);
1582 return;
1584 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
1585 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
1586 m_pThread->m_bAutoDelete = FALSE;
1587 m_pThread->ResumeThread();
1590 void CCommitDlg::StopStatusThread()
1592 InterlockedExchange(&m_bRunThread, FALSE);
1593 WaitForSingleObject(m_pThread->m_hThread, 5000);
1594 if (!m_bThreadRunning)
1595 return;
1597 // we gave the thread a chance to quit. Since the thread didn't
1598 // listen to us we have to kill it.
1599 g_Git.KillRelatedThreads(m_pThread);
1600 InterlockedExchange(&m_bThreadRunning, FALSE);
1603 void CCommitDlg::OnBnClickedShowunversioned()
1605 m_tooltips.Pop(); // hide the tooltips
1606 UpdateData();
1607 m_regAddBeforeCommit = m_bShowUnversioned;
1608 if (!m_bBlock)
1610 DWORD dwShow = m_ListCtrl.GetShowFlags();
1611 if (DWORD(m_regAddBeforeCommit))
1612 dwShow |= GITSLC_SHOWUNVERSIONED;
1613 else
1614 dwShow &= ~GITSLC_SHOWUNVERSIONED;
1615 if(dwShow & GITSLC_SHOWUNVERSIONED)
1617 if (m_bWholeProject || m_bWholeProject2)
1618 m_ListCtrl.GetStatus(nullptr, false, false, true);
1619 else
1620 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1622 m_ListCtrl.StoreScrollPos();
1623 m_ListCtrl.Show(dwShow, 0, true, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
1624 UpdateCheckLinks();
1628 void CCommitDlg::OnStnClickedExternalwarning()
1630 m_tooltips.Popup();
1633 void CCommitDlg::OnEnChangeLogmessage()
1635 SendMessage(WM_UPDATEOKBUTTON);
1638 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1640 #if 0
1641 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1643 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1645 m_bShowUnversioned = TRUE;
1646 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED;
1647 m_ListCtrl.Show(dwShow);
1648 UpdateData(FALSE);
1651 #endif
1652 return 0;
1655 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1657 Refresh();
1658 return 0;
1661 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM lParam)
1663 BringWindowToTop();
1664 SetForegroundWindow();
1665 SetActiveWindow();
1666 // if multiple files/folders are dropped
1667 // this handler is called for every single item
1668 // separately.
1669 // To avoid creating multiple refresh threads and
1670 // causing crashes, we only add the items to the
1671 // list control and start a timer.
1672 // When the timer expires, we start the refresh thread,
1673 // but only if it isn't already running - otherwise we
1674 // restart the timer.
1675 CTGitPath path;
1676 path.SetFromWin((LPCTSTR)lParam);
1678 // check whether the dropped file belongs to the very same repository
1679 CString projectDir;
1680 if (!path.HasAdminDir(&projectDir) || !CPathUtils::ArePathStringsEqual(g_Git.m_CurrentDir, projectDir))
1681 return 0;
1683 // just add all the items we get here.
1684 // if the item is versioned, the add will fail but nothing
1685 // more will happen.
1686 CString cmd;
1687 cmd.Format(L"git.exe add -- \"%s\"", (LPCTSTR)path.GetWinPathString());
1688 g_Git.Run(cmd, nullptr, CP_UTF8);
1690 if (!m_ListCtrl.HasPath(path))
1692 if (m_pathList.AreAllPathsFiles())
1694 m_pathList.AddPath(path);
1695 m_pathList.RemoveDuplicates();
1696 m_updatedPathList.AddPath(path);
1697 m_updatedPathList.RemoveDuplicates();
1699 else
1701 // if the path list contains folders, we have to check whether
1702 // our just (maybe) added path is a child of one of those. If it is
1703 // a child of a folder already in the list, we must not add it. Otherwise
1704 // that path could show up twice in the list.
1705 bool bHasParentInList = false;
1706 for (int i=0; i<m_pathList.GetCount(); ++i)
1708 if (m_pathList[i].IsAncestorOf(path))
1710 bHasParentInList = true;
1711 break;
1714 if (!bHasParentInList)
1716 m_pathList.AddPath(path);
1717 m_pathList.RemoveDuplicates();
1718 m_updatedPathList.AddPath(path);
1719 m_updatedPathList.RemoveDuplicates();
1723 m_ListCtrl.ResetChecked(path);
1725 // Always start the timer, since the status of an existing item might have changed
1726 SetTimer(REFRESHTIMER, 200, nullptr);
1727 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Item %s dropped, timer started\n", path.GetWinPath());
1728 return 0;
1731 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM lparam)
1733 m_cLogMessage.SetAutoCompletionList(std::move(*reinterpret_cast<std::map<CString, int>*>(lparam)), '*');
1734 return 0;
1737 //////////////////////////////////////////////////////////////////////////
1738 // functions which run in the status thread
1739 //////////////////////////////////////////////////////////////////////////
1741 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1743 CString strLine;
1746 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1747 while (m_bRunThread && file.ReadString(strLine))
1749 if (strLine.IsEmpty())
1750 continue;
1751 if (strLine[0] == L'#')
1752 continue;
1753 int eqpos = strLine.Find('=');
1754 CString rgx;
1755 rgx = strLine.Mid(eqpos+1).Trim();
1757 int pos = -1;
1758 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1760 mapRegex[strLine.Left(pos)] = rgx;
1761 strLine = strLine.Mid(pos+1).Trim();
1763 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1765 file.Close();
1767 catch (CFileException* pE)
1769 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException loading auto list regex file\n");
1770 pE->Delete();
1774 void CCommitDlg::ParseSnippetFile(const CString& sFile, std::map<CString, CString>& mapSnippet)
1776 CString strLine;
1779 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1780 while (m_bRunThread && file.ReadString(strLine))
1782 if (strLine.IsEmpty())
1783 continue;
1784 if (strLine[0] == L'#') // comment char
1785 continue;
1786 int eqpos = strLine.Find(L'=');
1787 if (eqpos <= 0)
1788 continue;
1789 CString key = strLine.Left(eqpos);
1790 auto rawvalue = strLine.GetBuffer() + eqpos + 1;
1791 CString value;
1792 bool isEscaped = false;
1793 for (int i = 0, len = strLine.GetLength() - eqpos - 1; i < len; ++i)
1795 wchar_t c = rawvalue[i];
1796 if (isEscaped)
1798 switch (c)
1800 case L't': c = L'\t'; break;
1801 case L'n': c = L'\n'; break;
1802 case L'r': c = L'\r'; break;
1803 case L'\\': c = L'\\'; break;
1804 default: value += rawvalue[i - 1]; break; // i is known to be > 0
1806 value += c;
1807 isEscaped = false;
1809 else if (c == L'\\')
1810 isEscaped = true;
1811 else
1812 value += c;
1814 mapSnippet[key] = value;
1816 file.Close();
1818 catch (CFileException* pE)
1820 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException loading auto list regex file\n");
1821 pE->Delete();
1825 void CCommitDlg::GetAutocompletionList(std::map<CString, int>& autolist)
1827 // the auto completion list is made of strings from each selected files.
1828 // the strings used are extracted from the files with regexes found
1829 // in the file "autolist.txt".
1830 // the format of that file is:
1831 // file extensions separated with commas '=' regular expression to use
1832 // example:
1833 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1834 // .cpp = (?<=[^\s]::)\b\w+\b
1836 std::map<CString, CString> mapRegex;
1837 CString sRegexFile = CPathUtils::GetAppDirectory();
1838 CRegDWORD regtimeout = CRegDWORD(L"Software\\TortoiseGit\\AutocompleteParseTimeout", 5);
1839 ULONGLONG timeoutvalue = ULONGLONG(DWORD(regtimeout)) * 1000UL;;
1840 sRegexFile += L"autolist.txt";
1841 if (!m_bRunThread)
1842 return;
1843 ParseRegexFile(sRegexFile, mapRegex);
1844 sRegexFile = CPathUtils::GetAppDataDirectory();
1845 sRegexFile += L"autolist.txt";
1846 if (PathFileExists(sRegexFile))
1847 ParseRegexFile(sRegexFile, mapRegex);
1849 m_snippet.clear();
1850 CString sSnippetFile = CPathUtils::GetAppDirectory();
1851 sSnippetFile += L"snippet.txt";
1852 ParseSnippetFile(sSnippetFile, m_snippet);
1853 sSnippetFile = CPathUtils::GetAppDataDirectory();
1854 sSnippetFile += L"snippet.txt";
1855 if (PathFileExists(sSnippetFile))
1856 ParseSnippetFile(sSnippetFile, m_snippet);
1857 for (const auto& snip : m_snippet)
1858 autolist.emplace(snip.first, AUTOCOMPLETE_SNIPPET);
1860 ULONGLONG starttime = GetTickCount64();
1862 // now we have two arrays of strings, where the first array contains all
1863 // file extensions we can use and the second the corresponding regex strings
1864 // to apply to those files.
1866 // the next step is to go over all files shown in the commit dialog
1867 // and scan them for strings we can use
1868 int nListItems = m_ListCtrl.GetItemCount();
1870 for (int i=0; i<nListItems && m_bRunThread; ++i)
1872 // stop parsing after timeout
1873 if ((!m_bRunThread) || (GetTickCount64() - starttime > timeoutvalue))
1874 return;
1876 CString sWinPath;
1877 CString sPartPath;
1878 CString sExt;
1879 int action;
1881 auto locker(m_ListCtrl.AcquireReadLock());
1882 auto path = m_ListCtrl.GetListEntry(i);
1884 if (!path)
1885 continue;
1887 sWinPath = path->GetWinPathString();
1888 sPartPath = path->GetGitPathString();
1889 sExt = path->GetFileExtension();
1890 action = path->m_Action;
1892 autolist.emplace(sPartPath, AUTOCOMPLETE_FILENAME);
1894 int pos = 0;
1895 int lastPos = 0;
1896 while ((pos = sPartPath.Find('/', pos)) >= 0)
1898 ++pos;
1899 lastPos = pos;
1900 autolist.emplace(sPartPath.Mid(pos), AUTOCOMPLETE_FILENAME);
1903 // Last inserted entry is a file name.
1904 // Some users prefer to also list file name without extension.
1905 if (CRegDWORD(L"Software\\TortoiseGit\\AutocompleteRemovesExtensions", FALSE))
1907 int dotPos = sPartPath.ReverseFind('.');
1908 if ((dotPos >= 0) && (dotPos > lastPos))
1909 autolist.emplace(sPartPath.Mid(lastPos, dotPos - lastPos), AUTOCOMPLETE_FILENAME);
1912 if (action == CTGitPath::LOGACTIONS_UNVER && !CRegDWORD(L"Software\\TortoiseGit\\AutocompleteParseUnversioned", FALSE))
1913 continue;
1914 if (action == CTGitPath::LOGACTIONS_IGNORE)
1915 continue;
1917 sExt.MakeLower();
1918 // find the regex string which corresponds to the file extension
1919 CString rdata = mapRegex[sExt];
1920 if (rdata.IsEmpty())
1921 continue;
1923 ScanFile(autolist, sWinPath, rdata, sExt);
1925 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Auto completion list loaded in %I64u msec\n", GetTickCount64() - starttime);
1928 void CCommitDlg::ScanFile(std::map<CString, int>& autolist, const CString& sFilePath, const CString& sRegex, const CString& sExt)
1930 static std::map<CString, std::wregex> regexmap;
1932 std::wstring sFileContent;
1933 CAutoFile hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
1934 if (hFile)
1936 DWORD size = GetFileSize(hFile, nullptr);
1937 if (size > CRegDWORD(L"Software\\TortoiseGit\\AutocompleteParseMaxSize", 300000L))
1939 // no files bigger than 300k
1940 return;
1942 // allocate memory to hold file contents
1943 CBuffer oFile;
1946 oFile.SetLength(size);
1948 catch (CMemoryException*)
1950 return;
1952 DWORD readbytes;
1953 if (!ReadFile(hFile, oFile, size, &readbytes, nullptr))
1954 return;
1955 oFile.SetLength(readbytes);
1956 CFileTextLines filetextlines;
1957 CFileTextLines::UnicodeType type = filetextlines.CheckUnicodeType(oFile, readbytes);
1960 CBaseFilter* pFilter = nullptr;
1961 switch (type)
1963 case CFileTextLines::BINARY:
1964 return;
1965 case CFileTextLines::UTF8:
1966 case CFileTextLines::UTF8BOM:
1967 pFilter = new CUtf8Filter(NULL);
1968 break;
1969 default:
1970 case CFileTextLines::ASCII:
1971 pFilter = new CAsciiFilter(NULL);
1972 break;
1973 case CFileTextLines::UTF16_BE:
1974 case CFileTextLines::UTF16_BEBOM:
1975 pFilter = new CUtf16beFilter(NULL);
1976 break;
1977 case CFileTextLines::UTF16_LE:
1978 case CFileTextLines::UTF16_LEBOM:
1979 pFilter = new CUtf16leFilter(NULL);
1980 break;
1981 case CFileTextLines::UTF32_BE:
1982 pFilter = new CUtf32beFilter(NULL);
1983 break;
1984 case CFileTextLines::UTF32_LE:
1985 pFilter = new CUtf32leFilter(NULL);
1986 break;
1988 pFilter->Decode(oFile);
1989 delete pFilter;
1991 catch (CMemoryException*)
1993 return;
1995 sFileContent = std::wstring((wchar_t*)oFile, oFile.GetLength() / sizeof(wchar_t));
1997 if (sFileContent.empty() || !m_bRunThread)
1998 return;
2002 std::wregex regCheck;
2003 std::map<CString, std::wregex>::const_iterator regIt;
2004 if ((regIt = regexmap.find(sExt)) != regexmap.end())
2005 regCheck = regIt->second;
2006 else
2008 regCheck = std::wregex(sRegex, std::regex_constants::icase | std::regex_constants::ECMAScript);
2009 regexmap[sExt] = regCheck;
2011 const std::wsregex_iterator end;
2012 for (std::wsregex_iterator it(sFileContent.cbegin(), sFileContent.cend(), regCheck); it != end; ++it)
2014 const std::wsmatch match = *it;
2015 for (size_t i = 1; i < match.size(); ++i)
2017 if (match[i].second-match[i].first)
2018 autolist.emplace(std::wstring(match[i]).c_str(), AUTOCOMPLETE_PROGRAMCODE);
2022 catch (std::exception&) {}
2025 // CSciEditContextMenuInterface
2026 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
2028 CString sMenuItemText;
2029 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITHASH);
2030 m_nPopupPickCommitHash = nCmd++;
2031 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPickCommitHash, sMenuItemText);
2033 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITMESSAGE);
2034 m_nPopupPickCommitMessage = nCmd++;
2035 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPickCommitMessage, sMenuItemText);
2037 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTEFILELIST);
2038 m_nPopupPasteListCmd = nCmd++;
2039 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
2041 ReloadHistoryEntries();
2042 if (!m_History.IsEmpty())
2044 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
2045 m_nPopupPasteLastMessage = nCmd++;
2046 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
2048 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
2049 m_nPopupRecentMessage = nCmd++;
2050 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
2054 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
2056 if (cmd == m_nPopupPickCommitHash)
2058 // use the git log to allow selection of a version
2059 CLogDlg dlg;
2060 // tell the dialog to use mode for selecting revisions
2061 dlg.SetSelect(true);
2062 // only one revision must be selected however
2063 dlg.SingleSelection(true);
2064 dlg.ShowWorkingTreeChanges(false);
2065 if (dlg.DoModal() == IDOK && !dlg.GetSelectedHash().empty())
2066 pSciEdit->InsertText(dlg.GetSelectedHash().at(0).ToString());
2067 return true;
2070 if (cmd == m_nPopupPickCommitMessage)
2072 // use the git log to allow selection of a version
2073 CLogDlg dlg;
2074 // tell the dialog to use mode for selecting revisions
2075 dlg.SetSelect(true);
2076 // only one revision must be selected however
2077 dlg.SingleSelection(true);
2078 dlg.ShowWorkingTreeChanges(false);
2079 if (dlg.DoModal() == IDOK && !dlg.GetSelectedHash().empty())
2081 GitRev rev;
2082 if (rev.GetCommit(dlg.GetSelectedHash().at(0).ToString()))
2084 MessageBox(rev.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2085 return false;
2087 CString message = rev.GetSubject() + L"\r\n" + rev.GetBody();
2088 pSciEdit->InsertText(message);
2090 return true;
2093 if (cmd == m_nPopupPasteListCmd)
2095 CString logmsg;
2096 auto locker(m_ListCtrl.AcquireReadLock());
2097 int nListItems = m_ListCtrl.GetItemCount();
2098 for (int i=0; i<nListItems; ++i)
2100 auto entry = m_ListCtrl.GetListEntry(i);
2101 if (entry&&entry->m_Checked)
2103 CString status = entry->GetActionName();
2104 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
2105 status = L"Add"; // I18N TODO
2107 //git_wc_status_kind status = entry->status;
2108 WORD langID = (WORD)CRegStdDWORD(L"Software\\TortoiseGit\\LanguageID", GetUserDefaultLangID());
2109 if (m_ProjectProperties.bFileListInEnglish)
2110 langID = 1033;
2112 logmsg.AppendFormat(L"%-10s %s\r\n", (LPCTSTR)status, (LPCTSTR)m_ListCtrl.GetItemText(i, 0));
2115 pSciEdit->InsertText(logmsg);
2116 return true;
2119 if(cmd == m_nPopupPasteLastMessage)
2121 if (m_History.IsEmpty())
2122 return false;
2124 CString logmsg;
2125 logmsg +=m_History.GetEntry(0);
2126 pSciEdit->InsertText(logmsg);
2127 return true;
2130 if(cmd == m_nPopupRecentMessage )
2132 OnBnClickedHistory();
2133 return true;
2135 return false;
2138 void CCommitDlg::HandleSnippet(int type, const CString &text, CSciEdit *pSciEdit)
2140 if (type == AUTOCOMPLETE_SNIPPET)
2142 CString target = m_snippet[text];
2143 pSciEdit->GetWordUnderCursor(true);
2144 pSciEdit->InsertText(target, false);
2148 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
2150 switch (nIDEvent)
2152 case ENDDIALOGTIMER:
2153 KillTimer(ENDDIALOGTIMER);
2154 EndDialog(0);
2155 break;
2156 case REFRESHTIMER:
2157 if (m_bThreadRunning)
2159 SetTimer(REFRESHTIMER, 200, nullptr);
2160 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Wait some more before refreshing\n");
2162 else
2164 KillTimer(REFRESHTIMER);
2165 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Refreshing after items dropped\n");
2166 Refresh();
2168 break;
2169 case FILLPATCHVTIMER:
2170 FillPatchView();
2171 break;
2173 __super::OnTimer(nIDEvent);
2176 void CCommitDlg::OnBnClickedHistory()
2178 m_tooltips.Pop(); // hide the tooltips
2179 if (m_pathList.IsEmpty())
2180 return;
2182 CHistoryDlg historyDlg;
2183 ReloadHistoryEntries();
2184 historyDlg.SetHistory(m_History);
2185 if (historyDlg.DoModal() != IDOK)
2186 return;
2188 CString sMsg = historyDlg.GetSelectedText();
2189 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
2191 CString sBugID = m_ProjectProperties.FindBugID(sMsg);
2192 if ((!sBugID.IsEmpty()) && ((GetDlgItem(IDC_BUGID)->IsWindowVisible())))
2193 SetDlgItemText(IDC_BUGID, sBugID);
2194 if (m_sLogTemplate.Compare(m_cLogMessage.GetText()) != 0)
2195 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
2196 else
2197 m_cLogMessage.SetText(sMsg);
2200 SendMessage(WM_UPDATEOKBUTTON);
2201 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2204 void CCommitDlg::OnBnClickedBugtraqbutton()
2206 m_tooltips.Pop(); // hide the tooltips
2207 CString sMsg = m_cLogMessage.GetText();
2209 if (!m_BugTraqProvider)
2210 return;
2212 ATL::CComBSTR parameters(m_bugtraq_association.GetParameters());
2213 ATL::CComBSTR commonRoot(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
2214 CBstrSafeVector pathList(m_pathList.GetCount());
2216 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
2217 pathList.PutElement(index, m_pathList[index].GetGitPathString());
2219 ATL::CComBSTR originalMessage(sMsg);
2220 ATL::CComBSTR temp;
2222 // first try the IBugTraqProvider2 interface
2223 CComPtr<IBugTraqProvider2> pProvider2;
2224 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
2225 bool bugIdOutSet = false;
2226 if (SUCCEEDED(hr))
2228 ATL::CComBSTR repositoryRoot(g_Git.m_CurrentDir);
2229 ATL::CComBSTR bugIDOut;
2230 GetDlgItemText(IDC_BUGID, m_sBugID);
2231 ATL::CComBSTR bugID(m_sBugID);
2232 CBstrSafeVector revPropNames;
2233 CBstrSafeVector revPropValues;
2234 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
2236 CString sErr;
2237 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2238 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
2240 else
2242 if (bugIDOut)
2244 bugIdOutSet = true;
2245 m_sBugID = bugIDOut;
2246 SetDlgItemText(IDC_BUGID, m_sBugID);
2248 m_cLogMessage.SetText((LPCTSTR)temp);
2251 else
2253 // if IBugTraqProvider2 failed, try IBugTraqProvider
2254 CComPtr<IBugTraqProvider> pProvider;
2255 hr = m_BugTraqProvider.QueryInterface(&pProvider);
2256 if (FAILED(hr))
2258 CString sErr;
2259 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2260 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
2261 return;
2264 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
2266 CString sErr;
2267 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2268 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
2270 else
2271 m_cLogMessage.SetText((LPCTSTR)temp);
2273 m_sLogMessage = m_cLogMessage.GetText();
2274 if (!m_ProjectProperties.sMessage.IsEmpty())
2276 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
2277 if (!sBugID.IsEmpty() && !bugIdOutSet)
2278 SetDlgItemText(IDC_BUGID, sBugID);
2281 m_cLogMessage.SetFocus();
2284 void CCommitDlg::FillPatchView(bool onlySetTimer)
2286 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2288 KillTimer(FILLPATCHVTIMER);
2289 if (onlySetTimer)
2291 SetTimer(FILLPATCHVTIMER, 100, nullptr);
2292 return;
2295 auto locker(m_ListCtrl.AcquireReadWeakLock(50));
2296 if (!locker.IsAcquired())
2298 SetTimer(FILLPATCHVTIMER, 100, nullptr);
2299 return;
2301 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
2302 CString cmd,out;
2304 while(pos)
2306 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
2307 auto p = m_ListCtrl.GetListEntry(nSelect);
2308 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
2310 CString head = L"HEAD";
2311 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
2312 head = L"HEAD~1";
2313 cmd.Format(L"git.exe diff %s -- \"%s\"", (LPCTSTR)head, (LPCTSTR)p->GetGitPathString());
2314 g_Git.Run(cmd, &out, CP_UTF8);
2318 m_patchViewdlg.SetText(out);
2321 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
2323 this->FillPatchView(true);
2324 return 0;
2328 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
2330 SendMessage(WM_UPDATEOKBUTTON);
2331 return 0;
2334 LRESULT CCommitDlg::OnCheck(WPARAM wnd, LPARAM)
2336 HWND hwnd = (HWND)wnd;
2337 bool check = !(GetAsyncKeyState(VK_SHIFT) & 0x8000);
2338 if (hwnd == GetDlgItem(IDC_CHECKALL)->GetSafeHwnd())
2339 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, check);
2340 else if (hwnd == GetDlgItem(IDC_CHECKNONE)->GetSafeHwnd())
2341 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, !check);
2342 else if (hwnd == GetDlgItem(IDC_CHECKUNVERSIONED)->GetSafeHwnd())
2343 m_ListCtrl.Check(GITSLC_SHOWUNVERSIONED, check);
2344 else if (hwnd == GetDlgItem(IDC_CHECKVERSIONED)->GetSafeHwnd())
2345 m_ListCtrl.Check(GITSLC_SHOWVERSIONED, check);
2346 else if (hwnd == GetDlgItem(IDC_CHECKADDED)->GetSafeHwnd())
2347 m_ListCtrl.Check(GITSLC_SHOWADDED, check);
2348 else if (hwnd == GetDlgItem(IDC_CHECKDELETED)->GetSafeHwnd())
2349 m_ListCtrl.Check(GITSLC_SHOWREMOVED, check);
2350 else if (hwnd == GetDlgItem(IDC_CHECKMODIFIED)->GetSafeHwnd())
2351 m_ListCtrl.Check(GITSLC_SHOWMODIFIED, check);
2352 else if (hwnd == GetDlgItem(IDC_CHECKFILES)->GetSafeHwnd())
2353 m_ListCtrl.Check(GITSLC_SHOWFILES, check);
2354 else if (hwnd == GetDlgItem(IDC_CHECKSUBMODULES)->GetSafeHwnd())
2355 m_ListCtrl.Check(GITSLC_SHOWSUBMODULES, check);
2357 return 0;
2360 LRESULT CCommitDlg::OnUpdateOKButton(WPARAM, LPARAM)
2362 if (m_bBlock)
2363 return 0;
2365 CString text = m_cLogMessage.GetText().Trim();
2366 bool bValidLogSize = !text.IsEmpty() && text.GetLength() >= m_ProjectProperties.nMinLogSize;
2367 bool bAmendOrSelectFilesOrMerge = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit) || CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
2369 DialogEnableWindow(IDOK, bValidLogSize && (m_bCommitMessageOnly || bAmendOrSelectFilesOrMerge));
2371 return 0;
2374 LRESULT CCommitDlg::OnUpdateDataFalse(WPARAM, LPARAM)
2376 UpdateData(FALSE);
2377 return 0;
2380 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
2382 switch (message) {
2383 case WM_NOTIFY:
2384 if (wParam == IDC_SPLITTER)
2386 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2387 DoSize(pHdr->delta);
2389 break;
2390 case WM_COMMAND:
2391 if (m_hAccelOkButton && LOWORD(wParam) >= WM_USER && LOWORD(wParam) <= WM_USER + m_accellerators.size())
2393 for (const auto& entry : m_accellerators)
2395 if (entry.second.wmid != LOWORD(wParam))
2396 continue;
2397 if (entry.second.id == -1)
2398 m_ctrlOkButton.PostMessage(WM_KEYDOWN, VK_F4, NULL);
2399 else
2401 m_ctrlOkButton.SetCurrentEntry(entry.second.id);
2402 OnOK();
2404 return 0;
2407 break;
2410 return __super::DefWindowProc(message, wParam, lParam);
2413 void CCommitDlg::SetSplitterRange()
2415 if ((m_ListCtrl)&&(m_cLogMessage))
2417 CRect rcTop;
2418 m_cLogMessage.GetWindowRect(rcTop);
2419 ScreenToClient(rcTop);
2420 CRect rcMiddle;
2421 m_ListCtrl.GetWindowRect(rcMiddle);
2422 ScreenToClient(rcMiddle);
2423 if (rcMiddle.Height() && rcMiddle.Width())
2424 m_wndSplitter.SetRange(rcTop.top + 100, rcMiddle.bottom - 80);
2428 void CCommitDlg::DoSize(int delta)
2430 RemoveAnchor(IDC_MESSAGEGROUP);
2431 RemoveAnchor(IDC_LOGMESSAGE);
2432 RemoveAnchor(IDC_SPLITTER);
2433 RemoveAnchor(IDC_SIGNOFF);
2434 RemoveAnchor(IDC_COMMIT_AMEND);
2435 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
2436 RemoveAnchor(IDC_COMMIT_SETDATETIME);
2437 RemoveAnchor(IDC_COMMIT_DATEPICKER);
2438 RemoveAnchor(IDC_COMMIT_TIMEPICKER);
2439 RemoveAnchor(IDC_COMMIT_AS_COMMIT_DATE);
2440 RemoveAnchor(IDC_COMMIT_SETAUTHOR);
2441 RemoveAnchor(IDC_COMMIT_AUTHORDATA);
2442 RemoveAnchor(IDC_LISTGROUP);
2443 RemoveAnchor(IDC_FILELIST);
2444 RemoveAnchor(IDC_TEXT_INFO);
2445 RemoveAnchor(IDC_SELECTLABEL);
2446 RemoveAnchor(IDC_CHECKALL);
2447 RemoveAnchor(IDC_CHECKNONE);
2448 RemoveAnchor(IDC_CHECKUNVERSIONED);
2449 RemoveAnchor(IDC_CHECKVERSIONED);
2450 RemoveAnchor(IDC_CHECKADDED);
2451 RemoveAnchor(IDC_CHECKDELETED);
2452 RemoveAnchor(IDC_CHECKMODIFIED);
2453 RemoveAnchor(IDC_CHECKFILES);
2454 RemoveAnchor(IDC_CHECKSUBMODULES);
2456 auto hdwp = BeginDeferWindowPos(24);
2457 CSplitterControl::ChangeRect(hdwp, &m_cLogMessage, 0, 0, 0, delta);
2458 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_MESSAGEGROUP), 0, 0, 0, delta);
2459 CSplitterControl::ChangeRect(hdwp, &m_ListCtrl, 0, delta, 0, 0);
2460 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_LISTGROUP), 0, delta, 0, 0);
2461 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_SIGNOFF), 0, delta, 0, delta);
2462 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_AMEND), 0, delta, 0, delta);
2463 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_AMENDDIFF), 0, delta, 0, delta);
2464 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_SETDATETIME), 0, delta, 0, delta);
2465 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_DATEPICKER), 0, delta, 0, delta);
2466 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_TIMEPICKER), 0, delta, 0, delta);
2467 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_AS_COMMIT_DATE), 0, delta, 0, delta);
2468 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_SETAUTHOR), 0, delta, 0, delta);
2469 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_COMMIT_AUTHORDATA), 0, delta, 0, delta);
2470 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_TEXT_INFO), 0, delta, 0, delta);
2471 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_SELECTLABEL), 0, delta, 0, delta);
2472 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKALL), 0, delta, 0, delta);
2473 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKNONE), 0, delta, 0, delta);
2474 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKUNVERSIONED), 0, delta, 0, delta);
2475 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKVERSIONED), 0, delta, 0, delta);
2476 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKADDED), 0, delta, 0, delta);
2477 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKDELETED), 0, delta, 0, delta);
2478 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKMODIFIED), 0, delta, 0, delta);
2479 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKFILES), 0, delta, 0, delta);
2480 CSplitterControl::ChangeRect(hdwp, GetDlgItem(IDC_CHECKSUBMODULES), 0, delta, 0, delta);
2481 EndDeferWindowPos(hdwp);
2483 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
2484 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
2485 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
2486 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
2487 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
2488 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
2489 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
2490 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
2491 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
2492 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
2493 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
2494 AddAnchor(IDC_COMMIT_AS_COMMIT_DATE, TOP_LEFT);
2495 AddAnchor(IDC_COMMIT_SETAUTHOR, TOP_LEFT);
2496 AddAnchor(IDC_COMMIT_AUTHORDATA, TOP_LEFT, TOP_RIGHT);
2497 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
2498 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
2499 AddAnchor(IDC_CHECKALL, TOP_LEFT);
2500 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
2501 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
2502 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
2503 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
2504 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
2505 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
2506 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
2507 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
2508 ArrangeLayout();
2509 // adjust the minimum size of the dialog to prevent the resizing from
2510 // moving the list control too far down.
2511 CRect rcLogMsg;
2512 m_cLogMessage.GetClientRect(rcLogMsg);
2513 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
2515 SetSplitterRange();
2516 m_cLogMessage.Invalidate();
2517 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
2520 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
2522 // first, let the resizing take place
2523 __super::OnSize(nType, cx, cy);
2525 //set range
2526 SetSplitterRange();
2529 CString CCommitDlg::GetSignedOffByLine()
2531 CString str;
2533 CString username = g_Git.GetUserName();
2534 CString email = g_Git.GetUserEmail();
2535 username.Remove(L'\n');
2536 email.Remove(L'\n');
2538 str.Format(L"Signed-off-by: %s <%s>", (LPCTSTR)username, (LPCTSTR)email);
2540 return str;
2543 void CCommitDlg::OnBnClickedSignOff()
2545 CString str = GetSignedOffByLine();
2547 if (m_cLogMessage.GetText().Find(str) == -1) {
2548 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
2549 int lastNewline = m_cLogMessage.GetText().ReverseFind(L'\n');
2550 int foundByLine = -1;
2551 if (lastNewline > 0)
2552 foundByLine = m_cLogMessage.GetText().Find(L"-by: ", lastNewline);
2554 if (foundByLine == -1 || foundByLine < lastNewline)
2555 str = L"\r\n" + str;
2557 m_cLogMessage.SetText(m_cLogMessage.GetText() + L"\r\n" + str + L"\r\n");
2561 void CCommitDlg::OnBnClickedCommitAmend()
2563 this->UpdateData();
2564 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
2566 GitRev rev;
2567 if (rev.GetCommit(L"HEAD"))
2568 MessageBox(rev.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2569 m_AmendStr = rev.GetSubject() + L'\n' + rev.GetBody();
2572 if(this->m_bCommitAmend)
2574 this->m_NoAmendStr=this->m_cLogMessage.GetText();
2575 m_cLogMessage.SetText(m_AmendStr);
2576 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
2577 if (m_bSetCommitDateTime)
2578 m_AsCommitDateCtrl.ShowWindow(SW_SHOW);
2580 else
2582 this->m_AmendStr=this->m_cLogMessage.GetText();
2583 m_cLogMessage.SetText(m_NoAmendStr);
2584 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
2585 m_AsCommitDateCtrl.ShowWindow(SW_HIDE);
2586 m_AsCommitDateCtrl.SetCheck(FALSE);
2587 OnBnClickedCommitAsCommitDate();
2590 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2591 OnBnClickedCommitSetauthor(); // to update the commit author
2593 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2594 Refresh();
2597 void CCommitDlg::OnBnClickedCommitMessageOnly()
2599 this->UpdateData();
2600 this->m_ListCtrl.EnableWindow(m_bCommitMessageOnly ? FALSE : TRUE);
2601 SendMessage(WM_UPDATEOKBUTTON);
2604 void CCommitDlg::OnBnClickedWholeProject()
2606 m_tooltips.Pop(); // hide the tooltips
2607 UpdateData();
2608 m_ListCtrl.Clear();
2609 if (!m_bBlock)
2611 if (m_bWholeProject || m_bWholeProject2)
2612 m_ListCtrl.GetStatus(nullptr, true, false, true);
2613 else
2614 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
2616 m_regShowWholeProject = m_bWholeProject;
2618 DWORD dwShow = m_ListCtrl.GetShowFlags();
2619 if (DWORD(m_regAddBeforeCommit))
2620 dwShow |= GITSLC_SHOWUNVERSIONED;
2621 else
2622 dwShow &= ~GITSLC_SHOWUNVERSIONED;
2624 m_ListCtrl.StoreScrollPos();
2625 m_ListCtrl.Show(dwShow, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
2626 UpdateCheckLinks();
2629 SetDlgTitle();
2632 void CCommitDlg::OnFocusMessage()
2634 m_cLogMessage.SetFocus();
2637 void CCommitDlg::OnFocusFileList()
2639 m_ListCtrl.SetFocus();
2642 void CCommitDlg::OnScnUpdateUI(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2644 int pos = (int)this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
2645 int line = (int)this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
2646 int column = (int)this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
2648 CString str;
2649 str.Format(L"%d/%d", line + 1, column + 1);
2650 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
2652 if(*pResult)
2653 *pResult=0;
2656 void CCommitDlg::TogglePatchView()
2658 OnStnClickedViewPatch();
2661 void CCommitDlg::OnStnClickedViewPatch()
2663 m_patchViewdlg.m_ParentDlg = this;
2664 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
2666 BOOL viewPatchEnabled = FALSE;
2667 viewPatchEnabled = g_Git.GetConfigValueBool(L"tgit.commitshowpatch");
2668 if (viewPatchEnabled == FALSE)
2669 g_Git.SetConfigValue(L"tgit.commitshowpatch", L"true");
2670 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
2671 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2672 CRect rect;
2673 this->GetWindowRect(&rect);
2675 m_patchViewdlg.ShowWindow(SW_SHOW);
2677 m_patchViewdlg.SetWindowPos(nullptr, rect.right, rect.top, (DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\TortoiseProc\\PatchDlgWidth", rect.Width()), rect.Height(),
2678 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
2680 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2682 ShowViewPatchText(false);
2683 FillPatchView();
2685 else
2687 g_Git.SetConfigValue(L"tgit.commitshowpatch", L"false");
2688 m_patchViewdlg.ShowWindow(SW_HIDE);
2689 m_patchViewdlg.DestroyWindow();
2690 ShowViewPatchText(true);
2692 this->m_ctrlShowPatch.Invalidate();
2695 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
2697 __super::OnMoving(fwSide, pRect);
2699 if (::IsWindow(m_patchViewdlg.m_hWnd))
2701 RECT patchrect;
2702 m_patchViewdlg.GetWindowRect(&patchrect);
2703 if (::IsWindow(m_hWnd))
2705 RECT thisrect;
2706 GetWindowRect(&thisrect);
2707 if (patchrect.left == thisrect.right)
2709 m_patchViewdlg.SetWindowPos(nullptr, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2710 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2716 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2718 __super::OnSizing(fwSide, pRect);
2720 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2722 CRect thisrect, patchrect;
2723 this->GetWindowRect(thisrect);
2724 this->m_patchViewdlg.GetWindowRect(patchrect);
2725 if(thisrect.right==patchrect.left)
2727 patchrect.left -= (thisrect.right - pRect->right);
2728 patchrect.right-= (thisrect.right - pRect->right);
2730 if( patchrect.bottom == thisrect.bottom)
2731 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2732 if( patchrect.top == thisrect.top)
2733 patchrect.top -= thisrect.top-pRect->top;
2734 m_patchViewdlg.MoveWindow(patchrect);
2739 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2741 *pResult = 0;
2742 TRACE("Item Changed\r\n");
2745 int CCommitDlg::CheckHeadDetach()
2747 CString output;
2748 if (CGit::GetCurrentBranchFromFile(g_Git.m_CurrentDir, output))
2750 int retval = CMessageBox::Show(GetSafeHwnd(), IDS_PROC_COMMIT_DETACHEDWARNING, IDS_APPNAME, MB_YESNOCANCEL | MB_ICONWARNING);
2751 if(retval == IDYES)
2753 if (CAppUtils::CreateBranchTag(FALSE, nullptr, true) == FALSE)
2754 return 1;
2756 else if (retval == IDCANCEL)
2757 return 1;
2759 return 0;
2762 void CCommitDlg::OnBnClickedCommitAmenddiff()
2764 UpdateData();
2765 Refresh();
2768 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2770 UpdateData();
2771 Refresh();
2774 void CCommitDlg::OnBnClickedCommitSetDateTime()
2776 UpdateData();
2778 if (m_bSetCommitDateTime)
2780 CTime authordate = CTime::GetCurrentTime();
2781 if (m_bCommitAmend)
2783 GitRev headRevision;
2784 if (headRevision.GetCommit(L"HEAD"))
2785 MessageBox(headRevision.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2786 authordate = headRevision.GetAuthorDate();
2787 m_AsCommitDateCtrl.ShowWindow(SW_SHOW);
2790 m_CommitDate.SetTime(&authordate);
2791 m_CommitTime.SetTime(&authordate);
2793 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
2794 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
2796 else
2798 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_HIDE);
2799 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_HIDE);
2800 m_AsCommitDateCtrl.ShowWindow(SW_HIDE);
2801 m_AsCommitDateCtrl.SetCheck(FALSE);
2802 OnBnClickedCommitAsCommitDate();
2806 void CCommitDlg::OnBnClickedCommitAsCommitDate()
2808 GetDlgItem(IDC_COMMIT_DATEPICKER)->EnableWindow(!m_AsCommitDateCtrl.GetCheck());
2809 GetDlgItem(IDC_COMMIT_TIMEPICKER)->EnableWindow(!m_AsCommitDateCtrl.GetCheck());
2812 void CCommitDlg::OnBnClickedCheckNewBranch()
2814 UpdateData();
2815 if (m_bCreateNewBranch)
2817 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_HIDE);
2818 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_SHOW);
2820 else
2822 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
2823 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);
2827 bool CCommitDlg::RestoreFiles(bool doNotAsk, bool allowCancel)
2829 if (m_ListCtrl.m_restorepaths.empty())
2830 return true;
2832 if (!doNotAsk)
2834 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);
2835 if (ret == 3)
2836 return false;
2837 if (ret == 2)
2838 return true;
2841 for (const auto& item : m_ListCtrl.m_restorepaths)
2842 CopyFile(item.second, g_Git.CombinePath(item.first), FALSE);
2843 m_ListCtrl.m_restorepaths.clear();
2845 return true;
2848 void CCommitDlg::UpdateCheckLinks()
2850 DialogEnableWindow(IDC_CHECKALL, true);
2851 DialogEnableWindow(IDC_CHECKNONE, true);
2852 DialogEnableWindow(IDC_CHECKUNVERSIONED, m_ListCtrl.GetUnversionedCount() > 0);
2853 DialogEnableWindow(IDC_CHECKVERSIONED, m_ListCtrl.GetItemCount() > m_ListCtrl.GetUnversionedCount());
2854 DialogEnableWindow(IDC_CHECKADDED, m_ListCtrl.GetAddedCount() > 0);
2855 DialogEnableWindow(IDC_CHECKDELETED, m_ListCtrl.GetDeletedCount() > 0);
2856 DialogEnableWindow(IDC_CHECKMODIFIED, m_ListCtrl.GetModifiedCount() > 0);
2857 DialogEnableWindow(IDC_CHECKFILES, m_ListCtrl.GetFileCount() > 0);
2858 DialogEnableWindow(IDC_CHECKSUBMODULES, m_ListCtrl.GetSubmoduleCount() > 0);
2861 void CCommitDlg::OnBnClickedCommitSetauthor()
2863 UpdateData();
2865 if (m_bSetAuthor)
2867 m_sAuthor.Format(L"%s <%s>", (LPCTSTR)g_Git.GetUserName(), (LPCTSTR)g_Git.GetUserEmail());
2868 if (m_bCommitAmend)
2870 GitRev headRevision;
2871 if (headRevision.GetCommit(L"HEAD"))
2872 MessageBox(headRevision.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2873 m_sAuthor.Format(L"%s <%s>", (LPCTSTR)headRevision.GetAuthorName(), (LPCTSTR)headRevision.GetAuthorEmail());
2876 UpdateData(FALSE);
2878 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_SHOW);
2880 else
2881 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_HIDE);
2884 bool CCommitDlg::RunStartCommitHook()
2886 DWORD exitcode = 0xFFFFFFFF;
2887 CString error;
2888 if (CHooks::Instance().StartCommit(g_Git.m_CurrentDir, m_pathList, m_sLogMessage, exitcode, error))
2890 if (exitcode)
2892 CString temp;
2893 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2894 MessageBox(temp, L"TortoiseGit", MB_ICONERROR);
2895 return false;
2898 return true;
2901 void CCommitDlg::OnSysColorChange()
2903 __super::OnSysColorChange();
2904 m_cLogMessage.SetColors(true);
2905 m_cLogMessage.SetFont(CAppUtils::GetLogFontName(), CAppUtils::GetLogFontSize());