1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2014 - TortoiseSVN
4 // Copyright (C) 2008-2016 - 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.
21 #include "TortoiseProc.h"
22 #include "CommitDlg.h"
23 #include "MessageBox.h"
25 #include "PathUtils.h"
28 #include "GitStatus.h"
29 #include "HistoryDlg.h"
31 #include "UnicodeUtils.h"
32 #include "../TGitCache/CacheInterface.h"
33 #include "ProgressDlg.h"
34 #include "ShellUpdater.h"
35 #include "Commands/PushCommand.h"
38 #include "SysProgressDlg.h"
39 #include "MassiveGitTask.h"
41 #include "BstrSafeVector.h"
42 #include "StringUtils.h"
43 #include "FileTextLines.h"
48 static char THIS_FILE
[] = __FILE__
;
51 UINT
CCommitDlg::WM_AUTOLISTREADY
= RegisterWindowMessage(L
"TORTOISEGIT_AUTOLISTREADY_MSG");
52 UINT
CCommitDlg::WM_UPDATEOKBUTTON
= RegisterWindowMessage(L
"TORTOISEGIT_COMMIT_UPDATEOKBUTTON");
53 UINT
CCommitDlg::WM_UPDATEDATAFALSE
= RegisterWindowMessage(L
"TORTOISEGIT_COMMIT_UPDATEDATAFALSE");
55 IMPLEMENT_DYNAMIC(CCommitDlg
, CResizableStandAloneDialog
)
56 CCommitDlg::CCommitDlg(CWnd
* pParent
/*=nullptr*/)
57 : CResizableStandAloneDialog(CCommitDlg::IDD
, pParent
)
58 , m_bShowUnversioned(FALSE
)
60 , m_bThreadRunning(FALSE
)
63 , m_bWholeProject(FALSE
)
64 , m_bWholeProject2(FALSE
)
65 , m_bKeepChangeList(TRUE
)
66 , m_bDoNotAutoselectSubmodules(FALSE
)
68 , m_bSelectFilesForCommit(TRUE
)
69 , m_bNoPostActions(FALSE
)
71 , m_bSetCommitDateTime(FALSE
)
72 , m_bCreateNewBranch(FALSE
)
73 , m_bForceCommitAmend(false)
74 , m_bCommitMessageOnly(FALSE
)
77 , m_PostCmd(GIT_POSTCOMMIT_CMD_NOTHING
)
78 , m_bAmendDiffToLastCommit(FALSE
)
79 , m_nPopupPasteListCmd(0)
80 , m_nPopupPasteLastMessage(0)
81 , m_nPopupRecentMessage(0)
82 , m_nPopupPickCommitHash(0)
83 , m_nPopupPickCommitMessage(0)
85 , m_bWarnDetachedHead(true)
86 , m_hAccelOkButton(nullptr)
87 , m_bDoNotStoreLastSelectedLine(true)
89 this->m_bCommitAmend
=FALSE
;
92 CCommitDlg::~CCommitDlg()
95 DestroyAcceleratorTable(m_hAccelOkButton
);
99 void CCommitDlg::DoDataExchange(CDataExchange
* pDX
)
101 CResizableStandAloneDialog::DoDataExchange(pDX
);
102 DDX_Control(pDX
, IDC_FILELIST
, m_ListCtrl
);
103 DDX_Control(pDX
, IDC_LOGMESSAGE
, m_cLogMessage
);
104 DDX_Check(pDX
, IDC_SHOWUNVERSIONED
, m_bShowUnversioned
);
105 DDX_Check(pDX
, IDC_COMMIT_SETDATETIME
, m_bSetCommitDateTime
);
106 DDX_Check(pDX
, IDC_CHECK_NEWBRANCH
, m_bCreateNewBranch
);
107 DDX_Text(pDX
, IDC_NEWBRANCH
, m_sCreateNewBranch
);
108 DDX_Text(pDX
, IDC_BUGID
, m_sBugID
);
109 DDX_Text(pDX
, IDC_COMMIT_AUTHORDATA
, m_sAuthor
);
110 DDX_Check(pDX
, IDC_WHOLE_PROJECT
, m_bWholeProject
);
111 DDX_Control(pDX
, IDC_SPLITTER
, m_wndSplitter
);
112 DDX_Check(pDX
, IDC_KEEPLISTS
, m_bKeepChangeList
);
113 DDX_Check(pDX
, IDC_NOAUTOSELECTSUBMODULES
, m_bDoNotAutoselectSubmodules
);
114 DDX_Check(pDX
,IDC_COMMIT_AMEND
,m_bCommitAmend
);
115 DDX_Check(pDX
, IDC_COMMIT_MESSAGEONLY
, m_bCommitMessageOnly
);
116 DDX_Check(pDX
,IDC_COMMIT_AMENDDIFF
,m_bAmendDiffToLastCommit
);
117 DDX_Check(pDX
, IDC_COMMIT_SETAUTHOR
, m_bSetAuthor
);
118 DDX_Control(pDX
,IDC_VIEW_PATCH
,m_ctrlShowPatch
);
119 DDX_Control(pDX
, IDC_COMMIT_DATEPICKER
, m_CommitDate
);
120 DDX_Control(pDX
, IDC_COMMIT_TIMEPICKER
, m_CommitTime
);
121 DDX_Control(pDX
, IDC_COMMIT_AS_COMMIT_DATE
, m_AsCommitDateCtrl
);
122 DDX_Control(pDX
, IDC_CHECKALL
, m_CheckAll
);
123 DDX_Control(pDX
, IDC_CHECKNONE
, m_CheckNone
);
124 DDX_Control(pDX
, IDC_CHECKUNVERSIONED
, m_CheckUnversioned
);
125 DDX_Control(pDX
, IDC_CHECKVERSIONED
, m_CheckVersioned
);
126 DDX_Control(pDX
, IDC_CHECKADDED
, m_CheckAdded
);
127 DDX_Control(pDX
, IDC_CHECKDELETED
, m_CheckDeleted
);
128 DDX_Control(pDX
, IDC_CHECKMODIFIED
, m_CheckModified
);
129 DDX_Control(pDX
, IDC_CHECKFILES
, m_CheckFiles
);
130 DDX_Control(pDX
, IDC_CHECKSUBMODULES
, m_CheckSubmodules
);
131 DDX_Control(pDX
, IDOK
, m_ctrlOkButton
);
134 BEGIN_MESSAGE_MAP(CCommitDlg
, CResizableStandAloneDialog
)
135 ON_BN_CLICKED(IDC_SHOWUNVERSIONED
, OnBnClickedShowunversioned
)
136 ON_NOTIFY(SCN_UPDATEUI
, IDC_LOGMESSAGE
, OnScnUpdateUI
)
137 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
138 ON_BN_CLICKED(IDC_BUGTRAQBUTTON
, OnBnClickedBugtraqbutton
)
139 ON_EN_CHANGE(IDC_LOGMESSAGE
, OnEnChangeLogmessage
)
140 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
, OnGitStatusListCtrlItemCountChanged
)
141 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
142 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE
, OnFileDropped
)
143 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED
, &CCommitDlg::OnGitStatusListCtrlCheckChanged
)
144 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED
, &CCommitDlg::OnGitStatusListCtrlItemChanged
)
146 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED
, &CCommitDlg::OnCheck
)
147 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY
, OnAutoListReady
)
148 ON_REGISTERED_MESSAGE(WM_UPDATEOKBUTTON
, OnUpdateOKButton
)
149 ON_REGISTERED_MESSAGE(WM_UPDATEDATAFALSE
, OnUpdateDataFalse
)
152 ON_WM_SYSCOLORCHANGE()
153 ON_STN_CLICKED(IDC_EXTERNALWARNING
, &CCommitDlg::OnStnClickedExternalwarning
)
154 ON_BN_CLICKED(IDC_SIGNOFF
, &CCommitDlg::OnBnClickedSignOff
)
155 ON_BN_CLICKED(IDC_COMMIT_AMEND
, &CCommitDlg::OnBnClickedCommitAmend
)
156 ON_BN_CLICKED(IDC_COMMIT_MESSAGEONLY
, &CCommitDlg::OnBnClickedCommitMessageOnly
)
157 ON_BN_CLICKED(IDC_WHOLE_PROJECT
, &CCommitDlg::OnBnClickedWholeProject
)
158 ON_COMMAND(ID_FOCUS_MESSAGE
,&CCommitDlg::OnFocusMessage
)
159 ON_COMMAND(ID_FOCUS_FILELIST
, OnFocusFileList
)
160 ON_STN_CLICKED(IDC_VIEW_PATCH
, &CCommitDlg::OnStnClickedViewPatch
)
164 ON_NOTIFY(HDN_ITEMCHANGED
, 0, &CCommitDlg::OnHdnItemchangedFilelist
)
165 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF
, &CCommitDlg::OnBnClickedCommitAmenddiff
)
166 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES
, &CCommitDlg::OnBnClickedNoautoselectsubmodules
)
167 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME
, &CCommitDlg::OnBnClickedCommitSetDateTime
)
168 ON_BN_CLICKED(IDC_COMMIT_AS_COMMIT_DATE
, &CCommitDlg::OnBnClickedCommitAsCommitDate
)
169 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH
, &CCommitDlg::OnBnClickedCheckNewBranch
)
170 ON_BN_CLICKED(IDC_COMMIT_SETAUTHOR
, &CCommitDlg::OnBnClickedCommitSetauthor
)
173 int GetCommitTemplate(CString
&msg
)
175 CString tplFilename
= g_Git
.GetConfigValue(L
"commit.template");
176 if (tplFilename
.IsEmpty())
179 if (tplFilename
[0] == L
'/')
181 if (tplFilename
.GetLength() >= 3)
183 // handle "/d/TortoiseGit/tpl.txt" -> "d:/TortoiseGit/tpl.txt"
184 if (tplFilename
[2] == L
'/')
186 LPWSTR buf
= tplFilename
.GetBuffer();
189 tplFilename
.ReleaseBuffer();
194 tplFilename
.Replace(L
'/', L
'\\');
196 if (!CGit::LoadTextFile(tplFilename
, msg
))
201 BOOL
CCommitDlg::OnInitDialog()
203 CResizableStandAloneDialog::OnInitDialog();
204 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
206 if (m_sLogMessage
.IsEmpty())
208 if (!m_bForceCommitAmend
)
209 GetCommitTemplate(m_sLogMessage
);
212 GitAdminDir::GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
213 CGit::LoadTextFile(dotGitPath
+ L
"SQUASH_MSG", m_sLogMessage
);
214 CGit::LoadTextFile(dotGitPath
+ L
"MERGE_MSG", m_sLogMessage
);
216 if (!RunStartCommitHook())
222 m_regAddBeforeCommit
= CRegDWORD(L
"Software\\TortoiseGit\\AddBeforeCommit", TRUE
);
223 m_bShowUnversioned
= m_regAddBeforeCommit
;
225 CString
regPath(g_Git
.m_CurrentDir
);
226 regPath
.Replace(L
':', L
'_');
227 m_regShowWholeProject
= CRegDWORD(L
"Software\\TortoiseGit\\TortoiseProc\\ShowWholeProject\\" + regPath
, FALSE
);
228 m_bWholeProject
= m_regShowWholeProject
;
230 m_History
.SetMaxHistoryItems((LONG
)CRegDWORD(L
"Software\\TortoiseGit\\MaxHistoryItems", 25));
232 m_regKeepChangelists
= CRegDWORD(L
"Software\\TortoiseGit\\KeepChangeLists", FALSE
);
233 m_bKeepChangeList
= m_regKeepChangelists
;
235 m_regDoNotAutoselectSubmodules
= CRegDWORD(L
"Software\\TortoiseGit\\DoNotAutoselectSubmodules", FALSE
);
236 m_bDoNotAutoselectSubmodules
= m_regDoNotAutoselectSubmodules
;
238 m_hAccel
= LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG
));
240 if (m_pathList
.IsEmpty())
241 m_bWholeProject2
= true;
243 if(this->m_pathList
.GetCount() == 1 && m_pathList
[0].IsEmpty())
244 m_bWholeProject2
= true;
249 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_SHOW
);
251 if (m_bSetCommitDateTime
)
253 m_CommitDate
.SetTime(&m_wantCommitTime
);
254 m_CommitTime
.SetTime(&m_wantCommitTime
);
255 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_SHOW
);
256 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_SHOW
);
261 m_ListCtrl
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
, L
"CommitDlg", (GITSLC_POPALL
^ (GITSLC_POPCOMMIT
| GITSLC_POPSAVEAS
| GITSLC_PREPAREDIFF
)), true, true);
262 m_ListCtrl
.SetStatLabel(GetDlgItem(IDC_STATISTICS
));
263 m_ListCtrl
.SetCancelBool(&m_bCancelled
);
264 m_ListCtrl
.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT
);
265 m_ListCtrl
.EnableFileDrop();
266 m_ListCtrl
.SetBackgroundImage(IDI_COMMIT_BKG
);
268 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
269 m_ProjectProperties
.ReadProps();
271 m_cLogMessage
.Init(m_ProjectProperties
);
272 m_cLogMessage
.SetFont(CAppUtils::GetLogFontName(), CAppUtils::GetLogFontSize());
273 m_cLogMessage
.RegisterContextMenuHandler(this);
274 std::map
<int, UINT
> icons
;
275 icons
[AUTOCOMPLETE_SPELLING
] = IDI_SPELL
;
276 icons
[AUTOCOMPLETE_FILENAME
] = IDI_FILE
;
277 icons
[AUTOCOMPLETE_PROGRAMCODE
] = IDI_CODE
;
278 icons
[AUTOCOMPLETE_SNIPPET
] = IDI_SNIPPET
;
279 m_cLogMessage
.SetIcon(icons
);
281 OnEnChangeLogmessage();
283 m_tooltips
.AddTool(IDC_EXTERNALWARNING
, IDS_COMMITDLG_EXTERNALS
);
284 m_tooltips
.AddTool(IDC_COMMIT_AMEND
,IDS_COMMIT_AMEND_TT
);
285 m_tooltips
.AddTool(IDC_MERGEACTIVE
, IDC_MERGEACTIVE_TT
);
286 m_tooltips
.AddTool(IDC_COMMIT_MESSAGEONLY
, IDS_COMMIT_MESSAGEONLY_TT
);
287 m_tooltips
.AddTool(IDC_COMMIT_AS_COMMIT_DATE
, IDS_COMMIT_AS_COMMIT_DATE_TT
);
289 CBugTraqAssociations bugtraq_associations
;
290 bugtraq_associations
.Load(m_ProjectProperties
.GetProviderUUID(), m_ProjectProperties
.sProviderParams
);
292 if (bugtraq_associations
.FindProvider(g_Git
.m_CurrentDir
, &m_bugtraq_association
))
294 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
295 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
297 CComPtr
<IBugTraqProvider
> pProvider
;
298 HRESULT hr
= pProvider
.CoCreateInstance(m_bugtraq_association
.GetProviderClass());
301 m_BugTraqProvider
= pProvider
;
303 ATL::CComBSTR
parameters(m_bugtraq_association
.GetParameters());
304 if (SUCCEEDED(hr
= pProvider
->GetLinkText(GetSafeHwnd(), parameters
, &temp
)))
306 SetDlgItemText(IDC_BUGTRAQBUTTON
, temp
);
307 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(TRUE
);
308 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_SHOW
);
312 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
314 else if (!m_ProjectProperties
.sMessage
.IsEmpty())
316 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_SHOW
);
317 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_SHOW
);
318 if (!m_ProjectProperties
.sLabel
.IsEmpty())
319 SetDlgItemText(IDC_BUGIDLABEL
, m_ProjectProperties
.sLabel
);
320 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
321 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
322 GetDlgItem(IDC_BUGID
)->SetFocus();
323 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(m_sLogMessage
);
324 if (!sBugID
.IsEmpty())
326 SetDlgItemText(IDC_BUGID
, sBugID
);
331 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
332 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
333 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
334 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
335 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
338 if (!m_sLogMessage
.IsEmpty())
340 m_cLogMessage
.SetText(m_sLogMessage
);
341 m_cLogMessage
.Call(SCI_SETCURRENTPOS
, 0);
342 m_cLogMessage
.Call(SCI_SETSEL
, 0, 0);
345 GetWindowText(m_sWindowTitle
);
347 AdjustControlSize(IDC_SHOWUNVERSIONED
);
348 AdjustControlSize(IDC_WHOLE_PROJECT
);
349 AdjustControlSize(IDC_CHECK_NEWBRANCH
);
350 AdjustControlSize(IDC_COMMIT_AMEND
);
351 AdjustControlSize(IDC_COMMIT_MESSAGEONLY
);
352 AdjustControlSize(IDC_COMMIT_AMENDDIFF
);
353 AdjustControlSize(IDC_COMMIT_SETDATETIME
);
354 AdjustControlSize(IDC_COMMIT_SETAUTHOR
);
355 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES
);
356 AdjustControlSize(IDC_KEEPLISTS
);
357 AdjustControlSize(IDC_COMMIT_AS_COMMIT_DATE
);
359 // line up all controls and adjust their sizes.
360 #define LINKSPACING 9
361 RECT rc
= AdjustControlSize(IDC_SELECTLABEL
);
362 rc
.right
-= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
363 rc
= AdjustStaticSize(IDC_CHECKALL
, rc
, LINKSPACING
);
364 rc
= AdjustStaticSize(IDC_CHECKNONE
, rc
, LINKSPACING
);
365 rc
= AdjustStaticSize(IDC_CHECKUNVERSIONED
, rc
, LINKSPACING
);
366 rc
= AdjustStaticSize(IDC_CHECKVERSIONED
, rc
, LINKSPACING
);
367 rc
= AdjustStaticSize(IDC_CHECKADDED
, rc
, LINKSPACING
);
368 rc
= AdjustStaticSize(IDC_CHECKDELETED
, rc
, LINKSPACING
);
369 rc
= AdjustStaticSize(IDC_CHECKMODIFIED
, rc
, LINKSPACING
);
370 rc
= AdjustStaticSize(IDC_CHECKFILES
, rc
, LINKSPACING
);
371 rc
= AdjustStaticSize(IDC_CHECKSUBMODULES
, rc
, LINKSPACING
);
373 GetClientRect(m_DlgOrigRect
);
374 m_cLogMessage
.GetClientRect(m_LogMsgOrigRect
);
376 AddAnchor(IDC_COMMITLABEL
, TOP_LEFT
, TOP_RIGHT
);
377 AddAnchor(IDC_BUGIDLABEL
, TOP_RIGHT
);
378 AddAnchor(IDC_BUGID
, TOP_RIGHT
);
379 AddAnchor(IDC_BUGTRAQBUTTON
, TOP_RIGHT
);
380 AddAnchor(IDC_COMMIT_TO
, TOP_LEFT
, TOP_RIGHT
);
381 AddAnchor(IDC_CHECK_NEWBRANCH
, TOP_RIGHT
);
382 AddAnchor(IDC_NEWBRANCH
, TOP_LEFT
, TOP_RIGHT
);
383 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
384 // AddAnchor(IDC_HISTORY, TOP_LEFT);
385 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
386 AddAnchor(IDC_SIGNOFF
, TOP_RIGHT
);
387 AddAnchor(IDC_VIEW_PATCH
, BOTTOM_RIGHT
);
388 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
389 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
390 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
391 AddAnchor(IDC_SHOWUNVERSIONED
, BOTTOM_LEFT
);
392 AddAnchor(IDC_EXTERNALWARNING
, BOTTOM_RIGHT
);
393 AddAnchor(IDC_STATISTICS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
394 AddAnchor(IDC_TEXT_INFO
, TOP_RIGHT
);
395 AddAnchor(IDC_WHOLE_PROJECT
, BOTTOM_LEFT
);
396 AddAnchor(IDC_KEEPLISTS
, BOTTOM_LEFT
);
397 AddAnchor(IDC_NOAUTOSELECTSUBMODULES
, BOTTOM_LEFT
);
398 AddAnchor(IDOK
, BOTTOM_RIGHT
);
399 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
400 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
401 AddAnchor(IDC_MERGEACTIVE
, BOTTOM_RIGHT
);
402 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
403 AddAnchor(IDC_COMMIT_MESSAGEONLY
, BOTTOM_LEFT
);
404 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
405 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
406 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
407 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
408 AddAnchor(IDC_COMMIT_AS_COMMIT_DATE
, TOP_LEFT
);
409 AddAnchor(IDC_COMMIT_SETAUTHOR
, TOP_LEFT
);
410 AddAnchor(IDC_COMMIT_AUTHORDATA
, TOP_LEFT
, TOP_RIGHT
);
412 AddAnchor(IDC_SELECTLABEL
, TOP_LEFT
);
413 AddAnchor(IDC_CHECKALL
, TOP_LEFT
);
414 AddAnchor(IDC_CHECKNONE
, TOP_LEFT
);
415 AddAnchor(IDC_CHECKUNVERSIONED
, TOP_LEFT
);
416 AddAnchor(IDC_CHECKVERSIONED
, TOP_LEFT
);
417 AddAnchor(IDC_CHECKADDED
, TOP_LEFT
);
418 AddAnchor(IDC_CHECKDELETED
, TOP_LEFT
);
419 AddAnchor(IDC_CHECKMODIFIED
, TOP_LEFT
);
420 AddAnchor(IDC_CHECKFILES
, TOP_LEFT
);
421 AddAnchor(IDC_CHECKSUBMODULES
, TOP_LEFT
);
424 CenterWindow(CWnd::FromHandle(hWndExplorer
));
425 EnableSaveRestore(L
"CommitDlg");
426 DWORD yPos
= CRegDWORD(L
"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer");
427 RECT rcDlg
, rcLogMsg
, rcFileList
;
428 GetClientRect(&rcDlg
);
429 m_cLogMessage
.GetWindowRect(&rcLogMsg
);
430 ScreenToClient(&rcLogMsg
);
431 m_ListCtrl
.GetWindowRect(&rcFileList
);
432 ScreenToClient(&rcFileList
);
436 m_wndSplitter
.GetWindowRect(&rectSplitter
);
437 ScreenToClient(&rectSplitter
);
438 int delta
= yPos
- rectSplitter
.top
;
439 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
441 m_wndSplitter
.SetWindowPos(nullptr, rectSplitter
.left
, yPos
, 0, 0, SWP_NOSIZE
);
448 if (m_bForceCommitAmend
|| m_bCommitAmend
)
449 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
451 // add all directories to the watcher
453 for (int i=0; i<m_pathList.GetCount(); ++i)
455 if (m_pathList[i].IsDirectory())
456 m_pathwatcher.AddPath(m_pathList[i]);
459 m_updatedPathList
= m_pathList
;
462 CRegDWORD err
= CRegDWORD(L
"Software\\TortoiseGit\\ErrorOccurred", FALSE
);
463 CRegDWORD historyhint
= CRegDWORD(L
"Software\\TortoiseGit\\HistoryHintShown", FALSE
);
464 if ((((DWORD
)err
)!=FALSE
)&&((((DWORD
)historyhint
)==FALSE
)))
467 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
471 this->m_ctrlShowPatch
.SetURL(CString());
473 if (g_Git
.GetConfigValueBool(L
"tgit.commitshowpatch"))
474 OnStnClickedViewPatch();
476 if (CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive())
478 DialogEnableWindow(IDC_CHECK_NEWBRANCH
, FALSE
);
479 m_bCreateNewBranch
= FALSE
;
480 GetDlgItem(IDC_MERGEACTIVE
)->ShowWindow(SW_SHOW
);
481 CMessageBox::ShowCheck(GetSafeHwnd(), IDS_COMMIT_MERGE_HINT
, IDS_APPNAME
, MB_ICONINFORMATION
, L
"CommitMergeHint", IDS_MSGBOX_DONOTSHOWAGAIN
);
486 return FALSE
; // return TRUE unless you set the focus to a control
487 // EXCEPTION: OCX Property Pages should return FALSE
490 void CCommitDlg::PrepareOkButton()
492 if (m_bNoPostActions
)
494 m_regLastAction
= CRegDWORD(L
"Software\\TortoiseGit\\CommitLastAction", 0);
496 for (auto labelId
: { IDS_COMMIT_COMMIT
, IDS_COMMIT_RECOMMIT
, IDS_COMMIT_COMMITPUSH
})
500 label
.LoadString(labelId
);
501 m_ctrlOkButton
.AddEntry(label
);
502 TCHAR accellerator
= CStringUtils::GetAccellerator(label
);
503 if (accellerator
== L
'\0')
505 ++m_accellerators
[accellerator
].cnt
;
506 if (m_accellerators
[accellerator
].cnt
> 1)
507 m_accellerators
[accellerator
].id
= -1;
509 m_accellerators
[accellerator
].id
= i
- 1;
511 m_ctrlOkButton
.SetCurrentEntry(m_regLastAction
);
512 if (m_accellerators
.size())
514 LPACCEL lpaccelNew
= (LPACCEL
)LocalAlloc(LPTR
, m_accellerators
.size() * sizeof(ACCEL
));
517 SCOPE_EXIT
{ LocalFree(lpaccelNew
); };
519 for (auto& entry
: m_accellerators
)
521 lpaccelNew
[i
].cmd
= (WORD
)(WM_USER
+ 1 + entry
.second
.id
);
522 lpaccelNew
[i
].fVirt
= FVIRTKEY
| FALT
;
523 lpaccelNew
[i
].key
= entry
.first
;
524 entry
.second
.wmid
= lpaccelNew
[i
].cmd
;
527 m_hAccelOkButton
= CreateAcceleratorTable(lpaccelNew
, (int)m_accellerators
.size());
531 static bool UpdateIndex(CMassiveGitTask
&mgt
, CSysProgressDlg
&sysProgressDlg
, int progress
, int maxProgress
)
533 if (!mgt
.GetListCount())
536 if (sysProgressDlg
.HasUserCancelled())
539 if (sysProgressDlg
.IsVisible())
541 sysProgressDlg
.SetTitle(IDS_APPNAME
);
542 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT
)));
543 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX
)));
544 sysProgressDlg
.SetProgress(progress
, maxProgress
);
545 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing
549 return mgt
.Execute(cancel
);
555 if (g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, head
))
557 CString remote
, remotebranch
;
558 g_Git
.GetRemotePushBranch(head
, remote
, remotebranch
);
559 if (remote
.IsEmpty() || remotebranch
.IsEmpty())
565 CAppUtils::DoPush(CAppUtils::IsSSHPutty(), false, false, false, false, false, false, head
, remote
, remotebranch
, false, 0);
568 void CCommitDlg::OnOK()
572 if (m_bThreadRunning
)
579 if (m_ListCtrl
.GetConflictedCount() != 0 && CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROGRS_CONFLICTSOCCURED
, IDS_APPNAME
, 1, IDI_EXCLAMATION
, IDS_OKBUTTON
, IDS_IGNOREBUTTON
, 0, L
"CommitWarnOnUnresolved") == 1)
581 auto pos
= m_ListCtrl
.GetFirstSelectedItemPosition();
583 m_ListCtrl
.SetItemState(m_ListCtrl
.GetNextSelectedItem(pos
), 0, LVIS_SELECTED
);
584 int nListItems
= m_ListCtrl
.GetItemCount();
585 for (int i
= 0; i
< nListItems
; ++i
)
587 auto entry
= m_ListCtrl
.GetListEntry(i
);
588 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
590 m_ListCtrl
.EnsureVisible(i
, FALSE
);
591 m_ListCtrl
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
592 m_ListCtrl
.SetFocus();
599 if (m_bCreateNewBranch
)
601 if (!g_Git
.IsBranchNameValid(m_sCreateNewBranch
))
603 ShowEditBalloon(IDC_NEWBRANCH
, IDS_B_T_NOTEMPTY
, IDS_ERR_ERROR
, TTI_ERROR
);
606 if (g_Git
.BranchTagExists(m_sCreateNewBranch
))
608 // branch already exists
610 msg
.LoadString(IDS_B_EXISTS
);
611 msg
+= L
' ' + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME
));
612 ShowEditBalloon(IDC_NEWBRANCH
, msg
, CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
615 if (g_Git
.BranchTagExists(m_sCreateNewBranch
, false))
617 // tag with the same name exists -> shortref is ambiguous
618 if (CMessageBox::Show(m_hWnd
, IDS_B_SAMETAGNAMEEXISTS
, IDS_APPNAME
, 2, IDI_EXCLAMATION
, IDS_CONTINUEBUTTON
, IDS_ABORTBUTTON
) == 2)
624 GetDlgItemText(IDC_BUGID
, id
);
625 if (!m_ProjectProperties
.CheckBugID(id
))
627 ShowEditBalloon(IDC_BUGID
, IDS_COMMITDLG_ONLYNUMBERS
, IDS_ERR_ERROR
, TTI_ERROR
);
630 m_sLogMessage
= m_cLogMessage
.GetText();
631 if ( m_sLogMessage
.IsEmpty() )
633 // no message entered, go round again
634 CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
637 if ((m_ProjectProperties
.bWarnIfNoIssue
) && (id
.IsEmpty() && !m_ProjectProperties
.HasBugID(m_sLogMessage
)))
639 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOISSUEWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
643 if (m_ProjectProperties
.bWarnNoSignedOffBy
== TRUE
&& m_cLogMessage
.GetText().Find(GetSignedOffByLine()) == -1)
645 UINT retval
= CMessageBox::Show(this->m_hWnd
, IDS_PROC_COMMIT_NOSIGNOFFLINE
, IDS_APPNAME
, 1, IDI_WARNING
, IDS_PROC_COMMIT_ADDSIGNOFFBUTTON
, IDS_PROC_COMMIT_NOADDSIGNOFFBUTTON
, IDS_ABORTBUTTON
);
648 OnBnClickedSignOff();
649 m_sLogMessage
= m_cLogMessage
.GetText();
651 else if (retval
== 3)
655 if (CHooks::Instance().IsHookPresent(pre_commit_hook
, g_Git
.m_CurrentDir
)) {
656 DWORD exitcode
= 0xFFFFFFFF;
659 m_ListCtrl
.WriteCheckedNamesToPathList(list
);
660 if (CHooks::Instance().PreCommit(g_Git
.m_CurrentDir
, list
, m_sLogMessage
, exitcode
, error
))
665 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
666 MessageBox(temp
, L
"TortoiseGit", MB_ICONERROR
);
672 int nListItems
= m_ListCtrl
.GetItemCount();
673 for (int i
= 0; i
< nListItems
&& !m_bCommitMessageOnly
; ++i
)
675 auto entry
= m_ListCtrl
.GetListEntry(i
);
676 if (!entry
->m_Checked
|| !entry
->IsDirectory())
680 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
683 subgit
.m_CurrentDir
= g_Git
.CombinePath(entry
);
685 subgit
.Run(L
"git.exe status --porcelain", &subcmdout
, CP_UTF8
);
686 dirty
= !subcmdout
.IsEmpty();
691 cmd
.Format(L
"git.exe diff -- \"%s\"", entry
->GetWinPath());
692 g_Git
.Run(cmd
, &cmdout
, CP_UTF8
);
693 dirty
= CStringUtils::EndsWith(cmdout
, L
"-dirty\n");
699 message
.Format(IDS_COMMITDLG_SUBMODULEDIRTY
, (LPCTSTR
)entry
->GetGitPathString());
700 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
)));
704 cmdCommit
.Format(L
"/command:commit /path:\"%s\\%s\"", (LPCTSTR
)g_Git
.m_CurrentDir
, entry
->GetWinPath());
705 CAppUtils::RunTortoiseGitProc(cmdCommit
);
708 else if (result
== 2)
715 if (!m_bCommitMessageOnly
)
716 m_ListCtrl
.WriteCheckedNamesToPathList(m_selectedPathList
);
717 m_pathwatcher
.Stop();
718 InterlockedExchange(&m_bBlock
, TRUE
);
719 //first add all the unversioned files the user selected
720 //and check if all versioned files are selected
723 CMassiveGitTask
mgtReAddAfterCommit(L
"add --ignore-errors -f");
724 CMassiveGitTask
mgtReDelAfterCommit(L
"rm --cached --ignore-unmatch");
729 bool bAddSuccess
=true;
730 bool bCloseCommitDlg
=false;
732 CSysProgressDlg sysProgressDlg
;
733 if (nListItems
>= 25)
735 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT
)));
736 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX
)));
737 sysProgressDlg
.SetTime(true);
738 sysProgressDlg
.SetShowProgressBar(true);
739 sysProgressDlg
.ShowModal(this, true);
742 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
743 ULONGLONG currentTicks
= GetTickCount64();
745 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_COMMIT_UPDATE_INDEX
))
750 CAutoRepository
repository(g_Git
.GetGitRepository());
753 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L
"Could not open repository."), L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
758 CString revRef
= L
"HEAD";
759 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
761 if (CGit::GetHash(repository
, revHash
, revRef
))
763 MessageBox(g_Git
.GetLibGit2LastErr(L
"Could not get HEAD hash after committing."), L
"TortoiseGit", MB_ICONERROR
);
768 if (!revHash
.IsEmpty() && git_commit_lookup(commit
.GetPointer(), repository
, (const git_oid
*)revHash
.m_hash
))
770 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L
"Could not get last commit."), L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
775 if (!revHash
.IsEmpty() && git_commit_tree(tree
.GetPointer(), commit
))
777 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L
"Could not read tree of commit."), L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
782 if (git_repository_index(index
.GetPointer(), repository
))
784 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L
"Could not get the repository index."), L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
789 if (!revHash
.IsEmpty() && (git_index_new(indexOld
.GetPointer()) || git_index_read_tree(indexOld
, tree
)))
791 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L
"Could not read the tree into the index."), L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
797 for (int j
= 0; j
< nListItems
; ++j
)
799 auto entry
= m_ListCtrl
.GetListEntry(j
);
801 if (sysProgressDlg
.IsVisible())
803 if (GetTickCount64() - currentTicks
> 1000UL || j
== nListItems
- 1 || j
== 0)
805 sysProgressDlg
.SetLine(2, entry
->GetGitPathString(), true);
806 sysProgressDlg
.SetProgress(j
, nListItems
);
807 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too often: this takes time!
808 currentTicks
= GetTickCount64();
812 CStringA filePathA
= CUnicodeUtils::GetMulti(entry
->GetGitPathString(), CP_UTF8
).TrimRight(L
'/');
814 if (entry
->m_Checked
&& !m_bCommitMessageOnly
)
816 if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
817 git_index_remove_bypath(index
, filePathA
); // ignore error
820 if (git_index_add_bypath(index
, filePathA
))
823 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L
"Could not add \"" + entry
->GetGitPathString() + L
"\" to index."), L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
828 if ((entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
) && !entry
->GetGitOldPathString().IsEmpty())
829 git_index_remove_bypath(index
, CUnicodeUtils::GetUTF8(entry
->GetGitOldPathString())); // ignore error
835 if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
837 git_index_remove_bypath(index
, filePathA
); // ignore error
838 mgtReAddAfterCommit
.AddFile(*entry
);
840 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
&& !entry
->GetGitOldPathString().IsEmpty())
842 const git_index_entry
* oldIndexEntry
= nullptr;
843 if ((oldIndexEntry
= git_index_get_bypath(indexOld
, CUnicodeUtils::GetUTF8(entry
->GetGitOldPathString()), 0)) == nullptr || git_index_add(index
, oldIndexEntry
))
846 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L
"Could not reset \"" + entry
->GetGitOldPathString() + L
"\" to old index entry."), L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
849 mgtReDelAfterCommit
.AddFile(entry
->GetGitOldPathString());
852 else if (!(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
854 const git_index_entry
* oldIndexEntry
= nullptr;
855 if ((oldIndexEntry
= git_index_get_bypath(indexOld
, filePathA
, 0)) == nullptr || git_index_add(index
, oldIndexEntry
))
858 CMessageBox::Show(GetSafeHwnd(), CGit::GetLibGit2LastErr(L
"Could not reset \"" + entry
->GetGitPathString() + L
"\" to old index entry."), L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
861 if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
&& !(entry
->m_Action
& CTGitPath::LOGACTIONS_MISSING
))
862 mgtReDelAfterCommit
.AddFile(entry
->GetGitPathString());
866 if (sysProgressDlg
.HasUserCancelled())
872 if (bAddSuccess
&& git_index_write(index
))
875 for (int j
= 0; bAddSuccess
&& j
< nListItems
; ++j
)
876 CShellUpdater::Instance().AddPathForUpdate(*m_ListCtrl
.GetListEntry(j
));
881 // ***************************************************
882 // ATTENTION: Similar code in RebaseDlg.cpp!!!
883 // ***************************************************
884 CMassiveGitTask
mgtAdd(L
"add -f");
885 CMassiveGitTask
mgtUpdateIndexForceRemove(L
"update-index --force-remove");
886 CMassiveGitTask
mgtUpdateIndex(L
"update-index");
887 CMassiveGitTask
mgtRm(L
"rm --ignore-unmatch");
888 CMassiveGitTask
mgtRmFCache(L
"rm -f --cache");
889 CString resetCmd
= L
"reset";
890 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
891 resetCmd
+= L
" HEAD~1";;
892 CMassiveGitTask
mgtReset(resetCmd
, TRUE
, true);
893 for (int j
= 0; j
< nListItems
; ++j
)
895 auto entry
= m_ListCtrl
.GetListEntry(j
);
897 if (entry
->m_Checked
&& !m_bCommitMessageOnly
)
899 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
900 mgtAdd
.AddFile(entry
->GetGitPathString());
901 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
902 mgtUpdateIndexForceRemove
.AddFile(entry
->GetGitPathString());
904 mgtUpdateIndex
.AddFile(entry
->GetGitPathString());
906 if ((entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
) && !entry
->GetGitOldPathString().IsEmpty())
907 mgtRm
.AddFile(entry
->GetGitOldPathString());
913 if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
914 { //To init git repository, there are not HEAD, so we can use git reset command
915 mgtRmFCache
.AddFile(entry
->GetGitPathString());
916 mgtReAddAfterCommit
.AddFile(*entry
);
918 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
&& !entry
->GetGitOldPathString().IsEmpty())
920 mgtReset
.AddFile(entry
->GetGitOldPathString());
921 mgtReDelAfterCommit
.AddFile(entry
->GetGitOldPathString());
924 else if (!(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
926 mgtReset
.AddFile(entry
->GetGitPathString());
927 if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
&& !(entry
->m_Action
& CTGitPath::LOGACTIONS_MISSING
))
928 mgtReDelAfterCommit
.AddFile(entry
->GetGitPathString());
932 if (sysProgressDlg
.HasUserCancelled())
939 CMassiveGitTask tasks
[] = { mgtAdd
, mgtUpdateIndexForceRemove
, mgtUpdateIndex
, mgtRm
, mgtRmFCache
, mgtReset
};
940 int progress
= 0, maxProgress
= 0;
941 for (int j
= 0; j
< _countof(tasks
); ++j
)
942 maxProgress
+= tasks
[j
].GetListCount();
943 for (int j
= 0; j
< _countof(tasks
); ++j
)
944 bAddSuccess
= bAddSuccess
&& UpdateIndex(tasks
[j
], sysProgressDlg
, progress
+= tasks
[j
].GetListCount(), maxProgress
);
946 if (sysProgressDlg
.HasUserCancelled())
949 for (int j
= 0; bAddSuccess
&& j
< nListItems
; ++j
)
950 CShellUpdater::Instance().AddPathForUpdate(*m_ListCtrl
.GetListEntry(j
));
953 if (sysProgressDlg
.HasUserCancelled())
956 sysProgressDlg
.Stop();
958 if (bAddSuccess
&& m_bCreateNewBranch
)
960 if (g_Git
.Run(L
"git.exe branch " + m_sCreateNewBranch
, &out
, CP_UTF8
))
962 MessageBox(L
"Creating new branch failed:\n" + out
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
965 if (g_Git
.Run(L
"git.exe checkout " + m_sCreateNewBranch
+ L
" --", &out
, CP_UTF8
))
967 MessageBox(L
"Switching to new branch failed:\n" + out
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
972 if (bAddSuccess
&& m_bWarnDetachedHead
&& CheckHeadDetach())
976 CString sExistingBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
977 sExistingBugID
.Trim();
978 if (!m_sBugID
.IsEmpty() && m_sBugID
.Compare(sExistingBugID
))
980 m_sBugID
.Replace(L
", ", L
",");
981 m_sBugID
.Replace(L
" ,", L
",");
982 CString sBugID
= m_ProjectProperties
.sMessage
;
983 sBugID
.Replace(L
"%BUGID%", m_sBugID
);
984 if (m_ProjectProperties
.bAppend
)
985 m_sLogMessage
+= L
'\n' + sBugID
+ L
'\n';
987 m_sLogMessage
= sBugID
+ L
'\n' + m_sLogMessage
;
990 // now let the bugtraq plugin check the commit message
991 CComPtr
<IBugTraqProvider2
> pProvider2
;
992 if (m_BugTraqProvider
)
994 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
998 ATL::CComBSTR
repositoryRoot(g_Git
.m_CurrentDir
);
999 ATL::CComBSTR
parameters(m_bugtraq_association
.GetParameters());
1000 ATL::CComBSTR
commonRoot(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
1001 ATL::CComBSTR
commitMessage(m_sLogMessage
);
1002 CBstrSafeVector
pathList(m_selectedPathList
.GetCount());
1004 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
1005 pathList
.PutElement(index
, m_selectedPathList
[index
].GetGitPathString());
1007 if (FAILED(hr
= pProvider2
->CheckCommit(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, commitMessage
, &temp
)))
1011 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), ce
.GetMessageAndDescription().c_str());
1012 CMessageBox::Show(GetSafeHwnd(), sErr
, L
"TortoiseGit", MB_ICONERROR
);
1016 CString sError
= temp
;
1017 if (!sError
.IsEmpty())
1019 CMessageBox::Show(GetSafeHwnd(), sError
, L
"TortoiseGit", MB_ICONERROR
);
1020 InterlockedExchange(&m_bBlock
, FALSE
);
1027 if (m_bCommitMessageOnly
|| bAddSuccess
&& (nchecked
|| m_bCommitAmend
|| CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive()))
1029 bCloseCommitDlg
= true;
1031 CString tempfile
=::GetTempFile();
1033 if (CAppUtils::SaveCommitUnicodeFile(tempfile
, m_sLogMessage
))
1035 CMessageBox::Show(GetSafeHwnd(), L
"Could not save commit message", L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
1036 InterlockedExchange(&m_bBlock
, FALSE
);
1040 CTGitPath path
=g_Git
.m_CurrentDir
;
1042 BOOL IsGitSVN
= path
.GetAdminDirMask() & ITEMIS_GITSVN
;
1046 if(this->m_bCommitAmend
)
1050 if (m_bSetCommitDateTime
)
1053 m_CommitDate
.GetTime(date
);
1054 m_CommitTime
.GetTime(time
);
1055 if (m_bCommitAmend
&& m_AsCommitDateCtrl
.GetCheck())
1056 dateTime
= CAppUtils::GetMsysgitVersion() > 0x02010000 ? L
"--date=\"now\"" : L
"--date=\"\"" ;
1058 dateTime
.Format(L
"--date=%sT%s", (LPCTSTR
)date
.Format(L
"%Y-%m-%d"), (LPCTSTR
)time
.Format(L
"%H:%M:%S"));
1062 author
.Format(L
"--author=\"%s\"", (LPCTSTR
)m_sAuthor
);
1063 CString allowEmpty
= m_bCommitMessageOnly
? L
"--allow-empty" : L
"";
1064 // TODO: make sure notes.amend.rewrite does still work when switching to libgit2
1065 cmd
.Format(L
"git.exe commit %s %s %s %s -F \"%s\"", (LPCTSTR
)author
, (LPCTSTR
)dateTime
, (LPCTSTR
)amend
, (LPCTSTR
)allowEmpty
, (LPCTSTR
)tempfile
);
1067 CCommitProgressDlg progress
;
1068 progress
.m_bBufferAll
=true; // improve show speed when there are many file added.
1069 progress
.m_GitCmd
=cmd
;
1070 progress
.m_bShowCommand
= FALSE
; // don't show the commit command
1071 progress
.m_PreText
= out
; // show any output already generated in log window
1072 if (m_ctrlOkButton
.GetCurrentEntry() > 0)
1073 progress
.m_AutoClose
= GitProgressAutoClose::AUTOCLOSE_IF_NO_ERRORS
;
1075 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
1077 if (status
|| m_bNoPostActions
|| m_bAutoClose
)
1081 postCmdList
.emplace_back(IDI_COMMIT
, IDS_MENUSVNDCOMMIT
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_DCOMMIT
; });
1083 postCmdList
.emplace_back(IDI_PUSH
, IDS_MENUPUSH
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_PUSH
; });
1084 postCmdList
.emplace_back(IDI_PULL
, IDS_MENUPULL
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_PULL
; });
1085 postCmdList
.emplace_back(IDI_COMMIT
, IDS_PROC_COMMIT_RECOMMIT
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_RECOMMIT
; });
1086 postCmdList
.emplace_back(IDI_TAG
, IDS_MENUTAG
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_CREATETAG
; });
1089 m_PostCmd
= GIT_POSTCOMMIT_CMD_NOTHING
;
1092 if (!m_bNoPostActions
)
1093 m_regLastAction
= (int)m_ctrlOkButton
.GetCurrentEntry();
1094 if (m_ctrlOkButton
.GetCurrentEntry() == 1)
1095 m_PostCmd
= GIT_POSTCOMMIT_CMD_RECOMMIT
;
1097 ::DeleteFile(tempfile
);
1099 if (m_BugTraqProvider
&& progress
.m_GitStatus
== 0)
1101 CComPtr
<IBugTraqProvider2
> pProvider
;
1102 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
1105 ATL::CComBSTR
commonRoot(g_Git
.m_CurrentDir
);
1106 CBstrSafeVector
pathList(m_selectedPathList
.GetCount());
1108 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
1109 pathList
.PutElement(index
, m_selectedPathList
[index
].GetGitPathString());
1111 ATL::CComBSTR
logMessage(m_sLogMessage
);
1114 if (g_Git
.GetHash(hash
, L
"HEAD"))
1115 MessageBox(g_Git
.GetGitLastErr(L
"Could not get HEAD hash after committing."), L
"TortoiseGit", MB_ICONERROR
);
1116 LONG version
= g_Git
.Hash2int(hash
);
1119 if (FAILED(hr
= pProvider
->OnCommitFinished(GetSafeHwnd(),
1126 CString sErr
= temp
;
1127 if (!sErr
.IsEmpty())
1128 CMessageBox::Show(GetSafeHwnd(), sErr
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
1132 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, ce
.GetSource().c_str(), ce
.GetMessageAndDescription().c_str());
1133 CMessageBox::Show(GetSafeHwnd(), sErr
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
1138 RestoreFiles(progress
.m_GitStatus
== 0, false);
1139 if (((DWORD
)CRegStdDWORD(L
"Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit", TRUE
)) == TRUE
)
1141 BOOL cancel
= FALSE
;
1142 mgtReAddAfterCommit
.Execute(cancel
);
1143 mgtReDelAfterCommit
.Execute(cancel
);
1146 if (!progress
.m_GitStatus
)
1148 DWORD exitcode
= 0xFFFFFFFF;
1150 if (CHooks::Instance().PostCommit(g_Git
.m_CurrentDir
, amend
.IsEmpty(), exitcode
, error
))
1155 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
1156 MessageBox(temp
, L
"TortoiseGit", MB_ICONERROR
);
1157 bCloseCommitDlg
= false;
1162 if (progress
.m_GitStatus
|| m_PostCmd
== GIT_POSTCOMMIT_CMD_RECOMMIT
)
1164 bCloseCommitDlg
= false;
1165 if (m_PostCmd
== GIT_POSTCOMMIT_CMD_RECOMMIT
)
1167 if (!m_sLogMessage
.IsEmpty())
1169 ReloadHistoryEntries();
1170 m_History
.AddEntry(m_sLogMessage
);
1174 this->m_sLogMessage
.Empty();
1175 GetCommitTemplate(m_sLogMessage
);
1176 m_cLogMessage
.SetText(m_sLogMessage
);
1177 if (m_bCreateNewBranch
)
1179 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_SHOW
);
1180 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_HIDE
);
1182 m_bCreateNewBranch
= FALSE
;
1184 if (!RunStartCommitHook())
1185 bCloseCommitDlg
= true;
1188 if (!progress
.m_GitStatus
)
1191 m_bCommitAmend
= FALSE
;
1197 else if(bAddSuccess
)
1199 CMessageBox::Show(this->m_hWnd
, IDS_ERROR_NOTHING_COMMIT
, IDS_COMMIT_FINISH
, MB_OK
| MB_ICONINFORMATION
);
1200 bCloseCommitDlg
=false;
1204 m_regAddBeforeCommit
= m_bShowUnversioned
;
1205 m_regKeepChangelists
= m_bKeepChangeList
;
1206 m_regDoNotAutoselectSubmodules
= m_bDoNotAutoselectSubmodules
;
1207 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
1208 m_bKeepChangeList
= FALSE
;
1209 InterlockedExchange(&m_bBlock
, FALSE
);
1211 if (!m_sLogMessage
.IsEmpty())
1213 ReloadHistoryEntries();
1214 m_History
.AddEntry(m_sLogMessage
);
1220 if (bCloseCommitDlg
)
1222 if (m_ctrlOkButton
.GetCurrentEntry() == 2)
1224 CResizableStandAloneDialog::OnOK();
1226 else if (m_PostCmd
== GIT_POSTCOMMIT_CMD_RECOMMIT
)
1228 m_bDoNotStoreLastSelectedLine
= true;
1230 this->BringWindowToTop();
1233 CShellUpdater::Instance().Flush();
1236 void CCommitDlg::SaveSplitterPos()
1240 CRegDWORD
regPos(L
"Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer");
1242 m_wndSplitter
.GetWindowRect(&rectSplitter
);
1243 ScreenToClient(&rectSplitter
);
1244 regPos
= rectSplitter
.top
;
1248 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
1250 return ((CCommitDlg
*)pVoid
)->StatusThread();
1253 void CCommitDlg::ReloadHistoryEntries()
1256 reg
.Format(L
"Software\\TortoiseGit\\History\\commit%s", (LPCTSTR
)m_ListCtrl
.m_sUUID
);
1257 reg
.Replace(L
':', L
'_');
1258 m_History
.Load(reg
, L
"logmsgs");
1261 UINT
CCommitDlg::StatusThread()
1263 //get the status of all selected file/folders recursively
1264 //and show the ones which have to be committed to the user
1265 //in a list control.
1266 m_pathwatcher
.Stop();
1268 m_ListCtrl
.SetBusy(true);
1269 g_Git
.RefreshGitIndex();
1271 m_bCancelled
= false;
1273 DialogEnableWindow(IDOK
, false);
1274 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
1275 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
1276 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, false);
1277 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
1278 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
1279 DialogEnableWindow(IDC_COMMIT_AMEND
, FALSE
);
1280 DialogEnableWindow(IDC_COMMIT_AMENDDIFF
, FALSE
);
1281 // read the list of recent log entries before querying the WC for status
1282 // -> the user may select one and modify / update it while we are crawling the WC
1284 DialogEnableWindow(IDC_CHECKALL
, false);
1285 DialogEnableWindow(IDC_CHECKNONE
, false);
1286 DialogEnableWindow(IDC_CHECKUNVERSIONED
, false);
1287 DialogEnableWindow(IDC_CHECKVERSIONED
, false);
1288 DialogEnableWindow(IDC_CHECKADDED
, false);
1289 DialogEnableWindow(IDC_CHECKDELETED
, false);
1290 DialogEnableWindow(IDC_CHECKMODIFIED
, false);
1291 DialogEnableWindow(IDC_CHECKFILES
, false);
1292 DialogEnableWindow(IDC_CHECKSUBMODULES
, false);
1295 GitAdminDir::GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
1296 if (PathFileExists(dotGitPath
+ L
"CHERRY_PICK_HEAD"))
1298 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
1299 m_bCommitAmend
= FALSE
;
1300 SendMessage(WM_UPDATEDATAFALSE
);
1303 if (!m_bDoNotStoreLastSelectedLine
)
1304 m_ListCtrl
.StoreScrollPos();
1305 // Initialise the list control with the status of the files/folders below us
1308 CTGitPathList
*pList
;
1309 m_ListCtrl
.m_amend
= (m_bCommitAmend
==TRUE
|| m_bForceCommitAmend
) && (m_bAmendDiffToLastCommit
==FALSE
);
1310 m_ListCtrl
.m_bDoNotAutoselectSubmodules
= (m_bDoNotAutoselectSubmodules
== TRUE
);
1312 if(m_bWholeProject
|| m_bWholeProject2
)
1315 pList
= &m_pathList
;
1317 success
=m_ListCtrl
.GetStatus(pList
);
1319 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1320 if(this->m_bShowUnversioned
)
1321 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
1323 m_ListCtrl
.CheckIfChangelistsArePresent(false);
1325 DWORD dwShow
= GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWLOCKS
| GITSLC_SHOWINCHANGELIST
| GITSLC_SHOWDIRECTFILES
;
1326 dwShow
|= DWORD(m_regAddBeforeCommit
) ? GITSLC_SHOWUNVERSIONED
: 0;
1329 if (!m_checkedPathList
.IsEmpty())
1330 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
1333 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
1334 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
1335 m_ListCtrl
.Show(dwShow
, dwCheck
);
1336 m_bSelectFilesForCommit
= true;
1339 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
1341 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
1342 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
1345 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
1346 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
1347 if (m_ListCtrl
.GetItemCount() != 0 && m_ListCtrl
.GetTopIndex() == 0 && (m_bDoNotStoreLastSelectedLine
|| CRegDWORD(L
"Software\\TortoiseGit\\RememberFileListPosition", TRUE
) != TRUE
))
1348 m_ListCtrl
.SetItemState(0, LVIS_SELECTED
, LVIS_SELECTED
);
1352 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
1353 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
1354 m_ListCtrl
.Show(dwShow
);
1356 m_bDoNotStoreLastSelectedLine
= false;
1358 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
1359 && !PathFileExists(dotGitPath
+ L
"MERGE_HEAD"))
1362 temp
.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
);
1363 if (CMessageBox::ShowCheck(GetSafeHwnd(), temp
, L
"TortoiseGit", MB_ICONINFORMATION
| MB_YESNO
, L
"NothingToCommitShowUnversioned", nullptr) == IDYES
)
1365 m_bShowUnversioned
= TRUE
;
1366 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
1367 dwShow
= (DWORD
)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWUNVERSIONED
| GITSLC_SHOWLOCKS
);
1368 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
1369 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
1376 // we don't have to block the commit dialog while we fetch the
1377 // auto completion list.
1378 m_pathwatcher
.ClearChangedPaths();
1379 InterlockedExchange(&m_bBlock
, FALSE
);
1380 if ((DWORD
)CRegDWORD(L
"Software\\TortoiseGit\\Autocompletion", TRUE
) == TRUE
)
1382 m_ListCtrl
.Block(TRUE
, TRUE
);
1383 GetAutocompletionList();
1384 m_ListCtrl
.Block(FALSE
, FALSE
);
1386 SendMessage(WM_UPDATEOKBUTTON
);
1387 m_ListCtrl
.Invalidate();
1390 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
1391 DialogEnableWindow(IDC_WHOLE_PROJECT
, !m_bWholeProject2
);
1392 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, true);
1393 if (m_ListCtrl
.HasChangeLists())
1394 DialogEnableWindow(IDC_KEEPLISTS
, true);
1396 // activate amend checkbox (if necessary)
1397 if (g_Git
.IsInitRepos())
1399 m_bCommitAmend
= FALSE
;
1400 SendMessage(WM_UPDATEDATAFALSE
);
1404 if (m_bForceCommitAmend
)
1406 m_bCommitAmend
= TRUE
;
1407 SendMessage(WM_UPDATEDATAFALSE
);
1410 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(!PathFileExists(dotGitPath
+ L
"CHERRY_PICK_HEAD"));
1413 if (g_Git
.GetHash(hash
, L
"HEAD"))
1415 MessageBox(g_Git
.GetGitLastErr(L
"Could not get HEAD hash."), L
"TortoiseGit", MB_ICONERROR
);
1417 if (!hash
.IsEmpty())
1419 GitRev headRevision
;
1420 if (headRevision
.GetParentFromHash(hash
))
1421 MessageBox(headRevision
.GetLastErr(), L
"TortoiseGit", MB_ICONERROR
);
1422 // do not allow to show diff to "last" revision if it has more that one parent
1423 if (headRevision
.ParentsCount() != 1)
1425 m_bAmendDiffToLastCommit
= TRUE
;
1426 SendMessage(WM_UPDATEDATAFALSE
);
1429 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->EnableWindow(TRUE
);
1435 // we have the list, now signal the main thread about it
1436 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
1439 InterlockedExchange(&m_bRunThread
, FALSE
);
1440 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1441 // force the cursor to normal
1447 void CCommitDlg::SetDlgTitle()
1449 if (m_sTitle
.IsEmpty())
1450 GetWindowText(m_sTitle
);
1452 if (m_bWholeProject
|| m_bWholeProject2
)
1453 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
1456 if (m_pathList
.GetCount() == 1)
1457 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.CombinePath(m_pathList
[0].GetUIPathString()), m_sTitle
);
1459 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.CombinePath(m_ListCtrl
.GetCommonDirectory(false)), m_sTitle
);
1463 void CCommitDlg::OnCancel()
1466 tmp
.LoadString(IDS_REALLYCANCEL
);
1467 tmp
.AppendChar(L
'\n');
1468 tmp
.AppendChar(L
'\n');
1469 tmp
.Append(CString(MAKEINTRESOURCE(IDS_HINTLASTMESSAGES
)));
1470 CString dontaskagain
;
1471 dontaskagain
.LoadString(IDS_MSGBOX_DONOTSHOWAGAIN
);
1472 if (CMessageBox::ShowCheck(GetSafeHwnd(), tmp
, L
"TortoiseGit", MB_ICONQUESTION
| MB_DEFBUTTON2
| MB_YESNO
, L
"CommitAskBeforeCancel", dontaskagain
) == IDNO
)
1475 m_bCancelled
= true;
1476 m_pathwatcher
.Stop();
1478 if (m_bThreadRunning
)
1480 if (!RestoreFiles())
1484 m_sLogMessage
= m_cLogMessage
.GetText();
1485 if (!m_sBugID
.IsEmpty())
1487 m_sBugID
.Replace(L
", ", L
",");
1488 m_sBugID
.Replace(L
" ,", L
",");
1489 CString sBugID
= m_ProjectProperties
.sMessage
;
1490 sBugID
.Replace(L
"%BUGID%", m_sBugID
);
1491 if (m_ProjectProperties
.bAppend
)
1492 m_sLogMessage
+= L
'\n' + sBugID
+ L
'\n';
1494 m_sLogMessage
= sBugID
+ L
'\n' + m_sLogMessage
;
1496 if ((m_sLogTemplate
.Compare(m_sLogMessage
) != 0) && !m_sLogMessage
.IsEmpty())
1498 ReloadHistoryEntries();
1499 m_History
.AddEntry(m_sLogMessage
);
1503 CResizableStandAloneDialog::OnCancel();
1506 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1510 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1514 if (m_hAccelOkButton
&& GetDlgItem(IDOK
)->IsWindowEnabled() && TranslateAccelerator(m_hWnd
, m_hAccelOkButton
, pMsg
))
1517 if (pMsg
->message
== WM_KEYDOWN
)
1519 switch (pMsg
->wParam
)
1524 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1530 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1532 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1533 PostMessage(WM_COMMAND
, IDOK
);
1536 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1538 // Pressing RETURN in the bug id control
1539 // moves the focus to the message
1540 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1548 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1551 void CCommitDlg::Refresh()
1553 if (m_bThreadRunning
)
1556 StartStatusThread();
1559 void CCommitDlg::StartStatusThread()
1561 if (InterlockedExchange(&m_bBlock
, TRUE
) != FALSE
)
1565 m_pThread
= nullptr;
1567 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
, 0, CREATE_SUSPENDED
);
1570 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1571 InterlockedExchange(&m_bBlock
, FALSE
);
1574 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
1575 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
1576 m_pThread
->m_bAutoDelete
= FALSE
;
1577 m_pThread
->ResumeThread();
1580 void CCommitDlg::StopStatusThread()
1582 InterlockedExchange(&m_bRunThread
, FALSE
);
1583 WaitForSingleObject(m_pThread
->m_hThread
, 5000);
1584 if (!m_bThreadRunning
)
1587 // we gave the thread a chance to quit. Since the thread didn't
1588 // listen to us we have to kill it.
1589 g_Git
.KillRelatedThreads(m_pThread
);
1590 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1593 void CCommitDlg::OnBnClickedShowunversioned()
1595 m_tooltips
.Pop(); // hide the tooltips
1597 m_regAddBeforeCommit
= m_bShowUnversioned
;
1600 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1601 if (DWORD(m_regAddBeforeCommit
))
1602 dwShow
|= GITSLC_SHOWUNVERSIONED
;
1604 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
1605 if(dwShow
& GITSLC_SHOWUNVERSIONED
)
1607 if (m_bWholeProject
|| m_bWholeProject2
)
1608 m_ListCtrl
.GetStatus(nullptr, false, false, true);
1610 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1612 m_ListCtrl
.StoreScrollPos();
1613 m_ListCtrl
.Show(dwShow
, 0, true, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
1618 void CCommitDlg::OnStnClickedExternalwarning()
1623 void CCommitDlg::OnEnChangeLogmessage()
1625 SendMessage(WM_UPDATEOKBUTTON
);
1628 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1631 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1633 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1635 m_bShowUnversioned
= TRUE
;
1636 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1637 m_ListCtrl
.Show(dwShow
);
1645 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1651 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM lParam
)
1654 SetForegroundWindow();
1656 // if multiple files/folders are dropped
1657 // this handler is called for every single item
1659 // To avoid creating multiple refresh threads and
1660 // causing crashes, we only add the items to the
1661 // list control and start a timer.
1662 // When the timer expires, we start the refresh thread,
1663 // but only if it isn't already running - otherwise we
1664 // restart the timer.
1666 path
.SetFromWin((LPCTSTR
)lParam
);
1668 // check whether the dropped file belongs to the very same repository
1670 if (!path
.HasAdminDir(&projectDir
) || !CTGitPath::ArePathStringsEqual(g_Git
.m_CurrentDir
, projectDir
))
1673 // just add all the items we get here.
1674 // if the item is versioned, the add will fail but nothing
1675 // more will happen.
1677 cmd
.Format(L
"git.exe add -- \"%s\"", path
.GetWinPathString());
1678 g_Git
.Run(cmd
, nullptr, CP_UTF8
);
1680 if (!m_ListCtrl
.HasPath(path
))
1682 if (m_pathList
.AreAllPathsFiles())
1684 m_pathList
.AddPath(path
);
1685 m_pathList
.RemoveDuplicates();
1686 m_updatedPathList
.AddPath(path
);
1687 m_updatedPathList
.RemoveDuplicates();
1691 // if the path list contains folders, we have to check whether
1692 // our just (maybe) added path is a child of one of those. If it is
1693 // a child of a folder already in the list, we must not add it. Otherwise
1694 // that path could show up twice in the list.
1695 bool bHasParentInList
= false;
1696 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1698 if (m_pathList
[i
].IsAncestorOf(path
))
1700 bHasParentInList
= true;
1704 if (!bHasParentInList
)
1706 m_pathList
.AddPath(path
);
1707 m_pathList
.RemoveDuplicates();
1708 m_updatedPathList
.AddPath(path
);
1709 m_updatedPathList
.RemoveDuplicates();
1713 m_ListCtrl
.ResetChecked(path
);
1715 // Always start the timer, since the status of an existing item might have changed
1716 SetTimer(REFRESHTIMER
, 200, nullptr);
1717 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) L
": Item %s dropped, timer started\n", path
.GetWinPath());
1721 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1723 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1727 //////////////////////////////////////////////////////////////////////////
1728 // functions which run in the status thread
1729 //////////////////////////////////////////////////////////////////////////
1731 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1736 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1737 while (m_bRunThread
&& file
.ReadString(strLine
))
1739 if (strLine
.IsEmpty())
1741 if (strLine
[0] == L
'#')
1743 int eqpos
= strLine
.Find('=');
1745 rgx
= strLine
.Mid(eqpos
+1).Trim();
1748 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1750 mapRegex
[strLine
.Left(pos
)] = rgx
;
1751 strLine
= strLine
.Mid(pos
+1).Trim();
1753 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1757 catch (CFileException
* pE
)
1759 CTraceToOutputDebugString::Instance()(__FUNCTION__
": CFileException loading auto list regex file\n");
1764 void CCommitDlg::ParseSnippetFile(const CString
& sFile
, std::map
<CString
, CString
>& mapSnippet
)
1769 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1770 while (m_bRunThread
&& file
.ReadString(strLine
))
1772 if (strLine
.IsEmpty())
1774 if (strLine
[0] == L
'#') // comment char
1776 int eqpos
= strLine
.Find('=');
1777 CString key
= strLine
.Left(eqpos
);
1778 CString value
= strLine
.Mid(eqpos
+ 1);
1779 value
.Replace(L
"\\\t", L
"\t");
1780 value
.Replace(L
"\\\r", L
"\r");
1781 value
.Replace(L
"\\\n", L
"\n");
1782 value
.Replace(L
"\\\\", L
"\\");
1783 mapSnippet
[key
] = value
;
1787 catch (CFileException
* pE
)
1789 CTraceToOutputDebugString::Instance()(__FUNCTION__
": CFileException loading auto list regex file\n");
1794 void CCommitDlg::GetAutocompletionList()
1796 // the auto completion list is made of strings from each selected files.
1797 // the strings used are extracted from the files with regexes found
1798 // in the file "autolist.txt".
1799 // the format of that file is:
1800 // file extensions separated with commas '=' regular expression to use
1802 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1803 // .cpp = (?<=[^\s]::)\b\w+\b
1805 std::map
<CString
, CString
> mapRegex
;
1806 CString sRegexFile
= CPathUtils::GetAppDirectory();
1807 CRegDWORD regtimeout
= CRegDWORD(L
"Software\\TortoiseGit\\AutocompleteParseTimeout", 5);
1808 ULONGLONG timeoutvalue
= ULONGLONG(DWORD(regtimeout
)) * 1000UL;;
1809 sRegexFile
+= L
"autolist.txt";
1812 ParseRegexFile(sRegexFile
, mapRegex
);
1813 sRegexFile
= CPathUtils::GetAppDataDirectory();
1814 sRegexFile
+= L
"autolist.txt";
1815 if (PathFileExists(sRegexFile
))
1816 ParseRegexFile(sRegexFile
, mapRegex
);
1819 CString sSnippetFile
= CPathUtils::GetAppDirectory();
1820 sSnippetFile
+= L
"snippet.txt";
1821 ParseSnippetFile(sSnippetFile
, m_snippet
);
1822 sSnippetFile
= CPathUtils::GetAppDataDirectory();
1823 sSnippetFile
+= L
"snippet.txt";
1824 if (PathFileExists(sSnippetFile
))
1825 ParseSnippetFile(sSnippetFile
, m_snippet
);
1826 for (const auto& snip
: m_snippet
)
1827 m_autolist
.emplace(snip
.first
, AUTOCOMPLETE_SNIPPET
);
1829 ULONGLONG starttime
= GetTickCount64();
1831 // now we have two arrays of strings, where the first array contains all
1832 // file extensions we can use and the second the corresponding regex strings
1833 // to apply to those files.
1835 // the next step is to go over all files shown in the commit dialog
1836 // and scan them for strings we can use
1837 int nListItems
= m_ListCtrl
.GetItemCount();
1839 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1841 // stop parsing after timeout
1842 if ((!m_bRunThread
) || (GetTickCount64() - starttime
> timeoutvalue
))
1845 auto path
= m_ListCtrl
.GetListEntry(i
);
1850 CString sPartPath
=path
->GetGitPathString();
1851 m_autolist
.emplace(sPartPath
, AUTOCOMPLETE_FILENAME
);
1855 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1859 m_autolist
.emplace(sPartPath
.Mid(pos
), AUTOCOMPLETE_FILENAME
);
1862 // Last inserted entry is a file name.
1863 // Some users prefer to also list file name without extension.
1864 if (CRegDWORD(L
"Software\\TortoiseGit\\AutocompleteRemovesExtensions", FALSE
))
1866 int dotPos
= sPartPath
.ReverseFind('.');
1867 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1868 m_autolist
.emplace(sPartPath
.Mid(lastPos
, dotPos
- lastPos
), AUTOCOMPLETE_FILENAME
);
1871 if (path
->m_Action
== CTGitPath::LOGACTIONS_UNVER
&& !CRegDWORD(L
"Software\\TortoiseGit\\AutocompleteParseUnversioned", FALSE
))
1873 if (path
->m_Action
== CTGitPath::LOGACTIONS_IGNORE
)
1876 CString sExt
= path
->GetFileExtension();
1878 // find the regex string which corresponds to the file extension
1879 CString rdata
= mapRegex
[sExt
];
1880 if (rdata
.IsEmpty())
1883 ScanFile(path
->GetWinPathString(), rdata
, sExt
);
1885 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) L
": Auto completion list loaded in %I64u msec\n", GetTickCount64() - starttime
);
1888 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
, const CString
& sExt
)
1890 static std::map
<CString
, std::tr1::wregex
> regexmap
;
1892 std::wstring sFileContent
;
1893 CAutoFile hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, nullptr, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, nullptr);
1896 DWORD size
= GetFileSize(hFile
, nullptr);
1897 if (size
> CRegDWORD(L
"Software\\TortoiseGit\\AutocompleteParseMaxSize", 300000L))
1899 // no files bigger than 300k
1902 // allocate memory to hold file contents
1906 oFile
.SetLength(size
);
1908 catch (CMemoryException
*)
1913 if (!ReadFile(hFile
, oFile
, size
, &readbytes
, nullptr))
1915 oFile
.SetLength(readbytes
);
1916 CFileTextLines filetextlines
;
1917 CFileTextLines::UnicodeType type
= filetextlines
.CheckUnicodeType(oFile
, readbytes
);
1920 CBaseFilter
* pFilter
= nullptr;
1923 case CFileTextLines::BINARY
:
1925 case CFileTextLines::UTF8
:
1926 case CFileTextLines::UTF8BOM
:
1927 pFilter
= new CUtf8Filter(NULL
);
1930 case CFileTextLines::ASCII
:
1931 pFilter
= new CAsciiFilter(NULL
);
1933 case CFileTextLines::UTF16_BE
:
1934 case CFileTextLines::UTF16_BEBOM
:
1935 pFilter
= new CUtf16beFilter(NULL
);
1937 case CFileTextLines::UTF16_LE
:
1938 case CFileTextLines::UTF16_LEBOM
:
1939 pFilter
= new CUtf16leFilter(NULL
);
1941 case CFileTextLines::UTF32_BE
:
1942 pFilter
= new CUtf32beFilter(NULL
);
1944 case CFileTextLines::UTF32_LE
:
1945 pFilter
= new CUtf32leFilter(NULL
);
1948 pFilter
->Decode(oFile
);
1951 catch (CMemoryException
*)
1955 sFileContent
= std::wstring((wchar_t*)oFile
, oFile
.GetLength() / sizeof(wchar_t));
1957 if (sFileContent
.empty() || !m_bRunThread
)
1962 std::tr1::wregex regCheck
;
1963 std::map
<CString
, std::tr1::wregex
>::const_iterator regIt
;
1964 if ((regIt
= regexmap
.find(sExt
)) != regexmap
.end())
1965 regCheck
= regIt
->second
;
1968 regCheck
= std::tr1::wregex(sRegex
, std::tr1::regex_constants::icase
| std::tr1::regex_constants::ECMAScript
);
1969 regexmap
[sExt
] = regCheck
;
1971 const std::tr1::wsregex_iterator end
;
1972 for (std::tr1::wsregex_iterator
it(sFileContent
.cbegin(), sFileContent
.cend(), regCheck
); it
!= end
; ++it
)
1974 const std::tr1::wsmatch match
= *it
;
1975 for (size_t i
= 1; i
< match
.size(); ++i
)
1977 if (match
[i
].second
-match
[i
].first
)
1978 m_autolist
.emplace(std::wstring(match
[i
]).c_str(), AUTOCOMPLETE_PROGRAMCODE
);
1982 catch (std::exception
) {}
1985 // CSciEditContextMenuInterface
1986 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1988 CString sMenuItemText
;
1989 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITHASH
);
1990 m_nPopupPickCommitHash
= nCmd
++;
1991 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPickCommitHash
, sMenuItemText
);
1993 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITMESSAGE
);
1994 m_nPopupPickCommitMessage
= nCmd
++;
1995 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPickCommitMessage
, sMenuItemText
);
1997 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTEFILELIST
);
1998 m_nPopupPasteListCmd
= nCmd
++;
1999 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
2001 ReloadHistoryEntries();
2002 if (!m_History
.IsEmpty())
2004 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
2005 m_nPopupPasteLastMessage
= nCmd
++;
2006 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
2008 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
2009 m_nPopupRecentMessage
= nCmd
++;
2010 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
2014 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
2016 if (cmd
== m_nPopupPickCommitHash
)
2018 // use the git log to allow selection of a version
2020 // tell the dialog to use mode for selecting revisions
2021 dlg
.SetSelect(true);
2022 // only one revision must be selected however
2023 dlg
.SingleSelection(true);
2024 dlg
.ShowWorkingTreeChanges(false);
2025 if (dlg
.DoModal() == IDOK
)
2026 pSciEdit
->InsertText(dlg
.GetSelectedHash().at(0).ToString());
2030 if (cmd
== m_nPopupPickCommitMessage
)
2032 // use the git log to allow selection of a version
2034 // tell the dialog to use mode for selecting revisions
2035 dlg
.SetSelect(true);
2036 // only one revision must be selected however
2037 dlg
.SingleSelection(true);
2038 dlg
.ShowWorkingTreeChanges(false);
2039 if (dlg
.DoModal() == IDOK
)
2042 if (rev
.GetCommit(dlg
.GetSelectedHash().at(0).ToString()))
2044 MessageBox(rev
.GetLastErr(), L
"TortoiseGit", MB_ICONERROR
);
2047 CString message
= rev
.GetSubject() + L
"\r\n" + rev
.GetBody();
2048 pSciEdit
->InsertText(message
);
2053 if (cmd
== m_nPopupPasteListCmd
)
2056 int nListItems
= m_ListCtrl
.GetItemCount();
2057 for (int i
=0; i
<nListItems
; ++i
)
2059 auto entry
= m_ListCtrl
.GetListEntry(i
);
2060 if (entry
&&entry
->m_Checked
)
2062 CString status
= entry
->GetActionName();
2063 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
2064 status
= L
"Add"; // I18N TODO
2066 //git_wc_status_kind status = entry->status;
2067 WORD langID
= (WORD
)CRegStdDWORD(L
"Software\\TortoiseGit\\LanguageID", GetUserDefaultLangID());
2068 if (m_ProjectProperties
.bFileListInEnglish
)
2071 logmsg
.AppendFormat(L
"%-10s %s\r\n", (LPCTSTR
)status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
, 0));
2074 pSciEdit
->InsertText(logmsg
);
2078 if(cmd
== m_nPopupPasteLastMessage
)
2080 if (m_History
.IsEmpty())
2084 logmsg
+=m_History
.GetEntry(0);
2085 pSciEdit
->InsertText(logmsg
);
2089 if(cmd
== m_nPopupRecentMessage
)
2091 OnBnClickedHistory();
2097 void CCommitDlg::HandleSnippet(int type
, const CString
&text
, CSciEdit
*pSciEdit
)
2099 if (type
== AUTOCOMPLETE_SNIPPET
)
2101 CString target
= m_snippet
[text
];
2102 pSciEdit
->GetWordUnderCursor(true);
2103 pSciEdit
->InsertText(target
, false);
2107 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
2111 case ENDDIALOGTIMER
:
2112 KillTimer(ENDDIALOGTIMER
);
2116 if (m_bThreadRunning
)
2118 SetTimer(REFRESHTIMER
, 200, nullptr);
2119 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Wait some more before refreshing\n");
2123 KillTimer(REFRESHTIMER
);
2124 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Refreshing after items dropped\n");
2128 case FILLPATCHVTIMER
:
2132 __super::OnTimer(nIDEvent
);
2135 void CCommitDlg::OnBnClickedHistory()
2137 m_tooltips
.Pop(); // hide the tooltips
2138 if (m_pathList
.IsEmpty())
2141 CHistoryDlg historyDlg
;
2142 ReloadHistoryEntries();
2143 historyDlg
.SetHistory(m_History
);
2144 if (historyDlg
.DoModal() != IDOK
)
2147 CString sMsg
= historyDlg
.GetSelectedText();
2148 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
2150 CString sBugID
= m_ProjectProperties
.FindBugID(sMsg
);
2151 if ((!sBugID
.IsEmpty()) && ((GetDlgItem(IDC_BUGID
)->IsWindowVisible())))
2152 SetDlgItemText(IDC_BUGID
, sBugID
);
2153 if (m_sLogTemplate
.Compare(m_cLogMessage
.GetText()) != 0)
2154 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
2156 m_cLogMessage
.SetText(sMsg
);
2159 SendMessage(WM_UPDATEOKBUTTON
);
2160 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
2163 void CCommitDlg::OnBnClickedBugtraqbutton()
2165 m_tooltips
.Pop(); // hide the tooltips
2166 CString sMsg
= m_cLogMessage
.GetText();
2168 if (!m_BugTraqProvider
)
2171 ATL::CComBSTR
parameters(m_bugtraq_association
.GetParameters());
2172 ATL::CComBSTR
commonRoot(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
2173 CBstrSafeVector
pathList(m_pathList
.GetCount());
2175 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
2176 pathList
.PutElement(index
, m_pathList
[index
].GetGitPathString());
2178 ATL::CComBSTR
originalMessage(sMsg
);
2181 // first try the IBugTraqProvider2 interface
2182 CComPtr
<IBugTraqProvider2
> pProvider2
;
2183 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
2184 bool bugIdOutSet
= false;
2187 ATL::CComBSTR
repositoryRoot(g_Git
.m_CurrentDir
);
2188 ATL::CComBSTR bugIDOut
;
2189 GetDlgItemText(IDC_BUGID
, m_sBugID
);
2190 ATL::CComBSTR
bugID(m_sBugID
);
2191 CBstrSafeVector revPropNames
;
2192 CBstrSafeVector revPropValues
;
2193 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
2196 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2197 CMessageBox::Show(GetSafeHwnd(), sErr
, L
"TortoiseGit", MB_ICONERROR
);
2204 m_sBugID
= bugIDOut
;
2205 SetDlgItemText(IDC_BUGID
, m_sBugID
);
2207 m_cLogMessage
.SetText((LPCTSTR
)temp
);
2212 // if IBugTraqProvider2 failed, try IBugTraqProvider
2213 CComPtr
<IBugTraqProvider
> pProvider
;
2214 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
2218 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2219 CMessageBox::Show(GetSafeHwnd(), sErr
, L
"TortoiseGit", MB_ICONERROR
);
2223 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
2226 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2227 CMessageBox::Show(GetSafeHwnd(), sErr
, L
"TortoiseGit", MB_ICONERROR
);
2230 m_cLogMessage
.SetText((LPCTSTR
)temp
);
2232 m_sLogMessage
= m_cLogMessage
.GetText();
2233 if (!m_ProjectProperties
.sMessage
.IsEmpty())
2235 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
2236 if (!sBugID
.IsEmpty() && !bugIdOutSet
)
2237 SetDlgItemText(IDC_BUGID
, sBugID
);
2240 m_cLogMessage
.SetFocus();
2243 void CCommitDlg::FillPatchView(bool onlySetTimer
)
2245 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2247 KillTimer(FILLPATCHVTIMER
);
2250 SetTimer(FILLPATCHVTIMER
, 100, nullptr);
2254 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
2259 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
2260 auto p
= m_ListCtrl
.GetListEntry(nSelect
);
2261 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
2263 CString head
= L
"HEAD";
2264 if(m_bCommitAmend
==TRUE
&& m_bAmendDiffToLastCommit
==FALSE
)
2266 cmd
.Format(L
"git.exe diff %s -- \"%s\"", (LPCTSTR
)head
, (LPCTSTR
)p
->GetGitPathString());
2267 g_Git
.Run(cmd
, &out
, CP_UTF8
);
2271 m_patchViewdlg
.SetText(out
);
2274 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM
/*wparam*/, LPARAM
/*lparam*/)
2276 this->FillPatchView(true);
2281 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
2283 SendMessage(WM_UPDATEOKBUTTON
);
2287 LRESULT
CCommitDlg::OnCheck(WPARAM wnd
, LPARAM
)
2289 HWND hwnd
= (HWND
)wnd
;
2290 bool check
= !(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
2291 if (hwnd
== GetDlgItem(IDC_CHECKALL
)->GetSafeHwnd())
2292 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, check
);
2293 else if (hwnd
== GetDlgItem(IDC_CHECKNONE
)->GetSafeHwnd())
2294 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, !check
);
2295 else if (hwnd
== GetDlgItem(IDC_CHECKUNVERSIONED
)->GetSafeHwnd())
2296 m_ListCtrl
.Check(GITSLC_SHOWUNVERSIONED
, check
);
2297 else if (hwnd
== GetDlgItem(IDC_CHECKVERSIONED
)->GetSafeHwnd())
2298 m_ListCtrl
.Check(GITSLC_SHOWVERSIONED
, check
);
2299 else if (hwnd
== GetDlgItem(IDC_CHECKADDED
)->GetSafeHwnd())
2300 m_ListCtrl
.Check(GITSLC_SHOWADDED
, check
);
2301 else if (hwnd
== GetDlgItem(IDC_CHECKDELETED
)->GetSafeHwnd())
2302 m_ListCtrl
.Check(GITSLC_SHOWREMOVED
, check
);
2303 else if (hwnd
== GetDlgItem(IDC_CHECKMODIFIED
)->GetSafeHwnd())
2304 m_ListCtrl
.Check(GITSLC_SHOWMODIFIED
, check
);
2305 else if (hwnd
== GetDlgItem(IDC_CHECKFILES
)->GetSafeHwnd())
2306 m_ListCtrl
.Check(GITSLC_SHOWFILES
, check
);
2307 else if (hwnd
== GetDlgItem(IDC_CHECKSUBMODULES
)->GetSafeHwnd())
2308 m_ListCtrl
.Check(GITSLC_SHOWSUBMODULES
, check
);
2313 LRESULT
CCommitDlg::OnUpdateOKButton(WPARAM
, LPARAM
)
2318 CString text
= m_cLogMessage
.GetText().Trim();
2319 bool bValidLogSize
= !text
.IsEmpty() && text
.GetLength() >= m_ProjectProperties
.nMinLogSize
;
2320 bool bAmendOrSelectFilesOrMerge
= m_ListCtrl
.GetSelected() > 0 || (m_bCommitAmend
&& m_bAmendDiffToLastCommit
) || CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
2322 DialogEnableWindow(IDOK
, bValidLogSize
&& (m_bCommitMessageOnly
|| bAmendOrSelectFilesOrMerge
));
2327 LRESULT
CCommitDlg::OnUpdateDataFalse(WPARAM
, LPARAM
)
2333 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
2337 if (wParam
== IDC_SPLITTER
)
2339 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
2340 DoSize(pHdr
->delta
);
2344 if (m_hAccelOkButton
&& LOWORD(wParam
) >= WM_USER
&& LOWORD(wParam
) <= WM_USER
+ m_accellerators
.size())
2346 for (const auto& entry
: m_accellerators
)
2348 if (entry
.second
.wmid
!= LOWORD(wParam
))
2350 if (entry
.second
.id
== -1)
2351 m_ctrlOkButton
.PostMessage(WM_KEYDOWN
, VK_F4
, NULL
);
2354 m_ctrlOkButton
.SetCurrentEntry(entry
.second
.id
);
2363 return __super::DefWindowProc(message
, wParam
, lParam
);
2366 void CCommitDlg::SetSplitterRange()
2368 if ((m_ListCtrl
)&&(m_cLogMessage
))
2371 m_cLogMessage
.GetWindowRect(rcTop
);
2372 ScreenToClient(rcTop
);
2374 m_ListCtrl
.GetWindowRect(rcMiddle
);
2375 ScreenToClient(rcMiddle
);
2376 if (rcMiddle
.Height() && rcMiddle
.Width())
2377 m_wndSplitter
.SetRange(rcTop
.top
+ 100, rcMiddle
.bottom
- 80);
2381 void CCommitDlg::DoSize(int delta
)
2383 RemoveAnchor(IDC_MESSAGEGROUP
);
2384 RemoveAnchor(IDC_LOGMESSAGE
);
2385 RemoveAnchor(IDC_SPLITTER
);
2386 RemoveAnchor(IDC_SIGNOFF
);
2387 RemoveAnchor(IDC_COMMIT_AMEND
);
2388 RemoveAnchor(IDC_COMMIT_AMENDDIFF
);
2389 RemoveAnchor(IDC_COMMIT_SETDATETIME
);
2390 RemoveAnchor(IDC_COMMIT_DATEPICKER
);
2391 RemoveAnchor(IDC_COMMIT_TIMEPICKER
);
2392 RemoveAnchor(IDC_COMMIT_AS_COMMIT_DATE
);
2393 RemoveAnchor(IDC_COMMIT_SETAUTHOR
);
2394 RemoveAnchor(IDC_COMMIT_AUTHORDATA
);
2395 RemoveAnchor(IDC_LISTGROUP
);
2396 RemoveAnchor(IDC_FILELIST
);
2397 RemoveAnchor(IDC_TEXT_INFO
);
2398 RemoveAnchor(IDC_SELECTLABEL
);
2399 RemoveAnchor(IDC_CHECKALL
);
2400 RemoveAnchor(IDC_CHECKNONE
);
2401 RemoveAnchor(IDC_CHECKUNVERSIONED
);
2402 RemoveAnchor(IDC_CHECKVERSIONED
);
2403 RemoveAnchor(IDC_CHECKADDED
);
2404 RemoveAnchor(IDC_CHECKDELETED
);
2405 RemoveAnchor(IDC_CHECKMODIFIED
);
2406 RemoveAnchor(IDC_CHECKFILES
);
2407 RemoveAnchor(IDC_CHECKSUBMODULES
);
2409 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
2410 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
2411 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
2412 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
2413 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
2414 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
2415 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF
),0,delta
);
2416 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME
),0,delta
);
2417 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER
),0,delta
);
2418 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER
),0,delta
);
2419 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AS_COMMIT_DATE
), 0, delta
);
2420 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETAUTHOR
), 0, delta
);
2421 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AUTHORDATA
), 0, delta
);
2422 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
2423 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL
), 0, delta
);
2424 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL
), 0, delta
);
2425 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE
), 0, delta
);
2426 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED
), 0, delta
);
2427 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED
), 0, delta
);
2428 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED
), 0, delta
);
2429 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED
), 0, delta
);
2430 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED
), 0, delta
);
2431 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES
), 0, delta
);
2432 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES
), 0, delta
);
2434 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
2435 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
2436 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
2437 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
2438 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
2439 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
2440 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
2441 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
2442 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
2443 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
2444 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
2445 AddAnchor(IDC_COMMIT_AS_COMMIT_DATE
, TOP_LEFT
);
2446 AddAnchor(IDC_COMMIT_SETAUTHOR
, TOP_LEFT
);
2447 AddAnchor(IDC_COMMIT_AUTHORDATA
, TOP_LEFT
, TOP_RIGHT
);
2448 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
2449 AddAnchor(IDC_SELECTLABEL
, TOP_LEFT
);
2450 AddAnchor(IDC_CHECKALL
, TOP_LEFT
);
2451 AddAnchor(IDC_CHECKNONE
, TOP_LEFT
);
2452 AddAnchor(IDC_CHECKUNVERSIONED
, TOP_LEFT
);
2453 AddAnchor(IDC_CHECKVERSIONED
, TOP_LEFT
);
2454 AddAnchor(IDC_CHECKADDED
, TOP_LEFT
);
2455 AddAnchor(IDC_CHECKDELETED
, TOP_LEFT
);
2456 AddAnchor(IDC_CHECKMODIFIED
, TOP_LEFT
);
2457 AddAnchor(IDC_CHECKFILES
, TOP_LEFT
);
2458 AddAnchor(IDC_CHECKSUBMODULES
, TOP_LEFT
);
2460 // adjust the minimum size of the dialog to prevent the resizing from
2461 // moving the list control too far down.
2463 m_cLogMessage
.GetClientRect(rcLogMsg
);
2464 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
2467 m_cLogMessage
.Invalidate();
2468 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
2471 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
2473 // first, let the resizing take place
2474 __super::OnSize(nType
, cx
, cy
);
2480 CString
CCommitDlg::GetSignedOffByLine()
2484 CString username
= g_Git
.GetUserName();
2485 CString email
= g_Git
.GetUserEmail();
2486 username
.Remove(L
'\n');
2487 email
.Remove(L
'\n');
2489 str
.Format(L
"Signed-off-by: %s <%s>", (LPCTSTR
)username
, (LPCTSTR
)email
);
2494 void CCommitDlg::OnBnClickedSignOff()
2496 CString str
= GetSignedOffByLine();
2498 if (m_cLogMessage
.GetText().Find(str
) == -1) {
2499 m_cLogMessage
.SetText(m_cLogMessage
.GetText().TrimRight());
2500 int lastNewline
= m_cLogMessage
.GetText().ReverseFind(L
'\n');
2501 int foundByLine
= -1;
2502 if (lastNewline
> 0)
2503 foundByLine
= m_cLogMessage
.GetText().Find(L
"-by: ", lastNewline
);
2505 if (foundByLine
== -1 || foundByLine
< lastNewline
)
2506 str
= L
"\r\n" + str
;
2508 m_cLogMessage
.SetText(m_cLogMessage
.GetText() + L
"\r\n" + str
+ L
"\r\n");
2512 void CCommitDlg::OnBnClickedCommitAmend()
2515 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
2518 if (rev
.GetCommit(L
"HEAD"))
2519 MessageBox(rev
.GetLastErr(), L
"TortoiseGit", MB_ICONERROR
);
2520 m_AmendStr
= rev
.GetSubject() + L
'\n' + rev
.GetBody();
2523 if(this->m_bCommitAmend
)
2525 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
2526 m_cLogMessage
.SetText(m_AmendStr
);
2527 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
2528 if (m_bSetCommitDateTime
)
2529 m_AsCommitDateCtrl
.ShowWindow(SW_SHOW
);
2533 this->m_AmendStr
=this->m_cLogMessage
.GetText();
2534 m_cLogMessage
.SetText(m_NoAmendStr
);
2535 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
2536 m_AsCommitDateCtrl
.ShowWindow(SW_HIDE
);
2537 m_AsCommitDateCtrl
.SetCheck(FALSE
);
2538 OnBnClickedCommitAsCommitDate();
2541 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2542 OnBnClickedCommitSetauthor(); // to update the commit author
2544 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
2548 void CCommitDlg::OnBnClickedCommitMessageOnly()
2551 this->m_ListCtrl
.EnableWindow(m_bCommitMessageOnly
? FALSE
: TRUE
);
2552 SendMessage(WM_UPDATEOKBUTTON
);
2555 void CCommitDlg::OnBnClickedWholeProject()
2557 m_tooltips
.Pop(); // hide the tooltips
2562 if (m_bWholeProject
|| m_bWholeProject2
)
2563 m_ListCtrl
.GetStatus(nullptr, true, false, true);
2565 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
2567 m_regShowWholeProject
= m_bWholeProject
;
2569 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
2570 if (DWORD(m_regAddBeforeCommit
))
2571 dwShow
|= GITSLC_SHOWUNVERSIONED
;
2573 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
2575 m_ListCtrl
.StoreScrollPos();
2576 m_ListCtrl
.Show(dwShow
, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
2583 void CCommitDlg::OnFocusMessage()
2585 m_cLogMessage
.SetFocus();
2588 void CCommitDlg::OnFocusFileList()
2590 m_ListCtrl
.SetFocus();
2593 void CCommitDlg::OnScnUpdateUI(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2595 int pos
= (int)this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
2596 int line
= (int)this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
2597 int column
= (int)this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
2600 str
.Format(L
"%d/%d", line
+ 1, column
+ 1);
2601 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
2607 void CCommitDlg::TogglePatchView()
2609 OnStnClickedViewPatch();
2612 void CCommitDlg::OnStnClickedViewPatch()
2614 m_patchViewdlg
.m_ParentDlg
= this;
2615 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
2617 BOOL viewPatchEnabled
= FALSE
;
2618 viewPatchEnabled
= g_Git
.GetConfigValueBool(L
"tgit.commitshowpatch");
2619 if (viewPatchEnabled
== FALSE
)
2620 g_Git
.SetConfigValue(L
"tgit.commitshowpatch", L
"true");
2621 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
2622 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
2624 this->GetWindowRect(&rect
);
2626 m_patchViewdlg
.ShowWindow(SW_SHOW
);
2628 m_patchViewdlg
.SetWindowPos(nullptr, rect
.right
, rect
.top
, (DWORD
)CRegStdDWORD(L
"Software\\TortoiseGit\\TortoiseProc\\PatchDlgWidth", rect
.Width()), rect
.Height(),
2629 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
2631 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
2633 ShowViewPatchText(false);
2638 g_Git
.SetConfigValue(L
"tgit.commitshowpatch", L
"false");
2639 m_patchViewdlg
.ShowWindow(SW_HIDE
);
2640 m_patchViewdlg
.DestroyWindow();
2641 ShowViewPatchText(true);
2643 this->m_ctrlShowPatch
.Invalidate();
2646 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
2648 __super::OnMoving(fwSide
, pRect
);
2650 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
2653 m_patchViewdlg
.GetWindowRect(&patchrect
);
2654 if (::IsWindow(m_hWnd
))
2657 GetWindowRect(&thisrect
);
2658 if (patchrect
.left
== thisrect
.right
)
2660 m_patchViewdlg
.SetWindowPos(nullptr, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
2661 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
2667 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
2669 __super::OnSizing(fwSide
, pRect
);
2671 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2673 CRect thisrect
, patchrect
;
2674 this->GetWindowRect(thisrect
);
2675 this->m_patchViewdlg
.GetWindowRect(patchrect
);
2676 if(thisrect
.right
==patchrect
.left
)
2678 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
2679 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
2681 if( patchrect
.bottom
== thisrect
.bottom
)
2682 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
2683 if( patchrect
.top
== thisrect
.top
)
2684 patchrect
.top
-= thisrect
.top
-pRect
->top
;
2685 m_patchViewdlg
.MoveWindow(patchrect
);
2690 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2693 TRACE("Item Changed\r\n");
2696 int CCommitDlg::CheckHeadDetach()
2699 if (CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, output
))
2701 int retval
= CMessageBox::Show(GetSafeHwnd(), IDS_PROC_COMMIT_DETACHEDWARNING
, IDS_APPNAME
, MB_YESNOCANCEL
| MB_ICONWARNING
);
2704 if (CAppUtils::CreateBranchTag(FALSE
, nullptr, true) == FALSE
)
2707 else if (retval
== IDCANCEL
)
2713 void CCommitDlg::OnBnClickedCommitAmenddiff()
2719 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2725 void CCommitDlg::OnBnClickedCommitSetDateTime()
2729 if (m_bSetCommitDateTime
)
2731 CTime authordate
= CTime::GetCurrentTime();
2734 GitRev headRevision
;
2735 if (headRevision
.GetCommit(L
"HEAD"))
2736 MessageBox(headRevision
.GetLastErr(), L
"TortoiseGit", MB_ICONERROR
);
2737 authordate
= headRevision
.GetAuthorDate();
2738 m_AsCommitDateCtrl
.ShowWindow(SW_SHOW
);
2741 m_CommitDate
.SetTime(&authordate
);
2742 m_CommitTime
.SetTime(&authordate
);
2744 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_SHOW
);
2745 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_SHOW
);
2749 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_HIDE
);
2750 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_HIDE
);
2751 m_AsCommitDateCtrl
.ShowWindow(SW_HIDE
);
2752 m_AsCommitDateCtrl
.SetCheck(FALSE
);
2753 OnBnClickedCommitAsCommitDate();
2757 void CCommitDlg::OnBnClickedCommitAsCommitDate()
2759 GetDlgItem(IDC_COMMIT_DATEPICKER
)->EnableWindow(!m_AsCommitDateCtrl
.GetCheck());
2760 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->EnableWindow(!m_AsCommitDateCtrl
.GetCheck());
2763 void CCommitDlg::OnBnClickedCheckNewBranch()
2766 if (m_bCreateNewBranch
)
2768 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_HIDE
);
2769 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_SHOW
);
2773 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_HIDE
);
2774 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_SHOW
);
2778 bool CCommitDlg::RestoreFiles(bool doNotAsk
, bool allowCancel
)
2780 if (m_ListCtrl
.m_restorepaths
.empty())
2785 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);
2792 for (const auto& item
: m_ListCtrl
.m_restorepaths
)
2793 CopyFile(item
.second
, g_Git
.CombinePath(item
.first
), FALSE
);
2794 m_ListCtrl
.m_restorepaths
.clear();
2799 void CCommitDlg::UpdateCheckLinks()
2801 DialogEnableWindow(IDC_CHECKALL
, true);
2802 DialogEnableWindow(IDC_CHECKNONE
, true);
2803 DialogEnableWindow(IDC_CHECKUNVERSIONED
, m_ListCtrl
.GetUnversionedCount() > 0);
2804 DialogEnableWindow(IDC_CHECKVERSIONED
, m_ListCtrl
.GetItemCount() > m_ListCtrl
.GetUnversionedCount());
2805 DialogEnableWindow(IDC_CHECKADDED
, m_ListCtrl
.GetAddedCount() > 0);
2806 DialogEnableWindow(IDC_CHECKDELETED
, m_ListCtrl
.GetDeletedCount() > 0);
2807 DialogEnableWindow(IDC_CHECKMODIFIED
, m_ListCtrl
.GetModifiedCount() > 0);
2808 DialogEnableWindow(IDC_CHECKFILES
, m_ListCtrl
.GetFileCount() > 0);
2809 DialogEnableWindow(IDC_CHECKSUBMODULES
, m_ListCtrl
.GetSubmoduleCount() > 0);
2812 void CCommitDlg::OnBnClickedCommitSetauthor()
2818 m_sAuthor
.Format(L
"%s <%s>", (LPCTSTR
)g_Git
.GetUserName(), (LPCTSTR
)g_Git
.GetUserEmail());
2821 GitRev headRevision
;
2822 if (headRevision
.GetCommit(L
"HEAD"))
2823 MessageBox(headRevision
.GetLastErr(), L
"TortoiseGit", MB_ICONERROR
);
2824 m_sAuthor
.Format(L
"%s <%s>", (LPCTSTR
)headRevision
.GetAuthorName(), (LPCTSTR
)headRevision
.GetAuthorEmail());
2829 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_SHOW
);
2832 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_HIDE
);
2835 bool CCommitDlg::RunStartCommitHook()
2837 DWORD exitcode
= 0xFFFFFFFF;
2839 if (CHooks::Instance().StartCommit(g_Git
.m_CurrentDir
, m_pathList
, m_sLogMessage
, exitcode
, error
))
2844 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2845 MessageBox(temp
, L
"TortoiseGit", MB_ICONERROR
);
2852 void CCommitDlg::OnSysColorChange()
2854 __super::OnSysColorChange();
2855 m_cLogMessage
.SetColors(true);
2856 m_cLogMessage
.SetFont(CAppUtils::GetLogFontName(), CAppUtils::GetLogFontSize());