1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2013 - TortoiseSVN
4 // Copyright (C) 2008-2015 - 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"
46 static char THIS_FILE
[] = __FILE__
;
49 UINT
CCommitDlg::WM_AUTOLISTREADY
= RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
50 UINT
CCommitDlg::WM_UPDATEOKBUTTON
= RegisterWindowMessage(_T("TORTOISEGIT_COMMIT_UPDATEOKBUTTON"));
51 UINT
CCommitDlg::WM_UPDATEDATAFALSE
= RegisterWindowMessage(_T("TORTOISEGIT_COMMIT_UPDATEDATAFALSE"));
53 IMPLEMENT_DYNAMIC(CCommitDlg
, CResizableStandAloneDialog
)
54 CCommitDlg::CCommitDlg(CWnd
* pParent
/*=NULL*/)
55 : CResizableStandAloneDialog(CCommitDlg::IDD
, pParent
)
56 , m_bShowUnversioned(FALSE
)
58 , m_bThreadRunning(FALSE
)
61 , m_bWholeProject(FALSE
)
62 , m_bWholeProject2(FALSE
)
63 , m_bKeepChangeList(TRUE
)
64 , m_bDoNotAutoselectSubmodules(FALSE
)
66 , m_bSelectFilesForCommit(TRUE
)
67 , m_bNoPostActions(FALSE
)
69 , m_bSetCommitDateTime(FALSE
)
70 , m_bCreateNewBranch(FALSE
)
71 , m_bForceCommitAmend(false)
72 , m_bCommitMessageOnly(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)
83 , m_bWarnDetachedHead(true)
85 this->m_bCommitAmend
=FALSE
;
88 CCommitDlg::~CCommitDlg()
96 void CCommitDlg::DoDataExchange(CDataExchange
* pDX
)
98 CResizableStandAloneDialog::DoDataExchange(pDX
);
99 DDX_Control(pDX
, IDC_FILELIST
, m_ListCtrl
);
100 DDX_Control(pDX
, IDC_LOGMESSAGE
, m_cLogMessage
);
101 DDX_Check(pDX
, IDC_SHOWUNVERSIONED
, m_bShowUnversioned
);
102 DDX_Check(pDX
, IDC_COMMIT_SETDATETIME
, m_bSetCommitDateTime
);
103 DDX_Check(pDX
, IDC_CHECK_NEWBRANCH
, m_bCreateNewBranch
);
104 DDX_Text(pDX
, IDC_NEWBRANCH
, m_sCreateNewBranch
);
105 DDX_Text(pDX
, IDC_BUGID
, m_sBugID
);
106 DDX_Text(pDX
, IDC_COMMIT_AUTHORDATA
, m_sAuthor
);
107 DDX_Check(pDX
, IDC_WHOLE_PROJECT
, m_bWholeProject
);
108 DDX_Control(pDX
, IDC_SPLITTER
, m_wndSplitter
);
109 DDX_Check(pDX
, IDC_KEEPLISTS
, m_bKeepChangeList
);
110 DDX_Check(pDX
, IDC_NOAUTOSELECTSUBMODULES
, m_bDoNotAutoselectSubmodules
);
111 DDX_Check(pDX
,IDC_COMMIT_AMEND
,m_bCommitAmend
);
112 DDX_Check(pDX
, IDC_COMMIT_MESSAGEONLY
, m_bCommitMessageOnly
);
113 DDX_Check(pDX
,IDC_COMMIT_AMENDDIFF
,m_bAmendDiffToLastCommit
);
114 DDX_Check(pDX
, IDC_COMMIT_SETAUTHOR
, m_bSetAuthor
);
115 DDX_Control(pDX
,IDC_VIEW_PATCH
,m_ctrlShowPatch
);
116 DDX_Control(pDX
, IDC_COMMIT_DATEPICKER
, m_CommitDate
);
117 DDX_Control(pDX
, IDC_COMMIT_TIMEPICKER
, m_CommitTime
);
118 DDX_Control(pDX
, IDC_COMMIT_AS_COMMIT_DATE
, m_AsCommitDateCtrl
);
121 BEGIN_MESSAGE_MAP(CCommitDlg
, CResizableStandAloneDialog
)
122 ON_BN_CLICKED(IDC_SHOWUNVERSIONED
, OnBnClickedShowunversioned
)
123 ON_NOTIFY(SCN_UPDATEUI
, IDC_LOGMESSAGE
, OnScnUpdateUI
)
124 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
125 ON_BN_CLICKED(IDC_BUGTRAQBUTTON
, OnBnClickedBugtraqbutton
)
126 ON_EN_CHANGE(IDC_LOGMESSAGE
, OnEnChangeLogmessage
)
127 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
, OnGitStatusListCtrlItemCountChanged
)
128 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
129 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE
, OnFileDropped
)
130 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED
, &CCommitDlg::OnGitStatusListCtrlCheckChanged
)
131 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED
, &CCommitDlg::OnGitStatusListCtrlItemChanged
)
133 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED
, &CCommitDlg::OnCheck
)
134 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY
, OnAutoListReady
)
135 ON_REGISTERED_MESSAGE(WM_UPDATEOKBUTTON
, OnUpdateOKButton
)
136 ON_REGISTERED_MESSAGE(WM_UPDATEDATAFALSE
, OnUpdateDataFalse
)
139 ON_STN_CLICKED(IDC_EXTERNALWARNING
, &CCommitDlg::OnStnClickedExternalwarning
)
140 ON_BN_CLICKED(IDC_SIGNOFF
, &CCommitDlg::OnBnClickedSignOff
)
141 ON_BN_CLICKED(IDC_COMMIT_AMEND
, &CCommitDlg::OnBnClickedCommitAmend
)
142 ON_BN_CLICKED(IDC_COMMIT_MESSAGEONLY
, &CCommitDlg::OnBnClickedCommitMessageOnly
)
143 ON_BN_CLICKED(IDC_WHOLE_PROJECT
, &CCommitDlg::OnBnClickedWholeProject
)
144 ON_COMMAND(ID_FOCUS_MESSAGE
,&CCommitDlg::OnFocusMessage
)
145 ON_COMMAND(ID_FOCUS_FILELIST
, OnFocusFileList
)
146 ON_STN_CLICKED(IDC_VIEW_PATCH
, &CCommitDlg::OnStnClickedViewPatch
)
150 ON_NOTIFY(HDN_ITEMCHANGED
, 0, &CCommitDlg::OnHdnItemchangedFilelist
)
151 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF
, &CCommitDlg::OnBnClickedCommitAmenddiff
)
152 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES
, &CCommitDlg::OnBnClickedNoautoselectsubmodules
)
153 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME
, &CCommitDlg::OnBnClickedCommitSetDateTime
)
154 ON_BN_CLICKED(IDC_COMMIT_AS_COMMIT_DATE
, &CCommitDlg::OnBnClickedCommitAsCommitDate
)
155 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH
, &CCommitDlg::OnBnClickedCheckNewBranch
)
156 ON_BN_CLICKED(IDC_COMMIT_SETAUTHOR
, &CCommitDlg::OnBnClickedCommitSetauthor
)
159 int GetCommitTemplate(CString
&msg
)
161 CString tplFilename
= g_Git
.GetConfigValue(_T("commit.template"));
162 if (tplFilename
.IsEmpty())
165 if (tplFilename
[0] == _T('/'))
167 if (tplFilename
.GetLength() >= 3)
169 // handle "/d/TortoiseGit/tpl.txt" -> "d:/TortoiseGit/tpl.txt"
170 if (tplFilename
[2] == _T('/'))
172 tplFilename
.GetBuffer()[0] = tplFilename
[1];
173 tplFilename
.GetBuffer()[1] = _T(':');
178 tplFilename
.Replace(_T('/'), _T('\\'));
180 if (!CGit::LoadTextFile(tplFilename
, msg
))
185 BOOL
CCommitDlg::OnInitDialog()
187 CResizableStandAloneDialog::OnInitDialog();
188 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
190 if (m_sLogMessage
.IsEmpty())
192 if (!m_bForceCommitAmend
)
193 GetCommitTemplate(m_sLogMessage
);
196 GitAdminDir::GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
197 bool loadedMsg
= !CGit::LoadTextFile(dotGitPath
+ _T("MERGE_MSG"), m_sLogMessage
);
198 loadedMsg
= loadedMsg
&& !CGit::LoadTextFile(dotGitPath
+ _T("SQUASH_MSG"), m_sLogMessage
);
200 RunStartCommitHook();
202 if (CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive())
204 DialogEnableWindow(IDC_CHECK_NEWBRANCH
, FALSE
);
205 m_bCreateNewBranch
= FALSE
;
206 GetDlgItem(IDC_MERGEACTIVE
)->ShowWindow(SW_SHOW
);
209 m_regAddBeforeCommit
= CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE
);
210 m_bShowUnversioned
= m_regAddBeforeCommit
;
212 CString
regPath(g_Git
.m_CurrentDir
);
213 regPath
.Replace(_T(":"), _T("_"));
214 m_regShowWholeProject
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ShowWholeProject\\") + regPath
, FALSE
);
215 m_bWholeProject
= m_regShowWholeProject
;
217 m_History
.SetMaxHistoryItems((LONG
)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
219 m_regKeepChangelists
= CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE
);
220 m_bKeepChangeList
= m_regKeepChangelists
;
222 m_regDoNotAutoselectSubmodules
= CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE
);
223 m_bDoNotAutoselectSubmodules
= m_regDoNotAutoselectSubmodules
;
225 m_hAccel
= LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG
));
227 if (m_pathList
.IsEmpty())
228 m_bWholeProject2
= true;
230 if(this->m_pathList
.GetCount() == 1 && m_pathList
[0].IsEmpty())
231 m_bWholeProject2
= true;
237 m_ListCtrl
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
, _T("CommitDlg"), (GITSLC_POPALL
^ (GITSLC_POPCOMMIT
| GITSLC_POPSAVEAS
| GITSLC_PREPAREDIFF
)), true, true);
238 m_ListCtrl
.SetStatLabel(GetDlgItem(IDC_STATISTICS
));
239 m_ListCtrl
.SetCancelBool(&m_bCancelled
);
240 m_ListCtrl
.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT
);
241 m_ListCtrl
.EnableFileDrop();
242 m_ListCtrl
.SetBackgroundImage(IDI_COMMIT_BKG
);
244 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
245 m_ProjectProperties
.ReadProps();
247 m_cLogMessage
.Init(m_ProjectProperties
);
248 m_cLogMessage
.SetFont((CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
249 m_cLogMessage
.RegisterContextMenuHandler(this);
250 std::map
<int, UINT
> icons
;
251 icons
[AUTOCOMPLETE_SPELLING
] = IDI_SPELL
;
252 icons
[AUTOCOMPLETE_FILENAME
] = IDI_FILE
;
253 icons
[AUTOCOMPLETE_PROGRAMCODE
] = IDI_CODE
;
254 icons
[AUTOCOMPLETE_SNIPPET
] = IDI_SNIPPET
;
255 m_cLogMessage
.SetIcon(icons
);
257 OnEnChangeLogmessage();
259 m_tooltips
.AddTool(IDC_EXTERNALWARNING
, IDS_COMMITDLG_EXTERNALS
);
260 m_tooltips
.AddTool(IDC_COMMIT_AMEND
,IDS_COMMIT_AMEND_TT
);
261 m_tooltips
.AddTool(IDC_MERGEACTIVE
, IDC_MERGEACTIVE_TT
);
262 m_tooltips
.AddTool(IDC_COMMIT_MESSAGEONLY
, IDS_COMMIT_MESSAGEONLY_TT
);
263 m_tooltips
.AddTool(IDC_COMMIT_AS_COMMIT_DATE
, IDS_COMMIT_AS_COMMIT_DATE_TT
);
265 CBugTraqAssociations bugtraq_associations
;
266 bugtraq_associations
.Load(m_ProjectProperties
.GetProviderUUID(), m_ProjectProperties
.sProviderParams
);
268 if (bugtraq_associations
.FindProvider(g_Git
.m_CurrentDir
, &m_bugtraq_association
))
270 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
271 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
273 CComPtr
<IBugTraqProvider
> pProvider
;
274 HRESULT hr
= pProvider
.CoCreateInstance(m_bugtraq_association
.GetProviderClass());
277 m_BugTraqProvider
= pProvider
;
279 ATL::CComBSTR
parameters(m_bugtraq_association
.GetParameters());
280 if (SUCCEEDED(hr
= pProvider
->GetLinkText(GetSafeHwnd(), parameters
, &temp
)))
282 SetDlgItemText(IDC_BUGTRAQBUTTON
, temp
);
283 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(TRUE
);
284 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_SHOW
);
288 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
290 else if (!m_ProjectProperties
.sMessage
.IsEmpty())
292 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_SHOW
);
293 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_SHOW
);
294 if (!m_ProjectProperties
.sLabel
.IsEmpty())
295 SetDlgItemText(IDC_BUGIDLABEL
, m_ProjectProperties
.sLabel
);
296 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
297 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
298 GetDlgItem(IDC_BUGID
)->SetFocus();
299 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(m_sLogMessage
);
300 if (!sBugID
.IsEmpty())
302 SetDlgItemText(IDC_BUGID
, sBugID
);
307 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
308 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
309 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
310 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
311 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
314 if (!m_sLogMessage
.IsEmpty())
316 m_cLogMessage
.SetText(m_sLogMessage
);
317 m_cLogMessage
.Call(SCI_SETCURRENTPOS
, 0);
318 m_cLogMessage
.Call(SCI_SETSEL
, 0, 0);
321 GetWindowText(m_sWindowTitle
);
323 AdjustControlSize(IDC_SHOWUNVERSIONED
);
324 AdjustControlSize(IDC_WHOLE_PROJECT
);
325 AdjustControlSize(IDC_CHECK_NEWBRANCH
);
326 AdjustControlSize(IDC_COMMIT_AMEND
);
327 AdjustControlSize(IDC_COMMIT_MESSAGEONLY
);
328 AdjustControlSize(IDC_COMMIT_AMENDDIFF
);
329 AdjustControlSize(IDC_COMMIT_SETDATETIME
);
330 AdjustControlSize(IDC_COMMIT_SETAUTHOR
);
331 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES
);
332 AdjustControlSize(IDC_KEEPLISTS
);
333 AdjustControlSize(IDC_COMMIT_AS_COMMIT_DATE
);
335 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKALL
);
336 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKNONE
);
337 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKUNVERSIONED
);
338 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKVERSIONED
);
339 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKADDED
);
340 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKDELETED
);
341 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKMODIFIED
);
342 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKFILES
);
343 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKSUBMODULES
);
345 // line up all controls and adjust their sizes.
346 #define LINKSPACING 9
347 RECT rc
= AdjustControlSize(IDC_SELECTLABEL
);
348 rc
.right
-= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
349 rc
= AdjustStaticSize(IDC_CHECKALL
, rc
, LINKSPACING
);
350 rc
= AdjustStaticSize(IDC_CHECKNONE
, rc
, LINKSPACING
);
351 rc
= AdjustStaticSize(IDC_CHECKUNVERSIONED
, rc
, LINKSPACING
);
352 rc
= AdjustStaticSize(IDC_CHECKVERSIONED
, rc
, LINKSPACING
);
353 rc
= AdjustStaticSize(IDC_CHECKADDED
, rc
, LINKSPACING
);
354 rc
= AdjustStaticSize(IDC_CHECKDELETED
, rc
, LINKSPACING
);
355 rc
= AdjustStaticSize(IDC_CHECKMODIFIED
, rc
, LINKSPACING
);
356 rc
= AdjustStaticSize(IDC_CHECKFILES
, rc
, LINKSPACING
);
357 rc
= AdjustStaticSize(IDC_CHECKSUBMODULES
, rc
, LINKSPACING
);
359 GetClientRect(m_DlgOrigRect
);
360 m_cLogMessage
.GetClientRect(m_LogMsgOrigRect
);
362 AddAnchor(IDC_COMMITLABEL
, TOP_LEFT
, TOP_RIGHT
);
363 AddAnchor(IDC_BUGIDLABEL
, TOP_RIGHT
);
364 AddAnchor(IDC_BUGID
, TOP_RIGHT
);
365 AddAnchor(IDC_BUGTRAQBUTTON
, TOP_RIGHT
);
366 AddAnchor(IDC_COMMIT_TO
, TOP_LEFT
, TOP_RIGHT
);
367 AddAnchor(IDC_CHECK_NEWBRANCH
, TOP_RIGHT
);
368 AddAnchor(IDC_NEWBRANCH
, TOP_LEFT
, TOP_RIGHT
);
369 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
370 // AddAnchor(IDC_HISTORY, TOP_LEFT);
371 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
372 AddAnchor(IDC_SIGNOFF
, TOP_RIGHT
);
373 AddAnchor(IDC_VIEW_PATCH
, BOTTOM_RIGHT
);
374 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
375 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
376 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
377 AddAnchor(IDC_SHOWUNVERSIONED
, BOTTOM_LEFT
);
378 AddAnchor(IDC_EXTERNALWARNING
, BOTTOM_RIGHT
);
379 AddAnchor(IDC_STATISTICS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
380 AddAnchor(IDC_TEXT_INFO
, TOP_RIGHT
);
381 AddAnchor(IDC_WHOLE_PROJECT
, BOTTOM_LEFT
);
382 AddAnchor(IDC_KEEPLISTS
, BOTTOM_LEFT
);
383 AddAnchor(IDC_NOAUTOSELECTSUBMODULES
, BOTTOM_LEFT
);
384 AddAnchor(IDOK
, BOTTOM_RIGHT
);
385 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
386 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
387 AddAnchor(IDC_MERGEACTIVE
, BOTTOM_RIGHT
);
388 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
389 AddAnchor(IDC_COMMIT_MESSAGEONLY
, BOTTOM_LEFT
);
390 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
391 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
392 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
393 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
394 AddAnchor(IDC_COMMIT_AS_COMMIT_DATE
, TOP_LEFT
);
395 AddAnchor(IDC_COMMIT_SETAUTHOR
, TOP_LEFT
);
396 AddAnchor(IDC_COMMIT_AUTHORDATA
, TOP_LEFT
, TOP_RIGHT
);
398 AddAnchor(IDC_SELECTLABEL
, TOP_LEFT
);
399 AddAnchor(IDC_CHECKALL
, TOP_LEFT
);
400 AddAnchor(IDC_CHECKNONE
, TOP_LEFT
);
401 AddAnchor(IDC_CHECKUNVERSIONED
, TOP_LEFT
);
402 AddAnchor(IDC_CHECKVERSIONED
, TOP_LEFT
);
403 AddAnchor(IDC_CHECKADDED
, TOP_LEFT
);
404 AddAnchor(IDC_CHECKDELETED
, TOP_LEFT
);
405 AddAnchor(IDC_CHECKMODIFIED
, TOP_LEFT
);
406 AddAnchor(IDC_CHECKFILES
, TOP_LEFT
);
407 AddAnchor(IDC_CHECKSUBMODULES
, TOP_LEFT
);
410 CenterWindow(CWnd::FromHandle(hWndExplorer
));
411 EnableSaveRestore(_T("CommitDlg"));
412 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
413 RECT rcDlg
, rcLogMsg
, rcFileList
;
414 GetClientRect(&rcDlg
);
415 m_cLogMessage
.GetWindowRect(&rcLogMsg
);
416 ScreenToClient(&rcLogMsg
);
417 m_ListCtrl
.GetWindowRect(&rcFileList
);
418 ScreenToClient(&rcFileList
);
422 m_wndSplitter
.GetWindowRect(&rectSplitter
);
423 ScreenToClient(&rectSplitter
);
424 int delta
= yPos
- rectSplitter
.top
;
425 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
427 m_wndSplitter
.SetWindowPos(NULL
, rectSplitter
.left
, yPos
, 0, 0, SWP_NOSIZE
);
434 if (m_bForceCommitAmend
|| m_bCommitAmend
)
435 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
437 // add all directories to the watcher
439 for (int i=0; i<m_pathList.GetCount(); ++i)
441 if (m_pathList[i].IsDirectory())
442 m_pathwatcher.AddPath(m_pathList[i]);
445 m_updatedPathList
= m_pathList
;
447 //first start a thread to obtain the file list with the status without
448 //blocking the dialog
449 InterlockedExchange(&m_bBlock
, TRUE
);
450 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
453 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
454 InterlockedExchange(&m_bBlock
, FALSE
);
458 m_pThread
->m_bAutoDelete
= FALSE
;
459 m_pThread
->ResumeThread();
461 CRegDWORD err
= CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE
);
462 CRegDWORD historyhint
= CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE
);
463 if ((((DWORD
)err
)!=FALSE
)&&((((DWORD
)historyhint
)==FALSE
)))
466 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
470 this->m_ctrlShowPatch
.SetURL(CString());
472 if (g_Git
.GetConfigValueBool(_T("tgit.commitshowpatch")))
473 OnStnClickedViewPatch();
475 return FALSE
; // return TRUE unless you set the focus to a control
476 // EXCEPTION: OCX Property Pages should return FALSE
479 static bool UpdateIndex(CMassiveGitTask
&mgt
, CSysProgressDlg
&sysProgressDlg
, int progress
, int maxProgress
)
481 if (!mgt
.GetListCount())
484 if (sysProgressDlg
.HasUserCancelled())
487 if (sysProgressDlg
.IsVisible())
489 sysProgressDlg
.SetTitle(IDS_APPNAME
);
490 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT
)));
491 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX
)));
492 sysProgressDlg
.SetProgress(progress
, maxProgress
);
493 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing
497 return mgt
.Execute(cancel
);
500 void CCommitDlg::OnOK()
504 if (m_bThreadRunning
)
507 InterlockedExchange(&m_bRunThread
, FALSE
);
508 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
509 if (m_bThreadRunning
)
511 // we gave the thread a chance to quit. Since the thread didn't
512 // listen to us we have to kill it.
513 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
514 InterlockedExchange(&m_bThreadRunning
, FALSE
);
519 if (m_bCreateNewBranch
)
521 if (!g_Git
.IsBranchNameValid(m_sCreateNewBranch
))
523 ShowEditBalloon(IDC_NEWBRANCH
, IDS_B_T_NOTEMPTY
, IDS_ERR_ERROR
, TTI_ERROR
);
526 if (g_Git
.BranchTagExists(m_sCreateNewBranch
))
528 // branch already exists
530 msg
.LoadString(IDS_B_EXISTS
);
531 msg
+= _T(" ") + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME
));
532 ShowEditBalloon(IDC_NEWBRANCH
, msg
, CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
535 if (g_Git
.BranchTagExists(m_sCreateNewBranch
, false))
537 // tag with the same name exists -> shortref is ambiguous
538 if (CMessageBox::Show(m_hWnd
, IDS_B_SAMETAGNAMEEXISTS
, IDS_APPNAME
, 2, IDI_EXCLAMATION
, IDS_CONTINUEBUTTON
, IDS_ABORTBUTTON
) == 2)
544 GetDlgItemText(IDC_BUGID
, id
);
545 if (!m_ProjectProperties
.CheckBugID(id
))
547 ShowEditBalloon(IDC_BUGID
, IDS_COMMITDLG_ONLYNUMBERS
, IDS_ERR_ERROR
, TTI_ERROR
);
550 m_sLogMessage
= m_cLogMessage
.GetText();
551 if ( m_sLogMessage
.IsEmpty() )
553 // no message entered, go round again
554 CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
557 if ((m_ProjectProperties
.bWarnIfNoIssue
) && (id
.IsEmpty() && !m_ProjectProperties
.HasBugID(m_sLogMessage
)))
559 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOISSUEWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
563 if (m_ProjectProperties
.bWarnNoSignedOffBy
== TRUE
&& m_cLogMessage
.GetText().Find(GetSignedOffByLine()) == -1)
565 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
);
568 OnBnClickedSignOff();
569 m_sLogMessage
= m_cLogMessage
.GetText();
571 else if (retval
== 3)
575 if (CHooks::Instance().IsHookPresent(pre_commit_hook
, g_Git
.m_CurrentDir
)) {
576 DWORD exitcode
= 0xFFFFFFFF;
579 m_ListCtrl
.WriteCheckedNamesToPathList(list
);
580 if (CHooks::Instance().PreCommit(g_Git
.m_CurrentDir
, list
, m_sLogMessage
, exitcode
, error
))
585 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
586 MessageBox(temp
, _T("TortoiseGit"), MB_ICONERROR
);
592 int nListItems
= m_ListCtrl
.GetItemCount();
593 bool needResetIndex
= false;
594 for (int i
= 0; i
< nListItems
&& !m_bCommitMessageOnly
; ++i
)
596 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
597 if (!entry
->m_Checked
&& !(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
598 needResetIndex
= true;
599 if (!entry
->m_Checked
|| !entry
->IsDirectory())
603 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
606 subgit
.m_CurrentDir
= g_Git
.CombinePath(entry
);
608 subgit
.Run(_T("git.exe status --porcelain"), &subcmdout
, CP_UTF8
);
609 dirty
= !subcmdout
.IsEmpty();
614 cmd
.Format(_T("git.exe diff -- \"%s\""), entry
->GetWinPathString());
615 g_Git
.Run(cmd
, &cmdout
, CP_UTF8
);
616 dirty
= cmdout
.Right(7) == _T("-dirty\n");
622 message
.Format(CString(MAKEINTRESOURCE(IDS_COMMITDLG_SUBMODULEDIRTY
)), entry
->GetGitPathString());
623 int result
= CMessageBox::Show(m_hWnd
, message
, _T("TortoiseGit"), 1, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_COMMIT
)), CString(MAKEINTRESOURCE(IDS_MSGBOX_IGNORE
)), CString(MAKEINTRESOURCE(IDS_MSGBOX_CANCEL
)));
627 cmdCommit
.Format(_T("/command:commit /path:\"%s\\%s\""), g_Git
.m_CurrentDir
, entry
->GetWinPathString());
628 CAppUtils::RunTortoiseGitProc(cmdCommit
);
631 else if (result
== 2)
638 if (!m_bCommitMessageOnly
)
639 m_ListCtrl
.WriteCheckedNamesToPathList(m_selectedPathList
);
640 m_pathwatcher
.Stop();
641 InterlockedExchange(&m_bBlock
, TRUE
);
642 //first add all the unversioned files the user selected
643 //and check if all versioned files are selected
646 CMassiveGitTask
mgtReAddAfterCommit(_T("add --ignore-errors -f"));
651 bool bAddSuccess
=true;
652 bool bCloseCommitDlg
=false;
654 CSysProgressDlg sysProgressDlg
;
655 if (nListItems
>= 25)
657 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT
)));
658 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX
)));
659 sysProgressDlg
.SetTime(true);
660 sysProgressDlg
.SetShowProgressBar(true);
661 sysProgressDlg
.ShowModal(this, true);
664 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
665 DWORD currentTicks
= GetTickCount();
667 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_COMMIT_UPDATE_INDEX
))
670 Do not use the libgit2 implementation right now, since it has several flaws:
671 * https://code.google.com/p/tortoisegit/issues/detail?id=1690: possible access denied problem
672 * https://code.google.com/p/tortoisegit/issues/detail?id=2224: filters not correctly applied
673 * changes to x-bit are not correctly committed, since we reset the index
678 CAutoRepository
repository(g_Git
.GetGitRepository());
681 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
686 CString revRef
= _T("HEAD");
687 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
688 revRef
= _T("HEAD~1");
689 if (CGit::GetHash(repository
, revHash
, revRef
))
691 MessageBox(g_Git
.GetLibGit2LastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR
);
696 if (!revHash
.IsEmpty() && needResetIndex
&& git_commit_lookup(commit
.GetPointer(), repository
, (const git_oid
*)revHash
.m_hash
))
698 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not get last commit.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
703 if (!revHash
.IsEmpty() && needResetIndex
&& git_commit_tree(tree
.GetPointer(), commit
))
705 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not read tree of commit.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
710 if (git_repository_index(index
.GetPointer(), repository
))
712 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not get the repository index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
716 // reset index to the one of the reference commit (HEAD or HEAD~1)
717 if (!revHash
.IsEmpty() && needResetIndex
&& git_index_read_tree(index
, tree
))
719 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not read the tree into the index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
722 else if (!revHash
.IsEmpty() && !needResetIndex
)
724 git_index_read(index
, true);
729 for (int j
= 0; j
< nListItems
; ++j
)
731 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
733 if (sysProgressDlg
.IsVisible())
735 if (GetTickCount() - currentTicks
> 1000 || j
== nListItems
- 1 || j
== 0)
737 sysProgressDlg
.SetLine(2, entry
->GetGitPathString(), true);
738 sysProgressDlg
.SetProgress(j
, nListItems
);
739 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too often: this takes time!
740 currentTicks
= GetTickCount();
744 CStringA filePathA
= CUnicodeUtils::GetMulti(entry
->GetGitPathString(), CP_UTF8
);
746 if (entry
->m_Checked
&& !m_bCommitMessageOnly
)
748 if (entry
->IsDirectory())
750 git_submodule
*submodule
= nullptr;
751 if (git_submodule_lookup(&submodule
, repository
, filePathA
))
754 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open submodule \"") + entry
->GetGitPathString() + _T("\".")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
757 if (git_submodule_add_to_index(submodule
, FALSE
))
760 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not add submodule \"") + entry
->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
764 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
766 git_index_remove_bypath(index
, filePathA
); // ignore error
770 if (git_index_add_bypath(index
, filePathA
))
773 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not add \"") + entry
->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
778 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
780 git_index_remove_bypath(index
, filePathA
); // ignore error
785 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
786 mgtReAddAfterCommit
.AddFile(*entry
);
788 if (sysProgressDlg
.HasUserCancelled())
794 CShellUpdater::Instance().AddPathForUpdate(*entry
);
796 if (bAddSuccess
&& git_index_write(index
))
802 // ***************************************************
803 // ATTENTION: Similar code in RebaseDlg.cpp!!!
804 // ***************************************************
805 CMassiveGitTask
mgtAdd(_T("add -f"));
806 CMassiveGitTask
mgtUpdateIndexForceRemove(_T("update-index --force-remove"));
807 CMassiveGitTask
mgtUpdateIndex(_T("update-index"));
808 CMassiveGitTask
mgtRm(_T("rm --ignore-unmatch"));
809 CMassiveGitTask
mgtRmFCache(_T("rm -f --cache"));
810 CString resetCmd
= _T("reset");
811 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
812 resetCmd
+= _T(" HEAD~1");;
813 CMassiveGitTask
mgtReset(resetCmd
, TRUE
, true);
814 for (int j
= 0; j
< nListItems
; ++j
)
816 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
818 if (entry
->m_Checked
&& !m_bCommitMessageOnly
)
820 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
821 mgtAdd
.AddFile(entry
->GetGitPathString());
822 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
823 mgtUpdateIndexForceRemove
.AddFile(entry
->GetGitPathString());
825 mgtUpdateIndex
.AddFile(entry
->GetGitPathString());
827 if ((entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
) && !entry
->GetGitOldPathString().IsEmpty())
828 mgtRm
.AddFile(entry
->GetGitOldPathString());
834 if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
835 { //To init git repository, there are not HEAD, so we can use git reset command
836 mgtRmFCache
.AddFile(entry
->GetGitPathString());
837 mgtReAddAfterCommit
.AddFile(*entry
);
839 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
&& !entry
->GetGitOldPathString().IsEmpty())
840 mgtReset
.AddFile(entry
->GetGitOldPathString());
842 else if (!(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
843 mgtReset
.AddFile(entry
->GetGitPathString());
846 if (sysProgressDlg
.HasUserCancelled())
853 CMassiveGitTask tasks
[] = { mgtAdd
, mgtUpdateIndexForceRemove
, mgtUpdateIndex
, mgtRm
, mgtRmFCache
, mgtReset
};
854 int progress
= 0, maxProgress
= 0;
855 for (int j
= 0; j
< _countof(tasks
); ++j
)
856 maxProgress
+= tasks
[j
].GetListCount();
857 for (int j
= 0; j
< _countof(tasks
); ++j
)
858 bAddSuccess
= bAddSuccess
&& UpdateIndex(tasks
[j
], sysProgressDlg
, progress
+= tasks
[j
].GetListCount(), maxProgress
);
860 if (sysProgressDlg
.HasUserCancelled())
863 for (int j
= 0; bAddSuccess
&& j
< nListItems
; ++j
)
864 CShellUpdater::Instance().AddPathForUpdate(*(CTGitPath
*)m_ListCtrl
.GetItemData(j
));
867 if (sysProgressDlg
.HasUserCancelled())
870 //sysProgressDlg.Stop();
872 if (bAddSuccess
&& m_bCreateNewBranch
)
874 if (g_Git
.Run(_T("git.exe branch ") + m_sCreateNewBranch
, &out
, CP_UTF8
))
876 MessageBox(_T("Creating new branch failed:\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
879 if (g_Git
.Run(_T("git.exe checkout ") + m_sCreateNewBranch
+ _T(" --"), &out
, CP_UTF8
))
881 MessageBox(_T("Switching to new branch failed:\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
886 if (bAddSuccess
&& m_bWarnDetachedHead
&& CheckHeadDetach())
890 CString sExistingBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
891 sExistingBugID
.Trim();
892 if (!m_sBugID
.IsEmpty() && m_sBugID
.Compare(sExistingBugID
))
894 m_sBugID
.Replace(_T(", "), _T(","));
895 m_sBugID
.Replace(_T(" ,"), _T(","));
896 CString sBugID
= m_ProjectProperties
.sMessage
;
897 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
898 if (m_ProjectProperties
.bAppend
)
899 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
901 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
904 // now let the bugtraq plugin check the commit message
905 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
906 if (m_BugTraqProvider
)
908 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
912 ATL::CComBSTR
repositoryRoot(g_Git
.m_CurrentDir
);
913 ATL::CComBSTR
parameters(m_bugtraq_association
.GetParameters());
914 ATL::CComBSTR
commonRoot(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
915 ATL::CComBSTR
commitMessage(m_sLogMessage
);
916 CBstrSafeVector
pathList(m_selectedPathList
.GetCount());
918 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
919 pathList
.PutElement(index
, m_selectedPathList
[index
].GetGitPathString());
921 if (FAILED(hr
= pProvider2
->CheckCommit(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, commitMessage
, &temp
)))
925 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), ce
.GetMessageAndDescription().c_str());
926 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
930 CString sError
= temp
;
931 if (!sError
.IsEmpty())
933 CMessageBox::Show(m_hWnd
, sError
, _T("TortoiseGit"), MB_ICONERROR
);
940 if (m_bCommitMessageOnly
|| bAddSuccess
&& (nchecked
|| m_bCommitAmend
|| CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive()))
942 bCloseCommitDlg
= true;
944 CString tempfile
=::GetTempFile();
946 if (CAppUtils::SaveCommitUnicodeFile(tempfile
, m_sLogMessage
))
948 CMessageBox::Show(nullptr, _T("Could not save commit message"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
952 CTGitPath path
=g_Git
.m_CurrentDir
;
954 BOOL IsGitSVN
= path
.GetAdminDirMask() & ITEMIS_GITSVN
;
958 if(this->m_bCommitAmend
)
963 if (m_bSetCommitDateTime
)
966 m_CommitDate
.GetTime(date
);
967 m_CommitTime
.GetTime(time
);
968 if (m_bCommitAmend
&& m_AsCommitDateCtrl
.GetCheck())
969 dateTime
= CAppUtils::GetMsysgitVersion() > 0x02010000 ? L
"--date=\"now\"" : L
"--date=\"\"" ;
971 dateTime
.Format(_T("--date=%sT%s"), date
.Format(_T("%Y-%m-%d")), time
.Format(_T("%H:%M:%S")));
975 author
.Format(_T("--author=\"%s\""), m_sAuthor
);
976 CString allowEmpty
= m_bCommitMessageOnly
? _T("--allow-empty") : _T("");
977 cmd
.Format(_T("git.exe commit %s %s %s %s -F \"%s\""), author
, dateTime
, amend
, allowEmpty
, tempfile
);
979 CCommitProgressDlg progress
;
980 progress
.m_bBufferAll
=true; // improve show speed when there are many file added.
981 progress
.m_GitCmd
=cmd
;
982 progress
.m_bShowCommand
= FALSE
; // don't show the commit command
983 progress
.m_PreText
= out
; // show any output already generated in log window
985 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
987 if (status
|| m_bNoPostActions
|| m_bAutoClose
)
991 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_MENUSVNDCOMMIT
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_DCOMMIT
; }));
993 postCmdList
.push_back(PostCmd(IDI_PUSH
, IDS_MENUPUSH
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_PUSH
; }));
994 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUPULL
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_PULL
; }));
995 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_PROC_COMMIT_RECOMMIT
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_RECOMMIT
; }));
996 postCmdList
.push_back(PostCmd(IDI_TAG
, IDS_MENUTAG
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_CREATETAG
; }));
999 m_PostCmd
= GIT_POSTCOMMIT_CMD_NOTHING
;
1002 if (progress
.m_GitStatus
|| m_PostCmd
== GIT_POSTCOMMIT_CMD_RECOMMIT
)
1004 bCloseCommitDlg
= false;
1005 if (m_PostCmd
== GIT_POSTCOMMIT_CMD_RECOMMIT
)
1007 if (!m_sLogMessage
.IsEmpty())
1009 m_History
.AddEntry(m_sLogMessage
);
1013 this->m_sLogMessage
.Empty();
1014 GetCommitTemplate(m_sLogMessage
);
1015 RunStartCommitHook();
1016 m_cLogMessage
.SetText(m_sLogMessage
);
1017 if (m_bCreateNewBranch
)
1019 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_SHOW
);
1020 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_HIDE
);
1022 m_bCreateNewBranch
= FALSE
;
1025 if (!progress
.m_GitStatus
)
1028 m_bCommitAmend
= FALSE
;
1033 this->BringWindowToTop();
1036 ::DeleteFile(tempfile
);
1038 if (m_BugTraqProvider
&& progress
.m_GitStatus
== 0)
1040 CComPtr
<IBugTraqProvider2
> pProvider
= NULL
;
1041 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
1044 ATL::CComBSTR
commonRoot(g_Git
.m_CurrentDir
);
1045 CBstrSafeVector
pathList(m_selectedPathList
.GetCount());
1047 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
1048 pathList
.PutElement(index
, m_selectedPathList
[index
].GetGitPathString());
1050 ATL::CComBSTR
logMessage(m_sLogMessage
);
1053 if (g_Git
.GetHash(hash
, _T("HEAD")))
1054 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR
);
1055 LONG version
= g_Git
.Hash2int(hash
);
1058 if (FAILED(hr
= pProvider
->OnCommitFinished(GetSafeHwnd(),
1065 CString sErr
= temp
;
1066 if (!sErr
.IsEmpty())
1067 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1071 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, ce
.GetSource().c_str(), ce
.GetMessageAndDescription().c_str());
1072 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1077 RestoreFiles(progress
.m_GitStatus
== 0);
1078 if (((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit"), TRUE
)) == TRUE
)
1080 BOOL cancel
= FALSE
;
1081 mgtReAddAfterCommit
.Execute(cancel
);
1084 else if(bAddSuccess
)
1086 CMessageBox::Show(this->m_hWnd
, IDS_ERROR_NOTHING_COMMIT
, IDS_COMMIT_FINISH
, MB_OK
| MB_ICONINFORMATION
);
1087 bCloseCommitDlg
=false;
1091 m_regAddBeforeCommit
= m_bShowUnversioned
;
1092 m_regKeepChangelists
= m_bKeepChangeList
;
1093 m_regDoNotAutoselectSubmodules
= m_bDoNotAutoselectSubmodules
;
1094 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
1095 m_bKeepChangeList
= FALSE
;
1096 InterlockedExchange(&m_bBlock
, FALSE
);
1098 if (!m_sLogMessage
.IsEmpty())
1100 m_History
.AddEntry(m_sLogMessage
);
1106 if( bCloseCommitDlg
)
1107 CResizableStandAloneDialog::OnOK();
1109 CShellUpdater::Instance().Flush();
1112 void CCommitDlg::SaveSplitterPos()
1116 CRegDWORD
regPos(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
1118 m_wndSplitter
.GetWindowRect(&rectSplitter
);
1119 ScreenToClient(&rectSplitter
);
1120 regPos
= rectSplitter
.top
;
1124 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
1126 return ((CCommitDlg
*)pVoid
)->StatusThread();
1129 UINT
CCommitDlg::StatusThread()
1131 //get the status of all selected file/folders recursively
1132 //and show the ones which have to be committed to the user
1133 //in a list control.
1134 InterlockedExchange(&m_bBlock
, TRUE
);
1135 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
1136 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
1138 m_pathwatcher
.Stop();
1140 m_ListCtrl
.SetBusy(true);
1141 g_Git
.RefreshGitIndex();
1143 m_bCancelled
= false;
1145 DialogEnableWindow(IDOK
, false);
1146 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
1147 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
1148 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, false);
1149 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
1150 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
1151 DialogEnableWindow(IDC_COMMIT_AMEND
, FALSE
);
1152 DialogEnableWindow(IDC_COMMIT_AMENDDIFF
, FALSE
);
1153 // read the list of recent log entries before querying the WC for status
1154 // -> the user may select one and modify / update it while we are crawling the WC
1156 DialogEnableWindow(IDC_CHECKALL
, false);
1157 DialogEnableWindow(IDC_CHECKNONE
, false);
1158 DialogEnableWindow(IDC_CHECKUNVERSIONED
, false);
1159 DialogEnableWindow(IDC_CHECKVERSIONED
, false);
1160 DialogEnableWindow(IDC_CHECKADDED
, false);
1161 DialogEnableWindow(IDC_CHECKDELETED
, false);
1162 DialogEnableWindow(IDC_CHECKMODIFIED
, false);
1163 DialogEnableWindow(IDC_CHECKFILES
, false);
1164 DialogEnableWindow(IDC_CHECKSUBMODULES
, false);
1166 if (m_History
.IsEmpty())
1169 reg
.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR
)m_ListCtrl
.m_sUUID
);
1170 reg
.Replace(_T(':'),_T('_'));
1171 m_History
.Load(reg
, _T("logmsgs"));
1175 GitAdminDir::GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
1176 if (PathFileExists(dotGitPath
+ _T("CHERRY_PICK_HEAD")))
1178 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
1179 m_bCommitAmend
= FALSE
;
1180 SendMessage(WM_UPDATEDATAFALSE
);
1183 // Initialise the list control with the status of the files/folders below us
1186 CTGitPathList
*pList
;
1187 m_ListCtrl
.m_amend
= (m_bCommitAmend
==TRUE
|| m_bForceCommitAmend
) && (m_bAmendDiffToLastCommit
==FALSE
);
1188 m_ListCtrl
.m_bDoNotAutoselectSubmodules
= (m_bDoNotAutoselectSubmodules
== TRUE
);
1190 if(m_bWholeProject
|| m_bWholeProject2
)
1193 pList
= &m_pathList
;
1195 success
=m_ListCtrl
.GetStatus(pList
);
1197 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1198 if(this->m_bShowUnversioned
)
1199 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
1201 m_ListCtrl
.CheckIfChangelistsArePresent(false);
1203 DWORD dwShow
= GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWLOCKS
| GITSLC_SHOWINCHANGELIST
| GITSLC_SHOWDIRECTFILES
;
1204 dwShow
|= DWORD(m_regAddBeforeCommit
) ? GITSLC_SHOWUNVERSIONED
: 0;
1207 if (!m_checkedPathList
.IsEmpty())
1208 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
1211 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
1212 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
1213 m_ListCtrl
.Show(dwShow
, dwCheck
);
1214 m_bSelectFilesForCommit
= true;
1217 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
1219 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
1220 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
1223 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
1224 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
1228 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
1229 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
1230 m_ListCtrl
.Show(dwShow
);
1233 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
1234 && !PathFileExists(dotGitPath
+ _T("MERGE_HEAD")))
1237 temp
.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
);
1238 if (CMessageBox::ShowCheck(m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONINFORMATION
| MB_YESNO
, _T("NothingToCommitShowUnversioned"), NULL
)==IDYES
)
1240 m_bShowUnversioned
= TRUE
;
1241 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
1242 DWORD dwShow
= (DWORD
)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWUNVERSIONED
| GITSLC_SHOWLOCKS
);
1243 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
1244 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
1251 // we don't have to block the commit dialog while we fetch the
1252 // auto completion list.
1253 m_pathwatcher
.ClearChangedPaths();
1254 InterlockedExchange(&m_bBlock
, FALSE
);
1255 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE
)==TRUE
)
1257 m_ListCtrl
.Block(TRUE
, TRUE
);
1258 GetAutocompletionList();
1259 m_ListCtrl
.Block(FALSE
, FALSE
);
1261 SendMessage(WM_UPDATEOKBUTTON
);
1264 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
1265 DialogEnableWindow(IDC_WHOLE_PROJECT
, !m_bWholeProject2
);
1266 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, true);
1267 if (m_ListCtrl
.HasChangeLists())
1268 DialogEnableWindow(IDC_KEEPLISTS
, true);
1270 // activate amend checkbox (if necessary)
1271 if (g_Git
.IsInitRepos())
1273 m_bCommitAmend
= FALSE
;
1274 SendMessage(WM_UPDATEDATAFALSE
);
1278 if (m_bForceCommitAmend
)
1280 m_bCommitAmend
= TRUE
;
1281 SendMessage(WM_UPDATEDATAFALSE
);
1284 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(!PathFileExists(dotGitPath
+ _T("CHERRY_PICK_HEAD")));
1287 if (g_Git
.GetHash(hash
, _T("HEAD")))
1289 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
1291 if (!hash
.IsEmpty())
1293 GitRev headRevision
;
1294 if (headRevision
.GetParentFromHash(hash
))
1295 MessageBox(headRevision
.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
1296 // do not allow to show diff to "last" revision if it has more that one parent
1297 if (headRevision
.ParentsCount() != 1)
1299 m_bAmendDiffToLastCommit
= TRUE
;
1300 SendMessage(WM_UPDATEDATAFALSE
);
1303 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->EnableWindow(TRUE
);
1309 // we have the list, now signal the main thread about it
1310 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
1313 InterlockedExchange(&m_bRunThread
, FALSE
);
1314 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1315 // force the cursor to normal
1321 void CCommitDlg::SetDlgTitle()
1323 if (m_sTitle
.IsEmpty())
1324 GetWindowText(m_sTitle
);
1326 if (m_bWholeProject
|| m_bWholeProject2
)
1327 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
1330 if (m_pathList
.GetCount() == 1)
1331 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.CombinePath(m_pathList
[0].GetUIPathString()), m_sTitle
);
1333 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.CombinePath(m_ListCtrl
.GetCommonDirectory(false)), m_sTitle
);
1337 void CCommitDlg::OnCancel()
1339 m_bCancelled
= true;
1340 m_pathwatcher
.Stop();
1342 if (m_bThreadRunning
)
1344 InterlockedExchange(&m_bRunThread
, FALSE
);
1345 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
1346 if (m_bThreadRunning
)
1348 // we gave the thread a chance to quit. Since the thread didn't
1349 // listen to us we have to kill it.
1350 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1351 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1356 m_sLogMessage
= m_cLogMessage
.GetText();
1357 if (!m_sBugID
.IsEmpty())
1359 m_sBugID
.Replace(_T(", "), _T(","));
1360 m_sBugID
.Replace(_T(" ,"), _T(","));
1361 CString sBugID
= m_ProjectProperties
.sMessage
;
1362 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
1363 if (m_ProjectProperties
.bAppend
)
1364 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
1366 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
1368 if ((m_sLogTemplate
.Compare(m_sLogMessage
) != 0) && !m_sLogMessage
.IsEmpty())
1370 m_History
.AddEntry(m_sLogMessage
);
1375 CResizableStandAloneDialog::OnCancel();
1378 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1382 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1387 if (pMsg
->message
== WM_KEYDOWN
)
1389 switch (pMsg
->wParam
)
1394 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1400 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1402 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1404 PostMessage(WM_COMMAND
, IDOK
);
1408 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1410 // Pressing RETURN in the bug id control
1411 // moves the focus to the message
1412 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1420 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1423 void CCommitDlg::Refresh()
1425 if (m_bThreadRunning
)
1428 InterlockedExchange(&m_bBlock
, TRUE
);
1429 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1430 if (m_pThread
==NULL
)
1432 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1433 InterlockedExchange(&m_bBlock
, FALSE
);
1437 m_pThread
->m_bAutoDelete
= FALSE
;
1438 m_pThread
->ResumeThread();
1442 void CCommitDlg::OnBnClickedShowunversioned()
1444 m_tooltips
.Pop(); // hide the tooltips
1446 m_regAddBeforeCommit
= m_bShowUnversioned
;
1449 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1450 if (DWORD(m_regAddBeforeCommit
))
1451 dwShow
|= GITSLC_SHOWUNVERSIONED
;
1453 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
1454 if(dwShow
& GITSLC_SHOWUNVERSIONED
)
1456 if (m_bWholeProject
|| m_bWholeProject2
)
1457 m_ListCtrl
.GetStatus(NULL
,false,false,true);
1459 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1461 m_ListCtrl
.Show(dwShow
, 0, true, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
1466 void CCommitDlg::OnStnClickedExternalwarning()
1471 void CCommitDlg::OnEnChangeLogmessage()
1473 SendMessage(WM_UPDATEOKBUTTON
);
1476 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1479 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1481 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1483 m_bShowUnversioned
= TRUE
;
1484 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1485 m_ListCtrl
.Show(dwShow
);
1493 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1499 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM
/*lParam*/)
1503 SetForegroundWindow();
1505 // if multiple files/folders are dropped
1506 // this handler is called for every single item
1508 // To avoid creating multiple refresh threads and
1509 // causing crashes, we only add the items to the
1510 // list control and start a timer.
1511 // When the timer expires, we start the refresh thread,
1512 // but only if it isn't already running - otherwise we
1513 // restart the timer.
1515 path
.SetFromWin((LPCTSTR
)lParam
);
1517 // just add all the items we get here.
1518 // if the item is versioned, the add will fail but nothing
1519 // more will happen.
1521 Git
.Add(CTGitPathList(path
), &m_ProjectProperties
, Git_depth_empty
, false, true, true);
1523 if (!m_ListCtrl
.HasPath(path
))
1525 if (m_pathList
.AreAllPathsFiles())
1527 m_pathList
.AddPath(path
);
1528 m_pathList
.RemoveDuplicates();
1529 m_updatedPathList
.AddPath(path
);
1530 m_updatedPathList
.RemoveDuplicates();
1534 // if the path list contains folders, we have to check whether
1535 // our just (maybe) added path is a child of one of those. If it is
1536 // a child of a folder already in the list, we must not add it. Otherwise
1537 // that path could show up twice in the list.
1538 bool bHasParentInList
= false;
1539 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1541 if (m_pathList
[i
].IsAncestorOf(path
))
1543 bHasParentInList
= true;
1547 if (!bHasParentInList
)
1549 m_pathList
.AddPath(path
);
1550 m_pathList
.RemoveDuplicates();
1551 m_updatedPathList
.AddPath(path
);
1552 m_updatedPathList
.RemoveDuplicates();
1557 // Always start the timer, since the status of an existing item might have changed
1558 SetTimer(REFRESHTIMER
, 200, NULL
);
1559 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": Item %s dropped, timer started\n"), path
.GetWinPath());
1564 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1566 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1570 //////////////////////////////////////////////////////////////////////////
1571 // functions which run in the status thread
1572 //////////////////////////////////////////////////////////////////////////
1574 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1579 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1580 while (m_bRunThread
&& file
.ReadString(strLine
))
1582 int eqpos
= strLine
.Find('=');
1584 rgx
= strLine
.Mid(eqpos
+1).Trim();
1587 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1589 mapRegex
[strLine
.Left(pos
)] = rgx
;
1590 strLine
= strLine
.Mid(pos
+1).Trim();
1592 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1596 catch (CFileException
* pE
)
1598 CTraceToOutputDebugString::Instance()(__FUNCTION__
": CFileException loading auto list regex file\n");
1603 void CCommitDlg::ParseSnippetFile(const CString
& sFile
, std::map
<CString
, CString
>& mapSnippet
)
1608 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1609 while (m_bRunThread
&& file
.ReadString(strLine
))
1611 if (strLine
.IsEmpty())
1613 if (strLine
.Left(1) == _T('#')) // comment char
1615 int eqpos
= strLine
.Find('=');
1616 CString key
= strLine
.Left(eqpos
);
1617 CString value
= strLine
.Mid(eqpos
+ 1);
1618 value
.Replace(_T("\\\t"), _T("\t"));
1619 value
.Replace(_T("\\\r"), _T("\r"));
1620 value
.Replace(_T("\\\n"), _T("\n"));
1621 value
.Replace(_T("\\\\"), _T("\\"));
1622 mapSnippet
[key
] = value
;
1626 catch (CFileException
* pE
)
1628 CTraceToOutputDebugString::Instance()(__FUNCTION__
": CFileException loading auto list regex file\n");
1633 void CCommitDlg::GetAutocompletionList()
1635 // the auto completion list is made of strings from each selected files.
1636 // the strings used are extracted from the files with regexes found
1637 // in the file "autolist.txt".
1638 // the format of that file is:
1639 // file extensions separated with commas '=' regular expression to use
1641 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1642 // .cpp = (?<=[^\s]::)\b\w+\b
1644 std::map
<CString
, CString
> mapRegex
;
1645 CString sRegexFile
= CPathUtils::GetAppDirectory();
1646 CRegDWORD regtimeout
= CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1647 DWORD timeoutvalue
= regtimeout
*1000;
1648 sRegexFile
+= _T("autolist.txt");
1651 ParseRegexFile(sRegexFile
, mapRegex
);
1652 sRegexFile
= CPathUtils::GetAppDataDirectory();
1653 sRegexFile
+= _T("autolist.txt");
1654 if (PathFileExists(sRegexFile
))
1655 ParseRegexFile(sRegexFile
, mapRegex
);
1658 CString sSnippetFile
= CPathUtils::GetAppDirectory();
1659 sSnippetFile
+= _T("snippet.txt");
1660 ParseSnippetFile(sSnippetFile
, m_snippet
);
1661 sSnippetFile
= CPathUtils::GetAppDataDirectory();
1662 sSnippetFile
+= _T("snippet.txt");
1663 if (PathFileExists(sSnippetFile
))
1664 ParseSnippetFile(sSnippetFile
, m_snippet
);
1665 for (auto snip
: m_snippet
)
1666 m_autolist
.insert(std::make_pair(snip
.first
, AUTOCOMPLETE_SNIPPET
));
1668 DWORD starttime
= GetTickCount();
1670 // now we have two arrays of strings, where the first array contains all
1671 // file extensions we can use and the second the corresponding regex strings
1672 // to apply to those files.
1674 // the next step is to go over all files shown in the commit dialog
1675 // and scan them for strings we can use
1676 int nListItems
= m_ListCtrl
.GetItemCount();
1678 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1680 // stop parsing after timeout
1681 if ((!m_bRunThread
) || (GetTickCount() - starttime
> timeoutvalue
))
1684 CTGitPath
*path
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1689 CString sPartPath
=path
->GetGitPathString();
1690 m_autolist
.insert(std::make_pair(sPartPath
, AUTOCOMPLETE_FILENAME
));
1694 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1698 m_autolist
.insert(std::make_pair(sPartPath
.Mid(pos
), AUTOCOMPLETE_FILENAME
));
1701 // Last inserted entry is a file name.
1702 // Some users prefer to also list file name without extension.
1703 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE
))
1705 int dotPos
= sPartPath
.ReverseFind('.');
1706 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1707 m_autolist
.insert(std::make_pair(sPartPath
.Mid(lastPos
, dotPos
- lastPos
), AUTOCOMPLETE_FILENAME
));
1710 if (path
->m_Action
== CTGitPath::LOGACTIONS_UNVER
&& !CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseUnversioned"), FALSE
))
1712 if (path
->m_Action
== CTGitPath::LOGACTIONS_IGNORE
)
1715 CString sExt
= path
->GetFileExtension();
1717 // find the regex string which corresponds to the file extension
1718 CString rdata
= mapRegex
[sExt
];
1719 if (rdata
.IsEmpty())
1722 ScanFile(path
->GetWinPathString(), rdata
, sExt
);
1724 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": Auto completion list loaded in %d msec\n"), GetTickCount() - starttime
);
1727 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
, const CString
& sExt
)
1729 static std::map
<CString
, std::tr1::wregex
> regexmap
;
1731 std::wstring sFileContent
;
1732 CAutoFile hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
1735 DWORD size
= GetFileSize(hFile
, NULL
);
1736 if (size
> CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseMaxSize"), 300000L))
1738 // no files bigger than 300k
1741 // allocate memory to hold file contents
1742 std::unique_ptr
<char[]> buffer(new char[size
]);
1744 if (!ReadFile(hFile
, buffer
.get(), size
, &readbytes
, NULL
))
1747 IsTextUnicode(buffer
.get(), readbytes
, &opts
);
1748 if (opts
& IS_TEXT_UNICODE_NULL_BYTES
)
1752 if (opts
& IS_TEXT_UNICODE_UNICODE_MASK
)
1754 sFileContent
= std::wstring((wchar_t*)buffer
.get(), readbytes
/ sizeof(WCHAR
));
1756 if ((opts
& IS_TEXT_UNICODE_NOT_UNICODE_MASK
) || (opts
== 0))
1758 const int ret
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
.get(), readbytes
, NULL
, 0);
1759 std::unique_ptr
<wchar_t[]> pWideBuf(new wchar_t[ret
]);
1760 const int ret2
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
.get(), readbytes
, pWideBuf
.get(), ret
);
1762 sFileContent
= std::wstring(pWideBuf
.get(), ret
);
1765 if (sFileContent
.empty() || !m_bRunThread
)
1773 std::tr1::wregex regCheck
;
1774 std::map
<CString
, std::tr1::wregex
>::const_iterator regIt
;
1775 if ((regIt
= regexmap
.find(sExt
)) != regexmap
.end())
1776 regCheck
= regIt
->second
;
1779 regCheck
= std::tr1::wregex(sRegex
, std::tr1::regex_constants::icase
| std::tr1::regex_constants::ECMAScript
);
1780 regexmap
[sExt
] = regCheck
;
1782 const std::tr1::wsregex_iterator end
;
1783 for (std::tr1::wsregex_iterator
it(sFileContent
.begin(), sFileContent
.end(), regCheck
); it
!= end
; ++it
)
1785 const std::tr1::wsmatch match
= *it
;
1786 for (size_t i
= 1; i
< match
.size(); ++i
)
1788 if (match
[i
].second
-match
[i
].first
)
1790 m_autolist
.insert(std::make_pair(std::wstring(match
[i
]).c_str(), AUTOCOMPLETE_PROGRAMCODE
));
1795 catch (std::exception
) {}
1798 // CSciEditContextMenuInterface
1799 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1801 CString sMenuItemText
;
1802 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITHASH
);
1803 m_nPopupPickCommitHash
= nCmd
++;
1804 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPickCommitHash
, sMenuItemText
);
1806 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITMESSAGE
);
1807 m_nPopupPickCommitMessage
= nCmd
++;
1808 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPickCommitMessage
, sMenuItemText
);
1810 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTEFILELIST
);
1811 m_nPopupPasteListCmd
= nCmd
++;
1812 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
1814 if (!m_History
.IsEmpty())
1816 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
1817 m_nPopupPasteLastMessage
= nCmd
++;
1818 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
1820 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
1821 m_nPopupRecentMessage
= nCmd
++;
1822 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
1826 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
1828 if (cmd
== m_nPopupPickCommitHash
)
1830 // use the git log to allow selection of a version
1832 // tell the dialog to use mode for selecting revisions
1833 dlg
.SetSelect(true);
1834 // only one revision must be selected however
1835 dlg
.SingleSelection(true);
1836 if (dlg
.DoModal() == IDOK
)
1838 // get selected hash if any
1839 CString selectedHash
= dlg
.GetSelectedHash();
1840 pSciEdit
->InsertText(selectedHash
);
1845 if (cmd
== m_nPopupPickCommitMessage
)
1847 // use the git log to allow selection of a version
1849 // tell the dialog to use mode for selecting revisions
1850 dlg
.SetSelect(true);
1851 // only one revision must be selected however
1852 dlg
.SingleSelection(true);
1853 if (dlg
.DoModal() == IDOK
)
1855 // get selected hash if any
1856 CString selectedHash
= dlg
.GetSelectedHash();
1858 if (rev
.GetCommit(selectedHash
))
1860 MessageBox(rev
.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
1863 CString message
= rev
.GetSubject() + _T("\r\n") + rev
.GetBody();
1864 pSciEdit
->InsertText(message
);
1869 if (cmd
== m_nPopupPasteListCmd
)
1872 int nListItems
= m_ListCtrl
.GetItemCount();
1873 for (int i
=0; i
<nListItems
; ++i
)
1875 CTGitPath
* entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1876 if (entry
&&entry
->m_Checked
)
1879 CString status
= entry
->GetActionName();
1880 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1881 status
= _T("Add"); // I18N TODO
1883 //git_wc_status_kind status = entry->status;
1884 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1885 if (m_ProjectProperties
.bFileListInEnglish
)
1888 line
.Format(_T("%-10s %s\r\n"),status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
,0));
1892 pSciEdit
->InsertText(logmsg
);
1896 if(cmd
== m_nPopupPasteLastMessage
)
1898 if (m_History
.IsEmpty())
1902 logmsg
+=m_History
.GetEntry(0);
1903 pSciEdit
->InsertText(logmsg
);
1907 if(cmd
== m_nPopupRecentMessage
)
1909 OnBnClickedHistory();
1915 void CCommitDlg::HandleSnippet(int type
, const CString
&text
, CSciEdit
*pSciEdit
)
1917 if (type
== AUTOCOMPLETE_SNIPPET
)
1919 CString target
= m_snippet
[text
];
1920 pSciEdit
->GetWordUnderCursor(true);
1921 pSciEdit
->InsertText(target
, false);
1925 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
1929 case ENDDIALOGTIMER
:
1930 KillTimer(ENDDIALOGTIMER
);
1934 if (m_bThreadRunning
)
1936 SetTimer(REFRESHTIMER
, 200, NULL
);
1937 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Wait some more before refreshing\n");
1941 KillTimer(REFRESHTIMER
);
1942 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Refreshing after items dropped\n");
1946 case FILLPATCHVTIMER
:
1950 __super::OnTimer(nIDEvent
);
1953 void CCommitDlg::OnBnClickedHistory()
1955 m_tooltips
.Pop(); // hide the tooltips
1956 if (m_pathList
.IsEmpty())
1959 CHistoryDlg historyDlg
;
1960 historyDlg
.SetHistory(m_History
);
1961 if (historyDlg
.DoModal() != IDOK
)
1964 CString sMsg
= historyDlg
.GetSelectedText();
1965 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
1967 CString sBugID
= m_ProjectProperties
.FindBugID(sMsg
);
1968 if ((!sBugID
.IsEmpty()) && ((GetDlgItem(IDC_BUGID
)->IsWindowVisible())))
1970 SetDlgItemText(IDC_BUGID
, sBugID
);
1972 if (m_sLogTemplate
.Compare(m_cLogMessage
.GetText()) != 0)
1973 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
1975 m_cLogMessage
.SetText(sMsg
);
1978 SendMessage(WM_UPDATEOKBUTTON
);
1979 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1983 void CCommitDlg::OnBnClickedBugtraqbutton()
1985 m_tooltips
.Pop(); // hide the tooltips
1986 CString sMsg
= m_cLogMessage
.GetText();
1988 if (m_BugTraqProvider
== NULL
)
1991 ATL::CComBSTR
parameters(m_bugtraq_association
.GetParameters());
1992 ATL::CComBSTR
commonRoot(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
1993 CBstrSafeVector
pathList(m_pathList
.GetCount());
1995 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
1996 pathList
.PutElement(index
, m_pathList
[index
].GetGitPathString());
1998 ATL::CComBSTR
originalMessage(sMsg
);
2001 // first try the IBugTraqProvider2 interface
2002 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
2003 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
2004 bool bugIdOutSet
= false;
2007 ATL::CComBSTR
repositoryRoot(g_Git
.m_CurrentDir
);
2008 ATL::CComBSTR bugIDOut
;
2009 GetDlgItemText(IDC_BUGID
, m_sBugID
);
2010 ATL::CComBSTR
bugID(m_sBugID
);
2011 CBstrSafeVector revPropNames
;
2012 CBstrSafeVector revPropValues
;
2013 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
2016 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2017 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2024 m_sBugID
= bugIDOut
;
2025 SetDlgItemText(IDC_BUGID
, m_sBugID
);
2027 m_cLogMessage
.SetText((LPCTSTR
)temp
);
2028 BSTR HUGEP
*pbRevNames
;
2029 BSTR HUGEP
*pbRevValues
;
2031 HRESULT hr1
= SafeArrayAccessData(revPropNames
, (void HUGEP
**)&pbRevNames
);
2034 HRESULT hr2
= SafeArrayAccessData(revPropValues
, (void HUGEP
**)&pbRevValues
);
2037 if (revPropNames
->rgsabound
->cElements
== revPropValues
->rgsabound
->cElements
)
2039 for (ULONG i
= 0; i
< revPropNames
->rgsabound
->cElements
; ++i
)
2041 // m_revProps[pbRevNames[i]] = pbRevValues[i];
2044 SafeArrayUnaccessData(revPropValues
);
2046 SafeArrayUnaccessData(revPropNames
);
2052 // if IBugTraqProvider2 failed, try IBugTraqProvider
2053 CComPtr
<IBugTraqProvider
> pProvider
= NULL
;
2054 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
2058 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2059 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2063 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
2066 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2067 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2070 m_cLogMessage
.SetText((LPCTSTR
)temp
);
2072 m_sLogMessage
= m_cLogMessage
.GetText();
2073 if (!m_ProjectProperties
.sMessage
.IsEmpty())
2075 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
2076 if (!sBugID
.IsEmpty() && !bugIdOutSet
)
2078 SetDlgItemText(IDC_BUGID
, sBugID
);
2082 m_cLogMessage
.SetFocus();
2085 void CCommitDlg::FillPatchView(bool onlySetTimer
)
2087 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2089 KillTimer(FILLPATCHVTIMER
);
2092 SetTimer(FILLPATCHVTIMER
, 100, NULL
);
2096 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
2101 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
2102 CTGitPath
* p
=(CTGitPath
*)m_ListCtrl
.GetItemData(nSelect
);
2103 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
2105 CString head
= _T("HEAD");
2106 if(m_bCommitAmend
==TRUE
&& m_bAmendDiffToLastCommit
==FALSE
)
2107 head
= _T("HEAD~1");
2108 cmd
.Format(_T("git.exe diff %s -- \"%s\""), head
, p
->GetGitPathString());
2109 g_Git
.Run(cmd
, &out
, CP_UTF8
);
2113 m_patchViewdlg
.SetText(out
);
2116 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM
/*wparam*/, LPARAM
/*lparam*/)
2118 this->FillPatchView(true);
2123 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
2125 SendMessage(WM_UPDATEOKBUTTON
);
2129 LRESULT
CCommitDlg::OnCheck(WPARAM wnd
, LPARAM
)
2131 HWND hwnd
= (HWND
)wnd
;
2132 bool check
= !(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
2133 if (hwnd
== GetDlgItem(IDC_CHECKALL
)->GetSafeHwnd())
2134 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, check
);
2135 else if (hwnd
== GetDlgItem(IDC_CHECKNONE
)->GetSafeHwnd())
2136 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, !check
);
2137 else if (hwnd
== GetDlgItem(IDC_CHECKUNVERSIONED
)->GetSafeHwnd())
2138 m_ListCtrl
.Check(GITSLC_SHOWUNVERSIONED
, check
);
2139 else if (hwnd
== GetDlgItem(IDC_CHECKVERSIONED
)->GetSafeHwnd())
2140 m_ListCtrl
.Check(GITSLC_SHOWVERSIONED
, check
);
2141 else if (hwnd
== GetDlgItem(IDC_CHECKADDED
)->GetSafeHwnd())
2142 m_ListCtrl
.Check(GITSLC_SHOWADDED
, check
);
2143 else if (hwnd
== GetDlgItem(IDC_CHECKDELETED
)->GetSafeHwnd())
2144 m_ListCtrl
.Check(GITSLC_SHOWREMOVED
, check
);
2145 else if (hwnd
== GetDlgItem(IDC_CHECKMODIFIED
)->GetSafeHwnd())
2146 m_ListCtrl
.Check(GITSLC_SHOWMODIFIED
, check
);
2147 else if (hwnd
== GetDlgItem(IDC_CHECKFILES
)->GetSafeHwnd())
2148 m_ListCtrl
.Check(GITSLC_SHOWFILES
, check
);
2149 else if (hwnd
== GetDlgItem(IDC_CHECKSUBMODULES
)->GetSafeHwnd())
2150 m_ListCtrl
.Check(GITSLC_SHOWSUBMODULES
, check
);
2155 LRESULT
CCommitDlg::OnUpdateOKButton(WPARAM
, LPARAM
)
2160 bool bValidLogSize
= m_cLogMessage
.GetText().GetLength() >= m_ProjectProperties
.nMinLogSize
&& m_cLogMessage
.GetText().GetLength() > 0;
2161 bool bAmendOrSelectFilesOrMerge
= m_ListCtrl
.GetSelected() > 0 || (m_bCommitAmend
&& m_bAmendDiffToLastCommit
) || CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
2163 DialogEnableWindow(IDOK
, bValidLogSize
&& (m_bCommitMessageOnly
|| bAmendOrSelectFilesOrMerge
));
2168 LRESULT
CCommitDlg::OnUpdateDataFalse(WPARAM
, LPARAM
)
2174 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
2178 if (wParam
== IDC_SPLITTER
)
2180 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
2181 DoSize(pHdr
->delta
);
2186 return __super::DefWindowProc(message
, wParam
, lParam
);
2189 void CCommitDlg::SetSplitterRange()
2191 if ((m_ListCtrl
)&&(m_cLogMessage
))
2194 m_cLogMessage
.GetWindowRect(rcTop
);
2195 ScreenToClient(rcTop
);
2197 m_ListCtrl
.GetWindowRect(rcMiddle
);
2198 ScreenToClient(rcMiddle
);
2199 if (rcMiddle
.Height() && rcMiddle
.Width())
2200 m_wndSplitter
.SetRange(rcTop
.top
+ 100, rcMiddle
.bottom
- 80);
2204 void CCommitDlg::DoSize(int delta
)
2206 RemoveAnchor(IDC_MESSAGEGROUP
);
2207 RemoveAnchor(IDC_LOGMESSAGE
);
2208 RemoveAnchor(IDC_SPLITTER
);
2209 RemoveAnchor(IDC_SIGNOFF
);
2210 RemoveAnchor(IDC_COMMIT_AMEND
);
2211 RemoveAnchor(IDC_COMMIT_AMENDDIFF
);
2212 RemoveAnchor(IDC_COMMIT_SETDATETIME
);
2213 RemoveAnchor(IDC_COMMIT_DATEPICKER
);
2214 RemoveAnchor(IDC_COMMIT_TIMEPICKER
);
2215 RemoveAnchor(IDC_COMMIT_AS_COMMIT_DATE
);
2216 RemoveAnchor(IDC_COMMIT_SETAUTHOR
);
2217 RemoveAnchor(IDC_COMMIT_AUTHORDATA
);
2218 RemoveAnchor(IDC_LISTGROUP
);
2219 RemoveAnchor(IDC_FILELIST
);
2220 RemoveAnchor(IDC_TEXT_INFO
);
2221 RemoveAnchor(IDC_SELECTLABEL
);
2222 RemoveAnchor(IDC_CHECKALL
);
2223 RemoveAnchor(IDC_CHECKNONE
);
2224 RemoveAnchor(IDC_CHECKUNVERSIONED
);
2225 RemoveAnchor(IDC_CHECKVERSIONED
);
2226 RemoveAnchor(IDC_CHECKADDED
);
2227 RemoveAnchor(IDC_CHECKDELETED
);
2228 RemoveAnchor(IDC_CHECKMODIFIED
);
2229 RemoveAnchor(IDC_CHECKFILES
);
2230 RemoveAnchor(IDC_CHECKSUBMODULES
);
2232 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
2233 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
2234 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
2235 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
2236 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
2237 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
2238 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF
),0,delta
);
2239 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME
),0,delta
);
2240 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER
),0,delta
);
2241 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER
),0,delta
);
2242 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AS_COMMIT_DATE
), 0, delta
);
2243 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETAUTHOR
), 0, delta
);
2244 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AUTHORDATA
), 0, delta
);
2245 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
2246 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL
), 0, delta
);
2247 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL
), 0, delta
);
2248 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE
), 0, delta
);
2249 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED
), 0, delta
);
2250 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED
), 0, delta
);
2251 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED
), 0, delta
);
2252 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED
), 0, delta
);
2253 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED
), 0, delta
);
2254 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES
), 0, delta
);
2255 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES
), 0, delta
);
2257 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
2258 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
2259 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
2260 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
2261 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
2262 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
2263 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
2264 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
2265 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
2266 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
2267 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
2268 AddAnchor(IDC_COMMIT_AS_COMMIT_DATE
, TOP_LEFT
);
2269 AddAnchor(IDC_COMMIT_SETAUTHOR
, TOP_LEFT
);
2270 AddAnchor(IDC_COMMIT_AUTHORDATA
, TOP_LEFT
, TOP_RIGHT
);
2271 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
2272 AddAnchor(IDC_SELECTLABEL
, TOP_LEFT
);
2273 AddAnchor(IDC_CHECKALL
, TOP_LEFT
);
2274 AddAnchor(IDC_CHECKNONE
, TOP_LEFT
);
2275 AddAnchor(IDC_CHECKUNVERSIONED
, TOP_LEFT
);
2276 AddAnchor(IDC_CHECKVERSIONED
, TOP_LEFT
);
2277 AddAnchor(IDC_CHECKADDED
, TOP_LEFT
);
2278 AddAnchor(IDC_CHECKDELETED
, TOP_LEFT
);
2279 AddAnchor(IDC_CHECKMODIFIED
, TOP_LEFT
);
2280 AddAnchor(IDC_CHECKFILES
, TOP_LEFT
);
2281 AddAnchor(IDC_CHECKSUBMODULES
, TOP_LEFT
);
2283 // adjust the minimum size of the dialog to prevent the resizing from
2284 // moving the list control too far down.
2286 m_cLogMessage
.GetClientRect(rcLogMsg
);
2287 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
2290 m_cLogMessage
.Invalidate();
2291 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
2294 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
2296 // first, let the resizing take place
2297 __super::OnSize(nType
, cx
, cy
);
2303 CString
CCommitDlg::GetSignedOffByLine()
2307 CString username
= g_Git
.GetUserName();
2308 CString email
= g_Git
.GetUserEmail();
2309 username
.Remove(_T('\n'));
2310 email
.Remove(_T('\n'));
2312 str
.Format(_T("Signed-off-by: %s <%s>"), username
, email
);
2317 void CCommitDlg::OnBnClickedSignOff()
2319 CString str
= GetSignedOffByLine();
2321 if (m_cLogMessage
.GetText().Find(str
) == -1) {
2322 m_cLogMessage
.SetText(m_cLogMessage
.GetText().TrimRight());
2323 int lastNewline
= m_cLogMessage
.GetText().ReverseFind(_T('\n'));
2324 int foundByLine
= -1;
2325 if (lastNewline
> 0)
2326 foundByLine
= m_cLogMessage
.GetText().Find(_T("-by: "), lastNewline
);
2328 if (foundByLine
== -1 || foundByLine
< lastNewline
)
2329 str
= _T("\r\n") + str
;
2331 m_cLogMessage
.SetText(m_cLogMessage
.GetText()+_T("\r\n")+str
+_T("\r\n"));
2335 void CCommitDlg::OnBnClickedCommitAmend()
2338 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
2341 if (rev
.GetCommit(CString(_T("HEAD"))))
2342 MessageBox(rev
.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
2343 m_AmendStr
=rev
.GetSubject()+_T("\n")+rev
.GetBody();
2346 if(this->m_bCommitAmend
)
2348 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
2349 m_cLogMessage
.SetText(m_AmendStr
);
2350 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
2351 if (m_bSetCommitDateTime
)
2352 m_AsCommitDateCtrl
.ShowWindow(SW_SHOW
);
2356 this->m_AmendStr
=this->m_cLogMessage
.GetText();
2357 m_cLogMessage
.SetText(m_NoAmendStr
);
2358 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
2359 m_AsCommitDateCtrl
.ShowWindow(SW_HIDE
);
2360 m_AsCommitDateCtrl
.SetCheck(FALSE
);
2361 OnBnClickedCommitAsCommitDate();
2364 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2365 OnBnClickedCommitSetauthor(); // to update the commit author
2367 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
2371 void CCommitDlg::OnBnClickedCommitMessageOnly()
2374 this->m_ListCtrl
.EnableWindow(m_bCommitMessageOnly
? FALSE
: TRUE
);
2375 SendMessage(WM_UPDATEOKBUTTON
);
2378 void CCommitDlg::OnBnClickedWholeProject()
2380 m_tooltips
.Pop(); // hide the tooltips
2385 if (m_bWholeProject
|| m_bWholeProject2
)
2386 m_ListCtrl
.GetStatus(NULL
,true,false,true);
2388 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
2390 m_regShowWholeProject
= m_bWholeProject
;
2392 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
2393 if (DWORD(m_regAddBeforeCommit
))
2394 dwShow
|= GITSLC_SHOWUNVERSIONED
;
2396 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
2398 m_ListCtrl
.Show(dwShow
, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
2405 void CCommitDlg::OnFocusMessage()
2407 m_cLogMessage
.SetFocus();
2410 void CCommitDlg::OnFocusFileList()
2412 m_ListCtrl
.SetFocus();
2415 void CCommitDlg::OnScnUpdateUI(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2417 int pos
= (int)this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
2418 int line
= (int)this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
2419 int column
= (int)this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
2422 str
.Format(_T("%d/%d"),line
+1,column
+1);
2423 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
2429 void CCommitDlg::TogglePatchView()
2431 OnStnClickedViewPatch();
2434 void CCommitDlg::OnStnClickedViewPatch()
2436 m_patchViewdlg
.m_pProjectProperties
= &this->m_ProjectProperties
;
2437 m_patchViewdlg
.m_ParentDlg
= this;
2438 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
2440 BOOL viewPatchEnabled
= FALSE
;
2441 viewPatchEnabled
= g_Git
.GetConfigValueBool(_T("tgit.commitshowpatch"));
2442 if (viewPatchEnabled
== FALSE
)
2443 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("true"));
2444 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
2445 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
2447 this->GetWindowRect(&rect
);
2449 m_patchViewdlg
.ShowWindow(SW_SHOW
);
2451 m_patchViewdlg
.SetWindowPos(NULL
,rect
.right
,rect
.top
,rect
.Width(),rect
.Height(),
2452 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
2454 ShowViewPatchText(false);
2459 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2460 m_patchViewdlg
.ShowWindow(SW_HIDE
);
2461 m_patchViewdlg
.DestroyWindow();
2462 ShowViewPatchText(true);
2464 this->m_ctrlShowPatch
.Invalidate();
2467 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
2469 __super::OnMoving(fwSide
, pRect
);
2471 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
2474 m_patchViewdlg
.GetWindowRect(&patchrect
);
2475 if (::IsWindow(m_hWnd
))
2478 GetWindowRect(&thisrect
);
2479 if (patchrect
.left
== thisrect
.right
)
2481 m_patchViewdlg
.SetWindowPos(NULL
, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
2482 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
2489 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
2491 __super::OnSizing(fwSide
, pRect
);
2493 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2495 CRect thisrect
, patchrect
;
2496 this->GetWindowRect(thisrect
);
2497 this->m_patchViewdlg
.GetWindowRect(patchrect
);
2498 if(thisrect
.right
==patchrect
.left
)
2500 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
2501 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
2503 if( patchrect
.bottom
== thisrect
.bottom
)
2505 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
2507 if( patchrect
.top
== thisrect
.top
)
2509 patchrect
.top
-= thisrect
.top
-pRect
->top
;
2511 m_patchViewdlg
.MoveWindow(patchrect
);
2516 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2519 TRACE("Item Changed\r\n");
2522 int CCommitDlg::CheckHeadDetach()
2525 if (CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, output
))
2527 int retval
= CMessageBox::Show(NULL
, IDS_PROC_COMMIT_DETACHEDWARNING
, IDS_APPNAME
, MB_YESNOCANCEL
| MB_ICONWARNING
);
2530 if (CAppUtils::CreateBranchTag(FALSE
, NULL
, true) == FALSE
)
2533 else if (retval
== IDCANCEL
)
2539 void CCommitDlg::OnBnClickedCommitAmenddiff()
2545 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2551 void CCommitDlg::OnBnClickedCommitSetDateTime()
2555 if (m_bSetCommitDateTime
)
2557 CTime authordate
= CTime::GetCurrentTime();
2560 GitRev headRevision
;
2561 if (headRevision
.GetCommit(_T("HEAD")))
2562 MessageBox(headRevision
.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
2563 authordate
= headRevision
.GetAuthorDate();
2564 m_AsCommitDateCtrl
.ShowWindow(SW_SHOW
);
2567 m_CommitDate
.SetTime(&authordate
);
2568 m_CommitTime
.SetTime(&authordate
);
2570 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_SHOW
);
2571 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_SHOW
);
2575 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_HIDE
);
2576 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_HIDE
);
2577 m_AsCommitDateCtrl
.ShowWindow(SW_HIDE
);
2578 m_AsCommitDateCtrl
.SetCheck(FALSE
);
2579 OnBnClickedCommitAsCommitDate();
2583 void CCommitDlg::OnBnClickedCommitAsCommitDate()
2585 GetDlgItem(IDC_COMMIT_DATEPICKER
)->EnableWindow(!m_AsCommitDateCtrl
.GetCheck());
2586 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->EnableWindow(!m_AsCommitDateCtrl
.GetCheck());
2589 void CCommitDlg::OnBnClickedCheckNewBranch()
2592 if (m_bCreateNewBranch
)
2594 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_HIDE
);
2595 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_SHOW
);
2599 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_HIDE
);
2600 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_SHOW
);
2604 void CCommitDlg::RestoreFiles(bool doNotAsk
)
2606 if (!m_ListCtrl
.m_restorepaths
.empty() && (doNotAsk
|| CMessageBox::Show(m_hWnd
, IDS_PROC_COMMIT_RESTOREFILES
, IDS_APPNAME
, 2, IDI_QUESTION
, IDS_PROC_COMMIT_RESTOREFILES_RESTORE
, IDS_PROC_COMMIT_RESTOREFILES_KEEP
) == 1))
2608 for (std::map
<CString
, CString
>::iterator it
= m_ListCtrl
.m_restorepaths
.begin(); it
!= m_ListCtrl
.m_restorepaths
.end(); ++it
)
2609 CopyFile(it
->second
, g_Git
.CombinePath(it
->first
), FALSE
);
2610 m_ListCtrl
.m_restorepaths
.clear();
2614 void CCommitDlg::UpdateCheckLinks()
2616 DialogEnableWindow(IDC_CHECKALL
, true);
2617 DialogEnableWindow(IDC_CHECKNONE
, true);
2618 DialogEnableWindow(IDC_CHECKUNVERSIONED
, m_ListCtrl
.GetUnversionedCount() > 0);
2619 DialogEnableWindow(IDC_CHECKVERSIONED
, m_ListCtrl
.GetItemCount() > m_ListCtrl
.GetUnversionedCount());
2620 DialogEnableWindow(IDC_CHECKADDED
, m_ListCtrl
.GetAddedCount() > 0);
2621 DialogEnableWindow(IDC_CHECKDELETED
, m_ListCtrl
.GetDeletedCount() > 0);
2622 DialogEnableWindow(IDC_CHECKMODIFIED
, m_ListCtrl
.GetModifiedCount() > 0);
2623 DialogEnableWindow(IDC_CHECKFILES
, m_ListCtrl
.GetFileCount() > 0);
2624 DialogEnableWindow(IDC_CHECKSUBMODULES
, m_ListCtrl
.GetSubmoduleCount() > 0);
2627 void CCommitDlg::OnBnClickedCommitSetauthor()
2633 m_sAuthor
.Format(_T("%s <%s>"), g_Git
.GetUserName(), g_Git
.GetUserEmail());
2636 GitRev headRevision
;
2637 if (headRevision
.GetCommit(_T("HEAD")))
2638 MessageBox(headRevision
.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
2639 m_sAuthor
.Format(_T("%s <%s>"), headRevision
.GetAuthorName(), headRevision
.GetAuthorEmail());
2644 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_SHOW
);
2647 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_HIDE
);
2650 void CCommitDlg::RunStartCommitHook()
2652 DWORD exitcode
= 0xFFFFFFFF;
2654 if (CHooks::Instance().StartCommit(g_Git
.m_CurrentDir
, m_pathList
, m_sLogMessage
, exitcode
, error
))
2659 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2660 MessageBox(temp
, _T("TortoiseGit"), MB_ICONERROR
);