1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2013 - TortoiseSVN
4 // Copyright (C) 2008-2013 - 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 "DirFileEnum.h"
24 #include "MessageBox.h"
26 #include "PathUtils.h"
29 #include "GitStatus.h"
30 #include "HistoryDlg.h"
32 #include "UnicodeUtils.h"
33 #include "../TGitCache/CacheInterface.h"
34 #include "ProgressDlg.h"
35 #include "ShellUpdater.h"
36 #include "Commands/PushCommand.h"
37 #include "PatchViewDlg.h"
40 #include "SysProgressDlg.h"
41 #include "MassiveGitTask.h"
47 static char THIS_FILE
[] = __FILE__
;
50 UINT
CCommitDlg::WM_AUTOLISTREADY
= RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
51 UINT
CCommitDlg::WM_UPDATEOKBUTTON
= RegisterWindowMessage(_T("TORTOISEGIT_COMMIT_UPDATEOKBUTTON"));
52 UINT
CCommitDlg::WM_UPDATEDATAFALSE
= RegisterWindowMessage(_T("TORTOISEGIT_COMMIT_UPDATEDATAFALSE"));
54 IMPLEMENT_DYNAMIC(CCommitDlg
, CResizableStandAloneDialog
)
55 CCommitDlg::CCommitDlg(CWnd
* pParent
/*=NULL*/)
56 : CResizableStandAloneDialog(CCommitDlg::IDD
, pParent
)
58 , m_bShowUnversioned(FALSE
)
60 , m_bThreadRunning(FALSE
)
63 , m_bWholeProject(FALSE
)
64 , m_bKeepChangeList(TRUE
)
65 , m_bDoNotAutoselectSubmodules(FALSE
)
67 , m_bSelectFilesForCommit(TRUE
)
68 , m_bNoPostActions(FALSE
)
70 , m_bSetCommitDateTime(FALSE
)
71 , m_bCreateNewBranch(FALSE
)
72 , m_bForceCommitAmend(false)
73 , m_bCommitMessageOnly(FALSE
)
76 , m_PostCmd(GIT_POSTCOMMIT_CMD_NOTHING
)
77 , m_bAmendDiffToLastCommit(FALSE
)
78 , m_nPopupPasteListCmd(0)
79 , m_nPopupPasteLastMessage(0)
80 , m_nPopupRecentMessage(0)
81 , m_nPopupPickCommitHash(0)
84 this->m_bCommitAmend
=FALSE
;
87 CCommitDlg::~CCommitDlg()
95 void CCommitDlg::DoDataExchange(CDataExchange
* pDX
)
97 CResizableStandAloneDialog::DoDataExchange(pDX
);
98 DDX_Control(pDX
, IDC_FILELIST
, m_ListCtrl
);
99 DDX_Control(pDX
, IDC_LOGMESSAGE
, m_cLogMessage
);
100 DDX_Check(pDX
, IDC_SHOWUNVERSIONED
, m_bShowUnversioned
);
101 DDX_Check(pDX
, IDC_COMMIT_SETDATETIME
, m_bSetCommitDateTime
);
102 DDX_Check(pDX
, IDC_CHECK_NEWBRANCH
, m_bCreateNewBranch
);
103 DDX_Text(pDX
, IDC_NEWBRANCH
, m_sCreateNewBranch
);
104 DDX_Text(pDX
, IDC_BUGID
, m_sBugID
);
105 DDX_Text(pDX
, IDC_COMMIT_AUTHORDATA
, m_sAuthor
);
106 DDX_Check(pDX
, IDC_WHOLE_PROJECT
, m_bWholeProject
);
107 DDX_Control(pDX
, IDC_SPLITTER
, m_wndSplitter
);
108 DDX_Check(pDX
, IDC_KEEPLISTS
, m_bKeepChangeList
);
109 DDX_Check(pDX
, IDC_NOAUTOSELECTSUBMODULES
, m_bDoNotAutoselectSubmodules
);
110 DDX_Check(pDX
,IDC_COMMIT_AMEND
,m_bCommitAmend
);
111 DDX_Check(pDX
, IDC_COMMIT_MESSAGEONLY
, m_bCommitMessageOnly
);
112 DDX_Check(pDX
,IDC_COMMIT_AMENDDIFF
,m_bAmendDiffToLastCommit
);
113 DDX_Check(pDX
, IDC_COMMIT_SETAUTHOR
, m_bSetAuthor
);
114 DDX_Control(pDX
,IDC_VIEW_PATCH
,m_ctrlShowPatch
);
115 DDX_Control(pDX
, IDC_COMMIT_DATEPICKER
, m_CommitDate
);
116 DDX_Control(pDX
, IDC_COMMIT_TIMEPICKER
, m_CommitTime
);
119 BEGIN_MESSAGE_MAP(CCommitDlg
, CResizableStandAloneDialog
)
120 ON_BN_CLICKED(IDC_SHOWUNVERSIONED
, OnBnClickedShowunversioned
)
121 ON_NOTIFY(SCN_UPDATEUI
, IDC_LOGMESSAGE
, OnScnUpdateUI
)
122 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
123 ON_BN_CLICKED(IDC_BUGTRAQBUTTON
, OnBnClickedBugtraqbutton
)
124 ON_EN_CHANGE(IDC_LOGMESSAGE
, OnEnChangeLogmessage
)
125 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
, OnGitStatusListCtrlItemCountChanged
)
126 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
127 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE
, OnFileDropped
)
128 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED
, &CCommitDlg::OnGitStatusListCtrlCheckChanged
)
129 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED
, &CCommitDlg::OnGitStatusListCtrlItemChanged
)
131 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED
, &CCommitDlg::OnCheck
)
132 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY
, OnAutoListReady
)
133 ON_REGISTERED_MESSAGE(WM_UPDATEOKBUTTON
, OnUpdateOKButton
)
134 ON_REGISTERED_MESSAGE(WM_UPDATEDATAFALSE
, OnUpdateDataFalse
)
137 ON_STN_CLICKED(IDC_EXTERNALWARNING
, &CCommitDlg::OnStnClickedExternalwarning
)
138 ON_BN_CLICKED(IDC_SIGNOFF
, &CCommitDlg::OnBnClickedSignOff
)
139 ON_BN_CLICKED(IDC_COMMIT_AMEND
, &CCommitDlg::OnBnClickedCommitAmend
)
140 ON_BN_CLICKED(IDC_COMMIT_MESSAGEONLY
, &CCommitDlg::OnBnClickedCommitMessageOnly
)
141 ON_BN_CLICKED(IDC_WHOLE_PROJECT
, &CCommitDlg::OnBnClickedWholeProject
)
142 ON_COMMAND(ID_FOCUS_MESSAGE
,&CCommitDlg::OnFocusMessage
)
143 ON_COMMAND(ID_FOCUS_FILELIST
, OnFocusFileList
)
144 ON_STN_CLICKED(IDC_VIEW_PATCH
, &CCommitDlg::OnStnClickedViewPatch
)
148 ON_NOTIFY(HDN_ITEMCHANGED
, 0, &CCommitDlg::OnHdnItemchangedFilelist
)
149 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF
, &CCommitDlg::OnBnClickedCommitAmenddiff
)
150 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES
, &CCommitDlg::OnBnClickedNoautoselectsubmodules
)
151 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME
, &CCommitDlg::OnBnClickedCommitSetDateTime
)
152 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH
, &CCommitDlg::OnBnClickedCheckNewBranch
)
153 ON_BN_CLICKED(IDC_COMMIT_SETAUTHOR
, &CCommitDlg::OnBnClickedCommitSetauthor
)
156 bool PrefillMessage(const CString
&filename
, CString
&msg
)
158 if (PathFileExists(filename
))
161 if (file
.Open(filename
, CFile::modeRead
| CFile::typeBinary
))
164 std::unique_ptr
<BYTE
[]> buf(new BYTE
[file
.GetLength()]);
165 UINT read
= file
.Read(buf
.get(), (UINT
)file
.GetLength());
166 g_Git
.StringAppend(&str
, buf
.get(), CP_UTF8
, read
);
167 str
.Replace(_T("\r\n"), _T("\n"));
168 str
.TrimRight(_T("\n"));
173 ::MessageBox(nullptr, _T("Could not open ") + filename
, _T("TortoiseGit"), MB_ICONERROR
);
174 return true; // load no further files
179 int GetCommitTemplate(CString
&msg
)
181 CString tplFilename
= g_Git
.GetConfigValue(_T("commit.template"));
182 if (tplFilename
.IsEmpty())
185 if (tplFilename
[0] == _T('/'))
187 if (tplFilename
.GetLength() >= 3)
189 // handle "/d/TortoiseGit/tpl.txt" -> "d:/TortoiseGit/tpl.txt"
190 if (tplFilename
[2] == _T('/'))
192 tplFilename
.GetBuffer()[0] = tplFilename
[1];
193 tplFilename
.GetBuffer()[1] = _T(':');
198 tplFilename
.Replace(_T('/'), _T('\\'));
200 if (!PrefillMessage(tplFilename
, msg
))
205 BOOL
CCommitDlg::OnInitDialog()
207 CResizableStandAloneDialog::OnInitDialog();
208 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
210 if (!m_bForceCommitAmend
)
211 GetCommitTemplate(this->m_sLogMessage
);
214 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
215 bool loadedMsg
= !PrefillMessage(dotGitPath
+ _T("MERGE_MSG"), m_sLogMessage
);
216 loadedMsg
= loadedMsg
&& !PrefillMessage(dotGitPath
+ _T("SQUASH_MSG"), m_sLogMessage
);
218 if (CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive())
220 DialogEnableWindow(IDC_CHECK_NEWBRANCH
, FALSE
);
221 m_bCreateNewBranch
= FALSE
;
222 GetDlgItem(IDC_MERGEACTIVE
)->ShowWindow(SW_SHOW
);
225 m_regAddBeforeCommit
= CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE
);
226 m_bShowUnversioned
= m_regAddBeforeCommit
;
228 CString
regPath(g_Git
.m_CurrentDir
);
229 regPath
.Replace(_T(":"), _T("_"));
230 m_regShowWholeProject
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ShowWholeProject\\") + regPath
, FALSE
);
231 m_bWholeProject
= m_regShowWholeProject
;
233 m_History
.SetMaxHistoryItems((LONG
)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
235 m_regKeepChangelists
= CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE
);
236 m_bKeepChangeList
= m_regKeepChangelists
;
238 m_regDoNotAutoselectSubmodules
= CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE
);
239 m_bDoNotAutoselectSubmodules
= m_regDoNotAutoselectSubmodules
;
241 m_hAccel
= LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG
));
244 // m_bWholeProject = config.KeepLocks();
250 m_ListCtrl
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
, _T("CommitDlg"),(GITSLC_POPALL
^ (GITSLC_POPCOMMIT
| GITSLC_POPSAVEAS
)), true, true);
251 m_ListCtrl
.SetStatLabel(GetDlgItem(IDC_STATISTICS
));
252 m_ListCtrl
.SetCancelBool(&m_bCancelled
);
253 m_ListCtrl
.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT
);
254 m_ListCtrl
.EnableFileDrop();
255 m_ListCtrl
.SetBackgroundImage(IDI_COMMIT_BKG
);
257 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
258 m_ProjectProperties
.ReadProps();
260 m_cLogMessage
.Init(m_ProjectProperties
);
261 m_cLogMessage
.SetFont((CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
262 m_cLogMessage
.RegisterContextMenuHandler(this);
264 OnEnChangeLogmessage();
266 m_tooltips
.Create(this);
267 m_tooltips
.AddTool(IDC_EXTERNALWARNING
, IDS_COMMITDLG_EXTERNALS
);
268 m_tooltips
.AddTool(IDC_COMMIT_AMEND
,IDS_COMMIT_AMEND_TT
);
269 m_tooltips
.AddTool(IDC_MERGEACTIVE
, IDC_MERGEACTIVE_TT
);
270 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
272 CBugTraqAssociations bugtraq_associations
;
273 bugtraq_associations
.Load(m_ProjectProperties
.GetProviderUUID(), m_ProjectProperties
.sProviderParams
);
275 if (bugtraq_associations
.FindProvider(g_Git
.m_CurrentDir
, &m_bugtraq_association
))
277 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
278 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
280 CComPtr
<IBugTraqProvider
> pProvider
;
281 HRESULT hr
= pProvider
.CoCreateInstance(m_bugtraq_association
.GetProviderClass());
284 m_BugTraqProvider
= pProvider
;
286 if (SUCCEEDED(hr
= pProvider
->GetLinkText(GetSafeHwnd(), m_bugtraq_association
.GetParameters().AllocSysString(), &temp
)))
288 SetDlgItemText(IDC_BUGTRAQBUTTON
, temp
);
289 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(TRUE
);
290 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_SHOW
);
296 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
298 else if (!m_ProjectProperties
.sMessage
.IsEmpty())
300 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_SHOW
);
301 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_SHOW
);
302 if (!m_ProjectProperties
.sLabel
.IsEmpty())
303 SetDlgItemText(IDC_BUGIDLABEL
, m_ProjectProperties
.sLabel
);
304 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
305 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
306 GetDlgItem(IDC_BUGID
)->SetFocus();
307 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(m_sLogMessage
);
308 if (!sBugID
.IsEmpty())
310 SetDlgItemText(IDC_BUGID
, sBugID
);
315 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
316 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
317 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
318 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
319 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
322 if (!m_sLogMessage
.IsEmpty())
324 m_cLogMessage
.SetText(m_sLogMessage
);
325 m_cLogMessage
.Call(SCI_SETCURRENTPOS
, 0);
326 m_cLogMessage
.Call(SCI_SETSEL
, 0, 0);
329 GetWindowText(m_sWindowTitle
);
331 AdjustControlSize(IDC_SHOWUNVERSIONED
);
332 AdjustControlSize(IDC_WHOLE_PROJECT
);
333 AdjustControlSize(IDC_CHECK_NEWBRANCH
);
334 AdjustControlSize(IDC_COMMIT_AMEND
);
335 AdjustControlSize(IDC_COMMIT_MESSAGEONLY
);
336 AdjustControlSize(IDC_COMMIT_AMENDDIFF
);
337 AdjustControlSize(IDC_COMMIT_SETDATETIME
);
338 AdjustControlSize(IDC_COMMIT_SETAUTHOR
);
339 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES
);
340 AdjustControlSize(IDC_KEEPLISTS
);
342 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKALL
);
343 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKNONE
);
344 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKUNVERSIONED
);
345 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKVERSIONED
);
346 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKADDED
);
347 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKDELETED
);
348 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKMODIFIED
);
349 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKFILES
);
350 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKSUBMODULES
);
352 // line up all controls and adjust their sizes.
353 #define LINKSPACING 9
354 RECT rc
= AdjustControlSize(IDC_SELECTLABEL
);
355 rc
.right
-= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
356 rc
= AdjustStaticSize(IDC_CHECKALL
, rc
, LINKSPACING
);
357 rc
= AdjustStaticSize(IDC_CHECKNONE
, rc
, LINKSPACING
);
358 rc
= AdjustStaticSize(IDC_CHECKUNVERSIONED
, rc
, LINKSPACING
);
359 rc
= AdjustStaticSize(IDC_CHECKVERSIONED
, rc
, LINKSPACING
);
360 rc
= AdjustStaticSize(IDC_CHECKADDED
, rc
, LINKSPACING
);
361 rc
= AdjustStaticSize(IDC_CHECKDELETED
, rc
, LINKSPACING
);
362 rc
= AdjustStaticSize(IDC_CHECKMODIFIED
, rc
, LINKSPACING
);
363 rc
= AdjustStaticSize(IDC_CHECKFILES
, rc
, LINKSPACING
);
364 rc
= AdjustStaticSize(IDC_CHECKSUBMODULES
, rc
, LINKSPACING
);
366 GetClientRect(m_DlgOrigRect
);
367 m_cLogMessage
.GetClientRect(m_LogMsgOrigRect
);
369 AddAnchor(IDC_COMMITLABEL
, TOP_LEFT
, TOP_RIGHT
);
370 AddAnchor(IDC_BUGIDLABEL
, TOP_RIGHT
);
371 AddAnchor(IDC_BUGID
, TOP_RIGHT
);
372 AddAnchor(IDC_BUGTRAQBUTTON
, TOP_RIGHT
);
373 AddAnchor(IDC_COMMIT_TO
, TOP_LEFT
, TOP_RIGHT
);
374 AddAnchor(IDC_CHECK_NEWBRANCH
, TOP_RIGHT
);
375 AddAnchor(IDC_NEWBRANCH
, TOP_LEFT
, TOP_RIGHT
);
376 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
377 // AddAnchor(IDC_HISTORY, TOP_LEFT);
378 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
379 AddAnchor(IDC_SIGNOFF
, TOP_RIGHT
);
380 AddAnchor(IDC_VIEW_PATCH
, BOTTOM_RIGHT
);
381 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
382 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
383 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
384 AddAnchor(IDC_SHOWUNVERSIONED
, BOTTOM_LEFT
);
385 AddAnchor(IDC_EXTERNALWARNING
, BOTTOM_RIGHT
);
386 AddAnchor(IDC_STATISTICS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
387 AddAnchor(IDC_TEXT_INFO
, TOP_RIGHT
);
388 AddAnchor(IDC_WHOLE_PROJECT
, BOTTOM_LEFT
);
389 AddAnchor(IDC_KEEPLISTS
, BOTTOM_LEFT
);
390 AddAnchor(IDC_NOAUTOSELECTSUBMODULES
, BOTTOM_LEFT
);
391 AddAnchor(IDOK
, BOTTOM_RIGHT
);
392 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
393 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
394 AddAnchor(IDC_MERGEACTIVE
, BOTTOM_RIGHT
);
395 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
396 AddAnchor(IDC_COMMIT_MESSAGEONLY
, BOTTOM_LEFT
);
397 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
398 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
399 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
400 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
401 AddAnchor(IDC_COMMIT_SETAUTHOR
, TOP_LEFT
);
402 AddAnchor(IDC_COMMIT_AUTHORDATA
, TOP_LEFT
, TOP_RIGHT
);
404 AddAnchor(IDC_SELECTLABEL
, TOP_LEFT
);
405 AddAnchor(IDC_CHECKALL
, TOP_LEFT
);
406 AddAnchor(IDC_CHECKNONE
, TOP_LEFT
);
407 AddAnchor(IDC_CHECKUNVERSIONED
, TOP_LEFT
);
408 AddAnchor(IDC_CHECKVERSIONED
, TOP_LEFT
);
409 AddAnchor(IDC_CHECKADDED
, TOP_LEFT
);
410 AddAnchor(IDC_CHECKDELETED
, TOP_LEFT
);
411 AddAnchor(IDC_CHECKMODIFIED
, TOP_LEFT
);
412 AddAnchor(IDC_CHECKFILES
, TOP_LEFT
);
413 AddAnchor(IDC_CHECKSUBMODULES
, TOP_LEFT
);
416 CenterWindow(CWnd::FromHandle(hWndExplorer
));
417 EnableSaveRestore(_T("CommitDlg"));
418 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
419 RECT rcDlg
, rcLogMsg
, rcFileList
;
420 GetClientRect(&rcDlg
);
421 m_cLogMessage
.GetWindowRect(&rcLogMsg
);
422 ScreenToClient(&rcLogMsg
);
423 m_ListCtrl
.GetWindowRect(&rcFileList
);
424 ScreenToClient(&rcFileList
);
428 m_wndSplitter
.GetWindowRect(&rectSplitter
);
429 ScreenToClient(&rectSplitter
);
430 int delta
= yPos
- rectSplitter
.top
;
431 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
433 m_wndSplitter
.SetWindowPos(NULL
, rectSplitter
.left
, yPos
, 0, 0, SWP_NOSIZE
);
440 // add all directories to the watcher
442 for (int i=0; i<m_pathList.GetCount(); ++i)
444 if (m_pathList[i].IsDirectory())
445 m_pathwatcher.AddPath(m_pathList[i]);
448 m_updatedPathList
= m_pathList
;
450 //first start a thread to obtain the file list with the status without
451 //blocking the dialog
452 InterlockedExchange(&m_bBlock
, TRUE
);
453 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
456 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
457 InterlockedExchange(&m_bBlock
, FALSE
);
461 m_pThread
->m_bAutoDelete
= FALSE
;
462 m_pThread
->ResumeThread();
464 CRegDWORD err
= CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE
);
465 CRegDWORD historyhint
= CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE
);
466 if ((((DWORD
)err
)!=FALSE
)&&((((DWORD
)historyhint
)==FALSE
)))
469 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
473 this->m_ctrlShowPatch
.SetURL(CString());
475 if (g_Git
.GetConfigValueBool(_T("tgit.commitshowpatch")))
476 OnStnClickedViewPatch();
478 return FALSE
; // return TRUE unless you set the focus to a control
479 // EXCEPTION: OCX Property Pages should return FALSE
482 static bool UpdateIndex(CMassiveGitTask
&mgt
, CSysProgressDlg
&sysProgressDlg
, int progress
, int maxProgress
)
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
, 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
, 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 int nListItems
= m_ListCtrl
.GetItemCount();
576 bool needResetIndex
= false;
577 for (int i
= 0; i
< nListItems
&& !m_bCommitMessageOnly
; ++i
)
579 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
580 if (!entry
->m_Checked
&& !(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
581 needResetIndex
= true;
582 if (!entry
->m_Checked
|| !entry
->IsDirectory())
586 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
589 subgit
.m_CurrentDir
= g_Git
.m_CurrentDir
+ _T("\\") + entry
->GetWinPathString();
591 subgit
.Run(_T("git.exe status --porcelain"), &subcmdout
, CP_UTF8
);
592 dirty
= !subcmdout
.IsEmpty();
597 cmd
.Format(_T("git.exe diff -- \"%s\""), entry
->GetWinPathString());
598 g_Git
.Run(cmd
, &cmdout
, CP_UTF8
);
599 dirty
= cmdout
.Right(7) == _T("-dirty\n");
605 message
.Format(CString(MAKEINTRESOURCE(IDS_COMMITDLG_SUBMODULEDIRTY
)), entry
->GetGitPathString());
606 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
)));
610 cmdCommit
.Format(_T("/command:commit /path:\"%s\\%s\""), g_Git
.m_CurrentDir
, entry
->GetWinPathString());
611 CAppUtils::RunTortoiseGitProc(cmdCommit
);
614 else if (result
== 2)
621 if (!m_bCommitMessageOnly
)
622 m_ListCtrl
.WriteCheckedNamesToPathList(m_selectedPathList
);
623 m_pathwatcher
.Stop();
624 InterlockedExchange(&m_bBlock
, TRUE
);
625 CDWordArray arDeleted
;
626 //first add all the unversioned files the user selected
627 //and check if all versioned files are selected
631 CTGitPathList itemsToAdd
;
632 CTGitPathList itemsToRemove
;
633 CMassiveGitTask
mgtReAddAfterCommit(_T("add --ignore-errors -f"));
638 bool bAddSuccess
=true;
639 bool bCloseCommitDlg
=false;
641 CSysProgressDlg sysProgressDlg
;
642 if (nListItems
>= 25)
644 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT
)));
645 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX
)));
646 sysProgressDlg
.SetTime(true);
647 sysProgressDlg
.SetShowProgressBar(true);
648 sysProgressDlg
.ShowModal(this, true);
651 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
652 DWORD currentTicks
= GetTickCount();
654 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_COMMIT_UPDATE_INDEX
))
657 Do not use the libgit2 implementation right now, since it has several flaws:
658 * https://github.com/libgit2/libgit2/issues/1397: crlf issue
659 * http://code.google.com/p/tortoisegit/issues/detail?id=1690: possible access denied problem
660 * https://github.com/libgit2/libgit2/pull/1291: git.exe path is searched again and again
661 * changes to x-bit are not correctly committed
666 git_repository
*repository
= nullptr;
667 CStringA gitdir
= CUnicodeUtils::GetMulti(CTGitPath(g_Git
.m_CurrentDir
).GetGitPathString(), CP_UTF8
);
668 if (git_repository_open(&repository
, gitdir
.GetBuffer()))
670 gitdir
.ReleaseBuffer();
671 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
674 gitdir
.ReleaseBuffer();
677 CString revRef
= _T("HEAD");
678 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
679 revRef
= _T("HEAD~1");
680 if (g_Git
.GetHash(revHash
, revRef
))
682 git_repository_free(repository
);
683 MessageBox(g_Git
.GetLibGit2LastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR
);
687 git_commit
*commit
= nullptr;
688 if (!revHash
.IsEmpty() && needResetIndex
&& git_commit_lookup(&commit
, repository
, (const git_oid
*)revHash
.m_hash
))
690 git_repository_free(repository
);
691 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not get last commit.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
695 git_tree
*tree
= nullptr;
696 if (!revHash
.IsEmpty() && needResetIndex
&& git_commit_tree(&tree
, commit
))
698 git_commit_free(commit
);
699 git_repository_free(repository
);
700 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not read tree of commit.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
704 git_index
*index
= nullptr;
705 if (git_repository_index(&index
, repository
))
709 if (commit
!= nullptr)
710 git_commit_free(commit
);
711 git_repository_free(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 git_index_free(index
);
721 git_commit_free(commit
);
722 git_repository_free(repository
);
723 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not read the tree into the index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
726 else if (!revHash
.IsEmpty() && !needResetIndex
)
728 git_index_read(index
, true);
733 for (int j
= 0; j
< nListItems
; ++j
)
735 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
737 if (sysProgressDlg
.IsVisible())
739 if (GetTickCount() - currentTicks
> 1000 || j
== nListItems
- 1 || j
== 0)
741 sysProgressDlg
.SetLine(2, entry
->GetGitPathString(), true);
742 sysProgressDlg
.SetProgress(j
, nListItems
);
743 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too often: this takes time!
744 currentTicks
= GetTickCount();
748 CStringA filePathA
= CUnicodeUtils::GetMulti(entry
->GetGitPathString(), CP_UTF8
);
750 if (entry
->m_Checked
&& !m_bCommitMessageOnly
)
752 if (entry
->IsDirectory())
754 git_submodule
*submodule
= nullptr;
755 if (git_submodule_lookup(&submodule
, repository
, filePathA
.GetBuffer()))
757 filePathA
.ReleaseBuffer();
759 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open submodule \"") + entry
->GetGitPathString() + _T("\".")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
762 filePathA
.ReleaseBuffer();
763 if (git_submodule_add_to_index(submodule
, FALSE
))
766 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not add submodule \"") + entry
->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
770 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
772 git_index_remove_bypath(index
, filePathA
.GetBuffer()); // ignore error
773 filePathA
.ReleaseBuffer();
777 if (git_index_add_bypath(index
, filePathA
.GetBuffer()))
779 filePathA
.ReleaseBuffer();
781 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not add \"") + entry
->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
784 filePathA
.ReleaseBuffer();
787 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
789 git_index_remove_bypath(index
, filePathA
.GetBuffer()); // ignore error
790 filePathA
.ReleaseBuffer();
795 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
796 mgtReAddAfterCommit
.AddFile(*entry
);
798 if (sysProgressDlg
.HasUserCancelled())
804 CShellUpdater::Instance().AddPathForUpdate(*entry
);
806 if (bAddSuccess
&& git_index_write(index
))
809 git_index_free(index
);
812 if (commit
!= nullptr)
813 git_commit_free(commit
);
814 git_repository_free(repository
);
819 // ***************************************************
820 // ATTENTION: Similar code in RebaseDlg.cpp!!!
821 // ***************************************************
822 CMassiveGitTask
mgtAdd(_T("add -f"));
823 CMassiveGitTask
mgtUpdateIndexForceRemove(_T("update-index --force-remove"));
824 CMassiveGitTask
mgtUpdateIndex(_T("update-index"));
825 CMassiveGitTask
mgtRm(_T("rm --ignore-unmatch"));
826 CMassiveGitTask
mgtRmFCache(_T("rm -f --cache"));
827 CString resetCmd
= _T("reset");
828 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
829 resetCmd
+= _T(" HEAD~1");;
830 CMassiveGitTask
mgtReset(resetCmd
, TRUE
, true);
831 for (int j
= 0; j
< nListItems
; ++j
)
833 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
835 if (entry
->m_Checked
&& !m_bCommitMessageOnly
)
837 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
838 mgtAdd
.AddFile(entry
->GetGitPathString());
839 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
840 mgtUpdateIndexForceRemove
.AddFile(entry
->GetGitPathString());
842 mgtUpdateIndex
.AddFile(entry
->GetGitPathString());
844 if ((entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
) && !entry
->GetGitOldPathString().IsEmpty())
845 mgtRm
.AddFile(entry
->GetGitOldPathString());
851 if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
852 { //To init git repository, there are not HEAD, so we can use git reset command
853 mgtRmFCache
.AddFile(entry
->GetGitPathString());
854 mgtReAddAfterCommit
.AddFile(*entry
);
856 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
&& !entry
->GetGitOldPathString().IsEmpty())
857 mgtReset
.AddFile(entry
->GetGitOldPathString());
859 else if (!(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
860 mgtReset
.AddFile(entry
->GetGitPathString());
863 if (sysProgressDlg
.HasUserCancelled())
870 CMassiveGitTask tasks
[] = { mgtAdd
, mgtUpdateIndexForceRemove
, mgtUpdateIndex
, mgtRm
, mgtRmFCache
, mgtReset
};
871 int progress
= 0, maxProgress
= 0;
872 for (int j
= 0; j
< _countof(tasks
); ++j
)
873 maxProgress
+= tasks
[j
].GetListCount();
874 for (int j
= 0; j
< _countof(tasks
); ++j
)
875 bAddSuccess
= bAddSuccess
&& UpdateIndex(tasks
[j
], sysProgressDlg
, progress
+= tasks
[j
].GetListCount(), maxProgress
);
877 if (sysProgressDlg
.HasUserCancelled())
880 for (int j
= 0; bAddSuccess
&& j
< nListItems
; ++j
)
881 CShellUpdater::Instance().AddPathForUpdate(*(CTGitPath
*)m_ListCtrl
.GetItemData(j
));
884 if (sysProgressDlg
.HasUserCancelled())
887 //sysProgressDlg.Stop();
889 if (bAddSuccess
&& m_bCreateNewBranch
)
891 if (g_Git
.Run(_T("git.exe branch ") + m_sCreateNewBranch
, &out
, CP_UTF8
))
893 MessageBox(_T("Creating new branch failed:\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
896 if (g_Git
.Run(_T("git.exe checkout ") + m_sCreateNewBranch
+ _T(" --"), &out
, CP_UTF8
))
898 MessageBox(_T("Switching to new branch failed:\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
903 if (bAddSuccess
&& CheckHeadDetach())
907 CString sExistingBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
908 sExistingBugID
.Trim();
909 if (!m_sBugID
.IsEmpty() && m_sBugID
.Compare(sExistingBugID
))
911 m_sBugID
.Replace(_T(", "), _T(","));
912 m_sBugID
.Replace(_T(" ,"), _T(","));
913 CString sBugID
= m_ProjectProperties
.sMessage
;
914 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
915 if (m_ProjectProperties
.bAppend
)
916 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
918 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
921 // now let the bugtraq plugin check the commit message
922 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
923 if (m_BugTraqProvider
)
925 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
929 CString common
= g_Git
.m_CurrentDir
;
930 BSTR repositoryRoot
= common
.AllocSysString();
931 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
932 BSTR commonRoot
= SysAllocString(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
933 BSTR commitMessage
= m_sLogMessage
.AllocSysString();
934 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_selectedPathList
.GetCount());
936 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
937 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
939 if (FAILED(hr
= pProvider2
->CheckCommit(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, commitMessage
, &temp
)))
943 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), ce
.GetMessageAndDescription().c_str());
944 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
948 CString sError
= temp
;
949 if (!sError
.IsEmpty())
951 CMessageBox::Show(m_hWnd
, sError
, _T("TortoiseGit"), MB_ICONERROR
);
959 if (m_bCommitMessageOnly
|| bAddSuccess
&& (nchecked
|| m_bCommitAmend
|| CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive()))
961 bCloseCommitDlg
= true;
963 CString tempfile
=::GetTempFile();
965 CAppUtils::SaveCommitUnicodeFile(tempfile
,m_sLogMessage
);
967 CTGitPath path
=g_Git
.m_CurrentDir
;
969 BOOL IsGitSVN
= path
.GetAdminDirMask() & ITEMIS_GITSVN
;
973 if(this->m_bCommitAmend
)
978 if (m_bSetCommitDateTime
)
981 m_CommitDate
.GetTime(date
);
982 m_CommitTime
.GetTime(time
);
983 dateTime
.Format(_T("--date=%sT%s"), date
.Format(_T("%Y-%m-%d")), time
.Format(_T("%H:%M:%S")));
987 author
.Format(_T("--author=\"%s\""), m_sAuthor
);
988 CString allowEmpty
= m_bCommitMessageOnly
? _T("--allow-empty") : _T("");
989 cmd
.Format(_T("git.exe commit %s %s %s %s -F \"%s\""), author
, dateTime
, amend
, allowEmpty
, tempfile
);
991 CCommitProgressDlg progress
;
992 progress
.m_bBufferAll
=true; // improve show speed when there are many file added.
993 progress
.m_GitCmd
=cmd
;
994 progress
.m_bShowCommand
= FALSE
; // don't show the commit command
995 progress
.m_PreText
= out
; // show any output already generated in log window
998 int indexReCommit
= -1;
1001 if (!m_bNoPostActions
&& !m_bAutoClose
)
1004 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUSVNDCOMMIT
)));
1005 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
1006 indexPull
= (int)progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPULL
)));
1007 indexReCommit
= (int)progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_RECOMMIT
)));
1008 indexTag
= (int)progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUTAG
)));
1011 INT_PTR userResponse
= progress
.DoModal();
1013 m_PostCmd
= GIT_POSTCOMMIT_CMD_NOTHING
;
1014 if(progress
.m_GitStatus
|| userResponse
== (IDC_PROGRESS_BUTTON1
+ indexReCommit
))
1016 bCloseCommitDlg
= false;
1017 if (userResponse
== IDC_PROGRESS_BUTTON1
+ indexReCommit
)
1019 this->m_sLogMessage
.Empty();
1020 m_cLogMessage
.SetText(m_sLogMessage
);
1021 if (m_bCreateNewBranch
)
1023 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_SHOW
);
1024 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_HIDE
);
1026 m_bCreateNewBranch
= FALSE
;
1029 m_bCommitAmend
= FALSE
;
1032 this->BringWindowToTop();
1034 else if (userResponse
== IDC_PROGRESS_BUTTON1
+ indexTag
)
1035 m_PostCmd
= GIT_POSTCOMMIT_CMD_CREATETAG
;
1036 else if (userResponse
== IDC_PROGRESS_BUTTON1
+ indexPull
)
1037 m_PostCmd
= GIT_POSTCOMMIT_CMD_PULL
;
1038 else if (userResponse
>= IDC_PROGRESS_BUTTON1
&& userResponse
< IDC_PROGRESS_BUTTON1
+ indexPull
)
1040 // User pressed 'DCommit' or 'Push' button after successful commit.
1041 if (userResponse
== IDC_PROGRESS_BUTTON1
&& IsGitSVN
)
1042 m_PostCmd
= GIT_POSTCOMMIT_CMD_DCOMMIT
;
1044 m_PostCmd
= GIT_POSTCOMMIT_CMD_PUSH
;
1047 ::DeleteFile(tempfile
);
1049 if (m_BugTraqProvider
&& progress
.m_GitStatus
== 0)
1051 CComPtr
<IBugTraqProvider2
> pProvider
= NULL
;
1052 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
1055 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
1056 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0,this->m_selectedPathList
.GetCount());
1058 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
1059 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
1061 BSTR logMessage
= m_sLogMessage
.AllocSysString();
1064 if (g_Git
.GetHash(hash
, _T("HEAD")))
1065 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR
);
1066 LONG version
= g_Git
.Hash2int(hash
);
1069 if (FAILED(hr
= pProvider
->OnCommitFinished(GetSafeHwnd(),
1076 CString sErr
= temp
;
1077 if (!sErr
.IsEmpty())
1078 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1082 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, ce
.GetSource().c_str(), ce
.GetMessageAndDescription().c_str());
1083 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1087 SysFreeString(temp
);
1090 RestoreFiles(progress
.m_GitStatus
== 0);
1091 if (((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit"), TRUE
)) == TRUE
)
1093 BOOL cancel
= FALSE
;
1094 mgtReAddAfterCommit
.Execute(cancel
);
1097 else if(bAddSuccess
)
1099 CMessageBox::Show(this->m_hWnd
, IDS_ERROR_NOTHING_COMMIT
, IDS_COMMIT_FINISH
, MB_OK
| MB_ICONINFORMATION
);
1100 bCloseCommitDlg
=false;
1104 m_regAddBeforeCommit
= m_bShowUnversioned
;
1105 m_regKeepChangelists
= m_bKeepChangeList
;
1106 m_regDoNotAutoselectSubmodules
= m_bDoNotAutoselectSubmodules
;
1107 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
1108 m_bKeepChangeList
= FALSE
;
1109 InterlockedExchange(&m_bBlock
, FALSE
);
1111 if (!m_sLogMessage
.IsEmpty())
1113 m_History
.AddEntry(m_sLogMessage
);
1119 if( bCloseCommitDlg
)
1120 CResizableStandAloneDialog::OnOK();
1122 CShellUpdater::Instance().Flush();
1125 void CCommitDlg::SaveSplitterPos()
1129 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
1131 m_wndSplitter
.GetWindowRect(&rectSplitter
);
1132 ScreenToClient(&rectSplitter
);
1133 regPos
= rectSplitter
.top
;
1137 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
1139 return ((CCommitDlg
*)pVoid
)->StatusThread();
1142 UINT
CCommitDlg::StatusThread()
1144 //get the status of all selected file/folders recursively
1145 //and show the ones which have to be committed to the user
1146 //in a list control.
1147 InterlockedExchange(&m_bBlock
, TRUE
);
1148 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
1149 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
1151 m_pathwatcher
.Stop();
1153 m_ListCtrl
.SetBusy(true);
1154 g_Git
.RefreshGitIndex();
1156 m_bCancelled
= false;
1158 DialogEnableWindow(IDOK
, false);
1159 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
1160 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
1161 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, false);
1162 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
1163 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
1164 DialogEnableWindow(IDC_COMMIT_AMEND
, FALSE
);
1165 DialogEnableWindow(IDC_COMMIT_AMENDDIFF
, FALSE
);
1166 // read the list of recent log entries before querying the WC for status
1167 // -> the user may select one and modify / update it while we are crawling the WC
1169 DialogEnableWindow(IDC_CHECKALL
, false);
1170 DialogEnableWindow(IDC_CHECKNONE
, false);
1171 DialogEnableWindow(IDC_CHECKUNVERSIONED
, false);
1172 DialogEnableWindow(IDC_CHECKVERSIONED
, false);
1173 DialogEnableWindow(IDC_CHECKADDED
, false);
1174 DialogEnableWindow(IDC_CHECKDELETED
, false);
1175 DialogEnableWindow(IDC_CHECKMODIFIED
, false);
1176 DialogEnableWindow(IDC_CHECKFILES
, false);
1177 DialogEnableWindow(IDC_CHECKSUBMODULES
, false);
1179 if (m_History
.IsEmpty())
1182 reg
.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR
)m_ListCtrl
.m_sUUID
);
1183 reg
.Replace(_T(':'),_T('_'));
1184 m_History
.Load(reg
, _T("logmsgs"));
1187 // Initialise the list control with the status of the files/folders below us
1190 CTGitPathList
*pList
;
1191 m_ListCtrl
.m_amend
= (m_bCommitAmend
==TRUE
|| m_bForceCommitAmend
) && (m_bAmendDiffToLastCommit
==FALSE
);
1192 m_ListCtrl
.m_bDoNotAutoselectSubmodules
= (m_bDoNotAutoselectSubmodules
== TRUE
);
1197 pList
= &m_pathList
;
1199 success
=m_ListCtrl
.GetStatus(pList
);
1201 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1202 if(this->m_bShowUnversioned
)
1203 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
1205 m_ListCtrl
.CheckIfChangelistsArePresent(false);
1207 DWORD dwShow
= GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWLOCKS
| GITSLC_SHOWINCHANGELIST
| GITSLC_SHOWDIRECTFILES
;
1208 dwShow
|= DWORD(m_regAddBeforeCommit
) ? GITSLC_SHOWUNVERSIONED
: 0;
1211 if (!m_checkedPathList
.IsEmpty())
1212 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
1215 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
1216 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
1217 m_ListCtrl
.Show(dwShow
, dwCheck
);
1218 m_bSelectFilesForCommit
= true;
1221 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
1223 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
1224 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
1227 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
1228 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
1232 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
1233 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
1234 m_ListCtrl
.Show(dwShow
);
1238 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
1239 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
1240 && !PathFileExists(dotGitPath
+ _T("MERGE_HEAD")))
1243 temp
.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
);
1244 if (CMessageBox::ShowCheck(m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONINFORMATION
| MB_YESNO
, _T("NothingToCommitShowUnversioned"), NULL
)==IDYES
)
1246 m_bShowUnversioned
= TRUE
;
1247 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
1248 DWORD dwShow
= (DWORD
)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWUNVERSIONED
| GITSLC_SHOWLOCKS
);
1249 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
1250 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
1257 // we don't have to block the commit dialog while we fetch the
1258 // auto completion list.
1259 m_pathwatcher
.ClearChangedPaths();
1260 InterlockedExchange(&m_bBlock
, FALSE
);
1261 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE
)==TRUE
)
1263 m_ListCtrl
.Block(TRUE
, TRUE
);
1264 GetAutocompletionList();
1265 m_ListCtrl
.Block(FALSE
, FALSE
);
1267 SendMessage(WM_UPDATEOKBUTTON
);
1270 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
1271 DialogEnableWindow(IDC_WHOLE_PROJECT
, !(m_pathList
.IsEmpty() || (m_pathList
.GetCount() == 1 && m_pathList
[0].IsEmpty())));
1272 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, true);
1273 if (m_ListCtrl
.HasChangeLists())
1274 DialogEnableWindow(IDC_KEEPLISTS
, true);
1276 // activate amend checkbox (if necessary)
1277 if (g_Git
.IsInitRepos())
1279 m_bCommitAmend
= FALSE
;
1280 SendMessage(WM_UPDATEDATAFALSE
);
1284 if (m_bForceCommitAmend
)
1286 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
1287 m_bCommitAmend
= TRUE
;
1288 SendMessage(WM_UPDATEDATAFALSE
);
1291 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(TRUE
);
1294 if (g_Git
.GetHash(hash
, _T("HEAD")))
1296 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
1298 if (!hash
.IsEmpty())
1300 GitRev headRevision
;
1303 headRevision
.GetParentFromHash(hash
);
1308 MessageBox(_T("Could not get parent from HEAD.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
1310 // do not allow to show diff to "last" revision if it has more that one parent
1311 if (headRevision
.ParentsCount() != 1)
1313 m_bAmendDiffToLastCommit
= TRUE
;
1314 SendMessage(WM_UPDATEDATAFALSE
);
1317 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->EnableWindow(TRUE
);
1323 // we have the list, now signal the main thread about it
1324 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
1327 InterlockedExchange(&m_bRunThread
, FALSE
);
1328 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1329 // force the cursor to normal
1335 void CCommitDlg::SetDlgTitle()
1337 if (m_sTitle
.IsEmpty())
1338 GetWindowText(m_sTitle
);
1340 if (m_bWholeProject
)
1341 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
1344 if (m_pathList
.GetCount() == 1)
1345 CAppUtils::SetWindowTitle(m_hWnd
, (g_Git
.m_CurrentDir
+ _T("\\") + m_pathList
[0].GetUIPathString()).TrimRight('\\'), m_sTitle
);
1347 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
+ _T("\\") + m_ListCtrl
.GetCommonDirectory(false), m_sTitle
);
1351 void CCommitDlg::OnCancel()
1353 m_bCancelled
= true;
1354 m_pathwatcher
.Stop();
1356 if (m_bThreadRunning
)
1358 InterlockedExchange(&m_bRunThread
, FALSE
);
1359 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
1360 if (m_bThreadRunning
)
1362 // we gave the thread a chance to quit. Since the thread didn't
1363 // listen to us we have to kill it.
1364 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1365 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1370 m_sLogMessage
= m_cLogMessage
.GetText();
1371 if (!m_sBugID
.IsEmpty())
1373 m_sBugID
.Replace(_T(", "), _T(","));
1374 m_sBugID
.Replace(_T(" ,"), _T(","));
1375 CString sBugID
= m_ProjectProperties
.sMessage
;
1376 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
1377 if (m_ProjectProperties
.bAppend
)
1378 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
1380 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
1382 if ((m_ProjectProperties
.sLogTemplate
.Compare(m_sLogMessage
) != 0) && !m_sLogMessage
.IsEmpty())
1384 m_History
.AddEntry(m_sLogMessage
);
1389 CResizableStandAloneDialog::OnCancel();
1392 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1395 m_tooltips
.RelayEvent(pMsg
);
1399 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1404 if (pMsg
->message
== WM_KEYDOWN
)
1406 switch (pMsg
->wParam
)
1411 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1417 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1419 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1421 PostMessage(WM_COMMAND
, IDOK
);
1425 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1427 // Pressing RETURN in the bug id control
1428 // moves the focus to the message
1429 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1437 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1440 void CCommitDlg::Refresh()
1442 if (m_bThreadRunning
)
1445 InterlockedExchange(&m_bBlock
, TRUE
);
1446 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1447 if (m_pThread
==NULL
)
1449 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1450 InterlockedExchange(&m_bBlock
, FALSE
);
1454 m_pThread
->m_bAutoDelete
= FALSE
;
1455 m_pThread
->ResumeThread();
1459 void CCommitDlg::OnBnClickedShowunversioned()
1461 m_tooltips
.Pop(); // hide the tooltips
1463 m_regAddBeforeCommit
= m_bShowUnversioned
;
1466 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1467 if (DWORD(m_regAddBeforeCommit
))
1468 dwShow
|= GITSLC_SHOWUNVERSIONED
;
1470 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
1471 if(dwShow
& GITSLC_SHOWUNVERSIONED
)
1474 m_ListCtrl
.GetStatus(NULL
,false,false,true);
1476 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1478 m_ListCtrl
.Show(dwShow
, 0, true, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
1483 void CCommitDlg::OnStnClickedExternalwarning()
1488 void CCommitDlg::OnEnChangeLogmessage()
1490 SendMessage(WM_UPDATEOKBUTTON
);
1493 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1496 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1498 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1500 m_bShowUnversioned
= TRUE
;
1501 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1502 m_ListCtrl
.Show(dwShow
);
1510 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1516 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM
/*lParam*/)
1520 SetForegroundWindow();
1522 // if multiple files/folders are dropped
1523 // this handler is called for every single item
1525 // To avoid creating multiple refresh threads and
1526 // causing crashes, we only add the items to the
1527 // list control and start a timer.
1528 // When the timer expires, we start the refresh thread,
1529 // but only if it isn't already running - otherwise we
1530 // restart the timer.
1532 path
.SetFromWin((LPCTSTR
)lParam
);
1534 // just add all the items we get here.
1535 // if the item is versioned, the add will fail but nothing
1536 // more will happen.
1538 Git
.Add(CTGitPathList(path
), &m_ProjectProperties
, Git_depth_empty
, false, true, true);
1540 if (!m_ListCtrl
.HasPath(path
))
1542 if (m_pathList
.AreAllPathsFiles())
1544 m_pathList
.AddPath(path
);
1545 m_pathList
.RemoveDuplicates();
1546 m_updatedPathList
.AddPath(path
);
1547 m_updatedPathList
.RemoveDuplicates();
1551 // if the path list contains folders, we have to check whether
1552 // our just (maybe) added path is a child of one of those. If it is
1553 // a child of a folder already in the list, we must not add it. Otherwise
1554 // that path could show up twice in the list.
1555 bool bHasParentInList
= false;
1556 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1558 if (m_pathList
[i
].IsAncestorOf(path
))
1560 bHasParentInList
= true;
1564 if (!bHasParentInList
)
1566 m_pathList
.AddPath(path
);
1567 m_pathList
.RemoveDuplicates();
1568 m_updatedPathList
.AddPath(path
);
1569 m_updatedPathList
.RemoveDuplicates();
1574 // Always start the timer, since the status of an existing item might have changed
1575 SetTimer(REFRESHTIMER
, 200, NULL
);
1576 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": Item %s dropped, timer started\n"), path
.GetWinPath());
1581 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1583 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1587 //////////////////////////////////////////////////////////////////////////
1588 // functions which run in the status thread
1589 //////////////////////////////////////////////////////////////////////////
1591 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1596 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1597 while (m_bRunThread
&& file
.ReadString(strLine
))
1599 int eqpos
= strLine
.Find('=');
1601 rgx
= strLine
.Mid(eqpos
+1).Trim();
1604 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1606 mapRegex
[strLine
.Left(pos
)] = rgx
;
1607 strLine
= strLine
.Mid(pos
+1).Trim();
1609 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1613 catch (CFileException
* pE
)
1615 CTraceToOutputDebugString::Instance()(__FUNCTION__
": CFileException loading auto list regex file\n");
1620 void CCommitDlg::GetAutocompletionList()
1622 // the auto completion list is made of strings from each selected files.
1623 // the strings used are extracted from the files with regexes found
1624 // in the file "autolist.txt".
1625 // the format of that file is:
1626 // file extensions separated with commas '=' regular expression to use
1628 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1629 // .cpp = (?<=[^\s]::)\b\w+\b
1631 std::map
<CString
, CString
> mapRegex
;
1632 CString sRegexFile
= CPathUtils::GetAppDirectory();
1633 CRegDWORD regtimeout
= CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1634 DWORD timeoutvalue
= regtimeout
*1000;
1635 sRegexFile
+= _T("autolist.txt");
1638 ParseRegexFile(sRegexFile
, mapRegex
);
1639 SHGetFolderPath(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, sRegexFile
.GetBuffer(MAX_PATH
+1));
1640 sRegexFile
.ReleaseBuffer();
1641 sRegexFile
+= _T("\\TortoiseGit\\autolist.txt");
1642 if (PathFileExists(sRegexFile
))
1644 ParseRegexFile(sRegexFile
, mapRegex
);
1646 DWORD starttime
= GetTickCount();
1648 // now we have two arrays of strings, where the first array contains all
1649 // file extensions we can use and the second the corresponding regex strings
1650 // to apply to those files.
1652 // the next step is to go over all files shown in the commit dialog
1653 // and scan them for strings we can use
1654 int nListItems
= m_ListCtrl
.GetItemCount();
1656 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1658 // stop parsing after timeout
1659 if ((!m_bRunThread
) || (GetTickCount() - starttime
> timeoutvalue
))
1662 CTGitPath
*path
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1667 CString sPartPath
=path
->GetGitPathString();
1668 m_autolist
.insert(sPartPath
);
1672 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1676 m_autolist
.insert(sPartPath
.Mid(pos
));
1679 // Last inserted entry is a file name.
1680 // Some users prefer to also list file name without extension.
1681 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE
))
1683 int dotPos
= sPartPath
.ReverseFind('.');
1684 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1685 m_autolist
.insert(sPartPath
.Mid(lastPos
, dotPos
- lastPos
));
1688 if (path
->m_Action
== CTGitPath::LOGACTIONS_UNVER
&& !CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseUnversioned"), FALSE
))
1690 if (path
->m_Action
== CTGitPath::LOGACTIONS_IGNORE
|| path
->m_Action
== CTGitPath::LOGACTIONS_DELETED
)
1693 CString sExt
= path
->GetFileExtension();
1695 // find the regex string which corresponds to the file extension
1696 CString rdata
= mapRegex
[sExt
];
1697 if (rdata
.IsEmpty())
1700 ScanFile(path
->GetWinPathString(), rdata
, sExt
);
1702 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": Auto completion list loaded in %d msec\n"), GetTickCount() - starttime
);
1705 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
, const CString
& sExt
)
1707 static std::map
<CString
, std::tr1::wregex
> regexmap
;
1709 std::wstring sFileContent
;
1710 CAutoFile hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
1713 DWORD size
= GetFileSize(hFile
, NULL
);
1714 if (size
> CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseMaxSize"), 300000L))
1716 // no files bigger than 300k
1719 // allocate memory to hold file contents
1720 std::unique_ptr
<char[]> buffer(new char[size
]);
1722 if (!ReadFile(hFile
, buffer
.get(), size
, &readbytes
, NULL
))
1725 IsTextUnicode(buffer
.get(), readbytes
, &opts
);
1726 if (opts
& IS_TEXT_UNICODE_NULL_BYTES
)
1730 if (opts
& IS_TEXT_UNICODE_UNICODE_MASK
)
1732 sFileContent
= std::wstring((wchar_t*)buffer
.get(), readbytes
/ sizeof(WCHAR
));
1734 if ((opts
& IS_TEXT_UNICODE_NOT_UNICODE_MASK
) || (opts
== 0))
1736 const int ret
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
.get(), readbytes
, NULL
, 0);
1737 std::unique_ptr
<wchar_t[]> pWideBuf(new wchar_t[ret
]);
1738 const int ret2
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
.get(), readbytes
, pWideBuf
.get(), ret
);
1740 sFileContent
= std::wstring(pWideBuf
.get(), ret
);
1743 if (sFileContent
.empty() || !m_bRunThread
)
1751 std::tr1::wregex regCheck
;
1752 std::map
<CString
, std::tr1::wregex
>::const_iterator regIt
;
1753 if ((regIt
= regexmap
.find(sExt
)) != regexmap
.end())
1754 regCheck
= regIt
->second
;
1757 regCheck
= std::tr1::wregex(sRegex
, std::tr1::regex_constants::icase
| std::tr1::regex_constants::ECMAScript
);
1758 regexmap
[sExt
] = regCheck
;
1760 const std::tr1::wsregex_iterator end
;
1761 for (std::tr1::wsregex_iterator
it(sFileContent
.begin(), sFileContent
.end(), regCheck
); it
!= end
; ++it
)
1763 const std::tr1::wsmatch match
= *it
;
1764 for (size_t i
= 1; i
< match
.size(); ++i
)
1766 if (match
[i
].second
-match
[i
].first
)
1768 m_autolist
.insert(std::wstring(match
[i
]).c_str());
1773 catch (std::exception
) {}
1776 // CSciEditContextMenuInterface
1777 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1779 CString sMenuItemText
;
1780 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITHASH
);
1781 m_nPopupPickCommitHash
= nCmd
++;
1782 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPickCommitHash
, sMenuItemText
);
1784 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITMESSAGE
);
1785 m_nPopupPickCommitMessage
= nCmd
++;
1786 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPickCommitMessage
, sMenuItemText
);
1788 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTEFILELIST
);
1789 m_nPopupPasteListCmd
= nCmd
++;
1790 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
1792 if (!m_History
.IsEmpty())
1794 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
1795 m_nPopupPasteLastMessage
= nCmd
++;
1796 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
1798 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
1799 m_nPopupRecentMessage
= nCmd
++;
1800 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
1804 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
1806 if (cmd
== m_nPopupPickCommitHash
)
1808 // use the git log to allow selection of a version
1810 // tell the dialog to use mode for selecting revisions
1811 dlg
.SetSelect(true);
1812 // only one revision must be selected however
1813 dlg
.SingleSelection(true);
1814 if (dlg
.DoModal() == IDOK
)
1816 // get selected hash if any
1817 CString selectedHash
= dlg
.GetSelectedHash();
1818 pSciEdit
->InsertText(selectedHash
);
1823 if (cmd
== m_nPopupPickCommitMessage
)
1825 // use the git log to allow selection of a version
1827 // tell the dialog to use mode for selecting revisions
1828 dlg
.SetSelect(true);
1829 // only one revision must be selected however
1830 dlg
.SingleSelection(true);
1831 if (dlg
.DoModal() == IDOK
)
1833 // get selected hash if any
1834 CString selectedHash
= dlg
.GetSelectedHash();
1836 rev
.GetCommit(selectedHash
);
1837 CString message
= rev
.GetSubject() + _T("\r\n") + rev
.GetBody();
1838 pSciEdit
->InsertText(message
);
1843 if (cmd
== m_nPopupPasteListCmd
)
1846 int nListItems
= m_ListCtrl
.GetItemCount();
1847 for (int i
=0; i
<nListItems
; ++i
)
1849 CTGitPath
* entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1850 if (entry
&&entry
->m_Checked
)
1853 CString status
= entry
->GetActionName();
1854 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1855 status
= _T("Add"); // I18N TODO
1857 //git_wc_status_kind status = entry->status;
1858 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1859 if (m_ProjectProperties
.bFileListInEnglish
)
1862 line
.Format(_T("%-10s %s\r\n"),status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
,0));
1866 pSciEdit
->InsertText(logmsg
);
1870 if(cmd
== m_nPopupPasteLastMessage
)
1872 if (m_History
.IsEmpty())
1876 logmsg
+=m_History
.GetEntry(0);
1877 pSciEdit
->InsertText(logmsg
);
1881 if(cmd
== m_nPopupRecentMessage
)
1883 OnBnClickedHistory();
1889 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
1893 case ENDDIALOGTIMER
:
1894 KillTimer(ENDDIALOGTIMER
);
1898 if (m_bThreadRunning
)
1900 SetTimer(REFRESHTIMER
, 200, NULL
);
1901 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Wait some more before refreshing\n");
1905 KillTimer(REFRESHTIMER
);
1906 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Refreshing after items dropped\n");
1910 case FILLPATCHVTIMER
:
1914 __super::OnTimer(nIDEvent
);
1917 void CCommitDlg::OnBnClickedHistory()
1919 m_tooltips
.Pop(); // hide the tooltips
1920 if (m_pathList
.IsEmpty())
1923 CHistoryDlg historyDlg
;
1924 historyDlg
.SetHistory(m_History
);
1925 if (historyDlg
.DoModal() != IDOK
)
1928 CString sMsg
= historyDlg
.GetSelectedText();
1929 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
1931 CString sBugID
= m_ProjectProperties
.FindBugID(sMsg
);
1932 if ((!sBugID
.IsEmpty()) && ((GetDlgItem(IDC_BUGID
)->IsWindowVisible())))
1934 SetDlgItemText(IDC_BUGID
, sBugID
);
1936 if (m_ProjectProperties
.sLogTemplate
.Compare(m_cLogMessage
.GetText())!=0)
1937 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
1939 m_cLogMessage
.SetText(sMsg
);
1942 SendMessage(WM_UPDATEOKBUTTON
);
1943 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1947 void CCommitDlg::OnBnClickedBugtraqbutton()
1949 m_tooltips
.Pop(); // hide the tooltips
1950 CString sMsg
= m_cLogMessage
.GetText();
1952 if (m_BugTraqProvider
== NULL
)
1955 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
1956 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
1957 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_pathList
.GetCount());
1959 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
1960 SafeArrayPutElement(pathList
, &index
, m_pathList
[index
].GetGitPathString().AllocSysString());
1962 BSTR originalMessage
= sMsg
.AllocSysString();
1964 // m_revProps.clear();
1966 // first try the IBugTraqProvider2 interface
1967 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
1968 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
1969 bool bugIdOutSet
= false;
1972 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1973 BSTR repositoryRoot
= g_Git
.m_CurrentDir
.AllocSysString();
1974 BSTR bugIDOut
= NULL
;
1975 GetDlgItemText(IDC_BUGID
, m_sBugID
);
1976 BSTR bugID
= m_sBugID
.AllocSysString();
1977 SAFEARRAY
* revPropNames
= NULL
;
1978 SAFEARRAY
* revPropValues
= NULL
;
1979 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
1982 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1983 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1990 m_sBugID
= bugIDOut
;
1991 SysFreeString(bugIDOut
);
1992 SetDlgItemText(IDC_BUGID
, m_sBugID
);
1994 SysFreeString(bugID
);
1995 SysFreeString(repositoryRoot
);
1996 m_cLogMessage
.SetText(temp
);
1997 BSTR HUGEP
*pbRevNames
;
1998 BSTR HUGEP
*pbRevValues
;
2000 HRESULT hr1
= SafeArrayAccessData(revPropNames
, (void HUGEP
**)&pbRevNames
);
2003 HRESULT hr2
= SafeArrayAccessData(revPropValues
, (void HUGEP
**)&pbRevValues
);
2006 if (revPropNames
->rgsabound
->cElements
== revPropValues
->rgsabound
->cElements
)
2008 for (ULONG i
= 0; i
< revPropNames
->rgsabound
->cElements
; ++i
)
2010 // m_revProps[pbRevNames[i]] = pbRevValues[i];
2013 SafeArrayUnaccessData(revPropValues
);
2015 SafeArrayUnaccessData(revPropNames
);
2018 SafeArrayDestroy(revPropNames
);
2020 SafeArrayDestroy(revPropValues
);
2025 // if IBugTraqProvider2 failed, try IBugTraqProvider
2026 CComPtr
<IBugTraqProvider
> pProvider
= NULL
;
2027 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
2031 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2032 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2033 SysFreeString(parameters
);
2034 SysFreeString(commonRoot
);
2035 SafeArrayDestroy(pathList
);
2036 SysFreeString(originalMessage
);
2040 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
2043 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2044 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2047 m_cLogMessage
.SetText(temp
);
2049 m_sLogMessage
= m_cLogMessage
.GetText();
2050 if (!m_ProjectProperties
.sMessage
.IsEmpty())
2052 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
2053 if (!sBugID
.IsEmpty() && !bugIdOutSet
)
2055 SetDlgItemText(IDC_BUGID
, sBugID
);
2059 m_cLogMessage
.SetFocus();
2061 SysFreeString(parameters
);
2062 SysFreeString(commonRoot
);
2063 SafeArrayDestroy(pathList
);
2064 SysFreeString(originalMessage
);
2065 SysFreeString(temp
);
2068 void CCommitDlg::FillPatchView(bool onlySetTimer
)
2070 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2072 KillTimer(FILLPATCHVTIMER
);
2075 SetTimer(FILLPATCHVTIMER
, 100, NULL
);
2078 m_patchViewdlg
.m_ctrlPatchView
.SetText(CString());
2080 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
2081 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, FALSE
);
2086 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
2087 CTGitPath
* p
=(CTGitPath
*)m_ListCtrl
.GetItemData(nSelect
);
2088 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
2090 CString head
= _T("HEAD");
2091 if(m_bCommitAmend
==TRUE
&& m_bAmendDiffToLastCommit
==FALSE
)
2092 head
= _T("HEAD~1");
2093 cmd
.Format(_T("git.exe diff %s -- \"%s\""), head
, p
->GetGitPathString());
2094 g_Git
.Run(cmd
, &out
, CP_UTF8
);
2098 m_patchViewdlg
.m_ctrlPatchView
.SetText(out
);
2099 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, TRUE
);
2100 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_GOTOPOS
, 0);
2102 m_patchViewdlg
.m_ctrlPatchView
.GetClientRect(rect
);
2103 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTH
, rect
.Width() - 4);
2106 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM
/*wparam*/, LPARAM
/*lparam*/)
2108 this->FillPatchView(true);
2113 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
2115 SendMessage(WM_UPDATEOKBUTTON
);
2119 LRESULT
CCommitDlg::OnCheck(WPARAM wnd
, LPARAM
)
2121 HWND hwnd
= (HWND
)wnd
;
2122 bool check
= !(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
2123 if (hwnd
== GetDlgItem(IDC_CHECKALL
)->GetSafeHwnd())
2124 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, check
);
2125 else if (hwnd
== GetDlgItem(IDC_CHECKNONE
)->GetSafeHwnd())
2126 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, !check
);
2127 else if (hwnd
== GetDlgItem(IDC_CHECKUNVERSIONED
)->GetSafeHwnd())
2128 m_ListCtrl
.Check(GITSLC_SHOWUNVERSIONED
, check
);
2129 else if (hwnd
== GetDlgItem(IDC_CHECKVERSIONED
)->GetSafeHwnd())
2130 m_ListCtrl
.Check(GITSLC_SHOWVERSIONED
, check
);
2131 else if (hwnd
== GetDlgItem(IDC_CHECKADDED
)->GetSafeHwnd())
2132 m_ListCtrl
.Check(GITSLC_SHOWADDED
, check
);
2133 else if (hwnd
== GetDlgItem(IDC_CHECKDELETED
)->GetSafeHwnd())
2134 m_ListCtrl
.Check(GITSLC_SHOWREMOVED
, check
);
2135 else if (hwnd
== GetDlgItem(IDC_CHECKMODIFIED
)->GetSafeHwnd())
2136 m_ListCtrl
.Check(GITSLC_SHOWMODIFIED
, check
);
2137 else if (hwnd
== GetDlgItem(IDC_CHECKFILES
)->GetSafeHwnd())
2138 m_ListCtrl
.Check(GITSLC_SHOWFILES
, check
);
2139 else if (hwnd
== GetDlgItem(IDC_CHECKSUBMODULES
)->GetSafeHwnd())
2140 m_ListCtrl
.Check(GITSLC_SHOWSUBMODULES
, check
);
2145 LRESULT
CCommitDlg::OnUpdateOKButton(WPARAM
, LPARAM
)
2150 bool bValidLogSize
= m_cLogMessage
.GetText().GetLength() >= m_ProjectProperties
.nMinLogSize
&& m_cLogMessage
.GetText().GetLength() > 0;
2151 bool bAmendOrSelectFilesOrMerge
= m_ListCtrl
.GetSelected() > 0 || (m_bCommitAmend
&& m_bAmendDiffToLastCommit
) || CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
2153 DialogEnableWindow(IDOK
, bValidLogSize
&& (m_bCommitMessageOnly
|| bAmendOrSelectFilesOrMerge
));
2158 LRESULT
CCommitDlg::OnUpdateDataFalse(WPARAM
, LPARAM
)
2164 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
2168 if (wParam
== IDC_SPLITTER
)
2170 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
2171 DoSize(pHdr
->delta
);
2176 return __super::DefWindowProc(message
, wParam
, lParam
);
2179 void CCommitDlg::SetSplitterRange()
2181 if ((m_ListCtrl
)&&(m_cLogMessage
))
2184 m_cLogMessage
.GetWindowRect(rcTop
);
2185 ScreenToClient(rcTop
);
2187 m_ListCtrl
.GetWindowRect(rcMiddle
);
2188 ScreenToClient(rcMiddle
);
2189 if (rcMiddle
.Height() && rcMiddle
.Width())
2190 m_wndSplitter
.SetRange(rcTop
.top
+ 100, rcMiddle
.bottom
- 80);
2194 void CCommitDlg::DoSize(int delta
)
2196 RemoveAnchor(IDC_MESSAGEGROUP
);
2197 RemoveAnchor(IDC_LOGMESSAGE
);
2198 RemoveAnchor(IDC_SPLITTER
);
2199 RemoveAnchor(IDC_SIGNOFF
);
2200 RemoveAnchor(IDC_COMMIT_AMEND
);
2201 RemoveAnchor(IDC_COMMIT_AMENDDIFF
);
2202 RemoveAnchor(IDC_COMMIT_SETDATETIME
);
2203 RemoveAnchor(IDC_COMMIT_DATEPICKER
);
2204 RemoveAnchor(IDC_COMMIT_TIMEPICKER
);
2205 RemoveAnchor(IDC_COMMIT_SETAUTHOR
);
2206 RemoveAnchor(IDC_COMMIT_AUTHORDATA
);
2207 RemoveAnchor(IDC_LISTGROUP
);
2208 RemoveAnchor(IDC_FILELIST
);
2209 RemoveAnchor(IDC_TEXT_INFO
);
2210 RemoveAnchor(IDC_SELECTLABEL
);
2211 RemoveAnchor(IDC_CHECKALL
);
2212 RemoveAnchor(IDC_CHECKNONE
);
2213 RemoveAnchor(IDC_CHECKUNVERSIONED
);
2214 RemoveAnchor(IDC_CHECKVERSIONED
);
2215 RemoveAnchor(IDC_CHECKADDED
);
2216 RemoveAnchor(IDC_CHECKDELETED
);
2217 RemoveAnchor(IDC_CHECKMODIFIED
);
2218 RemoveAnchor(IDC_CHECKFILES
);
2219 RemoveAnchor(IDC_CHECKSUBMODULES
);
2221 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
2222 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
2223 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
2224 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
2225 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
2226 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
2227 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF
),0,delta
);
2228 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME
),0,delta
);
2229 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER
),0,delta
);
2230 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER
),0,delta
);
2231 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETAUTHOR
), 0, delta
);
2232 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AUTHORDATA
), 0, delta
);
2233 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
2234 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL
), 0, delta
);
2235 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL
), 0, delta
);
2236 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE
), 0, delta
);
2237 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED
), 0, delta
);
2238 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED
), 0, delta
);
2239 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED
), 0, delta
);
2240 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED
), 0, delta
);
2241 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED
), 0, delta
);
2242 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES
), 0, delta
);
2243 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES
), 0, delta
);
2245 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
2246 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
2247 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
2248 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
2249 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
2250 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
2251 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
2252 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
2253 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
2254 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
2255 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
2256 AddAnchor(IDC_COMMIT_SETAUTHOR
, TOP_LEFT
);
2257 AddAnchor(IDC_COMMIT_AUTHORDATA
, TOP_LEFT
, TOP_RIGHT
);
2258 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
2259 AddAnchor(IDC_SELECTLABEL
, TOP_LEFT
);
2260 AddAnchor(IDC_CHECKALL
, TOP_LEFT
);
2261 AddAnchor(IDC_CHECKNONE
, TOP_LEFT
);
2262 AddAnchor(IDC_CHECKUNVERSIONED
, TOP_LEFT
);
2263 AddAnchor(IDC_CHECKVERSIONED
, TOP_LEFT
);
2264 AddAnchor(IDC_CHECKADDED
, TOP_LEFT
);
2265 AddAnchor(IDC_CHECKDELETED
, TOP_LEFT
);
2266 AddAnchor(IDC_CHECKMODIFIED
, TOP_LEFT
);
2267 AddAnchor(IDC_CHECKFILES
, TOP_LEFT
);
2268 AddAnchor(IDC_CHECKSUBMODULES
, TOP_LEFT
);
2270 // adjust the minimum size of the dialog to prevent the resizing from
2271 // moving the list control too far down.
2273 m_cLogMessage
.GetClientRect(rcLogMsg
);
2274 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
2277 m_cLogMessage
.Invalidate();
2278 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
2281 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
2283 // first, let the resizing take place
2284 __super::OnSize(nType
, cx
, cy
);
2290 CString
CCommitDlg::GetSignedOffByLine()
2294 CString username
= g_Git
.GetUserName();
2295 CString email
= g_Git
.GetUserEmail();
2296 username
.Remove(_T('\n'));
2297 email
.Remove(_T('\n'));
2299 str
.Format(_T("Signed-off-by: %s <%s>"), username
, email
);
2304 void CCommitDlg::OnBnClickedSignOff()
2306 CString str
= GetSignedOffByLine();
2308 if (m_cLogMessage
.GetText().Find(str
) == -1) {
2309 m_cLogMessage
.SetText(m_cLogMessage
.GetText().TrimRight());
2310 int lastNewline
= m_cLogMessage
.GetText().ReverseFind(_T('\n'));
2311 int foundByLine
= -1;
2312 if (lastNewline
> 0)
2313 foundByLine
= m_cLogMessage
.GetText().Find(_T("-by: "), lastNewline
);
2315 if (foundByLine
== -1 || foundByLine
< lastNewline
)
2316 str
= _T("\r\n") + str
;
2318 m_cLogMessage
.SetText(m_cLogMessage
.GetText()+_T("\r\n")+str
+_T("\r\n"));
2322 void CCommitDlg::OnBnClickedCommitAmend()
2325 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
2330 rev
.GetCommit(CString(_T("HEAD")));
2332 catch (const char *msg
)
2334 CMessageBox::Show(m_hWnd
, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
2336 m_AmendStr
=rev
.GetSubject()+_T("\n")+rev
.GetBody();
2339 if(this->m_bCommitAmend
)
2341 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
2342 m_cLogMessage
.SetText(m_AmendStr
);
2343 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
2347 this->m_AmendStr
=this->m_cLogMessage
.GetText();
2348 m_cLogMessage
.SetText(m_NoAmendStr
);
2349 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
2352 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2353 OnBnClickedCommitSetauthor(); // to update the commit author
2355 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
2359 void CCommitDlg::OnBnClickedCommitMessageOnly()
2362 this->m_ListCtrl
.EnableWindow(m_bCommitMessageOnly
? FALSE
: TRUE
);
2363 SendMessage(WM_UPDATEOKBUTTON
);
2366 void CCommitDlg::OnBnClickedWholeProject()
2368 m_tooltips
.Pop(); // hide the tooltips
2374 m_ListCtrl
.GetStatus(NULL
,true,false,true);
2376 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
2378 m_regShowWholeProject
= m_bWholeProject
;
2380 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
2381 if (DWORD(m_regAddBeforeCommit
))
2382 dwShow
|= GITSLC_SHOWUNVERSIONED
;
2384 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
2386 m_ListCtrl
.Show(dwShow
, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
2393 void CCommitDlg::OnFocusMessage()
2395 m_cLogMessage
.SetFocus();
2398 void CCommitDlg::OnFocusFileList()
2400 m_ListCtrl
.SetFocus();
2403 void CCommitDlg::OnScnUpdateUI(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2405 int pos
= (int)this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
2406 int line
= (int)this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
2407 int column
= (int)this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
2410 str
.Format(_T("%d/%d"),line
+1,column
+1);
2411 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
2416 void CCommitDlg::OnStnClickedViewPatch()
2418 m_patchViewdlg
.m_pProjectProperties
= &this->m_ProjectProperties
;
2419 m_patchViewdlg
.m_ParentCommitDlg
= this;
2420 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
2422 BOOL viewPatchEnabled
= FALSE
;
2423 viewPatchEnabled
= g_Git
.GetConfigValueBool(_T("tgit.commitshowpatch"));
2424 if (viewPatchEnabled
== FALSE
)
2425 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("true"));
2426 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
2427 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
2429 this->GetWindowRect(&rect
);
2431 m_patchViewdlg
.ShowWindow(SW_SHOW
);
2433 m_patchViewdlg
.SetWindowPos(NULL
,rect
.right
,rect
.top
,rect
.Width(),rect
.Height(),
2434 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
2436 ShowViewPatchText(false);
2441 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2442 m_patchViewdlg
.ShowWindow(SW_HIDE
);
2443 m_patchViewdlg
.DestroyWindow();
2444 ShowViewPatchText(true);
2446 this->m_ctrlShowPatch
.Invalidate();
2449 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
2451 __super::OnMoving(fwSide
, pRect
);
2453 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
2456 m_patchViewdlg
.GetWindowRect(&patchrect
);
2457 if (::IsWindow(m_hWnd
))
2460 GetWindowRect(&thisrect
);
2461 if (patchrect
.left
== thisrect
.right
)
2463 m_patchViewdlg
.SetWindowPos(NULL
, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
2464 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
2471 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
2473 __super::OnSizing(fwSide
, pRect
);
2475 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2477 CRect thisrect
, patchrect
;
2478 this->GetWindowRect(thisrect
);
2479 this->m_patchViewdlg
.GetWindowRect(patchrect
);
2480 if(thisrect
.right
==patchrect
.left
)
2482 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
2483 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
2485 if( patchrect
.bottom
== thisrect
.bottom
)
2487 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
2489 if( patchrect
.top
== thisrect
.top
)
2491 patchrect
.top
-= thisrect
.top
-pRect
->top
;
2493 m_patchViewdlg
.MoveWindow(patchrect
);
2498 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2501 TRACE("Item Changed\r\n");
2504 int CCommitDlg::CheckHeadDetach()
2507 if(g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
,output
))
2509 int retval
= CMessageBox::Show(NULL
, IDS_PROC_COMMIT_DETACHEDWARNING
, IDS_APPNAME
, MB_YESNOCANCEL
| MB_ICONWARNING
);
2512 if (CAppUtils::CreateBranchTag(FALSE
, NULL
, true) == FALSE
)
2515 else if (retval
== IDCANCEL
)
2521 void CCommitDlg::OnBnClickedCommitAmenddiff()
2527 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2533 void CCommitDlg::OnBnClickedCommitSetDateTime()
2537 if (m_bSetCommitDateTime
)
2539 CTime authordate
= CTime::GetCurrentTime();
2542 GitRev headRevision
;
2545 headRevision
.GetCommit(_T("HEAD"));
2547 catch (const char *msg
)
2549 CMessageBox::Show(m_hWnd
, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
2551 authordate
= headRevision
.GetAuthorDate();
2554 m_CommitDate
.SetTime(&authordate
);
2555 m_CommitTime
.SetTime(&authordate
);
2557 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_SHOW
);
2558 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_SHOW
);
2562 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_HIDE
);
2563 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_HIDE
);
2567 void CCommitDlg::OnBnClickedCheckNewBranch()
2570 if (m_bCreateNewBranch
)
2572 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_HIDE
);
2573 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_SHOW
);
2577 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_HIDE
);
2578 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_SHOW
);
2582 void CCommitDlg::RestoreFiles(bool doNotAsk
)
2584 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))
2586 for (std::map
<CString
, CString
>::iterator it
= m_ListCtrl
.m_restorepaths
.begin(); it
!= m_ListCtrl
.m_restorepaths
.end(); ++it
)
2587 CopyFile(it
->second
, g_Git
.m_CurrentDir
+ _T("\\") + it
->first
, FALSE
);
2588 m_ListCtrl
.m_restorepaths
.clear();
2592 void CCommitDlg::UpdateCheckLinks()
2594 DialogEnableWindow(IDC_CHECKALL
, true);
2595 DialogEnableWindow(IDC_CHECKNONE
, true);
2596 DialogEnableWindow(IDC_CHECKUNVERSIONED
, m_ListCtrl
.GetUnversionedCount() > 0);
2597 DialogEnableWindow(IDC_CHECKVERSIONED
, m_ListCtrl
.GetItemCount() > m_ListCtrl
.GetUnversionedCount());
2598 DialogEnableWindow(IDC_CHECKADDED
, m_ListCtrl
.GetAddedCount() > 0);
2599 DialogEnableWindow(IDC_CHECKDELETED
, m_ListCtrl
.GetDeletedCount() > 0);
2600 DialogEnableWindow(IDC_CHECKMODIFIED
, m_ListCtrl
.GetModifiedCount() > 0);
2601 DialogEnableWindow(IDC_CHECKFILES
, m_ListCtrl
.GetFileCount() > 0);
2602 DialogEnableWindow(IDC_CHECKSUBMODULES
, m_ListCtrl
.GetSubmoduleCount() > 0);
2605 void CCommitDlg::OnBnClickedCommitSetauthor()
2611 m_sAuthor
.Format(_T("%s <%s>"), g_Git
.GetUserName(), g_Git
.GetUserEmail());
2614 GitRev headRevision
;
2617 headRevision
.GetCommit(_T("HEAD"));
2619 catch (const char *msg
)
2621 CMessageBox::Show(m_hWnd
, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
2623 m_sAuthor
.Format(_T("%s <%s>"), headRevision
.GetAuthorName(), headRevision
.GetAuthorEmail());
2628 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_SHOW
);
2631 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_HIDE
);