1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2013 - TortoiseSVN
4 // Copyright (C) 2008-2014 - 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"
39 #include "SysProgressDlg.h"
40 #include "MassiveGitTask.h"
42 #include "BstrSafeVector.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
)
57 , m_bShowUnversioned(FALSE
)
59 , m_bThreadRunning(FALSE
)
62 , m_bWholeProject(FALSE
)
63 , m_bWholeProject2(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)
82 , m_nPopupPickCommitMessage(0)
85 this->m_bCommitAmend
=FALSE
;
88 CCommitDlg::~CCommitDlg()
96 void CCommitDlg::DoDataExchange(CDataExchange
* pDX
)
98 CResizableStandAloneDialog::DoDataExchange(pDX
);
99 DDX_Control(pDX
, IDC_FILELIST
, m_ListCtrl
);
100 DDX_Control(pDX
, IDC_LOGMESSAGE
, m_cLogMessage
);
101 DDX_Check(pDX
, IDC_SHOWUNVERSIONED
, m_bShowUnversioned
);
102 DDX_Check(pDX
, IDC_COMMIT_SETDATETIME
, m_bSetCommitDateTime
);
103 DDX_Check(pDX
, IDC_CHECK_NEWBRANCH
, m_bCreateNewBranch
);
104 DDX_Text(pDX
, IDC_NEWBRANCH
, m_sCreateNewBranch
);
105 DDX_Text(pDX
, IDC_BUGID
, m_sBugID
);
106 DDX_Text(pDX
, IDC_COMMIT_AUTHORDATA
, m_sAuthor
);
107 DDX_Check(pDX
, IDC_WHOLE_PROJECT
, m_bWholeProject
);
108 DDX_Control(pDX
, IDC_SPLITTER
, m_wndSplitter
);
109 DDX_Check(pDX
, IDC_KEEPLISTS
, m_bKeepChangeList
);
110 DDX_Check(pDX
, IDC_NOAUTOSELECTSUBMODULES
, m_bDoNotAutoselectSubmodules
);
111 DDX_Check(pDX
,IDC_COMMIT_AMEND
,m_bCommitAmend
);
112 DDX_Check(pDX
, IDC_COMMIT_MESSAGEONLY
, m_bCommitMessageOnly
);
113 DDX_Check(pDX
,IDC_COMMIT_AMENDDIFF
,m_bAmendDiffToLastCommit
);
114 DDX_Check(pDX
, IDC_COMMIT_SETAUTHOR
, m_bSetAuthor
);
115 DDX_Control(pDX
,IDC_VIEW_PATCH
,m_ctrlShowPatch
);
116 DDX_Control(pDX
, IDC_COMMIT_DATEPICKER
, m_CommitDate
);
117 DDX_Control(pDX
, IDC_COMMIT_TIMEPICKER
, m_CommitTime
);
120 BEGIN_MESSAGE_MAP(CCommitDlg
, CResizableStandAloneDialog
)
121 ON_BN_CLICKED(IDC_SHOWUNVERSIONED
, OnBnClickedShowunversioned
)
122 ON_NOTIFY(SCN_UPDATEUI
, IDC_LOGMESSAGE
, OnScnUpdateUI
)
123 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
124 ON_BN_CLICKED(IDC_BUGTRAQBUTTON
, OnBnClickedBugtraqbutton
)
125 ON_EN_CHANGE(IDC_LOGMESSAGE
, OnEnChangeLogmessage
)
126 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
, OnGitStatusListCtrlItemCountChanged
)
127 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
128 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE
, OnFileDropped
)
129 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED
, &CCommitDlg::OnGitStatusListCtrlCheckChanged
)
130 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED
, &CCommitDlg::OnGitStatusListCtrlItemChanged
)
132 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED
, &CCommitDlg::OnCheck
)
133 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY
, OnAutoListReady
)
134 ON_REGISTERED_MESSAGE(WM_UPDATEOKBUTTON
, OnUpdateOKButton
)
135 ON_REGISTERED_MESSAGE(WM_UPDATEDATAFALSE
, OnUpdateDataFalse
)
138 ON_STN_CLICKED(IDC_EXTERNALWARNING
, &CCommitDlg::OnStnClickedExternalwarning
)
139 ON_BN_CLICKED(IDC_SIGNOFF
, &CCommitDlg::OnBnClickedSignOff
)
140 ON_BN_CLICKED(IDC_COMMIT_AMEND
, &CCommitDlg::OnBnClickedCommitAmend
)
141 ON_BN_CLICKED(IDC_COMMIT_MESSAGEONLY
, &CCommitDlg::OnBnClickedCommitMessageOnly
)
142 ON_BN_CLICKED(IDC_WHOLE_PROJECT
, &CCommitDlg::OnBnClickedWholeProject
)
143 ON_COMMAND(ID_FOCUS_MESSAGE
,&CCommitDlg::OnFocusMessage
)
144 ON_COMMAND(ID_FOCUS_FILELIST
, OnFocusFileList
)
145 ON_STN_CLICKED(IDC_VIEW_PATCH
, &CCommitDlg::OnStnClickedViewPatch
)
149 ON_NOTIFY(HDN_ITEMCHANGED
, 0, &CCommitDlg::OnHdnItemchangedFilelist
)
150 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF
, &CCommitDlg::OnBnClickedCommitAmenddiff
)
151 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES
, &CCommitDlg::OnBnClickedNoautoselectsubmodules
)
152 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME
, &CCommitDlg::OnBnClickedCommitSetDateTime
)
153 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH
, &CCommitDlg::OnBnClickedCheckNewBranch
)
154 ON_BN_CLICKED(IDC_COMMIT_SETAUTHOR
, &CCommitDlg::OnBnClickedCommitSetauthor
)
157 int GetCommitTemplate(CString
&msg
)
159 CString tplFilename
= g_Git
.GetConfigValue(_T("commit.template"));
160 if (tplFilename
.IsEmpty())
163 if (tplFilename
[0] == _T('/'))
165 if (tplFilename
.GetLength() >= 3)
167 // handle "/d/TortoiseGit/tpl.txt" -> "d:/TortoiseGit/tpl.txt"
168 if (tplFilename
[2] == _T('/'))
170 tplFilename
.GetBuffer()[0] = tplFilename
[1];
171 tplFilename
.GetBuffer()[1] = _T(':');
176 tplFilename
.Replace(_T('/'), _T('\\'));
178 if (!CGit::LoadTextFile(tplFilename
, msg
))
183 BOOL
CCommitDlg::OnInitDialog()
185 CResizableStandAloneDialog::OnInitDialog();
186 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
188 if (m_sLogMessage
.IsEmpty())
190 if (!m_bForceCommitAmend
)
191 GetCommitTemplate(m_sLogMessage
);
194 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
195 bool loadedMsg
= !CGit::LoadTextFile(dotGitPath
+ _T("MERGE_MSG"), m_sLogMessage
);
196 loadedMsg
= loadedMsg
&& !CGit::LoadTextFile(dotGitPath
+ _T("SQUASH_MSG"), m_sLogMessage
);
198 RunStartCommitHook();
200 if (CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive())
202 DialogEnableWindow(IDC_CHECK_NEWBRANCH
, FALSE
);
203 m_bCreateNewBranch
= FALSE
;
204 GetDlgItem(IDC_MERGEACTIVE
)->ShowWindow(SW_SHOW
);
207 m_regAddBeforeCommit
= CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE
);
208 m_bShowUnversioned
= m_regAddBeforeCommit
;
210 CString
regPath(g_Git
.m_CurrentDir
);
211 regPath
.Replace(_T(":"), _T("_"));
212 m_regShowWholeProject
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ShowWholeProject\\") + regPath
, FALSE
);
213 m_bWholeProject
= m_regShowWholeProject
;
215 m_History
.SetMaxHistoryItems((LONG
)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
217 m_regKeepChangelists
= CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE
);
218 m_bKeepChangeList
= m_regKeepChangelists
;
220 m_regDoNotAutoselectSubmodules
= CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE
);
221 m_bDoNotAutoselectSubmodules
= m_regDoNotAutoselectSubmodules
;
223 m_hAccel
= LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG
));
225 if (m_pathList
.IsEmpty())
226 m_bWholeProject2
= true;
228 if(this->m_pathList
.GetCount() == 1 && m_pathList
[0].IsEmpty())
229 m_bWholeProject2
= true;
235 m_ListCtrl
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
, _T("CommitDlg"),(GITSLC_POPALL
^ (GITSLC_POPCOMMIT
| GITSLC_POPSAVEAS
)), true, true);
236 m_ListCtrl
.SetStatLabel(GetDlgItem(IDC_STATISTICS
));
237 m_ListCtrl
.SetCancelBool(&m_bCancelled
);
238 m_ListCtrl
.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT
);
239 m_ListCtrl
.EnableFileDrop();
240 m_ListCtrl
.SetBackgroundImage(IDI_COMMIT_BKG
);
242 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
243 m_ProjectProperties
.ReadProps();
245 m_cLogMessage
.Init(m_ProjectProperties
);
246 m_cLogMessage
.SetFont((CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
247 m_cLogMessage
.RegisterContextMenuHandler(this);
248 std::map
<int, UINT
> icons
;
249 icons
[AUTOCOMPLETE_SPELLING
] = IDI_SPELL
;
250 icons
[AUTOCOMPLETE_FILENAME
] = IDI_FILE
;
251 icons
[AUTOCOMPLETE_PROGRAMCODE
] = IDI_CODE
;
252 icons
[AUTOCOMPLETE_SNIPPET
] = IDI_SNIPPET
;
253 m_cLogMessage
.SetIcon(icons
);
255 OnEnChangeLogmessage();
257 m_tooltips
.Create(this);
258 m_tooltips
.AddTool(IDC_EXTERNALWARNING
, IDS_COMMITDLG_EXTERNALS
);
259 m_tooltips
.AddTool(IDC_COMMIT_AMEND
,IDS_COMMIT_AMEND_TT
);
260 m_tooltips
.AddTool(IDC_MERGEACTIVE
, IDC_MERGEACTIVE_TT
);
261 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
263 CBugTraqAssociations bugtraq_associations
;
264 bugtraq_associations
.Load(m_ProjectProperties
.GetProviderUUID(), m_ProjectProperties
.sProviderParams
);
266 if (bugtraq_associations
.FindProvider(g_Git
.m_CurrentDir
, &m_bugtraq_association
))
268 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
269 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
271 CComPtr
<IBugTraqProvider
> pProvider
;
272 HRESULT hr
= pProvider
.CoCreateInstance(m_bugtraq_association
.GetProviderClass());
275 m_BugTraqProvider
= pProvider
;
277 ATL::CComBSTR
parameters(m_bugtraq_association
.GetParameters());
278 if (SUCCEEDED(hr
= pProvider
->GetLinkText(GetSafeHwnd(), parameters
, &temp
)))
280 SetDlgItemText(IDC_BUGTRAQBUTTON
, temp
);
281 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(TRUE
);
282 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_SHOW
);
286 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
288 else if (!m_ProjectProperties
.sMessage
.IsEmpty())
290 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_SHOW
);
291 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_SHOW
);
292 if (!m_ProjectProperties
.sLabel
.IsEmpty())
293 SetDlgItemText(IDC_BUGIDLABEL
, m_ProjectProperties
.sLabel
);
294 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
295 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
296 GetDlgItem(IDC_BUGID
)->SetFocus();
297 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(m_sLogMessage
);
298 if (!sBugID
.IsEmpty())
300 SetDlgItemText(IDC_BUGID
, sBugID
);
305 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
306 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
307 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
308 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
309 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
312 if (!m_sLogMessage
.IsEmpty())
314 m_cLogMessage
.SetText(m_sLogMessage
);
315 m_cLogMessage
.Call(SCI_SETCURRENTPOS
, 0);
316 m_cLogMessage
.Call(SCI_SETSEL
, 0, 0);
319 GetWindowText(m_sWindowTitle
);
321 AdjustControlSize(IDC_SHOWUNVERSIONED
);
322 AdjustControlSize(IDC_WHOLE_PROJECT
);
323 AdjustControlSize(IDC_CHECK_NEWBRANCH
);
324 AdjustControlSize(IDC_COMMIT_AMEND
);
325 AdjustControlSize(IDC_COMMIT_MESSAGEONLY
);
326 AdjustControlSize(IDC_COMMIT_AMENDDIFF
);
327 AdjustControlSize(IDC_COMMIT_SETDATETIME
);
328 AdjustControlSize(IDC_COMMIT_SETAUTHOR
);
329 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES
);
330 AdjustControlSize(IDC_KEEPLISTS
);
332 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKALL
);
333 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKNONE
);
334 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKUNVERSIONED
);
335 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKVERSIONED
);
336 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKADDED
);
337 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKDELETED
);
338 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKMODIFIED
);
339 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKFILES
);
340 m_linkControl
.ConvertStaticToLink(m_hWnd
, IDC_CHECKSUBMODULES
);
342 // line up all controls and adjust their sizes.
343 #define LINKSPACING 9
344 RECT rc
= AdjustControlSize(IDC_SELECTLABEL
);
345 rc
.right
-= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
346 rc
= AdjustStaticSize(IDC_CHECKALL
, rc
, LINKSPACING
);
347 rc
= AdjustStaticSize(IDC_CHECKNONE
, rc
, LINKSPACING
);
348 rc
= AdjustStaticSize(IDC_CHECKUNVERSIONED
, rc
, LINKSPACING
);
349 rc
= AdjustStaticSize(IDC_CHECKVERSIONED
, rc
, LINKSPACING
);
350 rc
= AdjustStaticSize(IDC_CHECKADDED
, rc
, LINKSPACING
);
351 rc
= AdjustStaticSize(IDC_CHECKDELETED
, rc
, LINKSPACING
);
352 rc
= AdjustStaticSize(IDC_CHECKMODIFIED
, rc
, LINKSPACING
);
353 rc
= AdjustStaticSize(IDC_CHECKFILES
, rc
, LINKSPACING
);
354 rc
= AdjustStaticSize(IDC_CHECKSUBMODULES
, rc
, LINKSPACING
);
356 GetClientRect(m_DlgOrigRect
);
357 m_cLogMessage
.GetClientRect(m_LogMsgOrigRect
);
359 AddAnchor(IDC_COMMITLABEL
, TOP_LEFT
, TOP_RIGHT
);
360 AddAnchor(IDC_BUGIDLABEL
, TOP_RIGHT
);
361 AddAnchor(IDC_BUGID
, TOP_RIGHT
);
362 AddAnchor(IDC_BUGTRAQBUTTON
, TOP_RIGHT
);
363 AddAnchor(IDC_COMMIT_TO
, TOP_LEFT
, TOP_RIGHT
);
364 AddAnchor(IDC_CHECK_NEWBRANCH
, TOP_RIGHT
);
365 AddAnchor(IDC_NEWBRANCH
, TOP_LEFT
, TOP_RIGHT
);
366 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
367 // AddAnchor(IDC_HISTORY, TOP_LEFT);
368 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
369 AddAnchor(IDC_SIGNOFF
, TOP_RIGHT
);
370 AddAnchor(IDC_VIEW_PATCH
, BOTTOM_RIGHT
);
371 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
372 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
373 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
374 AddAnchor(IDC_SHOWUNVERSIONED
, BOTTOM_LEFT
);
375 AddAnchor(IDC_EXTERNALWARNING
, BOTTOM_RIGHT
);
376 AddAnchor(IDC_STATISTICS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
377 AddAnchor(IDC_TEXT_INFO
, TOP_RIGHT
);
378 AddAnchor(IDC_WHOLE_PROJECT
, BOTTOM_LEFT
);
379 AddAnchor(IDC_KEEPLISTS
, BOTTOM_LEFT
);
380 AddAnchor(IDC_NOAUTOSELECTSUBMODULES
, BOTTOM_LEFT
);
381 AddAnchor(IDOK
, BOTTOM_RIGHT
);
382 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
383 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
384 AddAnchor(IDC_MERGEACTIVE
, BOTTOM_RIGHT
);
385 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
386 AddAnchor(IDC_COMMIT_MESSAGEONLY
, BOTTOM_LEFT
);
387 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
388 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
389 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
390 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
391 AddAnchor(IDC_COMMIT_SETAUTHOR
, TOP_LEFT
);
392 AddAnchor(IDC_COMMIT_AUTHORDATA
, TOP_LEFT
, TOP_RIGHT
);
394 AddAnchor(IDC_SELECTLABEL
, TOP_LEFT
);
395 AddAnchor(IDC_CHECKALL
, TOP_LEFT
);
396 AddAnchor(IDC_CHECKNONE
, TOP_LEFT
);
397 AddAnchor(IDC_CHECKUNVERSIONED
, TOP_LEFT
);
398 AddAnchor(IDC_CHECKVERSIONED
, TOP_LEFT
);
399 AddAnchor(IDC_CHECKADDED
, TOP_LEFT
);
400 AddAnchor(IDC_CHECKDELETED
, TOP_LEFT
);
401 AddAnchor(IDC_CHECKMODIFIED
, TOP_LEFT
);
402 AddAnchor(IDC_CHECKFILES
, TOP_LEFT
);
403 AddAnchor(IDC_CHECKSUBMODULES
, TOP_LEFT
);
406 CenterWindow(CWnd::FromHandle(hWndExplorer
));
407 EnableSaveRestore(_T("CommitDlg"));
408 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
409 RECT rcDlg
, rcLogMsg
, rcFileList
;
410 GetClientRect(&rcDlg
);
411 m_cLogMessage
.GetWindowRect(&rcLogMsg
);
412 ScreenToClient(&rcLogMsg
);
413 m_ListCtrl
.GetWindowRect(&rcFileList
);
414 ScreenToClient(&rcFileList
);
418 m_wndSplitter
.GetWindowRect(&rectSplitter
);
419 ScreenToClient(&rectSplitter
);
420 int delta
= yPos
- rectSplitter
.top
;
421 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
423 m_wndSplitter
.SetWindowPos(NULL
, rectSplitter
.left
, yPos
, 0, 0, SWP_NOSIZE
);
430 // add all directories to the watcher
432 for (int i=0; i<m_pathList.GetCount(); ++i)
434 if (m_pathList[i].IsDirectory())
435 m_pathwatcher.AddPath(m_pathList[i]);
438 m_updatedPathList
= m_pathList
;
440 //first start a thread to obtain the file list with the status without
441 //blocking the dialog
442 InterlockedExchange(&m_bBlock
, TRUE
);
443 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
446 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
447 InterlockedExchange(&m_bBlock
, FALSE
);
451 m_pThread
->m_bAutoDelete
= FALSE
;
452 m_pThread
->ResumeThread();
454 CRegDWORD err
= CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE
);
455 CRegDWORD historyhint
= CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE
);
456 if ((((DWORD
)err
)!=FALSE
)&&((((DWORD
)historyhint
)==FALSE
)))
459 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
463 this->m_ctrlShowPatch
.SetURL(CString());
465 if (g_Git
.GetConfigValueBool(_T("tgit.commitshowpatch")))
466 OnStnClickedViewPatch();
468 return FALSE
; // return TRUE unless you set the focus to a control
469 // EXCEPTION: OCX Property Pages should return FALSE
472 static bool UpdateIndex(CMassiveGitTask
&mgt
, CSysProgressDlg
&sysProgressDlg
, int progress
, int maxProgress
)
474 if (sysProgressDlg
.HasUserCancelled())
477 if (sysProgressDlg
.IsVisible())
479 sysProgressDlg
.SetTitle(IDS_APPNAME
);
480 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT
)));
481 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX
)));
482 sysProgressDlg
.SetProgress(progress
, maxProgress
);
483 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing
487 return mgt
.Execute(cancel
);
490 void CCommitDlg::OnOK()
494 if (m_bThreadRunning
)
497 InterlockedExchange(&m_bRunThread
, FALSE
);
498 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
499 if (m_bThreadRunning
)
501 // we gave the thread a chance to quit. Since the thread didn't
502 // listen to us we have to kill it.
503 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
504 InterlockedExchange(&m_bThreadRunning
, FALSE
);
509 if (m_bCreateNewBranch
)
511 if (!g_Git
.IsBranchNameValid(m_sCreateNewBranch
))
513 ShowEditBalloon(IDC_NEWBRANCH
, IDS_B_T_NOTEMPTY
, IDS_ERR_ERROR
, TTI_ERROR
);
516 if (g_Git
.BranchTagExists(m_sCreateNewBranch
))
518 // branch already exists
520 msg
.LoadString(IDS_B_EXISTS
);
521 msg
+= _T(" ") + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME
));
522 ShowEditBalloon(IDC_NEWBRANCH
, msg
, CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
525 if (g_Git
.BranchTagExists(m_sCreateNewBranch
, false))
527 // tag with the same name exists -> shortref is ambiguous
528 if (CMessageBox::Show(m_hWnd
, IDS_B_SAMETAGNAMEEXISTS
, IDS_APPNAME
, 2, IDI_EXCLAMATION
, IDS_CONTINUEBUTTON
, IDS_ABORTBUTTON
) == 2)
534 GetDlgItemText(IDC_BUGID
, id
);
535 if (!m_ProjectProperties
.CheckBugID(id
))
537 ShowEditBalloon(IDC_BUGID
, IDS_COMMITDLG_ONLYNUMBERS
, IDS_ERR_ERROR
, TTI_ERROR
);
540 m_sLogMessage
= m_cLogMessage
.GetText();
541 if ( m_sLogMessage
.IsEmpty() )
543 // no message entered, go round again
544 CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
547 if ((m_ProjectProperties
.bWarnIfNoIssue
) && (id
.IsEmpty() && !m_ProjectProperties
.HasBugID(m_sLogMessage
)))
549 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOISSUEWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
553 if (m_ProjectProperties
.bWarnNoSignedOffBy
== TRUE
&& m_cLogMessage
.GetText().Find(GetSignedOffByLine()) == -1)
555 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
);
558 OnBnClickedSignOff();
559 m_sLogMessage
= m_cLogMessage
.GetText();
561 else if (retval
== 3)
565 if (CHooks::Instance().IsHookPresent(pre_commit_hook
, g_Git
.m_CurrentDir
)) {
566 DWORD exitcode
= 0xFFFFFFFF;
569 m_ListCtrl
.WriteCheckedNamesToPathList(list
);
570 if (CHooks::Instance().PreCommit(g_Git
.m_CurrentDir
, list
, m_sLogMessage
, exitcode
, error
))
575 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
576 MessageBox(temp
, _T("TortoiseGit"), MB_ICONERROR
);
582 int nListItems
= m_ListCtrl
.GetItemCount();
583 bool needResetIndex
= false;
584 for (int i
= 0; i
< nListItems
&& !m_bCommitMessageOnly
; ++i
)
586 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
587 if (!entry
->m_Checked
&& !(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
588 needResetIndex
= true;
589 if (!entry
->m_Checked
|| !entry
->IsDirectory())
593 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
596 subgit
.m_CurrentDir
= g_Git
.CombinePath(entry
);
598 subgit
.Run(_T("git.exe status --porcelain"), &subcmdout
, CP_UTF8
);
599 dirty
= !subcmdout
.IsEmpty();
604 cmd
.Format(_T("git.exe diff -- \"%s\""), entry
->GetWinPathString());
605 g_Git
.Run(cmd
, &cmdout
, CP_UTF8
);
606 dirty
= cmdout
.Right(7) == _T("-dirty\n");
612 message
.Format(CString(MAKEINTRESOURCE(IDS_COMMITDLG_SUBMODULEDIRTY
)), entry
->GetGitPathString());
613 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
)));
617 cmdCommit
.Format(_T("/command:commit /path:\"%s\\%s\""), g_Git
.m_CurrentDir
, entry
->GetWinPathString());
618 CAppUtils::RunTortoiseGitProc(cmdCommit
);
621 else if (result
== 2)
628 if (!m_bCommitMessageOnly
)
629 m_ListCtrl
.WriteCheckedNamesToPathList(m_selectedPathList
);
630 m_pathwatcher
.Stop();
631 InterlockedExchange(&m_bBlock
, TRUE
);
632 //first add all the unversioned files the user selected
633 //and check if all versioned files are selected
636 CMassiveGitTask
mgtReAddAfterCommit(_T("add --ignore-errors -f"));
641 bool bAddSuccess
=true;
642 bool bCloseCommitDlg
=false;
644 CSysProgressDlg sysProgressDlg
;
645 if (nListItems
>= 25)
647 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT
)));
648 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX
)));
649 sysProgressDlg
.SetTime(true);
650 sysProgressDlg
.SetShowProgressBar(true);
651 sysProgressDlg
.ShowModal(this, true);
654 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
655 DWORD currentTicks
= GetTickCount();
657 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_COMMIT_UPDATE_INDEX
))
660 Do not use the libgit2 implementation right now, since it has several flaws:
661 * http://code.google.com/p/tortoisegit/issues/detail?id=1690: possible access denied problem
662 * https://code.google.com/p/tortoisegit/issues/detail?id=2224: filters not correctly applied
663 * changes to x-bit are not correctly committed, since we reset the index
668 CAutoRepository
repository(g_Git
.GetGitRepository());
671 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
676 CString revRef
= _T("HEAD");
677 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
678 revRef
= _T("HEAD~1");
679 if (CGit::GetHash(repository
, revHash
, revRef
))
681 MessageBox(g_Git
.GetLibGit2LastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR
);
686 if (!revHash
.IsEmpty() && needResetIndex
&& git_commit_lookup(commit
.GetPointer(), repository
, (const git_oid
*)revHash
.m_hash
))
688 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not get last commit.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
693 if (!revHash
.IsEmpty() && needResetIndex
&& git_commit_tree(tree
.GetPointer(), commit
))
695 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not read tree of commit.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
700 if (git_repository_index(index
.GetPointer(), repository
))
702 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not get the repository index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
706 // reset index to the one of the reference commit (HEAD or HEAD~1)
707 if (!revHash
.IsEmpty() && needResetIndex
&& git_index_read_tree(index
, tree
))
709 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not read the tree into the index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
712 else if (!revHash
.IsEmpty() && !needResetIndex
)
714 git_index_read(index
, true);
719 for (int j
= 0; j
< nListItems
; ++j
)
721 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
723 if (sysProgressDlg
.IsVisible())
725 if (GetTickCount() - currentTicks
> 1000 || j
== nListItems
- 1 || j
== 0)
727 sysProgressDlg
.SetLine(2, entry
->GetGitPathString(), true);
728 sysProgressDlg
.SetProgress(j
, nListItems
);
729 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too often: this takes time!
730 currentTicks
= GetTickCount();
734 CStringA filePathA
= CUnicodeUtils::GetMulti(entry
->GetGitPathString(), CP_UTF8
);
736 if (entry
->m_Checked
&& !m_bCommitMessageOnly
)
738 if (entry
->IsDirectory())
740 git_submodule
*submodule
= nullptr;
741 if (git_submodule_lookup(&submodule
, repository
, filePathA
))
744 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not open submodule \"") + entry
->GetGitPathString() + _T("\".")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
747 if (git_submodule_add_to_index(submodule
, FALSE
))
750 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not add submodule \"") + entry
->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
754 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
756 git_index_remove_bypath(index
, filePathA
); // ignore error
760 if (git_index_add_bypath(index
, filePathA
))
763 CMessageBox::Show(m_hWnd
, CGit::GetLibGit2LastErr(_T("Could not add \"") + entry
->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
768 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
770 git_index_remove_bypath(index
, filePathA
); // ignore error
775 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
776 mgtReAddAfterCommit
.AddFile(*entry
);
778 if (sysProgressDlg
.HasUserCancelled())
784 CShellUpdater::Instance().AddPathForUpdate(*entry
);
786 if (bAddSuccess
&& git_index_write(index
))
792 // ***************************************************
793 // ATTENTION: Similar code in RebaseDlg.cpp!!!
794 // ***************************************************
795 CMassiveGitTask
mgtAdd(_T("add -f"));
796 CMassiveGitTask
mgtUpdateIndexForceRemove(_T("update-index --force-remove"));
797 CMassiveGitTask
mgtUpdateIndex(_T("update-index"));
798 CMassiveGitTask
mgtRm(_T("rm --ignore-unmatch"));
799 CMassiveGitTask
mgtRmFCache(_T("rm -f --cache"));
800 CString resetCmd
= _T("reset");
801 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
802 resetCmd
+= _T(" HEAD~1");;
803 CMassiveGitTask
mgtReset(resetCmd
, TRUE
, true);
804 for (int j
= 0; j
< nListItems
; ++j
)
806 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
808 if (entry
->m_Checked
&& !m_bCommitMessageOnly
)
810 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
811 mgtAdd
.AddFile(entry
->GetGitPathString());
812 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
813 mgtUpdateIndexForceRemove
.AddFile(entry
->GetGitPathString());
815 mgtUpdateIndex
.AddFile(entry
->GetGitPathString());
817 if ((entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
) && !entry
->GetGitOldPathString().IsEmpty())
818 mgtRm
.AddFile(entry
->GetGitOldPathString());
824 if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
825 { //To init git repository, there are not HEAD, so we can use git reset command
826 mgtRmFCache
.AddFile(entry
->GetGitPathString());
827 mgtReAddAfterCommit
.AddFile(*entry
);
829 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
&& !entry
->GetGitOldPathString().IsEmpty())
830 mgtReset
.AddFile(entry
->GetGitOldPathString());
832 else if (!(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
833 mgtReset
.AddFile(entry
->GetGitPathString());
836 if (sysProgressDlg
.HasUserCancelled())
843 CMassiveGitTask tasks
[] = { mgtAdd
, mgtUpdateIndexForceRemove
, mgtUpdateIndex
, mgtRm
, mgtRmFCache
, mgtReset
};
844 int progress
= 0, maxProgress
= 0;
845 for (int j
= 0; j
< _countof(tasks
); ++j
)
846 maxProgress
+= tasks
[j
].GetListCount();
847 for (int j
= 0; j
< _countof(tasks
); ++j
)
848 bAddSuccess
= bAddSuccess
&& UpdateIndex(tasks
[j
], sysProgressDlg
, progress
+= tasks
[j
].GetListCount(), maxProgress
);
850 if (sysProgressDlg
.HasUserCancelled())
853 for (int j
= 0; bAddSuccess
&& j
< nListItems
; ++j
)
854 CShellUpdater::Instance().AddPathForUpdate(*(CTGitPath
*)m_ListCtrl
.GetItemData(j
));
857 if (sysProgressDlg
.HasUserCancelled())
860 //sysProgressDlg.Stop();
862 if (bAddSuccess
&& m_bCreateNewBranch
)
864 if (g_Git
.Run(_T("git.exe branch ") + m_sCreateNewBranch
, &out
, CP_UTF8
))
866 MessageBox(_T("Creating new branch failed:\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
869 if (g_Git
.Run(_T("git.exe checkout ") + m_sCreateNewBranch
+ _T(" --"), &out
, CP_UTF8
))
871 MessageBox(_T("Switching to new branch failed:\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
876 if (bAddSuccess
&& CheckHeadDetach())
880 CString sExistingBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
881 sExistingBugID
.Trim();
882 if (!m_sBugID
.IsEmpty() && m_sBugID
.Compare(sExistingBugID
))
884 m_sBugID
.Replace(_T(", "), _T(","));
885 m_sBugID
.Replace(_T(" ,"), _T(","));
886 CString sBugID
= m_ProjectProperties
.sMessage
;
887 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
888 if (m_ProjectProperties
.bAppend
)
889 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
891 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
894 // now let the bugtraq plugin check the commit message
895 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
896 if (m_BugTraqProvider
)
898 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
902 ATL::CComBSTR
repositoryRoot(g_Git
.m_CurrentDir
);
903 ATL::CComBSTR
parameters(m_bugtraq_association
.GetParameters());
904 ATL::CComBSTR
commonRoot(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
905 ATL::CComBSTR
commitMessage(m_sLogMessage
);
906 CBstrSafeVector
pathList(m_selectedPathList
.GetCount());
908 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
909 pathList
.PutElement(index
, m_selectedPathList
[index
].GetGitPathString());
911 if (FAILED(hr
= pProvider2
->CheckCommit(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, commitMessage
, &temp
)))
915 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), ce
.GetMessageAndDescription().c_str());
916 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
920 CString sError
= temp
;
921 if (!sError
.IsEmpty())
923 CMessageBox::Show(m_hWnd
, sError
, _T("TortoiseGit"), MB_ICONERROR
);
930 if (m_bCommitMessageOnly
|| bAddSuccess
&& (nchecked
|| m_bCommitAmend
|| CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive()))
932 bCloseCommitDlg
= true;
934 CString tempfile
=::GetTempFile();
936 if (CAppUtils::SaveCommitUnicodeFile(tempfile
, m_sLogMessage
))
938 CMessageBox::Show(nullptr, _T("Could not save commit message"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
942 CTGitPath path
=g_Git
.m_CurrentDir
;
944 BOOL IsGitSVN
= path
.GetAdminDirMask() & ITEMIS_GITSVN
;
948 if(this->m_bCommitAmend
)
953 if (m_bSetCommitDateTime
)
956 m_CommitDate
.GetTime(date
);
957 m_CommitTime
.GetTime(time
);
958 dateTime
.Format(_T("--date=%sT%s"), date
.Format(_T("%Y-%m-%d")), time
.Format(_T("%H:%M:%S")));
962 author
.Format(_T("--author=\"%s\""), m_sAuthor
);
963 CString allowEmpty
= m_bCommitMessageOnly
? _T("--allow-empty") : _T("");
964 cmd
.Format(_T("git.exe commit %s %s %s %s -F \"%s\""), author
, dateTime
, amend
, allowEmpty
, tempfile
);
966 CCommitProgressDlg progress
;
967 progress
.m_bBufferAll
=true; // improve show speed when there are many file added.
968 progress
.m_GitCmd
=cmd
;
969 progress
.m_bShowCommand
= FALSE
; // don't show the commit command
970 progress
.m_PreText
= out
; // show any output already generated in log window
972 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
974 if (status
|| m_bNoPostActions
|| m_bAutoClose
)
978 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_MENUSVNDCOMMIT
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_DCOMMIT
; }));
980 postCmdList
.push_back(PostCmd(IDI_PUSH
, IDS_MENUPUSH
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_PUSH
; }));
981 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUPULL
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_PULL
; }));
982 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_PROC_COMMIT_RECOMMIT
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_RECOMMIT
; }));
983 postCmdList
.push_back(PostCmd(IDI_TAG
, IDS_MENUTAG
, [&]{ m_PostCmd
= GIT_POSTCOMMIT_CMD_CREATETAG
; }));
986 m_PostCmd
= GIT_POSTCOMMIT_CMD_NOTHING
;
989 if (progress
.m_GitStatus
|| m_PostCmd
== GIT_POSTCOMMIT_CMD_RECOMMIT
)
991 bCloseCommitDlg
= false;
992 if (m_PostCmd
== GIT_POSTCOMMIT_CMD_RECOMMIT
)
994 if (!m_sLogMessage
.IsEmpty())
996 m_History
.AddEntry(m_sLogMessage
);
1000 this->m_sLogMessage
.Empty();
1001 GetCommitTemplate(m_sLogMessage
);
1002 RunStartCommitHook();
1003 m_cLogMessage
.SetText(m_sLogMessage
);
1004 if (m_bCreateNewBranch
)
1006 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_SHOW
);
1007 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_HIDE
);
1009 m_bCreateNewBranch
= FALSE
;
1013 m_bCommitAmend
= FALSE
;
1016 this->BringWindowToTop();
1019 ::DeleteFile(tempfile
);
1021 if (m_BugTraqProvider
&& progress
.m_GitStatus
== 0)
1023 CComPtr
<IBugTraqProvider2
> pProvider
= NULL
;
1024 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
1027 ATL::CComBSTR
commonRoot(g_Git
.m_CurrentDir
);
1028 CBstrSafeVector
pathList(m_selectedPathList
.GetCount());
1030 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
1031 pathList
.PutElement(index
, m_selectedPathList
[index
].GetGitPathString());
1033 ATL::CComBSTR
logMessage(m_sLogMessage
);
1036 if (g_Git
.GetHash(hash
, _T("HEAD")))
1037 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR
);
1038 LONG version
= g_Git
.Hash2int(hash
);
1041 if (FAILED(hr
= pProvider
->OnCommitFinished(GetSafeHwnd(),
1048 CString sErr
= temp
;
1049 if (!sErr
.IsEmpty())
1050 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1054 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, ce
.GetSource().c_str(), ce
.GetMessageAndDescription().c_str());
1055 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1060 RestoreFiles(progress
.m_GitStatus
== 0);
1061 if (((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit"), TRUE
)) == TRUE
)
1063 BOOL cancel
= FALSE
;
1064 mgtReAddAfterCommit
.Execute(cancel
);
1067 else if(bAddSuccess
)
1069 CMessageBox::Show(this->m_hWnd
, IDS_ERROR_NOTHING_COMMIT
, IDS_COMMIT_FINISH
, MB_OK
| MB_ICONINFORMATION
);
1070 bCloseCommitDlg
=false;
1074 m_regAddBeforeCommit
= m_bShowUnversioned
;
1075 m_regKeepChangelists
= m_bKeepChangeList
;
1076 m_regDoNotAutoselectSubmodules
= m_bDoNotAutoselectSubmodules
;
1077 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
1078 m_bKeepChangeList
= FALSE
;
1079 InterlockedExchange(&m_bBlock
, FALSE
);
1081 if (!m_sLogMessage
.IsEmpty())
1083 m_History
.AddEntry(m_sLogMessage
);
1089 if( bCloseCommitDlg
)
1090 CResizableStandAloneDialog::OnOK();
1092 CShellUpdater::Instance().Flush();
1095 void CCommitDlg::SaveSplitterPos()
1099 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
1101 m_wndSplitter
.GetWindowRect(&rectSplitter
);
1102 ScreenToClient(&rectSplitter
);
1103 regPos
= rectSplitter
.top
;
1107 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
1109 return ((CCommitDlg
*)pVoid
)->StatusThread();
1112 UINT
CCommitDlg::StatusThread()
1114 //get the status of all selected file/folders recursively
1115 //and show the ones which have to be committed to the user
1116 //in a list control.
1117 InterlockedExchange(&m_bBlock
, TRUE
);
1118 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
1119 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
1121 m_pathwatcher
.Stop();
1123 m_ListCtrl
.SetBusy(true);
1124 g_Git
.RefreshGitIndex();
1126 m_bCancelled
= false;
1128 DialogEnableWindow(IDOK
, false);
1129 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
1130 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
1131 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, false);
1132 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
1133 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
1134 DialogEnableWindow(IDC_COMMIT_AMEND
, FALSE
);
1135 DialogEnableWindow(IDC_COMMIT_AMENDDIFF
, FALSE
);
1136 // read the list of recent log entries before querying the WC for status
1137 // -> the user may select one and modify / update it while we are crawling the WC
1139 DialogEnableWindow(IDC_CHECKALL
, false);
1140 DialogEnableWindow(IDC_CHECKNONE
, false);
1141 DialogEnableWindow(IDC_CHECKUNVERSIONED
, false);
1142 DialogEnableWindow(IDC_CHECKVERSIONED
, false);
1143 DialogEnableWindow(IDC_CHECKADDED
, false);
1144 DialogEnableWindow(IDC_CHECKDELETED
, false);
1145 DialogEnableWindow(IDC_CHECKMODIFIED
, false);
1146 DialogEnableWindow(IDC_CHECKFILES
, false);
1147 DialogEnableWindow(IDC_CHECKSUBMODULES
, false);
1149 if (m_History
.IsEmpty())
1152 reg
.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR
)m_ListCtrl
.m_sUUID
);
1153 reg
.Replace(_T(':'),_T('_'));
1154 m_History
.Load(reg
, _T("logmsgs"));
1157 // Initialise the list control with the status of the files/folders below us
1160 CTGitPathList
*pList
;
1161 m_ListCtrl
.m_amend
= (m_bCommitAmend
==TRUE
|| m_bForceCommitAmend
) && (m_bAmendDiffToLastCommit
==FALSE
);
1162 m_ListCtrl
.m_bDoNotAutoselectSubmodules
= (m_bDoNotAutoselectSubmodules
== TRUE
);
1164 if(m_bWholeProject
|| m_bWholeProject2
)
1167 pList
= &m_pathList
;
1169 success
=m_ListCtrl
.GetStatus(pList
);
1171 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1172 if(this->m_bShowUnversioned
)
1173 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
1175 m_ListCtrl
.CheckIfChangelistsArePresent(false);
1177 DWORD dwShow
= GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWLOCKS
| GITSLC_SHOWINCHANGELIST
| GITSLC_SHOWDIRECTFILES
;
1178 dwShow
|= DWORD(m_regAddBeforeCommit
) ? GITSLC_SHOWUNVERSIONED
: 0;
1181 if (!m_checkedPathList
.IsEmpty())
1182 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
1185 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
1186 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
1187 m_ListCtrl
.Show(dwShow
, dwCheck
);
1188 m_bSelectFilesForCommit
= true;
1191 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
1193 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
1194 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
1197 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
1198 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
1202 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
1203 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
1204 m_ListCtrl
.Show(dwShow
);
1208 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
1209 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
1210 && !PathFileExists(dotGitPath
+ _T("MERGE_HEAD")))
1213 temp
.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
);
1214 if (CMessageBox::ShowCheck(m_hWnd
, temp
, _T("TortoiseGit"), MB_ICONINFORMATION
| MB_YESNO
, _T("NothingToCommitShowUnversioned"), NULL
)==IDYES
)
1216 m_bShowUnversioned
= TRUE
;
1217 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
1218 DWORD dwShow
= (DWORD
)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWUNVERSIONED
| GITSLC_SHOWLOCKS
);
1219 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
1220 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
1227 // we don't have to block the commit dialog while we fetch the
1228 // auto completion list.
1229 m_pathwatcher
.ClearChangedPaths();
1230 InterlockedExchange(&m_bBlock
, FALSE
);
1231 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE
)==TRUE
)
1233 m_ListCtrl
.Block(TRUE
, TRUE
);
1234 GetAutocompletionList();
1235 m_ListCtrl
.Block(FALSE
, FALSE
);
1237 SendMessage(WM_UPDATEOKBUTTON
);
1240 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
1241 DialogEnableWindow(IDC_WHOLE_PROJECT
, !m_bWholeProject2
);
1242 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, true);
1243 if (m_ListCtrl
.HasChangeLists())
1244 DialogEnableWindow(IDC_KEEPLISTS
, true);
1246 // activate amend checkbox (if necessary)
1247 if (g_Git
.IsInitRepos())
1249 m_bCommitAmend
= FALSE
;
1250 SendMessage(WM_UPDATEDATAFALSE
);
1254 if (m_bForceCommitAmend
)
1256 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
1257 m_bCommitAmend
= TRUE
;
1258 SendMessage(WM_UPDATEDATAFALSE
);
1261 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(TRUE
);
1264 if (g_Git
.GetHash(hash
, _T("HEAD")))
1266 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
1268 if (!hash
.IsEmpty())
1270 GitRev headRevision
;
1273 headRevision
.GetParentFromHash(hash
);
1278 MessageBox(_T("Could not get parent from HEAD.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
1280 // do not allow to show diff to "last" revision if it has more that one parent
1281 if (headRevision
.ParentsCount() != 1)
1283 m_bAmendDiffToLastCommit
= TRUE
;
1284 SendMessage(WM_UPDATEDATAFALSE
);
1287 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->EnableWindow(TRUE
);
1293 // we have the list, now signal the main thread about it
1294 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
1297 InterlockedExchange(&m_bRunThread
, FALSE
);
1298 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1299 // force the cursor to normal
1305 void CCommitDlg::SetDlgTitle()
1307 if (m_sTitle
.IsEmpty())
1308 GetWindowText(m_sTitle
);
1310 if (m_bWholeProject
|| m_bWholeProject2
)
1311 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
1314 if (m_pathList
.GetCount() == 1)
1315 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.CombinePath(m_pathList
[0].GetUIPathString()), m_sTitle
);
1317 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.CombinePath(m_ListCtrl
.GetCommonDirectory(false)), m_sTitle
);
1321 void CCommitDlg::OnCancel()
1323 m_bCancelled
= true;
1324 m_pathwatcher
.Stop();
1326 if (m_bThreadRunning
)
1328 InterlockedExchange(&m_bRunThread
, FALSE
);
1329 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
1330 if (m_bThreadRunning
)
1332 // we gave the thread a chance to quit. Since the thread didn't
1333 // listen to us we have to kill it.
1334 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1335 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1340 m_sLogMessage
= m_cLogMessage
.GetText();
1341 if (!m_sBugID
.IsEmpty())
1343 m_sBugID
.Replace(_T(", "), _T(","));
1344 m_sBugID
.Replace(_T(" ,"), _T(","));
1345 CString sBugID
= m_ProjectProperties
.sMessage
;
1346 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
1347 if (m_ProjectProperties
.bAppend
)
1348 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
1350 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
1352 if ((m_sLogTemplate
.Compare(m_sLogMessage
) != 0) && !m_sLogMessage
.IsEmpty())
1354 m_History
.AddEntry(m_sLogMessage
);
1359 CResizableStandAloneDialog::OnCancel();
1362 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1365 m_tooltips
.RelayEvent(pMsg
);
1369 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1374 if (pMsg
->message
== WM_KEYDOWN
)
1376 switch (pMsg
->wParam
)
1381 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1387 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1389 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1391 PostMessage(WM_COMMAND
, IDOK
);
1395 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1397 // Pressing RETURN in the bug id control
1398 // moves the focus to the message
1399 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1407 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1410 void CCommitDlg::Refresh()
1412 if (m_bThreadRunning
)
1415 InterlockedExchange(&m_bBlock
, TRUE
);
1416 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1417 if (m_pThread
==NULL
)
1419 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1420 InterlockedExchange(&m_bBlock
, FALSE
);
1424 m_pThread
->m_bAutoDelete
= FALSE
;
1425 m_pThread
->ResumeThread();
1429 void CCommitDlg::OnBnClickedShowunversioned()
1431 m_tooltips
.Pop(); // hide the tooltips
1433 m_regAddBeforeCommit
= m_bShowUnversioned
;
1436 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1437 if (DWORD(m_regAddBeforeCommit
))
1438 dwShow
|= GITSLC_SHOWUNVERSIONED
;
1440 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
1441 if(dwShow
& GITSLC_SHOWUNVERSIONED
)
1443 if (m_bWholeProject
|| m_bWholeProject2
)
1444 m_ListCtrl
.GetStatus(NULL
,false,false,true);
1446 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1448 m_ListCtrl
.Show(dwShow
, 0, true, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
1453 void CCommitDlg::OnStnClickedExternalwarning()
1458 void CCommitDlg::OnEnChangeLogmessage()
1460 SendMessage(WM_UPDATEOKBUTTON
);
1463 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1466 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1468 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1470 m_bShowUnversioned
= TRUE
;
1471 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1472 m_ListCtrl
.Show(dwShow
);
1480 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1486 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM
/*lParam*/)
1490 SetForegroundWindow();
1492 // if multiple files/folders are dropped
1493 // this handler is called for every single item
1495 // To avoid creating multiple refresh threads and
1496 // causing crashes, we only add the items to the
1497 // list control and start a timer.
1498 // When the timer expires, we start the refresh thread,
1499 // but only if it isn't already running - otherwise we
1500 // restart the timer.
1502 path
.SetFromWin((LPCTSTR
)lParam
);
1504 // just add all the items we get here.
1505 // if the item is versioned, the add will fail but nothing
1506 // more will happen.
1508 Git
.Add(CTGitPathList(path
), &m_ProjectProperties
, Git_depth_empty
, false, true, true);
1510 if (!m_ListCtrl
.HasPath(path
))
1512 if (m_pathList
.AreAllPathsFiles())
1514 m_pathList
.AddPath(path
);
1515 m_pathList
.RemoveDuplicates();
1516 m_updatedPathList
.AddPath(path
);
1517 m_updatedPathList
.RemoveDuplicates();
1521 // if the path list contains folders, we have to check whether
1522 // our just (maybe) added path is a child of one of those. If it is
1523 // a child of a folder already in the list, we must not add it. Otherwise
1524 // that path could show up twice in the list.
1525 bool bHasParentInList
= false;
1526 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1528 if (m_pathList
[i
].IsAncestorOf(path
))
1530 bHasParentInList
= true;
1534 if (!bHasParentInList
)
1536 m_pathList
.AddPath(path
);
1537 m_pathList
.RemoveDuplicates();
1538 m_updatedPathList
.AddPath(path
);
1539 m_updatedPathList
.RemoveDuplicates();
1544 // Always start the timer, since the status of an existing item might have changed
1545 SetTimer(REFRESHTIMER
, 200, NULL
);
1546 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": Item %s dropped, timer started\n"), path
.GetWinPath());
1551 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1553 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1557 //////////////////////////////////////////////////////////////////////////
1558 // functions which run in the status thread
1559 //////////////////////////////////////////////////////////////////////////
1561 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1566 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1567 while (m_bRunThread
&& file
.ReadString(strLine
))
1569 int eqpos
= strLine
.Find('=');
1571 rgx
= strLine
.Mid(eqpos
+1).Trim();
1574 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1576 mapRegex
[strLine
.Left(pos
)] = rgx
;
1577 strLine
= strLine
.Mid(pos
+1).Trim();
1579 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1583 catch (CFileException
* pE
)
1585 CTraceToOutputDebugString::Instance()(__FUNCTION__
": CFileException loading auto list regex file\n");
1590 void CCommitDlg::ParseSnippetFile(const CString
& sFile
, std::map
<CString
, CString
>& mapSnippet
)
1595 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1596 while (m_bRunThread
&& file
.ReadString(strLine
))
1598 if (strLine
.IsEmpty())
1600 if (strLine
.Left(1) == _T('#')) // comment char
1602 int eqpos
= strLine
.Find('=');
1603 CString key
= strLine
.Left(eqpos
);
1604 CString value
= strLine
.Mid(eqpos
+ 1);
1605 value
.Replace(_T("\\\t"), _T("\t"));
1606 value
.Replace(_T("\\\r"), _T("\r"));
1607 value
.Replace(_T("\\\n"), _T("\n"));
1608 value
.Replace(_T("\\\\"), _T("\\"));
1609 mapSnippet
[key
] = value
;
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
);
1648 CString sSnippetFile
= CPathUtils::GetAppDirectory();
1649 sSnippetFile
+= _T("snippet.txt");
1650 ParseSnippetFile(sSnippetFile
, m_snippet
);
1651 SHGetFolderPath(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, sSnippetFile
.GetBuffer(MAX_PATH
+1));
1652 sSnippetFile
.ReleaseBuffer();
1653 sSnippetFile
+= _T("\\TortoiseGit\\snippet.txt");
1654 if (PathFileExists(sSnippetFile
))
1655 ParseSnippetFile(sSnippetFile
, m_snippet
);
1656 for (auto snip
: m_snippet
)
1657 m_autolist
.insert(std::make_pair(snip
.first
, AUTOCOMPLETE_SNIPPET
));
1659 DWORD starttime
= GetTickCount();
1661 // now we have two arrays of strings, where the first array contains all
1662 // file extensions we can use and the second the corresponding regex strings
1663 // to apply to those files.
1665 // the next step is to go over all files shown in the commit dialog
1666 // and scan them for strings we can use
1667 int nListItems
= m_ListCtrl
.GetItemCount();
1669 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1671 // stop parsing after timeout
1672 if ((!m_bRunThread
) || (GetTickCount() - starttime
> timeoutvalue
))
1675 CTGitPath
*path
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1680 CString sPartPath
=path
->GetGitPathString();
1681 m_autolist
.insert(std::make_pair(sPartPath
, AUTOCOMPLETE_FILENAME
));
1685 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1689 m_autolist
.insert(std::make_pair(sPartPath
.Mid(pos
), AUTOCOMPLETE_FILENAME
));
1692 // Last inserted entry is a file name.
1693 // Some users prefer to also list file name without extension.
1694 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE
))
1696 int dotPos
= sPartPath
.ReverseFind('.');
1697 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1698 m_autolist
.insert(std::make_pair(sPartPath
.Mid(lastPos
, dotPos
- lastPos
), AUTOCOMPLETE_FILENAME
));
1701 if (path
->m_Action
== CTGitPath::LOGACTIONS_UNVER
&& !CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseUnversioned"), FALSE
))
1703 if (path
->m_Action
== CTGitPath::LOGACTIONS_IGNORE
|| path
->m_Action
== CTGitPath::LOGACTIONS_DELETED
)
1706 CString sExt
= path
->GetFileExtension();
1708 // find the regex string which corresponds to the file extension
1709 CString rdata
= mapRegex
[sExt
];
1710 if (rdata
.IsEmpty())
1713 ScanFile(path
->GetWinPathString(), rdata
, sExt
);
1715 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": Auto completion list loaded in %d msec\n"), GetTickCount() - starttime
);
1718 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
, const CString
& sExt
)
1720 static std::map
<CString
, std::tr1::wregex
> regexmap
;
1722 std::wstring sFileContent
;
1723 CAutoFile hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
1726 DWORD size
= GetFileSize(hFile
, NULL
);
1727 if (size
> CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseMaxSize"), 300000L))
1729 // no files bigger than 300k
1732 // allocate memory to hold file contents
1733 std::unique_ptr
<char[]> buffer(new char[size
]);
1735 if (!ReadFile(hFile
, buffer
.get(), size
, &readbytes
, NULL
))
1738 IsTextUnicode(buffer
.get(), readbytes
, &opts
);
1739 if (opts
& IS_TEXT_UNICODE_NULL_BYTES
)
1743 if (opts
& IS_TEXT_UNICODE_UNICODE_MASK
)
1745 sFileContent
= std::wstring((wchar_t*)buffer
.get(), readbytes
/ sizeof(WCHAR
));
1747 if ((opts
& IS_TEXT_UNICODE_NOT_UNICODE_MASK
) || (opts
== 0))
1749 const int ret
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
.get(), readbytes
, NULL
, 0);
1750 std::unique_ptr
<wchar_t[]> pWideBuf(new wchar_t[ret
]);
1751 const int ret2
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
.get(), readbytes
, pWideBuf
.get(), ret
);
1753 sFileContent
= std::wstring(pWideBuf
.get(), ret
);
1756 if (sFileContent
.empty() || !m_bRunThread
)
1764 std::tr1::wregex regCheck
;
1765 std::map
<CString
, std::tr1::wregex
>::const_iterator regIt
;
1766 if ((regIt
= regexmap
.find(sExt
)) != regexmap
.end())
1767 regCheck
= regIt
->second
;
1770 regCheck
= std::tr1::wregex(sRegex
, std::tr1::regex_constants::icase
| std::tr1::regex_constants::ECMAScript
);
1771 regexmap
[sExt
] = regCheck
;
1773 const std::tr1::wsregex_iterator end
;
1774 for (std::tr1::wsregex_iterator
it(sFileContent
.begin(), sFileContent
.end(), regCheck
); it
!= end
; ++it
)
1776 const std::tr1::wsmatch match
= *it
;
1777 for (size_t i
= 1; i
< match
.size(); ++i
)
1779 if (match
[i
].second
-match
[i
].first
)
1781 m_autolist
.insert(std::make_pair(std::wstring(match
[i
]).c_str(), AUTOCOMPLETE_PROGRAMCODE
));
1786 catch (std::exception
) {}
1789 // CSciEditContextMenuInterface
1790 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1792 CString sMenuItemText
;
1793 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITHASH
);
1794 m_nPopupPickCommitHash
= nCmd
++;
1795 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPickCommitHash
, sMenuItemText
);
1797 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITMESSAGE
);
1798 m_nPopupPickCommitMessage
= nCmd
++;
1799 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPickCommitMessage
, sMenuItemText
);
1801 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTEFILELIST
);
1802 m_nPopupPasteListCmd
= nCmd
++;
1803 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
1805 if (!m_History
.IsEmpty())
1807 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
1808 m_nPopupPasteLastMessage
= nCmd
++;
1809 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
1811 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
1812 m_nPopupRecentMessage
= nCmd
++;
1813 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
1817 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
1819 if (cmd
== m_nPopupPickCommitHash
)
1821 // use the git log to allow selection of a version
1823 // tell the dialog to use mode for selecting revisions
1824 dlg
.SetSelect(true);
1825 // only one revision must be selected however
1826 dlg
.SingleSelection(true);
1827 if (dlg
.DoModal() == IDOK
)
1829 // get selected hash if any
1830 CString selectedHash
= dlg
.GetSelectedHash();
1831 pSciEdit
->InsertText(selectedHash
);
1836 if (cmd
== m_nPopupPickCommitMessage
)
1838 // use the git log to allow selection of a version
1840 // tell the dialog to use mode for selecting revisions
1841 dlg
.SetSelect(true);
1842 // only one revision must be selected however
1843 dlg
.SingleSelection(true);
1844 if (dlg
.DoModal() == IDOK
)
1846 // get selected hash if any
1847 CString selectedHash
= dlg
.GetSelectedHash();
1849 rev
.GetCommit(selectedHash
);
1850 CString message
= rev
.GetSubject() + _T("\r\n") + rev
.GetBody();
1851 pSciEdit
->InsertText(message
);
1856 if (cmd
== m_nPopupPasteListCmd
)
1859 int nListItems
= m_ListCtrl
.GetItemCount();
1860 for (int i
=0; i
<nListItems
; ++i
)
1862 CTGitPath
* entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1863 if (entry
&&entry
->m_Checked
)
1866 CString status
= entry
->GetActionName();
1867 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1868 status
= _T("Add"); // I18N TODO
1870 //git_wc_status_kind status = entry->status;
1871 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1872 if (m_ProjectProperties
.bFileListInEnglish
)
1875 line
.Format(_T("%-10s %s\r\n"),status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
,0));
1879 pSciEdit
->InsertText(logmsg
);
1883 if(cmd
== m_nPopupPasteLastMessage
)
1885 if (m_History
.IsEmpty())
1889 logmsg
+=m_History
.GetEntry(0);
1890 pSciEdit
->InsertText(logmsg
);
1894 if(cmd
== m_nPopupRecentMessage
)
1896 OnBnClickedHistory();
1902 void CCommitDlg::HandleSnippet(int type
, const CString
&text
, CSciEdit
*pSciEdit
)
1904 if (type
== AUTOCOMPLETE_SNIPPET
)
1906 CString target
= m_snippet
[text
];
1907 pSciEdit
->GetWordUnderCursor(true);
1908 pSciEdit
->InsertText(target
, false);
1912 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
1916 case ENDDIALOGTIMER
:
1917 KillTimer(ENDDIALOGTIMER
);
1921 if (m_bThreadRunning
)
1923 SetTimer(REFRESHTIMER
, 200, NULL
);
1924 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Wait some more before refreshing\n");
1928 KillTimer(REFRESHTIMER
);
1929 CTraceToOutputDebugString::Instance()(__FUNCTION__
": Refreshing after items dropped\n");
1933 case FILLPATCHVTIMER
:
1937 __super::OnTimer(nIDEvent
);
1940 void CCommitDlg::OnBnClickedHistory()
1942 m_tooltips
.Pop(); // hide the tooltips
1943 if (m_pathList
.IsEmpty())
1946 CHistoryDlg historyDlg
;
1947 historyDlg
.SetHistory(m_History
);
1948 if (historyDlg
.DoModal() != IDOK
)
1951 CString sMsg
= historyDlg
.GetSelectedText();
1952 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
1954 CString sBugID
= m_ProjectProperties
.FindBugID(sMsg
);
1955 if ((!sBugID
.IsEmpty()) && ((GetDlgItem(IDC_BUGID
)->IsWindowVisible())))
1957 SetDlgItemText(IDC_BUGID
, sBugID
);
1959 if (m_sLogTemplate
.Compare(m_cLogMessage
.GetText()) != 0)
1960 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
1962 m_cLogMessage
.SetText(sMsg
);
1965 SendMessage(WM_UPDATEOKBUTTON
);
1966 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1970 void CCommitDlg::OnBnClickedBugtraqbutton()
1972 m_tooltips
.Pop(); // hide the tooltips
1973 CString sMsg
= m_cLogMessage
.GetText();
1975 if (m_BugTraqProvider
== NULL
)
1978 ATL::CComBSTR
parameters(m_bugtraq_association
.GetParameters());
1979 ATL::CComBSTR
commonRoot(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
1980 CBstrSafeVector
pathList(m_pathList
.GetCount());
1982 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
1983 pathList
.PutElement(index
, m_pathList
[index
].GetGitPathString());
1985 ATL::CComBSTR
originalMessage(sMsg
);
1988 // first try the IBugTraqProvider2 interface
1989 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
1990 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
1991 bool bugIdOutSet
= false;
1994 ATL::CComBSTR
repositoryRoot(g_Git
.m_CurrentDir
);
1995 ATL::CComBSTR bugIDOut
;
1996 GetDlgItemText(IDC_BUGID
, m_sBugID
);
1997 ATL::CComBSTR
bugID(m_sBugID
);
1998 CBstrSafeVector revPropNames
;
1999 CBstrSafeVector revPropValues
;
2000 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
2003 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2004 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2011 m_sBugID
= bugIDOut
;
2012 SetDlgItemText(IDC_BUGID
, m_sBugID
);
2014 m_cLogMessage
.SetText((LPCTSTR
)temp
);
2015 BSTR HUGEP
*pbRevNames
;
2016 BSTR HUGEP
*pbRevValues
;
2018 HRESULT hr1
= SafeArrayAccessData(revPropNames
, (void HUGEP
**)&pbRevNames
);
2021 HRESULT hr2
= SafeArrayAccessData(revPropValues
, (void HUGEP
**)&pbRevValues
);
2024 if (revPropNames
->rgsabound
->cElements
== revPropValues
->rgsabound
->cElements
)
2026 for (ULONG i
= 0; i
< revPropNames
->rgsabound
->cElements
; ++i
)
2028 // m_revProps[pbRevNames[i]] = pbRevValues[i];
2031 SafeArrayUnaccessData(revPropValues
);
2033 SafeArrayUnaccessData(revPropNames
);
2039 // if IBugTraqProvider2 failed, try IBugTraqProvider
2040 CComPtr
<IBugTraqProvider
> pProvider
= NULL
;
2041 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
2045 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2046 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2050 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
2053 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
2054 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
2057 m_cLogMessage
.SetText((LPCTSTR
)temp
);
2059 m_sLogMessage
= m_cLogMessage
.GetText();
2060 if (!m_ProjectProperties
.sMessage
.IsEmpty())
2062 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
2063 if (!sBugID
.IsEmpty() && !bugIdOutSet
)
2065 SetDlgItemText(IDC_BUGID
, sBugID
);
2069 m_cLogMessage
.SetFocus();
2072 void CCommitDlg::FillPatchView(bool onlySetTimer
)
2074 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2076 KillTimer(FILLPATCHVTIMER
);
2079 SetTimer(FILLPATCHVTIMER
, 100, NULL
);
2083 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
2088 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
2089 CTGitPath
* p
=(CTGitPath
*)m_ListCtrl
.GetItemData(nSelect
);
2090 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
2092 CString head
= _T("HEAD");
2093 if(m_bCommitAmend
==TRUE
&& m_bAmendDiffToLastCommit
==FALSE
)
2094 head
= _T("HEAD~1");
2095 cmd
.Format(_T("git.exe diff %s -- \"%s\""), head
, p
->GetGitPathString());
2096 g_Git
.Run(cmd
, &out
, CP_UTF8
);
2100 m_patchViewdlg
.SetText(out
);
2103 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM
/*wparam*/, LPARAM
/*lparam*/)
2105 this->FillPatchView(true);
2110 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
2112 SendMessage(WM_UPDATEOKBUTTON
);
2116 LRESULT
CCommitDlg::OnCheck(WPARAM wnd
, LPARAM
)
2118 HWND hwnd
= (HWND
)wnd
;
2119 bool check
= !(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
2120 if (hwnd
== GetDlgItem(IDC_CHECKALL
)->GetSafeHwnd())
2121 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, check
);
2122 else if (hwnd
== GetDlgItem(IDC_CHECKNONE
)->GetSafeHwnd())
2123 m_ListCtrl
.Check(GITSLC_SHOWEVERYTHING
, !check
);
2124 else if (hwnd
== GetDlgItem(IDC_CHECKUNVERSIONED
)->GetSafeHwnd())
2125 m_ListCtrl
.Check(GITSLC_SHOWUNVERSIONED
, check
);
2126 else if (hwnd
== GetDlgItem(IDC_CHECKVERSIONED
)->GetSafeHwnd())
2127 m_ListCtrl
.Check(GITSLC_SHOWVERSIONED
, check
);
2128 else if (hwnd
== GetDlgItem(IDC_CHECKADDED
)->GetSafeHwnd())
2129 m_ListCtrl
.Check(GITSLC_SHOWADDED
, check
);
2130 else if (hwnd
== GetDlgItem(IDC_CHECKDELETED
)->GetSafeHwnd())
2131 m_ListCtrl
.Check(GITSLC_SHOWREMOVED
, check
);
2132 else if (hwnd
== GetDlgItem(IDC_CHECKMODIFIED
)->GetSafeHwnd())
2133 m_ListCtrl
.Check(GITSLC_SHOWMODIFIED
, check
);
2134 else if (hwnd
== GetDlgItem(IDC_CHECKFILES
)->GetSafeHwnd())
2135 m_ListCtrl
.Check(GITSLC_SHOWFILES
, check
);
2136 else if (hwnd
== GetDlgItem(IDC_CHECKSUBMODULES
)->GetSafeHwnd())
2137 m_ListCtrl
.Check(GITSLC_SHOWSUBMODULES
, check
);
2142 LRESULT
CCommitDlg::OnUpdateOKButton(WPARAM
, LPARAM
)
2147 bool bValidLogSize
= m_cLogMessage
.GetText().GetLength() >= m_ProjectProperties
.nMinLogSize
&& m_cLogMessage
.GetText().GetLength() > 0;
2148 bool bAmendOrSelectFilesOrMerge
= m_ListCtrl
.GetSelected() > 0 || (m_bCommitAmend
&& m_bAmendDiffToLastCommit
) || CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
2150 DialogEnableWindow(IDOK
, bValidLogSize
&& (m_bCommitMessageOnly
|| bAmendOrSelectFilesOrMerge
));
2155 LRESULT
CCommitDlg::OnUpdateDataFalse(WPARAM
, LPARAM
)
2161 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
2165 if (wParam
== IDC_SPLITTER
)
2167 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
2168 DoSize(pHdr
->delta
);
2173 return __super::DefWindowProc(message
, wParam
, lParam
);
2176 void CCommitDlg::SetSplitterRange()
2178 if ((m_ListCtrl
)&&(m_cLogMessage
))
2181 m_cLogMessage
.GetWindowRect(rcTop
);
2182 ScreenToClient(rcTop
);
2184 m_ListCtrl
.GetWindowRect(rcMiddle
);
2185 ScreenToClient(rcMiddle
);
2186 if (rcMiddle
.Height() && rcMiddle
.Width())
2187 m_wndSplitter
.SetRange(rcTop
.top
+ 100, rcMiddle
.bottom
- 80);
2191 void CCommitDlg::DoSize(int delta
)
2193 RemoveAnchor(IDC_MESSAGEGROUP
);
2194 RemoveAnchor(IDC_LOGMESSAGE
);
2195 RemoveAnchor(IDC_SPLITTER
);
2196 RemoveAnchor(IDC_SIGNOFF
);
2197 RemoveAnchor(IDC_COMMIT_AMEND
);
2198 RemoveAnchor(IDC_COMMIT_AMENDDIFF
);
2199 RemoveAnchor(IDC_COMMIT_SETDATETIME
);
2200 RemoveAnchor(IDC_COMMIT_DATEPICKER
);
2201 RemoveAnchor(IDC_COMMIT_TIMEPICKER
);
2202 RemoveAnchor(IDC_COMMIT_SETAUTHOR
);
2203 RemoveAnchor(IDC_COMMIT_AUTHORDATA
);
2204 RemoveAnchor(IDC_LISTGROUP
);
2205 RemoveAnchor(IDC_FILELIST
);
2206 RemoveAnchor(IDC_TEXT_INFO
);
2207 RemoveAnchor(IDC_SELECTLABEL
);
2208 RemoveAnchor(IDC_CHECKALL
);
2209 RemoveAnchor(IDC_CHECKNONE
);
2210 RemoveAnchor(IDC_CHECKUNVERSIONED
);
2211 RemoveAnchor(IDC_CHECKVERSIONED
);
2212 RemoveAnchor(IDC_CHECKADDED
);
2213 RemoveAnchor(IDC_CHECKDELETED
);
2214 RemoveAnchor(IDC_CHECKMODIFIED
);
2215 RemoveAnchor(IDC_CHECKFILES
);
2216 RemoveAnchor(IDC_CHECKSUBMODULES
);
2218 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
2219 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
2220 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
2221 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
2222 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
2223 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
2224 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF
),0,delta
);
2225 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME
),0,delta
);
2226 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER
),0,delta
);
2227 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER
),0,delta
);
2228 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETAUTHOR
), 0, delta
);
2229 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AUTHORDATA
), 0, delta
);
2230 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
2231 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL
), 0, delta
);
2232 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL
), 0, delta
);
2233 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE
), 0, delta
);
2234 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED
), 0, delta
);
2235 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED
), 0, delta
);
2236 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED
), 0, delta
);
2237 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED
), 0, delta
);
2238 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED
), 0, delta
);
2239 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES
), 0, delta
);
2240 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES
), 0, delta
);
2242 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
2243 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
2244 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
2245 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
2246 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
2247 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
2248 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
2249 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
2250 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
2251 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
2252 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
2253 AddAnchor(IDC_COMMIT_SETAUTHOR
, TOP_LEFT
);
2254 AddAnchor(IDC_COMMIT_AUTHORDATA
, TOP_LEFT
, TOP_RIGHT
);
2255 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
2256 AddAnchor(IDC_SELECTLABEL
, TOP_LEFT
);
2257 AddAnchor(IDC_CHECKALL
, TOP_LEFT
);
2258 AddAnchor(IDC_CHECKNONE
, TOP_LEFT
);
2259 AddAnchor(IDC_CHECKUNVERSIONED
, TOP_LEFT
);
2260 AddAnchor(IDC_CHECKVERSIONED
, TOP_LEFT
);
2261 AddAnchor(IDC_CHECKADDED
, TOP_LEFT
);
2262 AddAnchor(IDC_CHECKDELETED
, TOP_LEFT
);
2263 AddAnchor(IDC_CHECKMODIFIED
, TOP_LEFT
);
2264 AddAnchor(IDC_CHECKFILES
, TOP_LEFT
);
2265 AddAnchor(IDC_CHECKSUBMODULES
, TOP_LEFT
);
2267 // adjust the minimum size of the dialog to prevent the resizing from
2268 // moving the list control too far down.
2270 m_cLogMessage
.GetClientRect(rcLogMsg
);
2271 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
2274 m_cLogMessage
.Invalidate();
2275 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
2278 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
2280 // first, let the resizing take place
2281 __super::OnSize(nType
, cx
, cy
);
2287 CString
CCommitDlg::GetSignedOffByLine()
2291 CString username
= g_Git
.GetUserName();
2292 CString email
= g_Git
.GetUserEmail();
2293 username
.Remove(_T('\n'));
2294 email
.Remove(_T('\n'));
2296 str
.Format(_T("Signed-off-by: %s <%s>"), username
, email
);
2301 void CCommitDlg::OnBnClickedSignOff()
2303 CString str
= GetSignedOffByLine();
2305 if (m_cLogMessage
.GetText().Find(str
) == -1) {
2306 m_cLogMessage
.SetText(m_cLogMessage
.GetText().TrimRight());
2307 int lastNewline
= m_cLogMessage
.GetText().ReverseFind(_T('\n'));
2308 int foundByLine
= -1;
2309 if (lastNewline
> 0)
2310 foundByLine
= m_cLogMessage
.GetText().Find(_T("-by: "), lastNewline
);
2312 if (foundByLine
== -1 || foundByLine
< lastNewline
)
2313 str
= _T("\r\n") + str
;
2315 m_cLogMessage
.SetText(m_cLogMessage
.GetText()+_T("\r\n")+str
+_T("\r\n"));
2319 void CCommitDlg::OnBnClickedCommitAmend()
2322 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
2327 rev
.GetCommit(CString(_T("HEAD")));
2329 catch (const char *msg
)
2331 CMessageBox::Show(m_hWnd
, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
2333 m_AmendStr
=rev
.GetSubject()+_T("\n")+rev
.GetBody();
2336 if(this->m_bCommitAmend
)
2338 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
2339 m_cLogMessage
.SetText(m_AmendStr
);
2340 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
2344 this->m_AmendStr
=this->m_cLogMessage
.GetText();
2345 m_cLogMessage
.SetText(m_NoAmendStr
);
2346 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
2349 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2350 OnBnClickedCommitSetauthor(); // to update the commit author
2352 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
2356 void CCommitDlg::OnBnClickedCommitMessageOnly()
2359 this->m_ListCtrl
.EnableWindow(m_bCommitMessageOnly
? FALSE
: TRUE
);
2360 SendMessage(WM_UPDATEOKBUTTON
);
2363 void CCommitDlg::OnBnClickedWholeProject()
2365 m_tooltips
.Pop(); // hide the tooltips
2370 if (m_bWholeProject
|| m_bWholeProject2
)
2371 m_ListCtrl
.GetStatus(NULL
,true,false,true);
2373 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
2375 m_regShowWholeProject
= m_bWholeProject
;
2377 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
2378 if (DWORD(m_regAddBeforeCommit
))
2379 dwShow
|= GITSLC_SHOWUNVERSIONED
;
2381 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
2383 m_ListCtrl
.Show(dwShow
, dwShow
& ~(CTGitPath::LOGACTIONS_UNVER
), true);
2390 void CCommitDlg::OnFocusMessage()
2392 m_cLogMessage
.SetFocus();
2395 void CCommitDlg::OnFocusFileList()
2397 m_ListCtrl
.SetFocus();
2400 void CCommitDlg::OnScnUpdateUI(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2402 int pos
= (int)this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
2403 int line
= (int)this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
2404 int column
= (int)this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
2407 str
.Format(_T("%d/%d"),line
+1,column
+1);
2408 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
2414 void CCommitDlg::TogglePatchView()
2416 OnStnClickedViewPatch();
2419 void CCommitDlg::OnStnClickedViewPatch()
2421 m_patchViewdlg
.m_pProjectProperties
= &this->m_ProjectProperties
;
2422 m_patchViewdlg
.m_ParentDlg
= this;
2423 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
2425 BOOL viewPatchEnabled
= FALSE
;
2426 viewPatchEnabled
= g_Git
.GetConfigValueBool(_T("tgit.commitshowpatch"));
2427 if (viewPatchEnabled
== FALSE
)
2428 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("true"));
2429 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
2430 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETSCROLLWIDTHTRACKING
, TRUE
);
2432 this->GetWindowRect(&rect
);
2434 m_patchViewdlg
.ShowWindow(SW_SHOW
);
2436 m_patchViewdlg
.SetWindowPos(NULL
,rect
.right
,rect
.top
,rect
.Width(),rect
.Height(),
2437 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
2439 ShowViewPatchText(false);
2444 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2445 m_patchViewdlg
.ShowWindow(SW_HIDE
);
2446 m_patchViewdlg
.DestroyWindow();
2447 ShowViewPatchText(true);
2449 this->m_ctrlShowPatch
.Invalidate();
2452 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
2454 __super::OnMoving(fwSide
, pRect
);
2456 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
2459 m_patchViewdlg
.GetWindowRect(&patchrect
);
2460 if (::IsWindow(m_hWnd
))
2463 GetWindowRect(&thisrect
);
2464 if (patchrect
.left
== thisrect
.right
)
2466 m_patchViewdlg
.SetWindowPos(NULL
, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
2467 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
2474 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
2476 __super::OnSizing(fwSide
, pRect
);
2478 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2480 CRect thisrect
, patchrect
;
2481 this->GetWindowRect(thisrect
);
2482 this->m_patchViewdlg
.GetWindowRect(patchrect
);
2483 if(thisrect
.right
==patchrect
.left
)
2485 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
2486 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
2488 if( patchrect
.bottom
== thisrect
.bottom
)
2490 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
2492 if( patchrect
.top
== thisrect
.top
)
2494 patchrect
.top
-= thisrect
.top
-pRect
->top
;
2496 m_patchViewdlg
.MoveWindow(patchrect
);
2501 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2504 TRACE("Item Changed\r\n");
2507 int CCommitDlg::CheckHeadDetach()
2510 if (CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, output
))
2512 int retval
= CMessageBox::Show(NULL
, IDS_PROC_COMMIT_DETACHEDWARNING
, IDS_APPNAME
, MB_YESNOCANCEL
| MB_ICONWARNING
);
2515 if (CAppUtils::CreateBranchTag(FALSE
, NULL
, true) == FALSE
)
2518 else if (retval
== IDCANCEL
)
2524 void CCommitDlg::OnBnClickedCommitAmenddiff()
2530 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2536 void CCommitDlg::OnBnClickedCommitSetDateTime()
2540 if (m_bSetCommitDateTime
)
2542 CTime authordate
= CTime::GetCurrentTime();
2545 GitRev headRevision
;
2548 headRevision
.GetCommit(_T("HEAD"));
2550 catch (const char *msg
)
2552 CMessageBox::Show(m_hWnd
, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
2554 authordate
= headRevision
.GetAuthorDate();
2557 m_CommitDate
.SetTime(&authordate
);
2558 m_CommitTime
.SetTime(&authordate
);
2560 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_SHOW
);
2561 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_SHOW
);
2565 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_HIDE
);
2566 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_HIDE
);
2570 void CCommitDlg::OnBnClickedCheckNewBranch()
2573 if (m_bCreateNewBranch
)
2575 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_HIDE
);
2576 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_SHOW
);
2580 GetDlgItem(IDC_NEWBRANCH
)->ShowWindow(SW_HIDE
);
2581 GetDlgItem(IDC_COMMIT_TO
)->ShowWindow(SW_SHOW
);
2585 void CCommitDlg::RestoreFiles(bool doNotAsk
)
2587 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))
2589 for (std::map
<CString
, CString
>::iterator it
= m_ListCtrl
.m_restorepaths
.begin(); it
!= m_ListCtrl
.m_restorepaths
.end(); ++it
)
2590 CopyFile(it
->second
, g_Git
.CombinePath(it
->first
), FALSE
);
2591 m_ListCtrl
.m_restorepaths
.clear();
2595 void CCommitDlg::UpdateCheckLinks()
2597 DialogEnableWindow(IDC_CHECKALL
, true);
2598 DialogEnableWindow(IDC_CHECKNONE
, true);
2599 DialogEnableWindow(IDC_CHECKUNVERSIONED
, m_ListCtrl
.GetUnversionedCount() > 0);
2600 DialogEnableWindow(IDC_CHECKVERSIONED
, m_ListCtrl
.GetItemCount() > m_ListCtrl
.GetUnversionedCount());
2601 DialogEnableWindow(IDC_CHECKADDED
, m_ListCtrl
.GetAddedCount() > 0);
2602 DialogEnableWindow(IDC_CHECKDELETED
, m_ListCtrl
.GetDeletedCount() > 0);
2603 DialogEnableWindow(IDC_CHECKMODIFIED
, m_ListCtrl
.GetModifiedCount() > 0);
2604 DialogEnableWindow(IDC_CHECKFILES
, m_ListCtrl
.GetFileCount() > 0);
2605 DialogEnableWindow(IDC_CHECKSUBMODULES
, m_ListCtrl
.GetSubmoduleCount() > 0);
2608 void CCommitDlg::OnBnClickedCommitSetauthor()
2614 m_sAuthor
.Format(_T("%s <%s>"), g_Git
.GetUserName(), g_Git
.GetUserEmail());
2617 GitRev headRevision
;
2620 headRevision
.GetCommit(_T("HEAD"));
2622 catch (const char *msg
)
2624 CMessageBox::Show(m_hWnd
, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
2626 m_sAuthor
.Format(_T("%s <%s>"), headRevision
.GetAuthorName(), headRevision
.GetAuthorEmail());
2631 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_SHOW
);
2634 GetDlgItem(IDC_COMMIT_AUTHORDATA
)->ShowWindow(SW_HIDE
);
2637 void CCommitDlg::RunStartCommitHook()
2639 DWORD exitcode
= 0xFFFFFFFF;
2641 if (CHooks::Instance().StartCommit(g_Git
.m_CurrentDir
, m_pathList
, m_sLogMessage
, exitcode
, error
))
2646 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2647 MessageBox(temp
, _T("TortoiseGit"), MB_ICONERROR
);