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 CFile::Remove(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_regShowWholeProject
= m_bWholeProject
;
1106 m_regKeepChangelists
= m_bKeepChangeList
;
1107 m_regDoNotAutoselectSubmodules
= m_bDoNotAutoselectSubmodules
;
1108 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
1109 m_bKeepChangeList
= FALSE
;
1110 InterlockedExchange(&m_bBlock
, FALSE
);
1112 if (!m_sLogMessage
.IsEmpty())
1114 m_History
.AddEntry(m_sLogMessage
);
1120 if( bCloseCommitDlg
)
1121 CResizableStandAloneDialog::OnOK();
1123 CShellUpdater::Instance().Flush();
1126 void CCommitDlg::SaveSplitterPos()
1130 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
1132 m_wndSplitter
.GetWindowRect(&rectSplitter
);
1133 ScreenToClient(&rectSplitter
);
1134 regPos
= rectSplitter
.top
;
1138 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
1140 return ((CCommitDlg
*)pVoid
)->StatusThread();
1143 UINT
CCommitDlg::StatusThread()
1145 //get the status of all selected file/folders recursively
1146 //and show the ones which have to be committed to the user
1147 //in a list control.
1148 InterlockedExchange(&m_bBlock
, TRUE
);
1149 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
1150 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
1152 m_pathwatcher
.Stop();
1154 m_ListCtrl
.SetBusy(true);
1155 g_Git
.RefreshGitIndex();
1157 m_bCancelled
= false;
1159 DialogEnableWindow(IDOK
, false);
1160 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
1161 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
1162 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, false);
1163 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
1164 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
1165 DialogEnableWindow(IDC_COMMIT_AMEND
, FALSE
);
1166 DialogEnableWindow(IDC_COMMIT_AMENDDIFF
, FALSE
);
1167 // read the list of recent log entries before querying the WC for status
1168 // -> the user may select one and modify / update it while we are crawling the WC
1170 DialogEnableWindow(IDC_CHECKALL
, false);
1171 DialogEnableWindow(IDC_CHECKNONE
, false);
1172 DialogEnableWindow(IDC_CHECKUNVERSIONED
, false);
1173 DialogEnableWindow(IDC_CHECKVERSIONED
, false);
1174 DialogEnableWindow(IDC_CHECKADDED
, false);
1175 DialogEnableWindow(IDC_CHECKDELETED
, false);
1176 DialogEnableWindow(IDC_CHECKMODIFIED
, false);
1177 DialogEnableWindow(IDC_CHECKFILES
, false);
1178 DialogEnableWindow(IDC_CHECKSUBMODULES
, false);
1180 if (m_History
.IsEmpty())
1183 reg
.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR
)m_ListCtrl
.m_sUUID
);
1184 reg
.Replace(_T(':'),_T('_'));
1185 m_History
.Load(reg
, _T("logmsgs"));
1188 // Initialise the list control with the status of the files/folders below us
1191 CTGitPathList
*pList
;
1192 m_ListCtrl
.m_amend
= (m_bCommitAmend
==TRUE
|| m_bForceCommitAmend
) && (m_bAmendDiffToLastCommit
==FALSE
);
1193 m_ListCtrl
.m_bDoNotAutoselectSubmodules
= (m_bDoNotAutoselectSubmodules
== TRUE
);
1198 pList
= &m_pathList
;
1200 success
=m_ListCtrl
.GetStatus(pList
);
1202 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1203 if(this->m_bShowUnversioned
)
1204 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
1206 m_ListCtrl
.CheckIfChangelistsArePresent(false);
1208 DWORD dwShow
= GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWLOCKS
| GITSLC_SHOWINCHANGELIST
| GITSLC_SHOWDIRECTFILES
;
1209 dwShow
|= DWORD(m_regAddBeforeCommit
) ? GITSLC_SHOWUNVERSIONED
: 0;
1212 if (!m_checkedPathList
.IsEmpty())
1213 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
1216 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
1217 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
1218 m_ListCtrl
.Show(dwShow
, dwCheck
);
1219 m_bSelectFilesForCommit
= true;
1222 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
1224 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
1225 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
1228 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
1229 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
1233 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
1234 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
1235 m_ListCtrl
.Show(dwShow
);
1239 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
1240 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
1241 && !PathFileExists(dotGitPath
+ _T("MERGE_HEAD")))
1244 temp
.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
);
1245 if (CMessageBox::ShowCheck(m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONINFORMATION
| MB_YESNO
, _T("NothingToCommitShowUnversioned"), NULL
)==IDYES
)
1247 m_bShowUnversioned
= TRUE
;
1248 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
1249 DWORD dwShow
= (DWORD
)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWUNVERSIONED
| GITSLC_SHOWLOCKS
);
1250 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
1251 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
1258 // we don't have to block the commit dialog while we fetch the
1259 // auto completion list.
1260 m_pathwatcher
.ClearChangedPaths();
1261 InterlockedExchange(&m_bBlock
, FALSE
);
1262 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE
)==TRUE
)
1264 m_ListCtrl
.Block(TRUE
, TRUE
);
1265 GetAutocompletionList();
1266 m_ListCtrl
.Block(FALSE
, FALSE
);
1268 SendMessage(WM_UPDATEOKBUTTON
);
1271 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
1272 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1273 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, true);
1274 if (m_ListCtrl
.HasChangeLists())
1275 DialogEnableWindow(IDC_KEEPLISTS
, true);
1277 // activate amend checkbox (if necessary)
1278 if (g_Git
.IsInitRepos())
1280 m_bCommitAmend
= FALSE
;
1281 SendMessage(WM_UPDATEDATAFALSE
);
1285 if (m_bForceCommitAmend
)
1287 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
1288 m_bCommitAmend
= TRUE
;
1289 SendMessage(WM_UPDATEDATAFALSE
);
1292 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(TRUE
);
1295 if (g_Git
.GetHash(hash
, _T("HEAD")))
1297 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
1299 if (!hash
.IsEmpty())
1301 GitRev headRevision
;
1304 headRevision
.GetParentFromHash(hash
);
1309 MessageBox(_T("Could not get parent from HEAD.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
1311 // do not allow to show diff to "last" revision if it has more that one parent
1312 if (headRevision
.ParentsCount() != 1)
1314 m_bAmendDiffToLastCommit
= TRUE
;
1315 SendMessage(WM_UPDATEDATAFALSE
);
1318 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->EnableWindow(TRUE
);
1324 // we have the list, now signal the main thread about it
1325 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
1328 InterlockedExchange(&m_bRunThread
, FALSE
);
1329 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1330 // force the cursor to normal
1336 void CCommitDlg::SetDlgTitle()
1338 if (m_sTitle
.IsEmpty())
1339 GetWindowText(m_sTitle
);
1341 if (m_bWholeProject
)
1342 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
1345 if (m_pathList
.GetCount() == 1)
1346 CAppUtils::SetWindowTitle(m_hWnd
, (g_Git
.m_CurrentDir
+ _T("\\") + m_pathList
[0].GetUIPathString()).TrimRight('\\'), m_sTitle
);
1348 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
+ _T("\\") + m_ListCtrl
.GetCommonDirectory(false), m_sTitle
);
1352 void CCommitDlg::OnCancel()
1354 m_bCancelled
= true;
1355 m_pathwatcher
.Stop();
1357 if (m_bThreadRunning
)
1359 InterlockedExchange(&m_bRunThread
, FALSE
);
1360 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
1361 if (m_bThreadRunning
)
1363 // we gave the thread a chance to quit. Since the thread didn't
1364 // listen to us we have to kill it.
1365 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1366 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1371 m_sLogMessage
= m_cLogMessage
.GetText();
1372 if (!m_sBugID
.IsEmpty())
1374 m_sBugID
.Replace(_T(", "), _T(","));
1375 m_sBugID
.Replace(_T(" ,"), _T(","));
1376 CString sBugID
= m_ProjectProperties
.sMessage
;
1377 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
1378 if (m_ProjectProperties
.bAppend
)
1379 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
1381 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
1383 if ((m_ProjectProperties
.sLogTemplate
.Compare(m_sLogMessage
) != 0) && !m_sLogMessage
.IsEmpty())
1385 m_History
.AddEntry(m_sLogMessage
);
1390 CResizableStandAloneDialog::OnCancel();
1393 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1396 m_tooltips
.RelayEvent(pMsg
);
1400 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1405 if (pMsg
->message
== WM_KEYDOWN
)
1407 switch (pMsg
->wParam
)
1412 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1418 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1420 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1422 PostMessage(WM_COMMAND
, IDOK
);
1426 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1428 // Pressing RETURN in the bug id control
1429 // moves the focus to the message
1430 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1438 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1441 void CCommitDlg::Refresh()
1443 if (m_bThreadRunning
)
1446 InterlockedExchange(&m_bBlock
, TRUE
);
1447 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1448 if (m_pThread
==NULL
)
1450 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1451 InterlockedExchange(&m_bBlock
, FALSE
);
1455 m_pThread
->m_bAutoDelete
= FALSE
;
1456 m_pThread
->ResumeThread();
1460 void CCommitDlg::OnBnClickedShowunversioned()
1462 m_tooltips
.Pop(); // hide the tooltips
1464 m_regAddBeforeCommit
= m_bShowUnversioned
;
1467 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1468 if (DWORD(m_regAddBeforeCommit
))
1469 dwShow
|= GITSLC_SHOWUNVERSIONED
;
1471 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
1472 if(dwShow
& GITSLC_SHOWUNVERSIONED
)
1475 m_ListCtrl
.GetStatus(NULL
,false,false,true);
1477 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1479 m_ListCtrl
.Show(dwShow
, 0, true, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
1484 void CCommitDlg::OnStnClickedExternalwarning()
1489 void CCommitDlg::OnEnChangeLogmessage()
1491 SendMessage(WM_UPDATEOKBUTTON
);
1494 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1497 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1499 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1501 m_bShowUnversioned
= TRUE
;
1502 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1503 m_ListCtrl
.Show(dwShow
);
1511 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1517 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM
/*lParam*/)
1521 SetForegroundWindow();
1523 // if multiple files/folders are dropped
1524 // this handler is called for every single item
1526 // To avoid creating multiple refresh threads and
1527 // causing crashes, we only add the items to the
1528 // list control and start a timer.
1529 // When the timer expires, we start the refresh thread,
1530 // but only if it isn't already running - otherwise we
1531 // restart the timer.
1533 path
.SetFromWin((LPCTSTR
)lParam
);
1535 // just add all the items we get here.
1536 // if the item is versioned, the add will fail but nothing
1537 // more will happen.
1539 Git
.Add(CTGitPathList(path
), &m_ProjectProperties
, Git_depth_empty
, false, true, true);
1541 if (!m_ListCtrl
.HasPath(path
))
1543 if (m_pathList
.AreAllPathsFiles())
1545 m_pathList
.AddPath(path
);
1546 m_pathList
.RemoveDuplicates();
1547 m_updatedPathList
.AddPath(path
);
1548 m_updatedPathList
.RemoveDuplicates();
1552 // if the path list contains folders, we have to check whether
1553 // our just (maybe) added path is a child of one of those. If it is
1554 // a child of a folder already in the list, we must not add it. Otherwise
1555 // that path could show up twice in the list.
1556 bool bHasParentInList
= false;
1557 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1559 if (m_pathList
[i
].IsAncestorOf(path
))
1561 bHasParentInList
= true;
1565 if (!bHasParentInList
)
1567 m_pathList
.AddPath(path
);
1568 m_pathList
.RemoveDuplicates();
1569 m_updatedPathList
.AddPath(path
);
1570 m_updatedPathList
.RemoveDuplicates();
1575 // Always start the timer, since the status of an existing item might have changed
1576 SetTimer(REFRESHTIMER
, 200, NULL
);
1577 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": Item %s dropped, timer started\n"), path
.GetWinPath());
1582 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1584 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1588 //////////////////////////////////////////////////////////////////////////
1589 // functions which run in the status thread
1590 //////////////////////////////////////////////////////////////////////////
1592 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1597 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1598 while (m_bRunThread
&& file
.ReadString(strLine
))
1600 int eqpos
= strLine
.Find('=');
1602 rgx
= strLine
.Mid(eqpos
+1).Trim();
1605 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1607 mapRegex
[strLine
.Left(pos
)] = rgx
;
1608 strLine
= strLine
.Mid(pos
+1).Trim();
1610 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1614 catch (CFileException
* pE
)
1616 CTraceToOutputDebugString::Instance()(__FUNCTION__
": CFileException loading auto list regex file\n");
1621 void CCommitDlg::GetAutocompletionList()
1623 // the auto completion list is made of strings from each selected files.
1624 // the strings used are extracted from the files with regexes found
1625 // in the file "autolist.txt".
1626 // the format of that file is:
1627 // file extensions separated with commas '=' regular expression to use
1629 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1630 // .cpp = (?<=[^\s]::)\b\w+\b
1632 std::map
<CString
, CString
> mapRegex
;
1633 CString sRegexFile
= CPathUtils::GetAppDirectory();
1634 CRegDWORD regtimeout
= CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1635 DWORD timeoutvalue
= regtimeout
*1000;
1636 sRegexFile
+= _T("autolist.txt");
1639 ParseRegexFile(sRegexFile
, mapRegex
);
1640 SHGetFolderPath(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, sRegexFile
.GetBuffer(MAX_PATH
+1));
1641 sRegexFile
.ReleaseBuffer();
1642 sRegexFile
+= _T("\\TortoiseGit\\autolist.txt");
1643 if (PathFileExists(sRegexFile
))
1645 ParseRegexFile(sRegexFile
, mapRegex
);
1647 DWORD starttime
= GetTickCount();
1649 // now we have two arrays of strings, where the first array contains all
1650 // file extensions we can use and the second the corresponding regex strings
1651 // to apply to those files.
1653 // the next step is to go over all files shown in the commit dialog
1654 // and scan them for strings we can use
1655 int nListItems
= m_ListCtrl
.GetItemCount();
1657 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1659 // stop parsing after timeout
1660 if ((!m_bRunThread
) || (GetTickCount() - starttime
> timeoutvalue
))
1663 CTGitPath
*path
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1668 CString sPartPath
=path
->GetGitPathString();
1669 m_autolist
.insert(sPartPath
);
1673 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1677 m_autolist
.insert(sPartPath
.Mid(pos
));
1680 // Last inserted entry is a file name.
1681 // Some users prefer to also list file name without extension.
1682 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE
))
1684 int dotPos
= sPartPath
.ReverseFind('.');
1685 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1686 m_autolist
.insert(sPartPath
.Mid(lastPos
, dotPos
- lastPos
));
1689 if (path
->m_Action
== CTGitPath::LOGACTIONS_UNVER
&& !CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseUnversioned"), FALSE
))
1691 if (path
->m_Action
== CTGitPath::LOGACTIONS_IGNORE
|| path
->m_Action
== CTGitPath::LOGACTIONS_DELETED
)
1694 CString sExt
= path
->GetFileExtension();
1696 // find the regex string which corresponds to the file extension
1697 CString rdata
= mapRegex
[sExt
];
1698 if (rdata
.IsEmpty())
1701 ScanFile(path
->GetWinPathString(), rdata
, sExt
);
1703 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": Auto completion list loaded in %d msec\n"), GetTickCount() - starttime
);
1706 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
, const CString
& sExt
)
1708 static std::map
<CString
, std::tr1::wregex
> regexmap
;
1710 std::wstring sFileContent
;
1711 CAutoFile hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
1714 DWORD size
= GetFileSize(hFile
, NULL
);
1715 if (size
> CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseMaxSize"), 300000L))
1717 // no files bigger than 300k
1720 // allocate memory to hold file contents
1721 std::unique_ptr
<char[]> buffer(new char[size
]);
1723 if (!ReadFile(hFile
, buffer
.get(), size
, &readbytes
, NULL
))
1726 IsTextUnicode(buffer
.get(), readbytes
, &opts
);
1727 if (opts
& IS_TEXT_UNICODE_NULL_BYTES
)
1731 if (opts
& IS_TEXT_UNICODE_UNICODE_MASK
)
1733 sFileContent
= std::wstring((wchar_t*)buffer
.get(), readbytes
/ sizeof(WCHAR
));
1735 if ((opts
& IS_TEXT_UNICODE_NOT_UNICODE_MASK
) || (opts
== 0))
1737 const int ret
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
.get(), readbytes
, NULL
, 0);
1738 std::unique_ptr
<wchar_t[]> pWideBuf(new wchar_t[ret
]);
1739 const int ret2
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
.get(), readbytes
, pWideBuf
.get(), ret
);
1741 sFileContent
= std::wstring(pWideBuf
.get(), ret
);
1744 if (sFileContent
.empty() || !m_bRunThread
)
1752 std::tr1::wregex regCheck
;
1753 std::map
<CString
, std::tr1::wregex
>::const_iterator regIt
;
1754 if ((regIt
= regexmap
.find(sExt
)) != regexmap
.end())
1755 regCheck
= regIt
->second
;
1758 regCheck
= std::tr1::wregex(sRegex
, std::tr1::regex_constants::icase
| std::tr1::regex_constants::ECMAScript
);
1759 regexmap
[sExt
] = regCheck
;
1761 const std::tr1::wsregex_iterator end
;
1762 for (std::tr1::wsregex_iterator
it(sFileContent
.begin(), sFileContent
.end(), regCheck
); it
!= end
; ++it
)
1764 const std::tr1::wsmatch match
= *it
;
1765 for (size_t i
= 1; i
< match
.size(); ++i
)
1767 if (match
[i
].second
-match
[i
].first
)
1769 m_autolist
.insert(std::wstring(match
[i
]).c_str());
1774 catch (std::exception
) {}
1777 // CSciEditContextMenuInterface
1778 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1780 CString sMenuItemText
;
1781 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITHASH
);
1782 m_nPopupPickCommitHash
= nCmd
++;
1783 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPickCommitHash
, sMenuItemText
);
1785 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITMESSAGE
);
1786 m_nPopupPickCommitMessage
= nCmd
++;
1787 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPickCommitMessage
, sMenuItemText
);
1789 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTEFILELIST
);
1790 m_nPopupPasteListCmd
= nCmd
++;
1791 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
1793 if (!m_History
.IsEmpty())
1795 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
1796 m_nPopupPasteLastMessage
= nCmd
++;
1797 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
1799 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
1800 m_nPopupRecentMessage
= nCmd
++;
1801 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
1805 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
1807 if (cmd
== m_nPopupPickCommitHash
)
1809 // use the git log to allow selection of a version
1811 // tell the dialog to use mode for selecting revisions
1812 dlg
.SetSelect(true);
1813 // only one revision must be selected however
1814 dlg
.SingleSelection(true);
1815 if (dlg
.DoModal() == IDOK
)
1817 // get selected hash if any
1818 CString selectedHash
= dlg
.GetSelectedHash();
1819 pSciEdit
->InsertText(selectedHash
);
1824 if (cmd
== m_nPopupPickCommitMessage
)
1826 // use the git log to allow selection of a version
1828 // tell the dialog to use mode for selecting revisions
1829 dlg
.SetSelect(true);
1830 // only one revision must be selected however
1831 dlg
.SingleSelection(true);
1832 if (dlg
.DoModal() == IDOK
)
1834 // get selected hash if any
1835 CString selectedHash
= dlg
.GetSelectedHash();
1837 rev
.GetCommit(selectedHash
);
1838 CString message
= rev
.GetSubject() + _T("\r\n") + rev
.GetBody();
1839 pSciEdit
->InsertText(message
);
1844 if (cmd
== m_nPopupPasteListCmd
)
1847 int nListItems
= m_ListCtrl
.GetItemCount();
1848 for (int i
=0; i
<nListItems
; ++i
)
1850 CTGitPath
* entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1851 if (entry
&&entry
->m_Checked
)
1854 CString status
= entry
->GetActionName();
1855 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1856 status
= _T("Add"); // I18N TODO
1858 //git_wc_status_kind status = entry->status;
1859 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1860 if (m_ProjectProperties
.bFileListInEnglish
)
1863 line
.Format(_T("%-10s %s\r\n"),status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
,0));
1867 pSciEdit
->InsertText(logmsg
);
1871 if(cmd
== m_nPopupPasteLastMessage
)
1873 if (m_History
.IsEmpty())
1877 logmsg
+=m_History
.GetEntry(0);
1878 pSciEdit
->InsertText(logmsg
);
1882 if(cmd
== m_nPopupRecentMessage
)
1884 OnBnClickedHistory();
1890 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
1894 case ENDDIALOGTIMER
:
1895 KillTimer(ENDDIALOGTIMER
);
1899 if (m_bThreadRunning
)
1901 SetTimer(REFRESHTIMER
, 200, NULL
);
1902 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Wait some more before refreshing\n");
1906 KillTimer(REFRESHTIMER
);
1907 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Refreshing after items dropped\n");
1911 case FILLPATCHVTIMER
:
1915 __super::OnTimer(nIDEvent
);
1918 void CCommitDlg::OnBnClickedHistory()
1920 m_tooltips
.Pop(); // hide the tooltips
1921 if (m_pathList
.IsEmpty())
1924 CHistoryDlg historyDlg
;
1925 historyDlg
.SetHistory(m_History
);
1926 if (historyDlg
.DoModal() != IDOK
)
1929 CString sMsg
= historyDlg
.GetSelectedText();
1930 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
1932 CString sBugID
= m_ProjectProperties
.FindBugID(sMsg
);
1933 if ((!sBugID
.IsEmpty()) && ((GetDlgItem(IDC_BUGID
)->IsWindowVisible())))
1935 SetDlgItemText(IDC_BUGID
, sBugID
);
1937 if (m_ProjectProperties
.sLogTemplate
.Compare(m_cLogMessage
.GetText())!=0)
1938 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
1940 m_cLogMessage
.SetText(sMsg
);
1943 SendMessage(WM_UPDATEOKBUTTON
);
1944 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1948 void CCommitDlg::OnBnClickedBugtraqbutton()
1950 m_tooltips
.Pop(); // hide the tooltips
1951 CString sMsg
= m_cLogMessage
.GetText();
1953 if (m_BugTraqProvider
== NULL
)
1956 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
1957 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
1958 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_pathList
.GetCount());
1960 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
1961 SafeArrayPutElement(pathList
, &index
, m_pathList
[index
].GetGitPathString().AllocSysString());
1963 BSTR originalMessage
= sMsg
.AllocSysString();
1965 // m_revProps.clear();
1967 // first try the IBugTraqProvider2 interface
1968 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
1969 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
1970 bool bugIdOutSet
= false;
1973 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1974 BSTR repositoryRoot
= g_Git
.m_CurrentDir
.AllocSysString();
1975 BSTR bugIDOut
= NULL
;
1976 GetDlgItemText(IDC_BUGID
, m_sBugID
);
1977 BSTR bugID
= m_sBugID
.AllocSysString();
1978 SAFEARRAY
* revPropNames
= NULL
;
1979 SAFEARRAY
* revPropValues
= NULL
;
1980 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
1983 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1984 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1991 m_sBugID
= bugIDOut
;
1992 SysFreeString(bugIDOut
);
1993 SetDlgItemText(IDC_BUGID
, m_sBugID
);
1995 SysFreeString(bugID
);
1996 SysFreeString(repositoryRoot
);
1997 m_cLogMessage
.SetText(temp
);
1998 BSTR HUGEP
*pbRevNames
;
1999 BSTR HUGEP
*pbRevValues
;
2001 HRESULT hr1
= SafeArrayAccessData(revPropNames
, (void HUGEP
**)&pbRevNames
);
2004 HRESULT hr2
= SafeArrayAccessData(revPropValues
, (void HUGEP
**)&pbRevValues
);
2007 if (revPropNames
->rgsabound
->cElements
== revPropValues
->rgsabound
->cElements
)
2009 for (ULONG i
= 0; i
< revPropNames
->rgsabound
->cElements
; ++i
)
2011 // m_revProps[pbRevNames[i]] = pbRevValues[i];
2014 SafeArrayUnaccessData(revPropValues
);
2016 SafeArrayUnaccessData(revPropNames
);
2019 SafeArrayDestroy(revPropNames
);
2021 SafeArrayDestroy(revPropValues
);
2026 // if IBugTraqProvider2 failed, try IBugTraqProvider
2027 CComPtr
<IBugTraqProvider
> pProvider
= NULL
;
2028 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
2032 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2033 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2034 SysFreeString(parameters
);
2035 SysFreeString(commonRoot
);
2036 SafeArrayDestroy(pathList
);
2037 SysFreeString(originalMessage
);
2041 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
2044 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2045 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2048 m_cLogMessage
.SetText(temp
);
2050 m_sLogMessage
= m_cLogMessage
.GetText();
2051 if (!m_ProjectProperties
.sMessage
.IsEmpty())
2053 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
2054 if (!sBugID
.IsEmpty() && !bugIdOutSet
)
2056 SetDlgItemText(IDC_BUGID
, sBugID
);
2060 m_cLogMessage
.SetFocus();
2062 SysFreeString(parameters
);
2063 SysFreeString(commonRoot
);
2064 SafeArrayDestroy(pathList
);
2065 SysFreeString(originalMessage
);
2066 SysFreeString(temp
);
2069 void CCommitDlg::FillPatchView(bool onlySetTimer
)
2071 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2073 KillTimer(FILLPATCHVTIMER
);
2076 SetTimer(FILLPATCHVTIMER
, 100, NULL
);
2079 m_patchViewdlg
.m_ctrlPatchView
.SetText(CString());
2081 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
2082 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, FALSE
);
2087 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
2088 CTGitPath
* p
=(CTGitPath
*)m_ListCtrl
.GetItemData(nSelect
);
2089 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
2091 CString head
= _T("HEAD");
2092 if(m_bCommitAmend
==TRUE
&& m_bAmendDiffToLastCommit
==FALSE
)
2093 head
= _T("HEAD~1");
2094 cmd
.Format(_T("git.exe diff %s -- \"%s\""), head
, p
->GetGitPathString());
2095 g_Git
.Run(cmd
, &out
, CP_UTF8
);
2099 m_patchViewdlg
.m_ctrlPatchView
.SetText(out
);
2100 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, TRUE
);
2101 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_GOTOPOS
, 0);
2103 m_patchViewdlg
.m_ctrlPatchView
.GetClientRect(rect
);
2104 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTH
, rect
.Width() - 4);
2107 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM
/*wparam*/, LPARAM
/*lparam*/)
2109 this->FillPatchView(true);
2114 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
2116 SendMessage(WM_UPDATEOKBUTTON
);
2120 LRESULT
CCommitDlg::OnCheck(WPARAM wnd
, LPARAM
)
2122 HWND hwnd
= (HWND
)wnd
;
2123 bool check
= !(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
2124 if (hwnd
== GetDlgItem(IDC_CHECKALL
)->GetSafeHwnd())
2125 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, check
);
2126 else if (hwnd
== GetDlgItem(IDC_CHECKNONE
)->GetSafeHwnd())
2127 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, !check
);
2128 else if (hwnd
== GetDlgItem(IDC_CHECKUNVERSIONED
)->GetSafeHwnd())
2129 m_ListCtrl
.Check(GITSLC_SHOWUNVERSIONED
, check
);
2130 else if (hwnd
== GetDlgItem(IDC_CHECKVERSIONED
)->GetSafeHwnd())
2131 m_ListCtrl
.Check(GITSLC_SHOWVERSIONED
, check
);
2132 else if (hwnd
== GetDlgItem(IDC_CHECKADDED
)->GetSafeHwnd())
2133 m_ListCtrl
.Check(GITSLC_SHOWADDED
, check
);
2134 else if (hwnd
== GetDlgItem(IDC_CHECKDELETED
)->GetSafeHwnd())
2135 m_ListCtrl
.Check(GITSLC_SHOWREMOVED
, check
);
2136 else if (hwnd
== GetDlgItem(IDC_CHECKMODIFIED
)->GetSafeHwnd())
2137 m_ListCtrl
.Check(GITSLC_SHOWMODIFIED
, check
);
2138 else if (hwnd
== GetDlgItem(IDC_CHECKFILES
)->GetSafeHwnd())
2139 m_ListCtrl
.Check(GITSLC_SHOWFILES
, check
);
2140 else if (hwnd
== GetDlgItem(IDC_CHECKSUBMODULES
)->GetSafeHwnd())
2141 m_ListCtrl
.Check(GITSLC_SHOWSUBMODULES
, check
);
2146 LRESULT
CCommitDlg::OnUpdateOKButton(WPARAM
, LPARAM
)
2151 bool bValidLogSize
= m_cLogMessage
.GetText().GetLength() >= m_ProjectProperties
.nMinLogSize
&& m_cLogMessage
.GetText().GetLength() > 0;
2152 bool bAmendOrSelectFilesOrMerge
= m_ListCtrl
.GetSelected() > 0 || (m_bCommitAmend
&& m_bAmendDiffToLastCommit
) || CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
2154 DialogEnableWindow(IDOK
, bValidLogSize
&& (m_bCommitMessageOnly
|| bAmendOrSelectFilesOrMerge
));
2159 LRESULT
CCommitDlg::OnUpdateDataFalse(WPARAM
, LPARAM
)
2165 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
2169 if (wParam
== IDC_SPLITTER
)
2171 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
2172 DoSize(pHdr
->delta
);
2177 return __super::DefWindowProc(message
, wParam
, lParam
);
2180 void CCommitDlg::SetSplitterRange()
2182 if ((m_ListCtrl
)&&(m_cLogMessage
))
2185 m_cLogMessage
.GetWindowRect(rcTop
);
2186 ScreenToClient(rcTop
);
2188 m_ListCtrl
.GetWindowRect(rcMiddle
);
2189 ScreenToClient(rcMiddle
);
2190 if (rcMiddle
.Height() && rcMiddle
.Width())
2191 m_wndSplitter
.SetRange(rcTop
.top
+ 100, rcMiddle
.bottom
- 80);
2195 void CCommitDlg::DoSize(int delta
)
2197 RemoveAnchor(IDC_MESSAGEGROUP
);
2198 RemoveAnchor(IDC_LOGMESSAGE
);
2199 RemoveAnchor(IDC_SPLITTER
);
2200 RemoveAnchor(IDC_SIGNOFF
);
2201 RemoveAnchor(IDC_COMMIT_AMEND
);
2202 RemoveAnchor(IDC_COMMIT_AMENDDIFF
);
2203 RemoveAnchor(IDC_COMMIT_SETDATETIME
);
2204 RemoveAnchor(IDC_COMMIT_DATEPICKER
);
2205 RemoveAnchor(IDC_COMMIT_TIMEPICKER
);
2206 RemoveAnchor(IDC_COMMIT_SETAUTHOR
);
2207 RemoveAnchor(IDC_COMMIT_AUTHORDATA
);
2208 RemoveAnchor(IDC_LISTGROUP
);
2209 RemoveAnchor(IDC_FILELIST
);
2210 RemoveAnchor(IDC_TEXT_INFO
);
2211 RemoveAnchor(IDC_SELECTLABEL
);
2212 RemoveAnchor(IDC_CHECKALL
);
2213 RemoveAnchor(IDC_CHECKNONE
);
2214 RemoveAnchor(IDC_CHECKUNVERSIONED
);
2215 RemoveAnchor(IDC_CHECKVERSIONED
);
2216 RemoveAnchor(IDC_CHECKADDED
);
2217 RemoveAnchor(IDC_CHECKDELETED
);
2218 RemoveAnchor(IDC_CHECKMODIFIED
);
2219 RemoveAnchor(IDC_CHECKFILES
);
2220 RemoveAnchor(IDC_CHECKSUBMODULES
);
2222 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
2223 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
2224 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
2225 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
2226 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
2227 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
2228 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF
),0,delta
);
2229 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME
),0,delta
);
2230 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER
),0,delta
);
2231 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER
),0,delta
);
2232 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETAUTHOR
), 0, delta
);
2233 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AUTHORDATA
), 0, delta
);
2234 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
2235 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL
), 0, delta
);
2236 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL
), 0, delta
);
2237 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE
), 0, delta
);
2238 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED
), 0, delta
);
2239 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED
), 0, delta
);
2240 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED
), 0, delta
);
2241 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED
), 0, delta
);
2242 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED
), 0, delta
);
2243 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES
), 0, delta
);
2244 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES
), 0, delta
);
2246 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
2247 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
2248 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
2249 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
2250 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
2251 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
2252 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
2253 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
2254 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
2255 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
2256 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
2257 AddAnchor(IDC_COMMIT_SETAUTHOR
, TOP_LEFT
);
2258 AddAnchor(IDC_COMMIT_AUTHORDATA
, TOP_LEFT
, TOP_RIGHT
);
2259 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
2260 AddAnchor(IDC_SELECTLABEL
, TOP_LEFT
);
2261 AddAnchor(IDC_CHECKALL
, TOP_LEFT
);
2262 AddAnchor(IDC_CHECKNONE
, TOP_LEFT
);
2263 AddAnchor(IDC_CHECKUNVERSIONED
, TOP_LEFT
);
2264 AddAnchor(IDC_CHECKVERSIONED
, TOP_LEFT
);
2265 AddAnchor(IDC_CHECKADDED
, TOP_LEFT
);
2266 AddAnchor(IDC_CHECKDELETED
, TOP_LEFT
);
2267 AddAnchor(IDC_CHECKMODIFIED
, TOP_LEFT
);
2268 AddAnchor(IDC_CHECKFILES
, TOP_LEFT
);
2269 AddAnchor(IDC_CHECKSUBMODULES
, TOP_LEFT
);
2271 // adjust the minimum size of the dialog to prevent the resizing from
2272 // moving the list control too far down.
2274 m_cLogMessage
.GetClientRect(rcLogMsg
);
2275 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
2278 m_cLogMessage
.Invalidate();
2279 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
2282 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
2284 // first, let the resizing take place
2285 __super::OnSize(nType
, cx
, cy
);
2291 CString
CCommitDlg::GetSignedOffByLine()
2295 CString username
= g_Git
.GetUserName();
2296 CString email
= g_Git
.GetUserEmail();
2297 username
.Remove(_T('\n'));
2298 email
.Remove(_T('\n'));
2300 str
.Format(_T("Signed-off-by: %s <%s>"), username
, email
);
2305 void CCommitDlg::OnBnClickedSignOff()
2307 CString str
= GetSignedOffByLine();
2309 if (m_cLogMessage
.GetText().Find(str
) == -1) {
2310 m_cLogMessage
.SetText(m_cLogMessage
.GetText().TrimRight());
2311 int lastNewline
= m_cLogMessage
.GetText().ReverseFind(_T('\n'));
2312 int foundByLine
= -1;
2313 if (lastNewline
> 0)
2314 foundByLine
= m_cLogMessage
.GetText().Find(_T("-by: "), lastNewline
);
2316 if (foundByLine
== -1 || foundByLine
< lastNewline
)
2317 str
= _T("\r\n") + str
;
2319 m_cLogMessage
.SetText(m_cLogMessage
.GetText()+_T("\r\n")+str
+_T("\r\n"));
2323 void CCommitDlg::OnBnClickedCommitAmend()
2326 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
2331 rev
.GetCommit(CString(_T("HEAD")));
2333 catch (const char *msg
)
2335 CMessageBox::Show(m_hWnd
, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
2337 m_AmendStr
=rev
.GetSubject()+_T("\n")+rev
.GetBody();
2340 if(this->m_bCommitAmend
)
2342 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
2343 m_cLogMessage
.SetText(m_AmendStr
);
2344 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
2348 this->m_AmendStr
=this->m_cLogMessage
.GetText();
2349 m_cLogMessage
.SetText(m_NoAmendStr
);
2350 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
2353 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2354 OnBnClickedCommitSetauthor(); // to update the commit author
2356 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
2360 void CCommitDlg::OnBnClickedCommitMessageOnly()
2363 this->m_ListCtrl
.EnableWindow(m_bCommitMessageOnly
? FALSE
: TRUE
);
2364 SendMessage(WM_UPDATEOKBUTTON
);
2367 void CCommitDlg::OnBnClickedWholeProject()
2369 m_tooltips
.Pop(); // hide the tooltips
2375 m_ListCtrl
.GetStatus(NULL
,true,false,true);
2377 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
2379 m_regShowWholeProject
= m_bWholeProject
;
2381 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
2382 if (DWORD(m_regAddBeforeCommit
))
2383 dwShow
|= GITSLC_SHOWUNVERSIONED
;
2385 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
2387 m_ListCtrl
.Show(dwShow
, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
2394 void CCommitDlg::OnFocusMessage()
2396 m_cLogMessage
.SetFocus();
2399 void CCommitDlg::OnFocusFileList()
2401 m_ListCtrl
.SetFocus();
2404 void CCommitDlg::OnScnUpdateUI(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2406 int pos
= (int)this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
2407 int line
= (int)this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
2408 int column
= (int)this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
2411 str
.Format(_T("%d/%d"),line
+1,column
+1);
2412 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
2417 void CCommitDlg::OnStnClickedViewPatch()
2419 m_patchViewdlg
.m_pProjectProperties
= &this->m_ProjectProperties
;
2420 m_patchViewdlg
.m_ParentCommitDlg
= this;
2421 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
2423 BOOL viewPatchEnabled
= FALSE
;
2424 viewPatchEnabled
= g_Git
.GetConfigValueBool(_T("tgit.commitshowpatch"));
2425 if (viewPatchEnabled
== FALSE
)
2426 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("true"));
2427 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
2428 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
2430 this->GetWindowRect(&rect
);
2432 m_patchViewdlg
.ShowWindow(SW_SHOW
);
2434 m_patchViewdlg
.SetWindowPos(NULL
,rect
.right
,rect
.top
,rect
.Width(),rect
.Height(),
2435 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
2437 ShowViewPatchText(false);
2442 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2443 m_patchViewdlg
.ShowWindow(SW_HIDE
);
2444 m_patchViewdlg
.DestroyWindow();
2445 ShowViewPatchText(true);
2447 this->m_ctrlShowPatch
.Invalidate();
2450 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
2452 __super::OnMoving(fwSide
, pRect
);
2454 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
2457 m_patchViewdlg
.GetWindowRect(&patchrect
);
2458 if (::IsWindow(m_hWnd
))
2461 GetWindowRect(&thisrect
);
2462 if (patchrect
.left
== thisrect
.right
)
2464 m_patchViewdlg
.SetWindowPos(NULL
, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
2465 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
2472 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
2474 __super::OnSizing(fwSide
, pRect
);
2476 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2478 CRect thisrect
, patchrect
;
2479 this->GetWindowRect(thisrect
);
2480 this->m_patchViewdlg
.GetWindowRect(patchrect
);
2481 if(thisrect
.right
==patchrect
.left
)
2483 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
2484 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
2486 if( patchrect
.bottom
== thisrect
.bottom
)
2488 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
2490 if( patchrect
.top
== thisrect
.top
)
2492 patchrect
.top
-= thisrect
.top
-pRect
->top
;
2494 m_patchViewdlg
.MoveWindow(patchrect
);
2499 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2502 TRACE("Item Changed\r\n");
2505 int CCommitDlg::CheckHeadDetach()
2508 if(g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
,output
))
2510 int retval
= CMessageBox::Show(NULL
, IDS_PROC_COMMIT_DETACHEDWARNING
, IDS_APPNAME
, MB_YESNOCANCEL
| MB_ICONWARNING
);
2513 if (CAppUtils::CreateBranchTag(FALSE
, NULL
, true) == FALSE
)
2516 else if (retval
== IDCANCEL
)
2522 void CCommitDlg::OnBnClickedCommitAmenddiff()
2528 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2534 void CCommitDlg::OnBnClickedCommitSetDateTime()
2538 if (m_bSetCommitDateTime
)
2540 CTime authordate
= CTime::GetCurrentTime();
2543 GitRev headRevision
;
2546 headRevision
.GetCommit(_T("HEAD"));
2548 catch (const char *msg
)
2550 CMessageBox::Show(m_hWnd
, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
2552 authordate
= headRevision
.GetAuthorDate();
2555 m_CommitDate
.SetTime(&authordate
);
2556 m_CommitTime
.SetTime(&authordate
);
2558 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_SHOW
);
2559 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_SHOW
);
2563 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_HIDE
);
2564 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_HIDE
);
2568 void CCommitDlg::OnBnClickedCheckNewBranch()
2571 if (m_bCreateNewBranch
)
2573 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_HIDE
);
2574 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_SHOW
);
2578 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_HIDE
);
2579 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_SHOW
);
2583 void CCommitDlg::RestoreFiles(bool doNotAsk
)
2585 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))
2587 for (std::map
<CString
, CString
>::iterator it
= m_ListCtrl
.m_restorepaths
.begin(); it
!= m_ListCtrl
.m_restorepaths
.end(); ++it
)
2588 CopyFile(it
->second
, g_Git
.m_CurrentDir
+ _T("\\") + it
->first
, FALSE
);
2589 m_ListCtrl
.m_restorepaths
.clear();
2593 void CCommitDlg::UpdateCheckLinks()
2595 DialogEnableWindow(IDC_CHECKALL
, true);
2596 DialogEnableWindow(IDC_CHECKNONE
, true);
2597 DialogEnableWindow(IDC_CHECKUNVERSIONED
, m_ListCtrl
.GetUnversionedCount() > 0);
2598 DialogEnableWindow(IDC_CHECKVERSIONED
, m_ListCtrl
.GetItemCount() > m_ListCtrl
.GetUnversionedCount());
2599 DialogEnableWindow(IDC_CHECKADDED
, m_ListCtrl
.GetAddedCount() > 0);
2600 DialogEnableWindow(IDC_CHECKDELETED
, m_ListCtrl
.GetDeletedCount() > 0);
2601 DialogEnableWindow(IDC_CHECKMODIFIED
, m_ListCtrl
.GetModifiedCount() > 0);
2602 DialogEnableWindow(IDC_CHECKFILES
, m_ListCtrl
.GetFileCount() > 0);
2603 DialogEnableWindow(IDC_CHECKSUBMODULES
, m_ListCtrl
.GetSubmoduleCount() > 0);
2606 void CCommitDlg::OnBnClickedCommitSetauthor()
2612 m_sAuthor
.Format(_T("%s <%s>"), g_Git
.GetUserName(), g_Git
.GetUserEmail());
2615 GitRev headRevision
;
2618 headRevision
.GetCommit(_T("HEAD"));
2620 catch (const char *msg
)
2622 CMessageBox::Show(m_hWnd
, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
2624 m_sAuthor
.Format(_T("%s <%s>"), headRevision
.GetAuthorName(), headRevision
.GetAuthorEmail());
2629 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_SHOW
);
2632 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_HIDE
);