SyncDlg: Disallow in/out changes to include local context menu
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob7d2b96e192a11c2e9b441c96152329268708a876
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2014 - TortoiseSVN
4 // Copyright (C) 2008-2017 - 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::GetAdminDirPath(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);
444 SetSplitterRange();
446 if (m_bForceCommitAmend || m_bCommitAmend)
447 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
449 // add all directories to the watcher
451 for (int i=0; i<m_pathList.GetCount(); ++i)
453 if (m_pathList[i].IsDirectory())
454 m_pathwatcher.AddPath(m_pathList[i]);
457 m_updatedPathList = m_pathList;
459 StartStatusThread();
460 CRegDWORD err = CRegDWORD(L"Software\\TortoiseGit\\ErrorOccurred", FALSE);
461 CRegDWORD historyhint = CRegDWORD(L"Software\\TortoiseGit\\HistoryHintShown", FALSE);
462 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
464 historyhint = TRUE;
465 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
467 err = FALSE;
469 this->m_ctrlShowPatch.SetURL(CString());
471 if (g_Git.GetConfigValueBool(L"tgit.commitshowpatch"))
472 OnStnClickedViewPatch();
474 if (CTGitPath(g_Git.m_CurrentDir).IsMergeActive())
476 DialogEnableWindow(IDC_CHECK_NEWBRANCH, FALSE);
477 m_bCreateNewBranch = FALSE;
478 GetDlgItem(IDC_MERGEACTIVE)->ShowWindow(SW_SHOW);
479 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_COMMIT_MERGE_HINT, IDS_APPNAME, MB_ICONINFORMATION, L"CommitMergeHint", IDS_MSGBOX_DONOTSHOWAGAIN);
482 PrepareOkButton();
484 return FALSE; // return TRUE unless you set the focus to a control
485 // EXCEPTION: OCX Property Pages should return FALSE
488 void CCommitDlg::PrepareOkButton()
490 if (m_bNoPostActions)
491 return;
492 m_regLastAction = CRegDWORD(L"Software\\TortoiseGit\\CommitLastAction", 0);
493 int i = 0;
494 for (auto labelId : { IDS_COMMIT_COMMIT, IDS_COMMIT_RECOMMIT, IDS_COMMIT_COMMITPUSH })
496 ++i;
497 CString label;
498 label.LoadString(labelId);
499 m_ctrlOkButton.AddEntry(label);
500 TCHAR accellerator = CStringUtils::GetAccellerator(label);
501 if (accellerator == L'\0')
502 continue;
503 ++m_accellerators[accellerator].cnt;
504 if (m_accellerators[accellerator].cnt > 1)
505 m_accellerators[accellerator].id = -1;
506 else
507 m_accellerators[accellerator].id = i - 1;
509 m_ctrlOkButton.SetCurrentEntry(m_regLastAction);
510 if (m_accellerators.size())
512 LPACCEL lpaccelNew = (LPACCEL)LocalAlloc(LPTR, m_accellerators.size() * sizeof(ACCEL));
513 if (!lpaccelNew)
514 return;
515 SCOPE_EXIT{ LocalFree(lpaccelNew); };
516 i = 0;
517 for (auto& entry : m_accellerators)
519 lpaccelNew[i].cmd = (WORD)(WM_USER + 1 + entry.second.id);
520 lpaccelNew[i].fVirt = FVIRTKEY | FALT;
521 lpaccelNew[i].key = entry.first;
522 entry.second.wmid = lpaccelNew[i].cmd;
523 ++i;
525 m_hAccelOkButton = CreateAcceleratorTable(lpaccelNew, (int)m_accellerators.size());
529 static bool UpdateIndex(CMassiveGitTask &mgt, CSysProgressDlg &sysProgressDlg, int progress, int maxProgress)
531 if (mgt.IsListEmpty())
532 return true;
534 if (sysProgressDlg.HasUserCancelled())
535 return false;
537 if (sysProgressDlg.IsVisible())
539 sysProgressDlg.SetTitle(IDS_APPNAME);
540 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
541 sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
542 sysProgressDlg.SetProgress(progress, maxProgress);
543 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing
546 BOOL cancel = FALSE;
547 return mgt.Execute(cancel);
550 static void DoPush()
552 CString head;
553 if (g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir, head))
554 return;
555 CString remote, remotebranch;
556 g_Git.GetRemotePushBranch(head, remote, remotebranch);
557 if (remote.IsEmpty() || remotebranch.IsEmpty())
559 CAppUtils::Push();
560 return;
563 CAppUtils::DoPush(CAppUtils::IsSSHPutty(), false, false, false, false, false, false, head, remote, remotebranch, false, 0);
566 void CCommitDlg::OnOK()
568 if (m_bBlock)
569 return;
570 if (m_bThreadRunning)
572 m_bCancelled = true;
573 StopStatusThread();
575 this->UpdateData();
577 if (m_ListCtrl.GetConflictedCount() != 0 && CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROGRS_CONFLICTSOCCURED, IDS_APPNAME, 1, IDI_EXCLAMATION, IDS_OKBUTTON, IDS_IGNOREBUTTON, 0, L"CommitWarnOnUnresolved") == 1)
579 auto pos = m_ListCtrl.GetFirstSelectedItemPosition();
580 while (pos)
581 m_ListCtrl.SetItemState(m_ListCtrl.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
582 int nListItems = m_ListCtrl.GetItemCount();
583 for (int i = 0; i < nListItems; ++i)
585 auto entry = m_ListCtrl.GetListEntry(i);
586 if (entry->m_Action & CTGitPath::LOGACTIONS_UNMERGED)
588 m_ListCtrl.EnsureVisible(i, FALSE);
589 m_ListCtrl.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
590 m_ListCtrl.SetFocus();
591 return;
594 return;
597 if (m_bCreateNewBranch)
599 if (!g_Git.IsBranchNameValid(m_sCreateNewBranch))
601 ShowEditBalloon(IDC_NEWBRANCH, IDS_B_T_NOTEMPTY, IDS_ERR_ERROR, TTI_ERROR);
602 return;
604 if (g_Git.BranchTagExists(m_sCreateNewBranch))
606 // branch already exists
607 CString msg;
608 msg.LoadString(IDS_B_EXISTS);
609 msg += L' ' + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME));
610 ShowEditBalloon(IDC_NEWBRANCH, msg, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
611 return;
613 if (g_Git.BranchTagExists(m_sCreateNewBranch, false))
615 // tag with the same name exists -> shortref is ambiguous
616 if (CMessageBox::Show(m_hWnd, IDS_B_SAMETAGNAMEEXISTS, IDS_APPNAME, 2, IDI_EXCLAMATION, IDS_CONTINUEBUTTON, IDS_ABORTBUTTON) == 2)
617 return;
621 CString id;
622 GetDlgItemText(IDC_BUGID, id);
623 if (!m_ProjectProperties.CheckBugID(id))
625 ShowEditBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDS_ERR_ERROR, TTI_ERROR);
626 return;
628 m_sLogMessage = m_cLogMessage.GetText();
629 if ( m_sLogMessage.IsEmpty() )
631 // no message entered, go round again
632 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
633 return;
635 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
637 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
638 return;
641 if (m_ProjectProperties.bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
643 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);
644 if (retval == 1)
646 OnBnClickedSignOff();
647 m_sLogMessage = m_cLogMessage.GetText();
649 else if (retval == 3)
650 return;
653 if (CHooks::Instance().IsHookPresent(pre_commit_hook, g_Git.m_CurrentDir)) {
654 DWORD exitcode = 0xFFFFFFFF;
655 CString error;
656 CTGitPathList list;
657 m_ListCtrl.WriteCheckedNamesToPathList(list);
658 if (CHooks::Instance().PreCommit(g_Git.m_CurrentDir, list, m_sLogMessage, exitcode, error))
660 if (exitcode)
662 CString temp;
663 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
664 MessageBox(temp, L"TortoiseGit", MB_ICONERROR);
665 return;
670 int nListItems = m_ListCtrl.GetItemCount();
671 for (int i = 0; i < nListItems && !m_bCommitMessageOnly; ++i)
673 auto entry = m_ListCtrl.GetListEntry(i);
674 if (!entry->m_Checked || !entry->IsDirectory())
675 continue;
677 bool dirty = false;
678 if (entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
680 CGit subgit;
681 subgit.m_CurrentDir = g_Git.CombinePath(entry);
682 CString subcmdout;
683 subgit.Run(L"git.exe status --porcelain", &subcmdout, CP_UTF8);
684 dirty = !subcmdout.IsEmpty();
686 else
688 CString cmd, cmdout;
689 cmd.Format(L"git.exe diff -- \"%s\"", entry->GetWinPath());
690 g_Git.Run(cmd, &cmdout, CP_UTF8);
691 dirty = CStringUtils::EndsWith(cmdout, L"-dirty\n");
694 if (dirty)
696 CString message;
697 message.Format(IDS_COMMITDLG_SUBMODULEDIRTY, (LPCTSTR)entry->GetGitPathString());
698 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)));
699 if (result == 1)
701 CString cmdCommit;
702 cmdCommit.Format(L"/command:commit /path:\"%s\\%s\"", (LPCTSTR)g_Git.m_CurrentDir, entry->GetWinPath());
703 CAppUtils::RunTortoiseGitProc(cmdCommit);
704 return;
706 else if (result == 2)
707 continue;
708 else
709 return;
713 if (!m_bCommitMessageOnly)
714 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
715 m_pathwatcher.Stop();
716 InterlockedExchange(&m_bBlock, TRUE);
717 //first add all the unversioned files the user selected
718 //and check if all versioned files are selected
719 int nchecked = 0;
721 CMassiveGitTask mgtReAddAfterCommit(L"add --ignore-errors -f");
722 CMassiveGitTask mgtReDelAfterCommit(L"rm --cached --ignore-unmatch");
724 CString cmd;
725 CString out;
727 bool bAddSuccess=true;
728 bool bCloseCommitDlg=false;
730 CSysProgressDlg sysProgressDlg;
731 if (nListItems >= 25)
733 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
734 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
735 sysProgressDlg.SetTime(true);
736 sysProgressDlg.SetShowProgressBar(true);
737 sysProgressDlg.ShowModal(this, true);
740 CBlockCacheForPath cacheBlock(g_Git.m_CurrentDir);
741 ULONGLONG currentTicks = GetTickCount64();
743 if (g_Git.UsingLibGit2(CGit::GIT_CMD_COMMIT_UPDATE_INDEX))
745 bAddSuccess = false;
748 CAutoRepository repository(g_Git.GetGitRepository());
749 if (!repository)
751 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not open repository."), L"TortoiseGit", MB_OK | MB_ICONERROR);
752 break;
755 CGitHash revHash;
756 CString revRef = L"HEAD";
757 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
758 revRef = L"HEAD~1";
759 if (CGit::GetHash(repository, revHash, revRef))
761 MessageBox(g_Git.GetLibGit2LastErr(L"Could not get HEAD hash after committing."), L"TortoiseGit", MB_ICONERROR);
762 break;
765 CAutoCommit commit;
766 if (!revHash.IsEmpty() && git_commit_lookup(commit.GetPointer(), repository, (const git_oid*)revHash.m_hash))
768 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not get last commit."), L"TortoiseGit", MB_OK | MB_ICONERROR);
769 break;
772 CAutoTree tree;
773 if (!revHash.IsEmpty() && git_commit_tree(tree.GetPointer(), commit))
775 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not read tree of commit."), L"TortoiseGit", MB_OK | MB_ICONERROR);
776 break;
779 CAutoIndex index;
780 if (git_repository_index(index.GetPointer(), repository))
782 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not get the repository index."), L"TortoiseGit", MB_OK | MB_ICONERROR);
783 break;
786 CAutoIndex indexOld;
787 if (!revHash.IsEmpty() && (git_index_new(indexOld.GetPointer()) || git_index_read_tree(indexOld, tree)))
789 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not read the tree into the index."), L"TortoiseGit", MB_OK | MB_ICONERROR);
790 break;
793 bAddSuccess = true;
795 for (int j = 0; j < nListItems; ++j)
797 auto entry = m_ListCtrl.GetListEntry(j);
799 if (sysProgressDlg.IsVisible())
801 if (GetTickCount64() - currentTicks > 1000UL || j == nListItems - 1 || j == 0)
803 sysProgressDlg.SetLine(2, entry->GetGitPathString(), true);
804 sysProgressDlg.SetProgress(j, nListItems);
805 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too often: this takes time!
806 currentTicks = GetTickCount64();
810 CStringA filePathA = CUnicodeUtils::GetMulti(entry->GetGitPathString(), CP_UTF8).TrimRight(L'/');
812 if (entry->m_Checked && !m_bCommitMessageOnly)
814 if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
815 git_index_remove_bypath(index, filePathA); // ignore error
816 else
818 if (git_index_add_bypath(index, filePathA))
820 bAddSuccess = false;
821 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not add \"" + entry->GetGitPathString() + L"\" to index."), L"TortoiseGit", MB_OK | MB_ICONERROR);
822 break;
826 if ((entry->m_Action & CTGitPath::LOGACTIONS_REPLACED) && !entry->GetGitOldPathString().IsEmpty())
827 git_index_remove_bypath(index, CUnicodeUtils::GetUTF8(entry->GetGitOldPathString())); // ignore error
829 ++nchecked;
831 else
833 if (entry->m_Action & CTGitPath::LOGACTIONS_ADDED || entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
835 git_index_remove_bypath(index, filePathA); // ignore error
836 mgtReAddAfterCommit.AddFile(*entry);
838 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED && !entry->GetGitOldPathString().IsEmpty())
840 const git_index_entry* oldIndexEntry = nullptr;
841 if ((oldIndexEntry = git_index_get_bypath(indexOld, CUnicodeUtils::GetUTF8(entry->GetGitOldPathString()), 0)) == nullptr || git_index_add(index, oldIndexEntry))
843 bAddSuccess = false;
844 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not reset \"" + entry->GetGitOldPathString() + L"\" to old index entry."), L"TortoiseGit", MB_OK | MB_ICONERROR);
845 break;
847 mgtReDelAfterCommit.AddFile(entry->GetGitOldPathString());
850 else if (!(entry->m_Action & CTGitPath::LOGACTIONS_UNVER))
852 const git_index_entry* oldIndexEntry = nullptr;
853 if ((oldIndexEntry = git_index_get_bypath(indexOld, filePathA, 0)) == nullptr || git_index_add(index, oldIndexEntry))
855 bAddSuccess = false;
856 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L"Could not reset \"" + entry->GetGitPathString() + L"\" to old index entry."), L"TortoiseGit", MB_OK | MB_ICONERROR);
857 break;
859 if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED && !(entry->m_Action & CTGitPath::LOGACTIONS_MISSING))
860 mgtReDelAfterCommit.AddFile(entry->GetGitPathString());
864 if (sysProgressDlg.HasUserCancelled())
866 bAddSuccess = false;
867 break;
870 if (bAddSuccess && git_index_write(index))
871 bAddSuccess = false;
873 for (int j = 0; bAddSuccess && j < nListItems; ++j)
874 CShellUpdater::Instance().AddPathForUpdate(*m_ListCtrl.GetListEntry(j));
875 } while (0);
877 else
879 // ***************************************************
880 // ATTENTION: Similar code in RebaseDlg.cpp!!!
881 // ***************************************************
882 CMassiveGitTask mgtAdd(L"add -f");
883 CMassiveGitTask mgtUpdateIndexForceRemove(L"update-index --force-remove");
884 CMassiveGitTask mgtUpdateIndex(L"update-index");
885 CMassiveGitTask mgtRm(L"rm --ignore-unmatch");
886 CMassiveGitTask mgtRmFCache(L"rm -f --cache");
887 CString resetCmd = L"reset";
888 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
889 resetCmd += L" HEAD~1";;
890 CMassiveGitTask mgtReset(resetCmd, TRUE, true);
891 for (int j = 0; j < nListItems; ++j)
893 auto entry = m_ListCtrl.GetListEntry(j);
895 if (entry->m_Checked && !m_bCommitMessageOnly)
897 if ((entry->m_Action & CTGitPath::LOGACTIONS_UNVER) || entry->IsDirectory())
898 mgtAdd.AddFile(entry->GetGitPathString());
899 else if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
900 mgtUpdateIndexForceRemove.AddFile(entry->GetGitPathString());
901 else
902 mgtUpdateIndex.AddFile(entry->GetGitPathString());
904 if ((entry->m_Action & CTGitPath::LOGACTIONS_REPLACED) && !entry->GetGitOldPathString().IsEmpty())
905 mgtRm.AddFile(entry->GetGitOldPathString());
907 ++nchecked;
909 else
911 if (entry->m_Action & CTGitPath::LOGACTIONS_ADDED || entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
912 { //To init git repository, there are not HEAD, so we can use git reset command
913 mgtRmFCache.AddFile(entry->GetGitPathString());
914 mgtReAddAfterCommit.AddFile(*entry);
916 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED && !entry->GetGitOldPathString().IsEmpty())
918 mgtReset.AddFile(entry->GetGitOldPathString());
919 mgtReDelAfterCommit.AddFile(entry->GetGitOldPathString());
922 else if (!(entry->m_Action & CTGitPath::LOGACTIONS_UNVER))
924 mgtReset.AddFile(entry->GetGitPathString());
925 if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED && !(entry->m_Action & CTGitPath::LOGACTIONS_MISSING))
926 mgtReDelAfterCommit.AddFile(entry->GetGitPathString());
930 if (sysProgressDlg.HasUserCancelled())
932 bAddSuccess = false;
933 break;
937 CMassiveGitTask tasks[] = { mgtAdd, mgtUpdateIndexForceRemove, mgtUpdateIndex, mgtRm, mgtRmFCache, mgtReset };
938 int progress = 0, maxProgress = 0;
939 for (int j = 0; j < _countof(tasks); ++j)
940 maxProgress += tasks[j].GetListCount();
941 for (int j = 0; j < _countof(tasks); ++j)
942 bAddSuccess = bAddSuccess && UpdateIndex(tasks[j], sysProgressDlg, progress += tasks[j].GetListCount(), maxProgress);
944 if (sysProgressDlg.HasUserCancelled())
945 bAddSuccess = false;
947 for (int j = 0; bAddSuccess && j < nListItems; ++j)
948 CShellUpdater::Instance().AddPathForUpdate(*m_ListCtrl.GetListEntry(j));
951 if (sysProgressDlg.HasUserCancelled())
952 bAddSuccess = false;
954 sysProgressDlg.Stop();
956 if (bAddSuccess && m_bCreateNewBranch)
958 if (g_Git.Run(L"git.exe branch " + m_sCreateNewBranch, &out, CP_UTF8))
960 MessageBox(L"Creating new branch failed:\n" + out, L"TortoiseGit", MB_OK | MB_ICONERROR);
961 bAddSuccess = false;
963 if (g_Git.Run(L"git.exe checkout " + m_sCreateNewBranch + L" --", &out, CP_UTF8))
965 MessageBox(L"Switching to new branch failed:\n" + out, L"TortoiseGit", MB_OK | MB_ICONERROR);
966 bAddSuccess = false;
970 if (bAddSuccess && m_bWarnDetachedHead && CheckHeadDetach())
971 bAddSuccess = false;
973 m_sBugID.Trim();
974 CString sExistingBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
975 sExistingBugID.Trim();
976 if (!m_sBugID.IsEmpty() && m_sBugID.Compare(sExistingBugID))
978 m_sBugID.Replace(L", ", L",");
979 m_sBugID.Replace(L" ,", L",");
980 CString sBugID = m_ProjectProperties.sMessage;
981 sBugID.Replace(L"%BUGID%", m_sBugID);
982 if (m_ProjectProperties.bAppend)
983 m_sLogMessage += L'\n' + sBugID + L'\n';
984 else
985 m_sLogMessage = sBugID + L'\n' + m_sLogMessage;
988 // now let the bugtraq plugin check the commit message
989 CComPtr<IBugTraqProvider2> pProvider2;
990 if (m_BugTraqProvider)
992 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
993 if (SUCCEEDED(hr))
995 ATL::CComBSTR temp;
996 ATL::CComBSTR repositoryRoot(g_Git.m_CurrentDir);
997 ATL::CComBSTR parameters(m_bugtraq_association.GetParameters());
998 ATL::CComBSTR commonRoot(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
999 ATL::CComBSTR commitMessage(m_sLogMessage);
1000 CBstrSafeVector pathList(m_selectedPathList.GetCount());
1002 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
1003 pathList.PutElement(index, m_selectedPathList[index].GetGitPathString());
1005 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
1007 COMError ce(hr);
1008 CString sErr;
1009 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
1010 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
1012 else
1014 CString sError = temp;
1015 if (!sError.IsEmpty())
1017 CMessageBox::Show(GetSafeHwnd(), sError, L"TortoiseGit", MB_ICONERROR);
1018 InterlockedExchange(&m_bBlock, FALSE);
1019 return;
1025 if (m_bCommitMessageOnly || bAddSuccess && (nchecked || m_bCommitAmend || CTGitPath(g_Git.m_CurrentDir).IsMergeActive()))
1027 bCloseCommitDlg = true;
1029 CString tempfile=::GetTempFile();
1031 if (CAppUtils::SaveCommitUnicodeFile(tempfile, m_sLogMessage))
1033 CMessageBox::Show(GetSafeHwnd(), L"Could not save commit message", L"TortoiseGit", MB_OK | MB_ICONERROR);
1034 InterlockedExchange(&m_bBlock, FALSE);
1035 return;
1038 CTGitPath path=g_Git.m_CurrentDir;
1040 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
1042 out.Empty();
1043 CString amend;
1044 if(this->m_bCommitAmend)
1045 amend = L"--amend";
1047 CString dateTime;
1048 if (m_bSetCommitDateTime)
1050 CTime date, time;
1051 m_CommitDate.GetTime(date);
1052 m_CommitTime.GetTime(time);
1053 if (m_bCommitAmend && m_AsCommitDateCtrl.GetCheck())
1054 dateTime = CAppUtils::GetMsysgitVersion() > 0x02010000 ? L"--date=\"now\"" : L"--date=\"\"" ;
1055 else
1056 dateTime.Format(L"--date=%sT%s", (LPCTSTR)date.Format(L"%Y-%m-%d"), (LPCTSTR)time.Format(L"%H:%M:%S"));
1058 CString author;
1059 if (m_bSetAuthor)
1060 author.Format(L"--author=\"%s\"", (LPCTSTR)m_sAuthor);
1061 CString allowEmpty = m_bCommitMessageOnly ? L"--allow-empty" : L"";
1062 // TODO: make sure notes.amend.rewrite does still work when switching to libgit2
1063 cmd.Format(L"git.exe commit %s %s %s %s -F \"%s\"", (LPCTSTR)author, (LPCTSTR)dateTime, (LPCTSTR)amend, (LPCTSTR)allowEmpty, (LPCTSTR)tempfile);
1065 CCommitProgressDlg progress;
1066 progress.m_bBufferAll=true; // improve show speed when there are many file added.
1067 progress.m_GitCmd=cmd;
1068 progress.m_bShowCommand = FALSE; // don't show the commit command
1069 progress.m_PreText = out; // show any output already generated in log window
1070 if (m_ctrlOkButton.GetCurrentEntry() > 0)
1071 progress.m_AutoClose = GitProgressAutoClose::AUTOCLOSE_IF_NO_ERRORS;
1073 progress.m_PostCmdCallback = [&](DWORD status, PostCmdList& postCmdList)
1075 if (status || m_bNoPostActions || m_bAutoClose)
1076 return;
1078 if (IsGitSVN)
1079 postCmdList.emplace_back(IDI_COMMIT, IDS_MENUSVNDCOMMIT, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_DCOMMIT; });
1081 postCmdList.emplace_back(IDI_PUSH, IDS_MENUPUSH, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_PUSH; });
1082 postCmdList.emplace_back(IDI_PULL, IDS_MENUPULL, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_PULL; });
1083 postCmdList.emplace_back(IDI_COMMIT, IDS_PROC_COMMIT_RECOMMIT, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_RECOMMIT; });
1084 postCmdList.emplace_back(IDI_TAG, IDS_MENUTAG, [&]{ m_PostCmd = GIT_POSTCOMMIT_CMD_CREATETAG; });
1087 m_PostCmd = GIT_POSTCOMMIT_CMD_NOTHING;
1088 progress.DoModal();
1090 if (!m_bNoPostActions)
1091 m_regLastAction = (int)m_ctrlOkButton.GetCurrentEntry();
1092 if (m_ctrlOkButton.GetCurrentEntry() == 1)
1093 m_PostCmd = GIT_POSTCOMMIT_CMD_RECOMMIT;
1095 ::DeleteFile(tempfile);
1097 if (m_BugTraqProvider && progress.m_GitStatus == 0)
1099 CComPtr<IBugTraqProvider2> pProvider;
1100 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
1101 if (SUCCEEDED(hr))
1103 ATL::CComBSTR commonRoot(g_Git.m_CurrentDir);
1104 CBstrSafeVector pathList(m_selectedPathList.GetCount());
1106 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
1107 pathList.PutElement(index, m_selectedPathList[index].GetGitPathString());
1109 ATL::CComBSTR logMessage(m_sLogMessage);
1111 CGitHash hash;
1112 if (g_Git.GetHash(hash, L"HEAD"))
1113 MessageBox(g_Git.GetGitLastErr(L"Could not get HEAD hash after committing."), L"TortoiseGit", MB_ICONERROR);
1114 LONG version = g_Git.Hash2int(hash);
1116 ATL::CComBSTR temp;
1117 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
1118 commonRoot,
1119 pathList,
1120 logMessage,
1121 (LONG)version,
1122 &temp)))
1124 CString sErr = temp;
1125 if (!sErr.IsEmpty())
1126 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_OK | MB_ICONERROR);
1127 else
1129 COMError ce(hr);
1130 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
1131 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_OK | MB_ICONERROR);
1136 RestoreFiles(progress.m_GitStatus == 0, false);
1137 if (((DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit", TRUE)) == TRUE)
1139 BOOL cancel = FALSE;
1140 mgtReAddAfterCommit.Execute(cancel);
1141 mgtReDelAfterCommit.Execute(cancel);
1144 if (!progress.m_GitStatus)
1146 DWORD exitcode = 0xFFFFFFFF;
1147 CString error;
1148 if (CHooks::Instance().PostCommit(g_Git.m_CurrentDir, amend.IsEmpty(), exitcode, error))
1150 if (exitcode)
1152 CString temp;
1153 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
1154 MessageBox(temp, L"TortoiseGit", MB_ICONERROR);
1155 bCloseCommitDlg = false;
1160 if (progress.m_GitStatus || m_PostCmd == GIT_POSTCOMMIT_CMD_RECOMMIT)
1162 bCloseCommitDlg = false;
1163 if (m_PostCmd == GIT_POSTCOMMIT_CMD_RECOMMIT)
1165 if (!m_sLogMessage.IsEmpty())
1167 ReloadHistoryEntries();
1168 m_History.AddEntry(m_sLogMessage);
1169 m_History.Save();
1172 this->m_sLogMessage.Empty();
1173 GetCommitTemplate(m_sLogMessage);
1174 m_cLogMessage.SetText(m_sLogMessage);
1175 if (m_bCreateNewBranch)
1177 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);
1178 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
1180 m_bCreateNewBranch = FALSE;
1181 m_ListCtrl.Clear();
1182 if (!RunStartCommitHook())
1183 bCloseCommitDlg = true;
1186 if (!progress.m_GitStatus)
1188 m_AmendStr.Empty();
1189 m_bCommitAmend = FALSE;
1192 UpdateData(FALSE);
1195 else if(bAddSuccess)
1197 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
1198 bCloseCommitDlg=false;
1201 UpdateData();
1202 m_regAddBeforeCommit = m_bShowUnversioned;
1203 m_regKeepChangelists = m_bKeepChangeList;
1204 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
1205 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
1206 m_bKeepChangeList = FALSE;
1207 InterlockedExchange(&m_bBlock, FALSE);
1209 if (!m_sLogMessage.IsEmpty())
1211 ReloadHistoryEntries();
1212 m_History.AddEntry(m_sLogMessage);
1213 m_History.Save();
1216 SaveSplitterPos();
1218 if (bCloseCommitDlg)
1220 if (m_ctrlOkButton.GetCurrentEntry() == 2)
1221 DoPush();
1222 CResizableStandAloneDialog::OnOK();
1224 else if (m_PostCmd == GIT_POSTCOMMIT_CMD_RECOMMIT)
1226 m_bDoNotStoreLastSelectedLine = true;
1227 this->Refresh();
1228 this->BringWindowToTop();
1231 CShellUpdater::Instance().Flush();
1234 void CCommitDlg::SaveSplitterPos()
1236 if (!IsIconic())
1238 CRegDWORD regPos(L"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer");
1239 RECT rectSplitter;
1240 m_wndSplitter.GetWindowRect(&rectSplitter);
1241 ScreenToClient(&rectSplitter);
1242 regPos = rectSplitter.top;
1246 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
1248 return ((CCommitDlg*)pVoid)->StatusThread();
1251 void CCommitDlg::ReloadHistoryEntries()
1253 CString reg;
1254 reg.Format(L"Software\\TortoiseGit\\History\\commit%s", (LPCTSTR)m_ListCtrl.m_sUUID);
1255 reg.Replace(L':', L'_');
1256 m_History.Load(reg, L"logmsgs");
1259 UINT CCommitDlg::StatusThread()
1261 //get the status of all selected file/folders recursively
1262 //and show the ones which have to be committed to the user
1263 //in a list control.
1264 m_pathwatcher.Stop();
1266 m_ListCtrl.SetBusy(true);
1267 g_Git.RefreshGitIndex();
1269 m_bCancelled = false;
1271 DialogEnableWindow(IDOK, false);
1272 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
1273 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
1274 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
1275 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
1276 DialogEnableWindow(IDC_EXTERNALWARNING, false);
1277 DialogEnableWindow(IDC_COMMIT_AMEND, FALSE);
1278 DialogEnableWindow(IDC_COMMIT_AMENDDIFF, FALSE);
1279 // read the list of recent log entries before querying the WC for status
1280 // -> the user may select one and modify / update it while we are crawling the WC
1282 DialogEnableWindow(IDC_CHECKALL, false);
1283 DialogEnableWindow(IDC_CHECKNONE, false);
1284 DialogEnableWindow(IDC_CHECKUNVERSIONED, false);
1285 DialogEnableWindow(IDC_CHECKVERSIONED, false);
1286 DialogEnableWindow(IDC_CHECKADDED, false);
1287 DialogEnableWindow(IDC_CHECKDELETED, false);
1288 DialogEnableWindow(IDC_CHECKMODIFIED, false);
1289 DialogEnableWindow(IDC_CHECKFILES, false);
1290 DialogEnableWindow(IDC_CHECKSUBMODULES, false);
1292 CString dotGitPath;
1293 GitAdminDir::GetAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
1294 if (PathFileExists(dotGitPath + L"CHERRY_PICK_HEAD"))
1296 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
1297 m_bCommitAmend = FALSE;
1298 SendMessage(WM_UPDATEDATAFALSE);
1301 if (!m_bDoNotStoreLastSelectedLine)
1302 m_ListCtrl.StoreScrollPos();
1303 // Initialise the list control with the status of the files/folders below us
1304 m_ListCtrl.Clear();
1305 BOOL success;
1306 CTGitPathList *pList;
1307 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE || m_bForceCommitAmend) && (m_bAmendDiffToLastCommit==FALSE);
1308 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
1310 if(m_bWholeProject || m_bWholeProject2)
1311 pList = nullptr;
1312 else
1313 pList = &m_pathList;
1315 success=m_ListCtrl.GetStatus(pList);
1317 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1318 if(this->m_bShowUnversioned)
1319 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
1321 m_ListCtrl.CheckIfChangelistsArePresent(false);
1323 DWORD dwShow = GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWINCHANGELIST | GITSLC_SHOWDIRECTFILES;
1324 dwShow |= DWORD(m_regAddBeforeCommit) ? GITSLC_SHOWUNVERSIONED : 0;
1325 if (success)
1327 if (!m_checkedPathList.IsEmpty())
1328 m_ListCtrl.Show(dwShow, m_checkedPathList);
1329 else
1331 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
1332 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
1333 m_ListCtrl.Show(dwShow, dwCheck);
1334 m_bSelectFilesForCommit = true;
1337 if (m_ListCtrl.HasExternalsFromDifferentRepos())
1339 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
1340 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
1343 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
1344 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
1345 if (m_ListCtrl.GetItemCount() != 0 && m_ListCtrl.GetTopIndex() == 0 && (m_bDoNotStoreLastSelectedLine || CRegDWORD(L"Software\\TortoiseGit\\RememberFileListPosition", TRUE) != TRUE))
1346 m_ListCtrl.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
1348 if (!success)
1350 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
1351 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
1352 m_ListCtrl.Show(dwShow);
1354 m_bDoNotStoreLastSelectedLine = false;
1356 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
1357 && !PathFileExists(dotGitPath + L"MERGE_HEAD"))
1359 CString temp;
1360 temp.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED);
1361 if (CMessageBox::ShowCheck(GetSafeHwnd(), temp, L"TortoiseGit", MB_ICONINFORMATION | MB_YESNO, L"NothingToCommitShowUnversioned", nullptr) == IDYES)
1363 m_bShowUnversioned = TRUE;
1364 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
1365 dwShow = (DWORD)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWUNVERSIONED);
1366 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
1367 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
1371 SetDlgTitle();
1373 m_autolist.clear();
1374 // we don't have to block the commit dialog while we fetch the
1375 // auto completion list.
1376 m_pathwatcher.ClearChangedPaths();
1377 InterlockedExchange(&m_bBlock, FALSE);
1378 if ((DWORD)CRegDWORD(L"Software\\TortoiseGit\\Autocompletion", TRUE) == TRUE)
1380 m_ListCtrl.Block(TRUE, TRUE);
1381 GetAutocompletionList();
1382 m_ListCtrl.Block(FALSE, FALSE);
1384 SendMessage(WM_UPDATEOKBUTTON);
1385 m_ListCtrl.Invalidate();
1386 if (m_bRunThread)
1388 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1389 DialogEnableWindow(IDC_WHOLE_PROJECT, !m_bWholeProject2);
1390 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1391 if (m_ListCtrl.HasChangeLists())
1392 DialogEnableWindow(IDC_KEEPLISTS, true);
1394 // activate amend checkbox (if necessary)
1395 if (g_Git.IsInitRepos())
1397 m_bCommitAmend = FALSE;
1398 SendMessage(WM_UPDATEDATAFALSE);
1400 else
1402 if (m_bForceCommitAmend)
1404 m_bCommitAmend = TRUE;
1405 SendMessage(WM_UPDATEDATAFALSE);
1407 else
1408 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(!PathFileExists(dotGitPath + L"CHERRY_PICK_HEAD"));
1410 CGitHash hash;
1411 if (g_Git.GetHash(hash, L"HEAD"))
1413 MessageBox(g_Git.GetGitLastErr(L"Could not get HEAD hash."), L"TortoiseGit", MB_ICONERROR);
1415 if (!hash.IsEmpty())
1417 GitRev headRevision;
1418 if (headRevision.GetParentFromHash(hash))
1419 MessageBox(headRevision.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
1420 // do not allow to show diff to "last" revision if it has more that one parent
1421 if (headRevision.ParentsCount() != 1)
1423 m_bAmendDiffToLastCommit = TRUE;
1424 SendMessage(WM_UPDATEDATAFALSE);
1426 else
1427 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(TRUE);
1431 UpdateCheckLinks();
1433 // we have the list, now signal the main thread about it
1434 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1437 InterlockedExchange(&m_bRunThread, FALSE);
1438 InterlockedExchange(&m_bThreadRunning, FALSE);
1439 // force the cursor to normal
1440 RefreshCursor();
1442 return 0;
1445 void CCommitDlg::SetDlgTitle()
1447 if (m_sTitle.IsEmpty())
1448 GetWindowText(m_sTitle);
1450 if (m_bWholeProject || m_bWholeProject2)
1451 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
1452 else
1454 if (m_pathList.GetCount() == 1)
1455 CAppUtils::SetWindowTitle(m_hWnd, g_Git.CombinePath(m_pathList[0].GetUIPathString()), m_sTitle);
1456 else
1457 CAppUtils::SetWindowTitle(m_hWnd, g_Git.CombinePath(m_ListCtrl.GetCommonDirectory(false)), m_sTitle);
1461 void CCommitDlg::OnCancel()
1463 CString tmp;
1464 tmp.LoadString(IDS_REALLYCANCEL);
1465 tmp.AppendChar(L'\n');
1466 tmp.AppendChar(L'\n');
1467 tmp.Append(CString(MAKEINTRESOURCE(IDS_HINTLASTMESSAGES)));
1468 CString dontaskagain;
1469 dontaskagain.LoadString(IDS_MSGBOX_DONOTSHOWAGAIN);
1470 if (CMessageBox::ShowCheck(GetSafeHwnd(), tmp, L"TortoiseGit", MB_ICONQUESTION | MB_DEFBUTTON2 | MB_YESNO, L"CommitAskBeforeCancel", dontaskagain) == IDNO)
1472 CMessageBox::SetRegistryValue(L"CommitAskBeforeCancel", IDYES);
1473 return;
1476 m_bCancelled = true;
1477 m_pathwatcher.Stop();
1479 if (m_bThreadRunning)
1480 StopStatusThread();
1481 if (!RestoreFiles())
1482 return;
1483 UpdateData();
1484 m_sBugID.Trim();
1485 m_sLogMessage = m_cLogMessage.GetText();
1486 if (!m_sBugID.IsEmpty())
1488 m_sBugID.Replace(L", ", L",");
1489 m_sBugID.Replace(L" ,", L",");
1490 CString sBugID = m_ProjectProperties.sMessage;
1491 sBugID.Replace(L"%BUGID%", m_sBugID);
1492 if (m_ProjectProperties.bAppend)
1493 m_sLogMessage += L'\n' + sBugID + L'\n';
1494 else
1495 m_sLogMessage = sBugID + L'\n' + m_sLogMessage;
1497 if ((m_sLogTemplate.Compare(m_sLogMessage) != 0) && !m_sLogMessage.IsEmpty())
1499 ReloadHistoryEntries();
1500 m_History.AddEntry(m_sLogMessage);
1501 m_History.Save();
1503 SaveSplitterPos();
1504 CResizableStandAloneDialog::OnCancel();
1507 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1509 if (m_hAccel)
1511 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1512 if (ret)
1513 return TRUE;
1515 if (m_hAccelOkButton && GetDlgItem(IDOK)->IsWindowEnabled() && TranslateAccelerator(m_hWnd, m_hAccelOkButton, pMsg))
1516 return TRUE;
1518 if (pMsg->message == WM_KEYDOWN)
1520 switch (pMsg->wParam)
1522 case VK_F5:
1524 if (m_bBlock)
1525 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1526 Refresh();
1528 break;
1529 case VK_RETURN:
1531 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1533 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1534 PostMessage(WM_COMMAND, IDOK);
1535 return TRUE;
1537 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1539 // Pressing RETURN in the bug id control
1540 // moves the focus to the message
1541 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1542 return TRUE;
1545 break;
1549 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1552 void CCommitDlg::Refresh()
1554 if (m_bThreadRunning)
1555 return;
1557 StartStatusThread();
1560 void CCommitDlg::StartStatusThread()
1562 if (InterlockedExchange(&m_bBlock, TRUE) != FALSE)
1563 return;
1565 delete m_pThread;
1566 m_pThread = nullptr;
1568 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
1569 if (!m_pThread)
1571 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1572 InterlockedExchange(&m_bBlock, FALSE);
1573 return;
1575 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
1576 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
1577 m_pThread->m_bAutoDelete = FALSE;
1578 m_pThread->ResumeThread();
1581 void CCommitDlg::StopStatusThread()
1583 InterlockedExchange(&m_bRunThread, FALSE);
1584 WaitForSingleObject(m_pThread->m_hThread, 5000);
1585 if (!m_bThreadRunning)
1586 return;
1588 // we gave the thread a chance to quit. Since the thread didn't
1589 // listen to us we have to kill it.
1590 g_Git.KillRelatedThreads(m_pThread);
1591 InterlockedExchange(&m_bThreadRunning, FALSE);
1594 void CCommitDlg::OnBnClickedShowunversioned()
1596 m_tooltips.Pop(); // hide the tooltips
1597 UpdateData();
1598 m_regAddBeforeCommit = m_bShowUnversioned;
1599 if (!m_bBlock)
1601 DWORD dwShow = m_ListCtrl.GetShowFlags();
1602 if (DWORD(m_regAddBeforeCommit))
1603 dwShow |= GITSLC_SHOWUNVERSIONED;
1604 else
1605 dwShow &= ~GITSLC_SHOWUNVERSIONED;
1606 if(dwShow & GITSLC_SHOWUNVERSIONED)
1608 if (m_bWholeProject || m_bWholeProject2)
1609 m_ListCtrl.GetStatus(nullptr, false, false, true);
1610 else
1611 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1613 m_ListCtrl.StoreScrollPos();
1614 m_ListCtrl.Show(dwShow, 0, true, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
1615 UpdateCheckLinks();
1619 void CCommitDlg::OnStnClickedExternalwarning()
1621 m_tooltips.Popup();
1624 void CCommitDlg::OnEnChangeLogmessage()
1626 SendMessage(WM_UPDATEOKBUTTON);
1629 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1631 #if 0
1632 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1634 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1636 m_bShowUnversioned = TRUE;
1637 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED;
1638 m_ListCtrl.Show(dwShow);
1639 UpdateData(FALSE);
1642 #endif
1643 return 0;
1646 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1648 Refresh();
1649 return 0;
1652 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM lParam)
1654 BringWindowToTop();
1655 SetForegroundWindow();
1656 SetActiveWindow();
1657 // if multiple files/folders are dropped
1658 // this handler is called for every single item
1659 // separately.
1660 // To avoid creating multiple refresh threads and
1661 // causing crashes, we only add the items to the
1662 // list control and start a timer.
1663 // When the timer expires, we start the refresh thread,
1664 // but only if it isn't already running - otherwise we
1665 // restart the timer.
1666 CTGitPath path;
1667 path.SetFromWin((LPCTSTR)lParam);
1669 // check whether the dropped file belongs to the very same repository
1670 CString projectDir;
1671 if (!path.HasAdminDir(&projectDir) || !CTGitPath::ArePathStringsEqual(g_Git.m_CurrentDir, projectDir))
1672 return 0;
1674 // just add all the items we get here.
1675 // if the item is versioned, the add will fail but nothing
1676 // more will happen.
1677 CString cmd;
1678 cmd.Format(L"git.exe add -- \"%s\"", path.GetWinPathString());
1679 g_Git.Run(cmd, nullptr, CP_UTF8);
1681 if (!m_ListCtrl.HasPath(path))
1683 if (m_pathList.AreAllPathsFiles())
1685 m_pathList.AddPath(path);
1686 m_pathList.RemoveDuplicates();
1687 m_updatedPathList.AddPath(path);
1688 m_updatedPathList.RemoveDuplicates();
1690 else
1692 // if the path list contains folders, we have to check whether
1693 // our just (maybe) added path is a child of one of those. If it is
1694 // a child of a folder already in the list, we must not add it. Otherwise
1695 // that path could show up twice in the list.
1696 bool bHasParentInList = false;
1697 for (int i=0; i<m_pathList.GetCount(); ++i)
1699 if (m_pathList[i].IsAncestorOf(path))
1701 bHasParentInList = true;
1702 break;
1705 if (!bHasParentInList)
1707 m_pathList.AddPath(path);
1708 m_pathList.RemoveDuplicates();
1709 m_updatedPathList.AddPath(path);
1710 m_updatedPathList.RemoveDuplicates();
1714 m_ListCtrl.ResetChecked(path);
1716 // Always start the timer, since the status of an existing item might have changed
1717 SetTimer(REFRESHTIMER, 200, nullptr);
1718 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Item %s dropped, timer started\n", path.GetWinPath());
1719 return 0;
1722 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1724 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1725 return 0;
1728 //////////////////////////////////////////////////////////////////////////
1729 // functions which run in the status thread
1730 //////////////////////////////////////////////////////////////////////////
1732 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1734 CString strLine;
1737 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1738 while (m_bRunThread && file.ReadString(strLine))
1740 if (strLine.IsEmpty())
1741 continue;
1742 if (strLine[0] == L'#')
1743 continue;
1744 int eqpos = strLine.Find('=');
1745 CString rgx;
1746 rgx = strLine.Mid(eqpos+1).Trim();
1748 int pos = -1;
1749 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1751 mapRegex[strLine.Left(pos)] = rgx;
1752 strLine = strLine.Mid(pos+1).Trim();
1754 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1756 file.Close();
1758 catch (CFileException* pE)
1760 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException loading auto list regex file\n");
1761 pE->Delete();
1765 void CCommitDlg::ParseSnippetFile(const CString& sFile, std::map<CString, CString>& mapSnippet)
1767 CString strLine;
1770 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1771 while (m_bRunThread && file.ReadString(strLine))
1773 if (strLine.IsEmpty())
1774 continue;
1775 if (strLine[0] == L'#') // comment char
1776 continue;
1777 int eqpos = strLine.Find('=');
1778 CString key = strLine.Left(eqpos);
1779 CString value = strLine.Mid(eqpos + 1);
1780 value.Replace(L"\\\t", L"\t");
1781 value.Replace(L"\\\r", L"\r");
1782 value.Replace(L"\\\n", L"\n");
1783 value.Replace(L"\\\\", L"\\");
1784 mapSnippet[key] = value;
1786 file.Close();
1788 catch (CFileException* pE)
1790 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException loading auto list regex file\n");
1791 pE->Delete();
1795 void CCommitDlg::GetAutocompletionList()
1797 // the auto completion list is made of strings from each selected files.
1798 // the strings used are extracted from the files with regexes found
1799 // in the file "autolist.txt".
1800 // the format of that file is:
1801 // file extensions separated with commas '=' regular expression to use
1802 // example:
1803 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1804 // .cpp = (?<=[^\s]::)\b\w+\b
1806 std::map<CString, CString> mapRegex;
1807 CString sRegexFile = CPathUtils::GetAppDirectory();
1808 CRegDWORD regtimeout = CRegDWORD(L"Software\\TortoiseGit\\AutocompleteParseTimeout", 5);
1809 ULONGLONG timeoutvalue = ULONGLONG(DWORD(regtimeout)) * 1000UL;;
1810 sRegexFile += L"autolist.txt";
1811 if (!m_bRunThread)
1812 return;
1813 ParseRegexFile(sRegexFile, mapRegex);
1814 sRegexFile = CPathUtils::GetAppDataDirectory();
1815 sRegexFile += L"autolist.txt";
1816 if (PathFileExists(sRegexFile))
1817 ParseRegexFile(sRegexFile, mapRegex);
1819 m_snippet.clear();
1820 CString sSnippetFile = CPathUtils::GetAppDirectory();
1821 sSnippetFile += L"snippet.txt";
1822 ParseSnippetFile(sSnippetFile, m_snippet);
1823 sSnippetFile = CPathUtils::GetAppDataDirectory();
1824 sSnippetFile += L"snippet.txt";
1825 if (PathFileExists(sSnippetFile))
1826 ParseSnippetFile(sSnippetFile, m_snippet);
1827 for (const auto& snip : m_snippet)
1828 m_autolist.emplace(snip.first, AUTOCOMPLETE_SNIPPET);
1830 ULONGLONG starttime = GetTickCount64();
1832 // now we have two arrays of strings, where the first array contains all
1833 // file extensions we can use and the second the corresponding regex strings
1834 // to apply to those files.
1836 // the next step is to go over all files shown in the commit dialog
1837 // and scan them for strings we can use
1838 int nListItems = m_ListCtrl.GetItemCount();
1840 for (int i=0; i<nListItems && m_bRunThread; ++i)
1842 // stop parsing after timeout
1843 if ((!m_bRunThread) || (GetTickCount64() - starttime > timeoutvalue))
1844 return;
1846 auto path = m_ListCtrl.GetListEntry(i);
1848 if (!path)
1849 continue;
1851 CString sPartPath =path->GetGitPathString();
1852 m_autolist.emplace(sPartPath, AUTOCOMPLETE_FILENAME);
1854 int pos = 0;
1855 int lastPos = 0;
1856 while ((pos = sPartPath.Find('/', pos)) >= 0)
1858 ++pos;
1859 lastPos = pos;
1860 m_autolist.emplace(sPartPath.Mid(pos), AUTOCOMPLETE_FILENAME);
1863 // Last inserted entry is a file name.
1864 // Some users prefer to also list file name without extension.
1865 if (CRegDWORD(L"Software\\TortoiseGit\\AutocompleteRemovesExtensions", FALSE))
1867 int dotPos = sPartPath.ReverseFind('.');
1868 if ((dotPos >= 0) && (dotPos > lastPos))
1869 m_autolist.emplace(sPartPath.Mid(lastPos, dotPos - lastPos), AUTOCOMPLETE_FILENAME);
1872 if (path->m_Action == CTGitPath::LOGACTIONS_UNVER && !CRegDWORD(L"Software\\TortoiseGit\\AutocompleteParseUnversioned", FALSE))
1873 continue;
1874 if (path->m_Action == CTGitPath::LOGACTIONS_IGNORE)
1875 continue;
1877 CString sExt = path->GetFileExtension();
1878 sExt.MakeLower();
1879 // find the regex string which corresponds to the file extension
1880 CString rdata = mapRegex[sExt];
1881 if (rdata.IsEmpty())
1882 continue;
1884 ScanFile(path->GetWinPathString(), rdata, sExt);
1886 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Auto completion list loaded in %I64u msec\n", GetTickCount64() - starttime);
1889 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex, const CString& sExt)
1891 static std::map<CString, std::tr1::wregex> regexmap;
1893 std::wstring sFileContent;
1894 CAutoFile hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
1895 if (hFile)
1897 DWORD size = GetFileSize(hFile, nullptr);
1898 if (size > CRegDWORD(L"Software\\TortoiseGit\\AutocompleteParseMaxSize", 300000L))
1900 // no files bigger than 300k
1901 return;
1903 // allocate memory to hold file contents
1904 CBuffer oFile;
1907 oFile.SetLength(size);
1909 catch (CMemoryException*)
1911 return;
1913 DWORD readbytes;
1914 if (!ReadFile(hFile, oFile, size, &readbytes, nullptr))
1915 return;
1916 oFile.SetLength(readbytes);
1917 CFileTextLines filetextlines;
1918 CFileTextLines::UnicodeType type = filetextlines.CheckUnicodeType(oFile, readbytes);
1921 CBaseFilter* pFilter = nullptr;
1922 switch (type)
1924 case CFileTextLines::BINARY:
1925 return;
1926 case CFileTextLines::UTF8:
1927 case CFileTextLines::UTF8BOM:
1928 pFilter = new CUtf8Filter(NULL);
1929 break;
1930 default:
1931 case CFileTextLines::ASCII:
1932 pFilter = new CAsciiFilter(NULL);
1933 break;
1934 case CFileTextLines::UTF16_BE:
1935 case CFileTextLines::UTF16_BEBOM:
1936 pFilter = new CUtf16beFilter(NULL);
1937 break;
1938 case CFileTextLines::UTF16_LE:
1939 case CFileTextLines::UTF16_LEBOM:
1940 pFilter = new CUtf16leFilter(NULL);
1941 break;
1942 case CFileTextLines::UTF32_BE:
1943 pFilter = new CUtf32beFilter(NULL);
1944 break;
1945 case CFileTextLines::UTF32_LE:
1946 pFilter = new CUtf32leFilter(NULL);
1947 break;
1949 pFilter->Decode(oFile);
1950 delete pFilter;
1952 catch (CMemoryException*)
1954 return;
1956 sFileContent = std::wstring((wchar_t*)oFile, oFile.GetLength() / sizeof(wchar_t));
1958 if (sFileContent.empty() || !m_bRunThread)
1959 return;
1963 std::tr1::wregex regCheck;
1964 std::map<CString, std::tr1::wregex>::const_iterator regIt;
1965 if ((regIt = regexmap.find(sExt)) != regexmap.end())
1966 regCheck = regIt->second;
1967 else
1969 regCheck = std::tr1::wregex(sRegex, std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript);
1970 regexmap[sExt] = regCheck;
1972 const std::tr1::wsregex_iterator end;
1973 for (std::tr1::wsregex_iterator it(sFileContent.cbegin(), sFileContent.cend(), regCheck); it != end; ++it)
1975 const std::tr1::wsmatch match = *it;
1976 for (size_t i = 1; i < match.size(); ++i)
1978 if (match[i].second-match[i].first)
1979 m_autolist.emplace(std::wstring(match[i]).c_str(), AUTOCOMPLETE_PROGRAMCODE);
1983 catch (std::exception&) {}
1986 // CSciEditContextMenuInterface
1987 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1989 CString sMenuItemText;
1990 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITHASH);
1991 m_nPopupPickCommitHash = nCmd++;
1992 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPickCommitHash, sMenuItemText);
1994 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITMESSAGE);
1995 m_nPopupPickCommitMessage = nCmd++;
1996 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPickCommitMessage, sMenuItemText);
1998 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTEFILELIST);
1999 m_nPopupPasteListCmd = nCmd++;
2000 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
2002 ReloadHistoryEntries();
2003 if (!m_History.IsEmpty())
2005 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
2006 m_nPopupPasteLastMessage = nCmd++;
2007 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
2009 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
2010 m_nPopupRecentMessage = nCmd++;
2011 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
2015 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
2017 if (cmd == m_nPopupPickCommitHash)
2019 // use the git log to allow selection of a version
2020 CLogDlg dlg;
2021 // tell the dialog to use mode for selecting revisions
2022 dlg.SetSelect(true);
2023 // only one revision must be selected however
2024 dlg.SingleSelection(true);
2025 dlg.ShowWorkingTreeChanges(false);
2026 if (dlg.DoModal() == IDOK)
2027 pSciEdit->InsertText(dlg.GetSelectedHash().at(0).ToString());
2028 return true;
2031 if (cmd == m_nPopupPickCommitMessage)
2033 // use the git log to allow selection of a version
2034 CLogDlg dlg;
2035 // tell the dialog to use mode for selecting revisions
2036 dlg.SetSelect(true);
2037 // only one revision must be selected however
2038 dlg.SingleSelection(true);
2039 dlg.ShowWorkingTreeChanges(false);
2040 if (dlg.DoModal() == IDOK)
2042 GitRev rev;
2043 if (rev.GetCommit(dlg.GetSelectedHash().at(0).ToString()))
2045 MessageBox(rev.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2046 return false;
2048 CString message = rev.GetSubject() + L"\r\n" + rev.GetBody();
2049 pSciEdit->InsertText(message);
2051 return true;
2054 if (cmd == m_nPopupPasteListCmd)
2056 CString logmsg;
2057 int nListItems = m_ListCtrl.GetItemCount();
2058 for (int i=0; i<nListItems; ++i)
2060 auto entry = m_ListCtrl.GetListEntry(i);
2061 if (entry&&entry->m_Checked)
2063 CString status = entry->GetActionName();
2064 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
2065 status = L"Add"; // I18N TODO
2067 //git_wc_status_kind status = entry->status;
2068 WORD langID = (WORD)CRegStdDWORD(L"Software\\TortoiseGit\\LanguageID", GetUserDefaultLangID());
2069 if (m_ProjectProperties.bFileListInEnglish)
2070 langID = 1033;
2072 logmsg.AppendFormat(L"%-10s %s\r\n", (LPCTSTR)status, (LPCTSTR)m_ListCtrl.GetItemText(i, 0));
2075 pSciEdit->InsertText(logmsg);
2076 return true;
2079 if(cmd == m_nPopupPasteLastMessage)
2081 if (m_History.IsEmpty())
2082 return false;
2084 CString logmsg;
2085 logmsg +=m_History.GetEntry(0);
2086 pSciEdit->InsertText(logmsg);
2087 return true;
2090 if(cmd == m_nPopupRecentMessage )
2092 OnBnClickedHistory();
2093 return true;
2095 return false;
2098 void CCommitDlg::HandleSnippet(int type, const CString &text, CSciEdit *pSciEdit)
2100 if (type == AUTOCOMPLETE_SNIPPET)
2102 CString target = m_snippet[text];
2103 pSciEdit->GetWordUnderCursor(true);
2104 pSciEdit->InsertText(target, false);
2108 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
2110 switch (nIDEvent)
2112 case ENDDIALOGTIMER:
2113 KillTimer(ENDDIALOGTIMER);
2114 EndDialog(0);
2115 break;
2116 case REFRESHTIMER:
2117 if (m_bThreadRunning)
2119 SetTimer(REFRESHTIMER, 200, nullptr);
2120 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Wait some more before refreshing\n");
2122 else
2124 KillTimer(REFRESHTIMER);
2125 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Refreshing after items dropped\n");
2126 Refresh();
2128 break;
2129 case FILLPATCHVTIMER:
2130 FillPatchView();
2131 break;
2133 __super::OnTimer(nIDEvent);
2136 void CCommitDlg::OnBnClickedHistory()
2138 m_tooltips.Pop(); // hide the tooltips
2139 if (m_pathList.IsEmpty())
2140 return;
2142 CHistoryDlg historyDlg;
2143 ReloadHistoryEntries();
2144 historyDlg.SetHistory(m_History);
2145 if (historyDlg.DoModal() != IDOK)
2146 return;
2148 CString sMsg = historyDlg.GetSelectedText();
2149 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
2151 CString sBugID = m_ProjectProperties.FindBugID(sMsg);
2152 if ((!sBugID.IsEmpty()) && ((GetDlgItem(IDC_BUGID)->IsWindowVisible())))
2153 SetDlgItemText(IDC_BUGID, sBugID);
2154 if (m_sLogTemplate.Compare(m_cLogMessage.GetText()) != 0)
2155 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
2156 else
2157 m_cLogMessage.SetText(sMsg);
2160 SendMessage(WM_UPDATEOKBUTTON);
2161 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2164 void CCommitDlg::OnBnClickedBugtraqbutton()
2166 m_tooltips.Pop(); // hide the tooltips
2167 CString sMsg = m_cLogMessage.GetText();
2169 if (!m_BugTraqProvider)
2170 return;
2172 ATL::CComBSTR parameters(m_bugtraq_association.GetParameters());
2173 ATL::CComBSTR commonRoot(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
2174 CBstrSafeVector pathList(m_pathList.GetCount());
2176 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
2177 pathList.PutElement(index, m_pathList[index].GetGitPathString());
2179 ATL::CComBSTR originalMessage(sMsg);
2180 ATL::CComBSTR temp;
2182 // first try the IBugTraqProvider2 interface
2183 CComPtr<IBugTraqProvider2> pProvider2;
2184 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
2185 bool bugIdOutSet = false;
2186 if (SUCCEEDED(hr))
2188 ATL::CComBSTR repositoryRoot(g_Git.m_CurrentDir);
2189 ATL::CComBSTR bugIDOut;
2190 GetDlgItemText(IDC_BUGID, m_sBugID);
2191 ATL::CComBSTR bugID(m_sBugID);
2192 CBstrSafeVector revPropNames;
2193 CBstrSafeVector revPropValues;
2194 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
2196 CString sErr;
2197 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2198 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
2200 else
2202 if (bugIDOut)
2204 bugIdOutSet = true;
2205 m_sBugID = bugIDOut;
2206 SetDlgItemText(IDC_BUGID, m_sBugID);
2208 m_cLogMessage.SetText((LPCTSTR)temp);
2211 else
2213 // if IBugTraqProvider2 failed, try IBugTraqProvider
2214 CComPtr<IBugTraqProvider> pProvider;
2215 hr = m_BugTraqProvider.QueryInterface(&pProvider);
2216 if (FAILED(hr))
2218 CString sErr;
2219 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2220 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
2221 return;
2224 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
2226 CString sErr;
2227 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2228 CMessageBox::Show(GetSafeHwnd(), sErr, L"TortoiseGit", MB_ICONERROR);
2230 else
2231 m_cLogMessage.SetText((LPCTSTR)temp);
2233 m_sLogMessage = m_cLogMessage.GetText();
2234 if (!m_ProjectProperties.sMessage.IsEmpty())
2236 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
2237 if (!sBugID.IsEmpty() && !bugIdOutSet)
2238 SetDlgItemText(IDC_BUGID, sBugID);
2241 m_cLogMessage.SetFocus();
2244 void CCommitDlg::FillPatchView(bool onlySetTimer)
2246 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2248 KillTimer(FILLPATCHVTIMER);
2249 if (onlySetTimer)
2251 SetTimer(FILLPATCHVTIMER, 100, nullptr);
2252 return;
2255 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
2256 CString cmd,out;
2258 while(pos)
2260 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
2261 auto p = m_ListCtrl.GetListEntry(nSelect);
2262 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
2264 CString head = L"HEAD";
2265 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
2266 head = L"HEAD~1";
2267 cmd.Format(L"git.exe diff %s -- \"%s\"", (LPCTSTR)head, (LPCTSTR)p->GetGitPathString());
2268 g_Git.Run(cmd, &out, CP_UTF8);
2272 m_patchViewdlg.SetText(out);
2275 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
2277 this->FillPatchView(true);
2278 return 0;
2282 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
2284 SendMessage(WM_UPDATEOKBUTTON);
2285 return 0;
2288 LRESULT CCommitDlg::OnCheck(WPARAM wnd, LPARAM)
2290 HWND hwnd = (HWND)wnd;
2291 bool check = !(GetAsyncKeyState(VK_SHIFT) & 0x8000);
2292 if (hwnd == GetDlgItem(IDC_CHECKALL)->GetSafeHwnd())
2293 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, check);
2294 else if (hwnd == GetDlgItem(IDC_CHECKNONE)->GetSafeHwnd())
2295 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, !check);
2296 else if (hwnd == GetDlgItem(IDC_CHECKUNVERSIONED)->GetSafeHwnd())
2297 m_ListCtrl.Check(GITSLC_SHOWUNVERSIONED, check);
2298 else if (hwnd == GetDlgItem(IDC_CHECKVERSIONED)->GetSafeHwnd())
2299 m_ListCtrl.Check(GITSLC_SHOWVERSIONED, check);
2300 else if (hwnd == GetDlgItem(IDC_CHECKADDED)->GetSafeHwnd())
2301 m_ListCtrl.Check(GITSLC_SHOWADDED, check);
2302 else if (hwnd == GetDlgItem(IDC_CHECKDELETED)->GetSafeHwnd())
2303 m_ListCtrl.Check(GITSLC_SHOWREMOVED, check);
2304 else if (hwnd == GetDlgItem(IDC_CHECKMODIFIED)->GetSafeHwnd())
2305 m_ListCtrl.Check(GITSLC_SHOWMODIFIED, check);
2306 else if (hwnd == GetDlgItem(IDC_CHECKFILES)->GetSafeHwnd())
2307 m_ListCtrl.Check(GITSLC_SHOWFILES, check);
2308 else if (hwnd == GetDlgItem(IDC_CHECKSUBMODULES)->GetSafeHwnd())
2309 m_ListCtrl.Check(GITSLC_SHOWSUBMODULES, check);
2311 return 0;
2314 LRESULT CCommitDlg::OnUpdateOKButton(WPARAM, LPARAM)
2316 if (m_bBlock)
2317 return 0;
2319 CString text = m_cLogMessage.GetText().Trim();
2320 bool bValidLogSize = !text.IsEmpty() && text.GetLength() >= m_ProjectProperties.nMinLogSize;
2321 bool bAmendOrSelectFilesOrMerge = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit) || CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
2323 DialogEnableWindow(IDOK, bValidLogSize && (m_bCommitMessageOnly || bAmendOrSelectFilesOrMerge));
2325 return 0;
2328 LRESULT CCommitDlg::OnUpdateDataFalse(WPARAM, LPARAM)
2330 UpdateData(FALSE);
2331 return 0;
2334 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
2336 switch (message) {
2337 case WM_NOTIFY:
2338 if (wParam == IDC_SPLITTER)
2340 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2341 DoSize(pHdr->delta);
2343 break;
2344 case WM_COMMAND:
2345 if (m_hAccelOkButton && LOWORD(wParam) >= WM_USER && LOWORD(wParam) <= WM_USER + m_accellerators.size())
2347 for (const auto& entry : m_accellerators)
2349 if (entry.second.wmid != LOWORD(wParam))
2350 continue;
2351 if (entry.second.id == -1)
2352 m_ctrlOkButton.PostMessage(WM_KEYDOWN, VK_F4, NULL);
2353 else
2355 m_ctrlOkButton.SetCurrentEntry(entry.second.id);
2356 OnOK();
2358 return 0;
2361 break;
2364 return __super::DefWindowProc(message, wParam, lParam);
2367 void CCommitDlg::SetSplitterRange()
2369 if ((m_ListCtrl)&&(m_cLogMessage))
2371 CRect rcTop;
2372 m_cLogMessage.GetWindowRect(rcTop);
2373 ScreenToClient(rcTop);
2374 CRect rcMiddle;
2375 m_ListCtrl.GetWindowRect(rcMiddle);
2376 ScreenToClient(rcMiddle);
2377 if (rcMiddle.Height() && rcMiddle.Width())
2378 m_wndSplitter.SetRange(rcTop.top + 100, rcMiddle.bottom - 80);
2382 void CCommitDlg::DoSize(int delta)
2384 RemoveAnchor(IDC_MESSAGEGROUP);
2385 RemoveAnchor(IDC_LOGMESSAGE);
2386 RemoveAnchor(IDC_SPLITTER);
2387 RemoveAnchor(IDC_SIGNOFF);
2388 RemoveAnchor(IDC_COMMIT_AMEND);
2389 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
2390 RemoveAnchor(IDC_COMMIT_SETDATETIME);
2391 RemoveAnchor(IDC_COMMIT_DATEPICKER);
2392 RemoveAnchor(IDC_COMMIT_TIMEPICKER);
2393 RemoveAnchor(IDC_COMMIT_AS_COMMIT_DATE);
2394 RemoveAnchor(IDC_COMMIT_SETAUTHOR);
2395 RemoveAnchor(IDC_COMMIT_AUTHORDATA);
2396 RemoveAnchor(IDC_LISTGROUP);
2397 RemoveAnchor(IDC_FILELIST);
2398 RemoveAnchor(IDC_TEXT_INFO);
2399 RemoveAnchor(IDC_SELECTLABEL);
2400 RemoveAnchor(IDC_CHECKALL);
2401 RemoveAnchor(IDC_CHECKNONE);
2402 RemoveAnchor(IDC_CHECKUNVERSIONED);
2403 RemoveAnchor(IDC_CHECKVERSIONED);
2404 RemoveAnchor(IDC_CHECKADDED);
2405 RemoveAnchor(IDC_CHECKDELETED);
2406 RemoveAnchor(IDC_CHECKMODIFIED);
2407 RemoveAnchor(IDC_CHECKFILES);
2408 RemoveAnchor(IDC_CHECKSUBMODULES);
2410 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
2411 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
2412 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
2413 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
2414 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
2415 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
2416 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
2417 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME),0,delta);
2418 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER),0,delta);
2419 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER),0,delta);
2420 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AS_COMMIT_DATE), 0, delta);
2421 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETAUTHOR), 0, delta);
2422 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AUTHORDATA), 0, delta);
2423 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
2424 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL), 0, delta);
2425 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL), 0, delta);
2426 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE), 0, delta);
2427 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED), 0, delta);
2428 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED), 0, delta);
2429 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED), 0, delta);
2430 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED), 0, delta);
2431 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED), 0, delta);
2432 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES), 0, delta);
2433 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES), 0, delta);
2435 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
2436 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
2437 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
2438 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
2439 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
2440 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
2441 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
2442 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
2443 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
2444 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
2445 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
2446 AddAnchor(IDC_COMMIT_AS_COMMIT_DATE, TOP_LEFT);
2447 AddAnchor(IDC_COMMIT_SETAUTHOR, TOP_LEFT);
2448 AddAnchor(IDC_COMMIT_AUTHORDATA, TOP_LEFT, TOP_RIGHT);
2449 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
2450 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
2451 AddAnchor(IDC_CHECKALL, TOP_LEFT);
2452 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
2453 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
2454 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
2455 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
2456 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
2457 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
2458 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
2459 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
2460 ArrangeLayout();
2461 // adjust the minimum size of the dialog to prevent the resizing from
2462 // moving the list control too far down.
2463 CRect rcLogMsg;
2464 m_cLogMessage.GetClientRect(rcLogMsg);
2465 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
2467 SetSplitterRange();
2468 m_cLogMessage.Invalidate();
2469 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
2472 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
2474 // first, let the resizing take place
2475 __super::OnSize(nType, cx, cy);
2477 //set range
2478 SetSplitterRange();
2481 CString CCommitDlg::GetSignedOffByLine()
2483 CString str;
2485 CString username = g_Git.GetUserName();
2486 CString email = g_Git.GetUserEmail();
2487 username.Remove(L'\n');
2488 email.Remove(L'\n');
2490 str.Format(L"Signed-off-by: %s <%s>", (LPCTSTR)username, (LPCTSTR)email);
2492 return str;
2495 void CCommitDlg::OnBnClickedSignOff()
2497 CString str = GetSignedOffByLine();
2499 if (m_cLogMessage.GetText().Find(str) == -1) {
2500 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
2501 int lastNewline = m_cLogMessage.GetText().ReverseFind(L'\n');
2502 int foundByLine = -1;
2503 if (lastNewline > 0)
2504 foundByLine = m_cLogMessage.GetText().Find(L"-by: ", lastNewline);
2506 if (foundByLine == -1 || foundByLine < lastNewline)
2507 str = L"\r\n" + str;
2509 m_cLogMessage.SetText(m_cLogMessage.GetText() + L"\r\n" + str + L"\r\n");
2513 void CCommitDlg::OnBnClickedCommitAmend()
2515 this->UpdateData();
2516 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
2518 GitRev rev;
2519 if (rev.GetCommit(L"HEAD"))
2520 MessageBox(rev.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2521 m_AmendStr = rev.GetSubject() + L'\n' + rev.GetBody();
2524 if(this->m_bCommitAmend)
2526 this->m_NoAmendStr=this->m_cLogMessage.GetText();
2527 m_cLogMessage.SetText(m_AmendStr);
2528 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
2529 if (m_bSetCommitDateTime)
2530 m_AsCommitDateCtrl.ShowWindow(SW_SHOW);
2532 else
2534 this->m_AmendStr=this->m_cLogMessage.GetText();
2535 m_cLogMessage.SetText(m_NoAmendStr);
2536 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
2537 m_AsCommitDateCtrl.ShowWindow(SW_HIDE);
2538 m_AsCommitDateCtrl.SetCheck(FALSE);
2539 OnBnClickedCommitAsCommitDate();
2542 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2543 OnBnClickedCommitSetauthor(); // to update the commit author
2545 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2546 Refresh();
2549 void CCommitDlg::OnBnClickedCommitMessageOnly()
2551 this->UpdateData();
2552 this->m_ListCtrl.EnableWindow(m_bCommitMessageOnly ? FALSE : TRUE);
2553 SendMessage(WM_UPDATEOKBUTTON);
2556 void CCommitDlg::OnBnClickedWholeProject()
2558 m_tooltips.Pop(); // hide the tooltips
2559 UpdateData();
2560 m_ListCtrl.Clear();
2561 if (!m_bBlock)
2563 if (m_bWholeProject || m_bWholeProject2)
2564 m_ListCtrl.GetStatus(nullptr, true, false, true);
2565 else
2566 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
2568 m_regShowWholeProject = m_bWholeProject;
2570 DWORD dwShow = m_ListCtrl.GetShowFlags();
2571 if (DWORD(m_regAddBeforeCommit))
2572 dwShow |= GITSLC_SHOWUNVERSIONED;
2573 else
2574 dwShow &= ~GITSLC_SHOWUNVERSIONED;
2576 m_ListCtrl.StoreScrollPos();
2577 m_ListCtrl.Show(dwShow, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
2578 UpdateCheckLinks();
2581 SetDlgTitle();
2584 void CCommitDlg::OnFocusMessage()
2586 m_cLogMessage.SetFocus();
2589 void CCommitDlg::OnFocusFileList()
2591 m_ListCtrl.SetFocus();
2594 void CCommitDlg::OnScnUpdateUI(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2596 int pos = (int)this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
2597 int line = (int)this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
2598 int column = (int)this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
2600 CString str;
2601 str.Format(L"%d/%d", line + 1, column + 1);
2602 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
2604 if(*pResult)
2605 *pResult=0;
2608 void CCommitDlg::TogglePatchView()
2610 OnStnClickedViewPatch();
2613 void CCommitDlg::OnStnClickedViewPatch()
2615 m_patchViewdlg.m_ParentDlg = this;
2616 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
2618 BOOL viewPatchEnabled = FALSE;
2619 viewPatchEnabled = g_Git.GetConfigValueBool(L"tgit.commitshowpatch");
2620 if (viewPatchEnabled == FALSE)
2621 g_Git.SetConfigValue(L"tgit.commitshowpatch", L"true");
2622 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
2623 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2624 CRect rect;
2625 this->GetWindowRect(&rect);
2627 m_patchViewdlg.ShowWindow(SW_SHOW);
2629 m_patchViewdlg.SetWindowPos(nullptr, rect.right, rect.top, (DWORD)CRegStdDWORD(L"Software\\TortoiseGit\\TortoiseProc\\PatchDlgWidth", rect.Width()), rect.Height(),
2630 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
2632 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2634 ShowViewPatchText(false);
2635 FillPatchView();
2637 else
2639 g_Git.SetConfigValue(L"tgit.commitshowpatch", L"false");
2640 m_patchViewdlg.ShowWindow(SW_HIDE);
2641 m_patchViewdlg.DestroyWindow();
2642 ShowViewPatchText(true);
2644 this->m_ctrlShowPatch.Invalidate();
2647 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
2649 __super::OnMoving(fwSide, pRect);
2651 if (::IsWindow(m_patchViewdlg.m_hWnd))
2653 RECT patchrect;
2654 m_patchViewdlg.GetWindowRect(&patchrect);
2655 if (::IsWindow(m_hWnd))
2657 RECT thisrect;
2658 GetWindowRect(&thisrect);
2659 if (patchrect.left == thisrect.right)
2661 m_patchViewdlg.SetWindowPos(nullptr, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2662 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2668 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2670 __super::OnSizing(fwSide, pRect);
2672 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2674 CRect thisrect, patchrect;
2675 this->GetWindowRect(thisrect);
2676 this->m_patchViewdlg.GetWindowRect(patchrect);
2677 if(thisrect.right==patchrect.left)
2679 patchrect.left -= (thisrect.right - pRect->right);
2680 patchrect.right-= (thisrect.right - pRect->right);
2682 if( patchrect.bottom == thisrect.bottom)
2683 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2684 if( patchrect.top == thisrect.top)
2685 patchrect.top -= thisrect.top-pRect->top;
2686 m_patchViewdlg.MoveWindow(patchrect);
2691 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2693 *pResult = 0;
2694 TRACE("Item Changed\r\n");
2697 int CCommitDlg::CheckHeadDetach()
2699 CString output;
2700 if (CGit::GetCurrentBranchFromFile(g_Git.m_CurrentDir, output))
2702 int retval = CMessageBox::Show(GetSafeHwnd(), IDS_PROC_COMMIT_DETACHEDWARNING, IDS_APPNAME, MB_YESNOCANCEL | MB_ICONWARNING);
2703 if(retval == IDYES)
2705 if (CAppUtils::CreateBranchTag(FALSE, nullptr, true) == FALSE)
2706 return 1;
2708 else if (retval == IDCANCEL)
2709 return 1;
2711 return 0;
2714 void CCommitDlg::OnBnClickedCommitAmenddiff()
2716 UpdateData();
2717 Refresh();
2720 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2722 UpdateData();
2723 Refresh();
2726 void CCommitDlg::OnBnClickedCommitSetDateTime()
2728 UpdateData();
2730 if (m_bSetCommitDateTime)
2732 CTime authordate = CTime::GetCurrentTime();
2733 if (m_bCommitAmend)
2735 GitRev headRevision;
2736 if (headRevision.GetCommit(L"HEAD"))
2737 MessageBox(headRevision.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2738 authordate = headRevision.GetAuthorDate();
2739 m_AsCommitDateCtrl.ShowWindow(SW_SHOW);
2742 m_CommitDate.SetTime(&authordate);
2743 m_CommitTime.SetTime(&authordate);
2745 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
2746 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
2748 else
2750 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_HIDE);
2751 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_HIDE);
2752 m_AsCommitDateCtrl.ShowWindow(SW_HIDE);
2753 m_AsCommitDateCtrl.SetCheck(FALSE);
2754 OnBnClickedCommitAsCommitDate();
2758 void CCommitDlg::OnBnClickedCommitAsCommitDate()
2760 GetDlgItem(IDC_COMMIT_DATEPICKER)->EnableWindow(!m_AsCommitDateCtrl.GetCheck());
2761 GetDlgItem(IDC_COMMIT_TIMEPICKER)->EnableWindow(!m_AsCommitDateCtrl.GetCheck());
2764 void CCommitDlg::OnBnClickedCheckNewBranch()
2766 UpdateData();
2767 if (m_bCreateNewBranch)
2769 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_HIDE);
2770 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_SHOW);
2772 else
2774 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
2775 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);
2779 bool CCommitDlg::RestoreFiles(bool doNotAsk, bool allowCancel)
2781 if (m_ListCtrl.m_restorepaths.empty())
2782 return true;
2784 if (!doNotAsk)
2786 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);
2787 if (ret == 3)
2788 return false;
2789 if (ret == 2)
2790 return true;
2793 for (const auto& item : m_ListCtrl.m_restorepaths)
2794 CopyFile(item.second, g_Git.CombinePath(item.first), FALSE);
2795 m_ListCtrl.m_restorepaths.clear();
2797 return true;
2800 void CCommitDlg::UpdateCheckLinks()
2802 DialogEnableWindow(IDC_CHECKALL, true);
2803 DialogEnableWindow(IDC_CHECKNONE, true);
2804 DialogEnableWindow(IDC_CHECKUNVERSIONED, m_ListCtrl.GetUnversionedCount() > 0);
2805 DialogEnableWindow(IDC_CHECKVERSIONED, m_ListCtrl.GetItemCount() > m_ListCtrl.GetUnversionedCount());
2806 DialogEnableWindow(IDC_CHECKADDED, m_ListCtrl.GetAddedCount() > 0);
2807 DialogEnableWindow(IDC_CHECKDELETED, m_ListCtrl.GetDeletedCount() > 0);
2808 DialogEnableWindow(IDC_CHECKMODIFIED, m_ListCtrl.GetModifiedCount() > 0);
2809 DialogEnableWindow(IDC_CHECKFILES, m_ListCtrl.GetFileCount() > 0);
2810 DialogEnableWindow(IDC_CHECKSUBMODULES, m_ListCtrl.GetSubmoduleCount() > 0);
2813 void CCommitDlg::OnBnClickedCommitSetauthor()
2815 UpdateData();
2817 if (m_bSetAuthor)
2819 m_sAuthor.Format(L"%s <%s>", (LPCTSTR)g_Git.GetUserName(), (LPCTSTR)g_Git.GetUserEmail());
2820 if (m_bCommitAmend)
2822 GitRev headRevision;
2823 if (headRevision.GetCommit(L"HEAD"))
2824 MessageBox(headRevision.GetLastErr(), L"TortoiseGit", MB_ICONERROR);
2825 m_sAuthor.Format(L"%s <%s>", (LPCTSTR)headRevision.GetAuthorName(), (LPCTSTR)headRevision.GetAuthorEmail());
2828 UpdateData(FALSE);
2830 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_SHOW);
2832 else
2833 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_HIDE);
2836 bool CCommitDlg::RunStartCommitHook()
2838 DWORD exitcode = 0xFFFFFFFF;
2839 CString error;
2840 if (CHooks::Instance().StartCommit(g_Git.m_CurrentDir, m_pathList, m_sLogMessage, exitcode, error))
2842 if (exitcode)
2844 CString temp;
2845 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2846 MessageBox(temp, L"TortoiseGit", MB_ICONERROR);
2847 return false;
2850 return true;
2853 void CCommitDlg::OnSysColorChange()
2855 __super::OnSysColorChange();
2856 m_cLogMessage.SetColors(true);
2857 m_cLogMessage.SetFont(CAppUtils::GetLogFontName(), CAppUtils::GetLogFontSize());