1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2011 - 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 "GitConfig.h"
25 #include "ProjectProperties.h"
26 #include "MessageBox.h"
28 #include "PathUtils.h"
31 #include "GitStatus.h"
32 #include "HistoryDlg.h"
34 #include "CommonResource.h"
35 #include "UnicodeUtils.h"
36 #include "ProgressDlg.h"
37 #include "ShellUpdater.h"
38 #include "Commands/PushCommand.h"
39 #include "PatchViewDlg.h"
46 static char THIS_FILE
[] = __FILE__
;
49 UINT
CCommitDlg::WM_AUTOLISTREADY
= RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
51 IMPLEMENT_DYNAMIC(CCommitDlg
, CResizableStandAloneDialog
)
52 CCommitDlg::CCommitDlg(CWnd
* pParent
/*=NULL*/)
53 : CResizableStandAloneDialog(CCommitDlg::IDD
, pParent
)
55 , m_bShowUnversioned(FALSE
)
57 , m_bThreadRunning(FALSE
)
60 , m_bWholeProject(FALSE
)
61 , m_bKeepChangeList(TRUE
)
62 , m_bDoNotAutoselectSubmodules(FALSE
)
64 , m_bSelectFilesForCommit(TRUE
)
65 , m_bNoPostActions(FALSE
)
67 , m_bSetCommitDateTime(FALSE
)
69 this->m_bCommitAmend
=FALSE
;
70 m_bPushAfterCommit
= FALSE
;
73 CCommitDlg::~CCommitDlg()
81 void CCommitDlg::DoDataExchange(CDataExchange
* pDX
)
83 CResizableStandAloneDialog::DoDataExchange(pDX
);
84 DDX_Control(pDX
, IDC_FILELIST
, m_ListCtrl
);
85 DDX_Control(pDX
, IDC_LOGMESSAGE
, m_cLogMessage
);
86 DDX_Check(pDX
, IDC_SHOWUNVERSIONED
, m_bShowUnversioned
);
87 DDX_Check(pDX
, IDC_COMMIT_SETDATETIME
, m_bSetCommitDateTime
);
88 DDX_Control(pDX
, IDC_SELECTALL
, m_SelectAll
);
89 DDX_Text(pDX
, IDC_BUGID
, m_sBugID
);
90 DDX_Check(pDX
, IDC_WHOLE_PROJECT
, m_bWholeProject
);
91 DDX_Control(pDX
, IDC_SPLITTER
, m_wndSplitter
);
92 DDX_Check(pDX
, IDC_KEEPLISTS
, m_bKeepChangeList
);
93 DDX_Check(pDX
, IDC_NOAUTOSELECTSUBMODULES
, m_bDoNotAutoselectSubmodules
);
94 DDX_Check(pDX
,IDC_COMMIT_AMEND
,m_bCommitAmend
);
95 DDX_Check(pDX
,IDC_COMMIT_AMENDDIFF
,m_bAmendDiffToLastCommit
);
96 DDX_Control(pDX
,IDC_VIEW_PATCH
,m_ctrlShowPatch
);
97 DDX_Control(pDX
, IDC_COMMIT_DATEPICKER
, m_CommitDate
);
98 DDX_Control(pDX
, IDC_COMMIT_TIMEPICKER
, m_CommitTime
);
101 BEGIN_MESSAGE_MAP(CCommitDlg
, CResizableStandAloneDialog
)
102 ON_BN_CLICKED(IDC_SELECTALL
, OnBnClickedSelectall
)
103 ON_BN_CLICKED(IDHELP
, OnBnClickedHelp
)
104 ON_BN_CLICKED(IDC_SHOWUNVERSIONED
, OnBnClickedShowunversioned
)
105 ON_NOTIFY(SCN_UPDATEUI
, IDC_LOGMESSAGE
, OnScnUpdateUI
)
106 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
107 ON_BN_CLICKED(IDC_BUGTRAQBUTTON
, OnBnClickedBugtraqbutton
)
108 ON_EN_CHANGE(IDC_LOGMESSAGE
, OnEnChangeLogmessage
)
109 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED
, OnGitStatusListCtrlItemCountChanged
)
110 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
111 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE
, OnFileDropped
)
112 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED
, &CCommitDlg::OnGitStatusListCtrlCheckChanged
)
113 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED
, &CCommitDlg::OnGitStatusListCtrlItemChanged
)
115 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY
, OnAutoListReady
)
118 ON_STN_CLICKED(IDC_EXTERNALWARNING
, &CCommitDlg::OnStnClickedExternalwarning
)
119 ON_BN_CLICKED(IDC_SIGNOFF
, &CCommitDlg::OnBnClickedSignOff
)
120 ON_BN_CLICKED(IDC_COMMIT_AMEND
, &CCommitDlg::OnBnClickedCommitAmend
)
121 ON_BN_CLICKED(IDC_WHOLE_PROJECT
, &CCommitDlg::OnBnClickedWholeProject
)
122 ON_COMMAND(ID_FOCUS_MESSAGE
,&CCommitDlg::OnFocusMessage
)
123 ON_STN_CLICKED(IDC_VIEW_PATCH
, &CCommitDlg::OnStnClickedViewPatch
)
127 ON_NOTIFY(HDN_ITEMCHANGED
, 0, &CCommitDlg::OnHdnItemchangedFilelist
)
128 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF
, &CCommitDlg::OnBnClickedCommitAmenddiff
)
129 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES
, &CCommitDlg::OnBnClickedNoautoselectsubmodules
)
130 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME
, &CCommitDlg::OnBnClickedCommitSetDateTime
)
133 BOOL
CCommitDlg::OnInitDialog()
135 CResizableStandAloneDialog::OnInitDialog();
136 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
138 CAppUtils::GetCommitTemplate(this->m_sLogMessage
);
140 if(PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_MSG")))
143 if(file
.Open(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_MSG"), CFile::modeRead
))
146 while(file
.ReadString(str
))
148 m_sLogMessage
+= str
;
150 m_sLogMessage
+= _T("\n");
154 m_regAddBeforeCommit
= CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE
);
155 m_bShowUnversioned
= m_regAddBeforeCommit
;
157 m_History
.SetMaxHistoryItems((LONG
)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
159 m_regKeepChangelists
= CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE
);
160 m_bKeepChangeList
= m_regKeepChangelists
;
162 m_regDoNotAutoselectSubmodules
= CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE
);
163 m_bDoNotAutoselectSubmodules
= m_regDoNotAutoselectSubmodules
;
165 m_hAccel
= LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG
));
168 // m_bWholeProject = config.KeepLocks();
170 if(this->m_pathList
.GetCount() == 0)
171 m_bWholeProject
=true;
173 if(this->m_pathList
.GetCount() == 1 && m_pathList
[0].IsEmpty())
174 m_bWholeProject
=true;
180 m_ListCtrl
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
|GITSLC_COLDEL
, _T("CommitDlg"),(GITSLC_POPALL
^ (GITSLC_POPCOMMIT
| GITSLC_POPSAVEAS
)));
181 m_ListCtrl
.SetSelectButton(&m_SelectAll
);
182 m_ListCtrl
.SetStatLabel(GetDlgItem(IDC_STATISTICS
));
183 m_ListCtrl
.SetCancelBool(&m_bCancelled
);
184 m_ListCtrl
.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT
);
185 m_ListCtrl
.EnableFileDrop();
186 m_ListCtrl
.SetBackgroundImage(IDI_COMMIT_BKG
);
188 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
189 m_ProjectProperties
.ReadPropsPathList(m_pathList
);
191 m_cLogMessage
.Init(m_ProjectProperties
);
192 m_cLogMessage
.SetFont((CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
193 m_cLogMessage
.RegisterContextMenuHandler(this);
195 OnEnChangeLogmessage();
197 m_tooltips
.Create(this);
198 m_tooltips
.AddTool(IDC_EXTERNALWARNING
, IDS_COMMITDLG_EXTERNALS
);
199 m_tooltips
.AddTool(IDC_COMMIT_AMEND
,IDS_COMMIT_AMEND_TT
);
200 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
202 m_SelectAll
.SetCheck(BST_INDETERMINATE
);
204 CBugTraqAssociations bugtraq_associations
;
205 bugtraq_associations
.Load();
207 if (bugtraq_associations
.FindProvider(g_Git
.m_CurrentDir
, &m_bugtraq_association
))
209 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
210 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
212 CComPtr
<IBugTraqProvider
> pProvider
;
213 HRESULT hr
= pProvider
.CoCreateInstance(m_bugtraq_association
.GetProviderClass());
216 m_BugTraqProvider
= pProvider
;
218 if (SUCCEEDED(hr
= pProvider
->GetLinkText(GetSafeHwnd(), m_bugtraq_association
.GetParameters().AllocSysString(), &temp
)))
220 SetDlgItemText(IDC_BUGTRAQBUTTON
, temp
);
221 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(TRUE
);
222 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_SHOW
);
228 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
230 else if (!m_ProjectProperties
.sMessage
.IsEmpty())
232 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_SHOW
);
233 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_SHOW
);
234 if (!m_ProjectProperties
.sLabel
.IsEmpty())
235 SetDlgItemText(IDC_BUGIDLABEL
, m_ProjectProperties
.sLabel
);
236 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
237 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
238 GetDlgItem(IDC_BUGID
)->SetFocus();
239 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(m_sLogMessage
);
240 if (!sBugID
.IsEmpty())
242 SetDlgItemText(IDC_BUGID
, sBugID
);
247 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
248 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
249 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
250 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
251 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
254 if (!m_sLogMessage
.IsEmpty())
255 m_cLogMessage
.SetText(m_sLogMessage
);
257 GetWindowText(m_sWindowTitle
);
259 AdjustControlSize(IDC_SHOWUNVERSIONED
);
260 AdjustControlSize(IDC_SELECTALL
);
261 AdjustControlSize(IDC_WHOLE_PROJECT
);
263 GetClientRect(m_DlgOrigRect
);
264 m_cLogMessage
.GetClientRect(m_LogMsgOrigRect
);
266 AddAnchor(IDC_COMMITLABEL
, TOP_LEFT
, TOP_RIGHT
);
267 AddAnchor(IDC_BUGIDLABEL
, TOP_RIGHT
);
268 AddAnchor(IDC_BUGID
, TOP_RIGHT
);
269 AddAnchor(IDC_BUGTRAQBUTTON
, TOP_RIGHT
);
270 AddAnchor(IDC_COMMIT_TO
, TOP_LEFT
, TOP_RIGHT
);
271 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
272 // AddAnchor(IDC_HISTORY, TOP_LEFT);
273 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
274 AddAnchor(IDC_SIGNOFF
, TOP_RIGHT
);
275 AddAnchor(IDC_VIEW_PATCH
, BOTTOM_RIGHT
);
276 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
277 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
278 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
279 AddAnchor(IDC_SHOWUNVERSIONED
, BOTTOM_LEFT
);
280 AddAnchor(IDC_SELECTALL
, BOTTOM_LEFT
);
281 AddAnchor(IDC_EXTERNALWARNING
, BOTTOM_RIGHT
);
282 AddAnchor(IDC_STATISTICS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
283 AddAnchor(IDC_TEXT_INFO
, TOP_RIGHT
);
284 AddAnchor(IDC_WHOLE_PROJECT
, BOTTOM_LEFT
);
285 AddAnchor(IDC_KEEPLISTS
, BOTTOM_LEFT
);
286 AddAnchor(IDC_NOAUTOSELECTSUBMODULES
, BOTTOM_LEFT
);
287 AddAnchor(IDOK
, BOTTOM_RIGHT
);
288 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
289 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
290 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
291 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
292 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
293 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
294 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
297 CenterWindow(CWnd::FromHandle(hWndExplorer
));
298 EnableSaveRestore(_T("CommitDlg"));
299 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
300 RECT rcDlg
, rcLogMsg
, rcFileList
;
301 GetClientRect(&rcDlg
);
302 m_cLogMessage
.GetWindowRect(&rcLogMsg
);
303 ScreenToClient(&rcLogMsg
);
304 m_ListCtrl
.GetWindowRect(&rcFileList
);
305 ScreenToClient(&rcFileList
);
309 m_wndSplitter
.GetWindowRect(&rectSplitter
);
310 ScreenToClient(&rectSplitter
);
311 int delta
= yPos
- rectSplitter
.top
;
312 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
314 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
319 // add all directories to the watcher
321 for (int i=0; i<m_pathList.GetCount(); ++i)
323 if (m_pathList[i].IsDirectory())
324 m_pathwatcher.AddPath(m_pathList[i]);
327 m_updatedPathList
= m_pathList
;
329 //first start a thread to obtain the file list with the status without
330 //blocking the dialog
331 InterlockedExchange(&m_bBlock
, TRUE
);
332 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
335 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
336 InterlockedExchange(&m_bBlock
, FALSE
);
340 m_pThread
->m_bAutoDelete
= FALSE
;
341 m_pThread
->ResumeThread();
343 CRegDWORD err
= CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE
);
344 CRegDWORD historyhint
= CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE
);
345 if ((((DWORD
)err
)!=FALSE
)&&((((DWORD
)historyhint
)==FALSE
)))
348 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
352 if (g_Git
.IsInitRepos())
354 m_bCommitAmend
= FALSE
;
355 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(FALSE
);
362 GetDlgItem(IDC_COMMIT_AMEND
)->EnableWindow(FALSE
);
363 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
366 CGitHash hash
= g_Git
.GetHash(_T("HEAD"));
368 headRevision
.GetParentFromHash(hash
);
369 // do not allow to show diff to "last" revision if it has more that one parent
370 if (headRevision
.ParentsCount() != 1)
372 m_bAmendDiffToLastCommit
= true;
374 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->EnableWindow(FALSE
);
378 this->m_ctrlShowPatch
.SetURL(CString());
380 BOOL viewPatchEnabled
= FALSE
;
381 m_ProjectProperties
.GetBOOLProps(viewPatchEnabled
, _T("tgit.commitshowpatch"));
382 if (viewPatchEnabled
)
383 OnStnClickedViewPatch();
385 return FALSE
; // return TRUE unless you set the focus to a control
386 // EXCEPTION: OCX Property Pages should return FALSE
389 void CCommitDlg::OnOK()
393 if (m_bThreadRunning
)
396 InterlockedExchange(&m_bRunThread
, FALSE
);
397 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
398 if (m_bThreadRunning
)
400 // we gave the thread a chance to quit. Since the thread didn't
401 // listen to us we have to kill it.
402 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
403 InterlockedExchange(&m_bThreadRunning
, FALSE
);
409 GetDlgItemText(IDC_BUGID
, id
);
410 if (!m_ProjectProperties
.CheckBugID(id
))
412 ShowBalloon(IDC_BUGID
, IDS_COMMITDLG_ONLYNUMBERS
, IDI_EXCLAMATION
);
415 m_sLogMessage
= m_cLogMessage
.GetText();
416 if ( m_sLogMessage
.IsEmpty() )
418 // no message entered, go round again
419 CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
422 if ((m_ProjectProperties
.bWarnIfNoIssue
) && (id
.IsEmpty() && !m_ProjectProperties
.HasBugID(m_sLogMessage
)))
424 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOISSUEWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
428 BOOL bWarnNoSignedOffBy
= FALSE
;
429 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy
, _T("tgit.warnnosignedoffby"));
430 if (bWarnNoSignedOffBy
== TRUE
&& m_cLogMessage
.GetText().Find(GetSignedOffByLine()) == -1)
432 UINT retval
= CMessageBox::Show(this->m_hWnd
, _T("You haven't entered your Signed-Off-By line!"), _T("TortoiseGit"), 1, IDI_WARNING
, _T("&Add it"), _T("&Commit w/o"), _T("A&bort"));
435 OnBnClickedSignOff();
436 m_sLogMessage
= m_cLogMessage
.GetText();
438 else if (retval
== 3)
442 m_ListCtrl
.WriteCheckedNamesToPathList(m_selectedPathList
);
444 CRegDWORD
regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE
);
445 if (!(DWORD
)regUnversionedRecurse
)
447 // Find unversioned directories which are marked for commit. The user might expect them
448 // to be added recursively since he cannot the the files. Let's ask the user if he knows
450 int nListItems
= m_ListCtrl
.GetItemCount();
451 for (int j
=0; j
<nListItems
; j
++)
453 const CGitStatusListCtrl::FileEntry
* entry
= m_ListCtrl
.GetListEntry(j
);
454 if (entry
->IsChecked() && (entry
->status
== Git_wc_status_unversioned
) && entry
->IsFolder() )
456 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
462 m_pathwatcher
.Stop();
463 InterlockedExchange(&m_bBlock
, TRUE
);
464 CDWordArray arDeleted
;
465 //first add all the unversioned files the user selected
466 //and check if all versioned files are selected
469 int nListItems
= m_ListCtrl
.GetItemCount();
471 CTGitPathList itemsToAdd
;
472 CTGitPathList itemsToRemove
;
473 //std::set<CString> checkedLists;
474 //std::set<CString> uncheckedLists;
476 // now let the bugtraq plugin check the commit message
477 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
478 if (m_BugTraqProvider
)
480 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
484 CString common
= g_Git
.m_CurrentDir
;
485 BSTR repositoryRoot
= common
.AllocSysString();
486 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
487 BSTR commonRoot
= SysAllocString(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
488 BSTR commitMessage
= m_sLogMessage
.AllocSysString();
489 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_selectedPathList
.GetCount());
491 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
492 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
494 if (FAILED(hr
= pProvider2
->CheckCommit(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, commitMessage
, &temp
)))
498 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), ce
.GetMessageAndDescription().c_str());
499 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
503 CString sError
= temp
;
504 if (!sError
.IsEmpty())
506 CMessageBox::Show(m_hWnd
, sError
, _T("TortoiseGit"), MB_ICONERROR
);
514 //CString checkedfiles;
515 //CString uncheckedfiles;
520 bool bAddSuccess
=true;
521 bool bCloseCommitDlg
=false;
523 for (int j
=0; j
<nListItems
; j
++)
525 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
526 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
527 if (entry
->m_Checked
)
530 if (entry
->status
== Git_wc_status_unversioned
)
532 itemsToAdd
.AddPath(entry
->GetPath());
534 if (entry
->status
== Git_wc_status_conflicted
)
536 bHasConflicted
= true;
538 if (entry
->status
== Git_wc_status_missing
)
540 itemsToRemove
.AddPath(entry
->GetPath());
542 if (entry
->status
== Git_wc_status_deleted
)
546 if (entry
->IsInExternal())
548 bCheckedInExternal
= true;
551 if( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
552 cmd
.Format(_T("git.exe add -f -- \"%s\""),entry
->GetGitPathString());
553 else if ( entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
554 cmd
.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry
->GetGitPathString());
556 cmd
.Format(_T("git.exe update-index -- \"%s\""),entry
->GetGitPathString());
558 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
560 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
561 bAddSuccess
= false ;
565 if( entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
566 cmd
.Format(_T("git.exe rm -- \"%s\""), entry
->GetGitOldPathString());
568 g_Git
.Run(cmd
,&out
,CP_ACP
);
572 //checkedLists.insert(entry->GetGitPathString());
573 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
577 //uncheckedLists.insert(entry->GetGitPathString());
578 if(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
579 { //To init git repository, there are not HEAD, so we can use git reset command
580 cmd
.Format(_T("git.exe rm -f --cache -- \"%s\""),entry
->GetGitPathString());
581 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
583 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
584 bAddSuccess
= false ;
585 bCloseCommitDlg
=false;
590 else if(!( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
) )
592 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
594 cmd
.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry
->GetGitPathString());
598 cmd
.Format(_T("git.exe reset -- \"%s\""), entry
->GetGitPathString());
600 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
602 /* when reset a unstage file will report error.
603 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
604 bAddSuccess = false ;
605 bCloseCommitDlg=false;
609 // && !entry->IsDirectory()
610 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
614 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
616 if ((entry
->status
!= Git_wc_status_unversioned
) &&
617 (entry
->status
!= Git_wc_status_ignored
))
620 uncheckedLists
.insert(entry
->GetChangeList());
623 // This algorithm is for the sake of simplicity of the complexity O(N?
624 for (int k
=0; k
<nListItems
; k
++)
626 const CGitStatusListCtrl::FileEntry
* entryK
= m_ListCtrl
.GetListEntry(k
);
627 if (entryK
->IsChecked() && entryK
->GetPath().IsAncestorOf(entry
->GetPath()) )
629 // Fall back to a non-recursive commit to prevent items being
630 // committed which aren't checked although its parent is checked
631 // (property change, directory deletion, ... )
632 m_bRecursive
= false;
641 CShellUpdater::Instance().AddPathForUpdate(*entry
);
644 //if(uncheckedfiles.GetLength()>0)
646 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
647 // g_Git.Run(cmd,&out);
651 if (!m_sBugID
.IsEmpty())
653 m_sBugID
.Replace(_T(", "), _T(","));
654 m_sBugID
.Replace(_T(" ,"), _T(","));
655 CString sBugID
= m_ProjectProperties
.sMessage
;
656 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
657 if (m_ProjectProperties
.bAppend
)
658 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
660 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
664 if(PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_HEAD")))
668 //if(checkedfiles.GetLength()>0)
669 if( bAddSuccess
&& (nchecked
||m_bCommitAmend
||bIsMerge
) )
671 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
672 // g_Git.Run(cmd,&out);
674 bCloseCommitDlg
= true;
676 CString tempfile
=::GetTempFile();
678 CAppUtils::SaveCommitUnicodeFile(tempfile
,m_sLogMessage
);
679 //file.WriteString(m_sLogMessage);
681 CTGitPath path
=g_Git
.m_CurrentDir
;
683 BOOL IsGitSVN
= path
.GetAdminDirMask() & ITEMIS_GITSVN
;
687 if(this->m_bCommitAmend
)
692 if (m_bSetCommitDateTime
)
695 m_CommitDate
.GetTime(date
);
696 m_CommitTime
.GetTime(time
);
697 dateTime
.Format(_T("--date=%sT%s"), date
.Format(_T("%Y-%m-%d")), time
.Format(_T("%H:%M:%S")));
699 cmd
.Format(_T("git.exe commit %s %s -F \"%s\""), dateTime
, amend
, tempfile
);
703 CCommitProgressDlg progress
;
704 progress
.m_bBufferAll
=true; // improve show speed when there are many file added.
705 progress
.m_GitCmd
=cmd
;
706 progress
.m_bShowCommand
= FALSE
; // don't show the commit command
707 progress
.m_PreText
= out
; // show any output already generated in log window
708 progress
.m_bAutoCloseOnSuccess
= m_bAutoClose
;
710 if (!m_bNoPostActions
&& !m_bAutoClose
)
712 progress
.m_PostCmdList
.Add( IsGitSVN
? _T("&DCommit"): _T("&Push"));
713 progress
.m_PostCmdList
.Add(_T("&ReCommit"));
716 m_PostCmd
= IsGitSVN
? GIT_POST_CMD_DCOMMIT
:GIT_POST_CMD_PUSH
;
718 DWORD userResponse
= progress
.DoModal();
720 if(progress
.m_GitStatus
|| userResponse
== (IDC_PROGRESS_BUTTON1
+1))
722 bCloseCommitDlg
= false;
723 if( userResponse
== (IDC_PROGRESS_BUTTON1
+1 ))
725 this->m_sLogMessage
.Empty();
726 m_cLogMessage
.SetText(m_sLogMessage
);
731 else if(userResponse
== IDC_PROGRESS_BUTTON1
)
733 //User pressed 'Push' button after successful commit.
734 m_bPushAfterCommit
=true;
737 CFile::Remove(tempfile
);
739 if (m_BugTraqProvider
&& progress
.m_GitStatus
== 0)
741 CComPtr
<IBugTraqProvider2
> pProvider
= NULL
;
742 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
745 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
746 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0,this->m_selectedPathList
.GetCount());
748 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
749 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
751 BSTR logMessage
= m_sLogMessage
.AllocSysString();
753 CGitHash hash
=g_Git
.GetHash(_T("HEAD"));
754 LONG version
= g_Git
.Hash2int(hash
);
757 if (FAILED(hr
= pProvider
->OnCommitFinished(GetSafeHwnd(),
766 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
770 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, ce
.GetSource().c_str(), ce
.GetMessageAndDescription().c_str());
771 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
782 CMessageBox::Show(this->m_hWnd
, IDS_ERROR_NOTHING_COMMIT
, IDS_COMMIT_FINISH
, MB_OK
| MB_ICONINFORMATION
);
783 bCloseCommitDlg
=false;
786 if (m_pathwatcher
.GetNumberOfChangedPaths() && m_bRecursive
)
788 // There are paths which got changed (touched at least).
789 // We have to find out if this affects the selection in the commit dialog
790 // If it could affect the selection, revert back to a non-recursive commit
791 CTGitPathList changedList
= m_pathwatcher
.GetChangedPaths();
792 changedList
.RemoveDuplicates();
793 for (int i
=0; i
<changedList
.GetCount(); ++i
)
795 if (changedList
[i
].IsAdminDir())
797 // something inside an admin dir was changed.
798 // if it's the entries file, then we have to fully refresh because
799 // files may have been added/removed from version control
800 if ((changedList
[i
].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
801 (changedList
[i
].GetWinPathString().Find(_T("\\tmp\\"))<0))
803 m_bRecursive
= false;
807 else if (!m_ListCtrl
.IsPathShown(changedList
[i
]))
809 // a path which is not shown in the list has changed
810 CGitStatusListCtrl::FileEntry
* entry
= m_ListCtrl
.GetListEntry(changedList
[i
]);
813 // check if the changed path would get committed by a recursive commit
814 if ((!entry
->IsFromDifferentRepository()) &&
815 (!entry
->IsInExternal()) &&
816 (!entry
->IsNested()) &&
817 (!entry
->IsChecked()))
819 m_bRecursive
= false;
828 // Now, do all the adds - make sure that the list is sorted so that parents
829 // are added before their children
830 itemsToAdd
.SortByPathname();
832 if (!Git
.Add(itemsToAdd
, &m_ProjectProperties
, Git_depth_empty
, FALSE
, FALSE
, TRUE
))
834 CMessageBox::Show(m_hWnd
, Git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
835 InterlockedExchange(&m_bBlock
, FALSE
);
840 // Remove any missing items
841 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
842 itemsToRemove
.SortByPathname();
843 Git
.Remove(itemsToRemove
, TRUE
);
845 //the next step: find all deleted files and check if they're
846 //inside a deleted folder. If that's the case, then remove those
847 //files from the list since they'll get deleted by the parent
848 //folder automatically.
849 m_ListCtrl
.Block(TRUE
, FALSE
);
850 INT_PTR nDeleted
= arDeleted
.GetCount();
851 for (INT_PTR i
=0; i
<arDeleted
.GetCount(); i
++)
853 if (m_ListCtrl
.GetCheck(arDeleted
.GetAt(i
)))
855 const CTGitPath
& path
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(i
))->GetPath();
856 if (path
.IsDirectory())
858 //now find all children of this directory
859 for (int j
=0; j
<arDeleted
.GetCount(); j
++)
863 CGitStatusListCtrl::FileEntry
* childEntry
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(j
));
864 if (childEntry
->IsChecked())
866 if (path
.IsAncestorOf(childEntry
->GetPath()))
868 m_ListCtrl
.SetEntryCheck(childEntry
, arDeleted
.GetAt(j
), false);
877 m_ListCtrl
.Block(FALSE
, FALSE
);
879 if ((nUnchecked
!= 0)||(bCheckedInExternal
)||(bHasConflicted
)||(!m_bRecursive
))
881 //save only the files the user has checked into the temporary file
882 m_ListCtrl
.WriteCheckedNamesToPathList(m_pathList
);
885 // the item count is used in the progress dialog to show the overall commit
887 // deleted items only send one notification event, all others send two
888 m_itemsCount
= ((m_selectedPathList
.GetCount() - nDeleted
- itemsToRemove
.GetCount()) * 2) + nDeleted
+ itemsToRemove
.GetCount();
890 if ((m_bRecursive
)&&(checkedLists
.size() == 1))
892 // all checked items belong to the same changelist
893 // find out if there are any unchecked items which belong to that changelist
894 if (uncheckedLists
.find(*checkedLists
.begin()) == uncheckedLists
.end())
895 m_sChangeList
= *checkedLists
.begin();
899 m_regAddBeforeCommit
= m_bShowUnversioned
;
900 if (!GetDlgItem(IDC_WHOLE_PROJECT
)->IsWindowEnabled())
901 m_bWholeProject
= FALSE
;
902 m_regKeepChangelists
= m_bKeepChangeList
;
903 m_regDoNotAutoselectSubmodules
= m_bDoNotAutoselectSubmodules
;
904 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
905 m_bKeepChangeList
= FALSE
;
906 InterlockedExchange(&m_bBlock
, FALSE
);
908 m_History
.AddEntry(m_sLogMessage
);
913 if( bCloseCommitDlg
)
914 CResizableStandAloneDialog::OnOK();
916 CShellUpdater::Instance().Flush();
919 void CCommitDlg::SaveSplitterPos()
923 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
925 m_wndSplitter
.GetWindowRect(&rectSplitter
);
926 ScreenToClient(&rectSplitter
);
927 regPos
= rectSplitter
.top
;
931 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
933 return ((CCommitDlg
*)pVoid
)->StatusThread();
936 UINT
CCommitDlg::StatusThread()
938 //get the status of all selected file/folders recursively
939 //and show the ones which have to be committed to the user
941 InterlockedExchange(&m_bBlock
, TRUE
);
942 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
943 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
945 m_pathwatcher
.Stop();
947 g_Git
.RefreshGitIndex();
949 m_bCancelled
= false;
951 DialogEnableWindow(IDOK
, false);
952 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
953 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
954 DialogEnableWindow(IDC_SELECTALL
, false);
955 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, false);
956 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
957 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
958 // read the list of recent log entries before querying the WC for status
959 // -> the user may select one and modify / update it while we are crawling the WC
961 if (m_History
.GetCount()==0)
964 reg
.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR
)m_ListCtrl
.m_sUUID
);
965 reg
.Replace(_T(':'),_T('_'));
966 m_History
.Load(reg
, _T("logmsgs"));
969 // Initialise the list control with the status of the files/folders below us
972 CTGitPathList
*pList
;
973 m_ListCtrl
.m_amend
= (m_bCommitAmend
==TRUE
) && (m_bAmendDiffToLastCommit
==FALSE
);
974 m_ListCtrl
.m_bDoNotAutoselectSubmodules
= (m_bDoNotAutoselectSubmodules
== TRUE
);
981 success
=m_ListCtrl
.GetStatus(pList
);
983 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
984 if(this->m_bShowUnversioned
)
985 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
987 m_ListCtrl
.CheckIfChangelistsArePresent(false);
989 DWORD dwShow
= GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWLOCKS
| GITSLC_SHOWINCHANGELIST
;
990 dwShow
|= DWORD(m_regAddBeforeCommit
) ? GITSLC_SHOWUNVERSIONED
: 0;
993 if (m_checkedPathList
.GetCount())
994 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
997 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
998 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
999 m_ListCtrl
.Show(dwShow
, dwCheck
);
1000 m_bSelectFilesForCommit
= true;
1003 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
1005 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
1006 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
1009 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
1010 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
1014 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
1015 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
1016 m_ListCtrl
.Show(dwShow
);
1018 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
1019 && !PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_HEAD")))
1021 if (CMessageBox::Show(m_hWnd
, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1023 m_bShowUnversioned
= TRUE
;
1024 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
1025 DWORD dwShow
= (DWORD
)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWUNVERSIONED
| GITSLC_SHOWLOCKS
);
1026 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
1027 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
1034 // we don't have to block the commit dialog while we fetch the
1035 // auto completion list.
1036 m_pathwatcher
.ClearChangedPaths();
1037 InterlockedExchange(&m_bBlock
, FALSE
);
1038 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE
)==TRUE
)
1040 m_ListCtrl
.Block(TRUE
, TRUE
);
1041 GetAutocompletionList();
1042 m_ListCtrl
.Block(FALSE
, FALSE
);
1047 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
1048 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1049 DialogEnableWindow(IDC_SELECTALL
, true);
1050 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, true);
1051 if (m_ListCtrl
.HasChangeLists())
1052 DialogEnableWindow(IDC_KEEPLISTS
, true);
1053 if (m_ListCtrl
.HasLocks())
1054 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1055 // we have the list, now signal the main thread about it
1056 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
1059 InterlockedExchange(&m_bRunThread
, FALSE
);
1060 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1061 // force the cursor to normal
1067 void CCommitDlg::SetDlgTitle()
1069 if (m_sTitle
.IsEmpty())
1070 GetWindowText(m_sTitle
);
1072 if (m_bWholeProject
)
1073 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
1076 if (m_pathList
.GetCount() == 1)
1077 CAppUtils::SetWindowTitle(m_hWnd
, (g_Git
.m_CurrentDir
+ _T("\\") + m_pathList
[0].GetUIPathString()).TrimRight('\\'), m_sTitle
);
1079 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
+ _T("\\") + m_ListCtrl
.GetCommonDirectory(false), m_sTitle
);
1083 void CCommitDlg::OnCancel()
1085 m_bCancelled
= true;
1086 m_pathwatcher
.Stop();
1091 if (m_bThreadRunning
)
1093 InterlockedExchange(&m_bRunThread
, FALSE
);
1094 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
1095 if (m_bThreadRunning
)
1097 // we gave the thread a chance to quit. Since the thread didn't
1098 // listen to us we have to kill it.
1099 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1100 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1105 m_sLogMessage
= m_cLogMessage
.GetText();
1106 if (!m_sBugID
.IsEmpty())
1108 m_sBugID
.Replace(_T(", "), _T(","));
1109 m_sBugID
.Replace(_T(" ,"), _T(","));
1110 CString sBugID
= m_ProjectProperties
.sMessage
;
1111 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
1112 if (m_ProjectProperties
.bAppend
)
1113 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
1115 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
1117 if (m_ProjectProperties
.sLogTemplate
.Compare(m_sLogMessage
) != 0)
1118 m_History
.AddEntry(m_sLogMessage
);
1121 CResizableStandAloneDialog::OnCancel();
1124 void CCommitDlg::OnBnClickedSelectall()
1126 m_tooltips
.Pop(); // hide the tooltips
1127 UINT state
= (m_SelectAll
.GetState() & 0x0003);
1128 if (state
== BST_INDETERMINATE
)
1130 // It is not at all useful to manually place the checkbox into the indeterminate state...
1131 // We will force this on to the unchecked state
1132 state
= BST_UNCHECKED
;
1133 m_SelectAll
.SetCheck(state
);
1135 m_ListCtrl
.SelectAll(state
== BST_CHECKED
);
1138 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1141 m_tooltips
.RelayEvent(pMsg
);
1145 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1150 if (pMsg
->message
== WM_KEYDOWN
)
1152 switch (pMsg
->wParam
)
1157 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1163 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1165 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1167 PostMessage(WM_COMMAND
, IDOK
);
1171 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1173 // Pressing RETURN in the bug id control
1174 // moves the focus to the message
1175 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1183 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1186 void CCommitDlg::Refresh()
1188 if (m_bThreadRunning
)
1191 InterlockedExchange(&m_bBlock
, TRUE
);
1192 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1193 if (m_pThread
==NULL
)
1195 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1196 InterlockedExchange(&m_bBlock
, FALSE
);
1200 m_pThread
->m_bAutoDelete
= FALSE
;
1201 m_pThread
->ResumeThread();
1205 void CCommitDlg::OnBnClickedHelp()
1210 void CCommitDlg::OnBnClickedShowunversioned()
1212 m_tooltips
.Pop(); // hide the tooltips
1214 m_regAddBeforeCommit
= m_bShowUnversioned
;
1217 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1218 if (DWORD(m_regAddBeforeCommit
))
1219 dwShow
|= GITSLC_SHOWUNVERSIONED
;
1221 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
1222 if(dwShow
& GITSLC_SHOWUNVERSIONED
)
1225 m_ListCtrl
.GetStatus(NULL
,false,false,true);
1227 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1229 m_ListCtrl
.Show(dwShow
,0,true,0,true);
1233 void CCommitDlg::OnStnClickedExternalwarning()
1238 void CCommitDlg::OnEnChangeLogmessage()
1243 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1246 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1248 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1250 m_bShowUnversioned
= TRUE
;
1251 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1252 m_ListCtrl
.Show(dwShow
);
1260 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1266 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM
/*lParam*/)
1270 SetForegroundWindow();
1272 // if multiple files/folders are dropped
1273 // this handler is called for every single item
1275 // To avoid creating multiple refresh threads and
1276 // causing crashes, we only add the items to the
1277 // list control and start a timer.
1278 // When the timer expires, we start the refresh thread,
1279 // but only if it isn't already running - otherwise we
1280 // restart the timer.
1282 path
.SetFromWin((LPCTSTR
)lParam
);
1284 // just add all the items we get here.
1285 // if the item is versioned, the add will fail but nothing
1286 // more will happen.
1288 Git
.Add(CTGitPathList(path
), &m_ProjectProperties
, Git_depth_empty
, false, true, true);
1290 if (!m_ListCtrl
.HasPath(path
))
1292 if (m_pathList
.AreAllPathsFiles())
1294 m_pathList
.AddPath(path
);
1295 m_pathList
.RemoveDuplicates();
1296 m_updatedPathList
.AddPath(path
);
1297 m_updatedPathList
.RemoveDuplicates();
1301 // if the path list contains folders, we have to check whether
1302 // our just (maybe) added path is a child of one of those. If it is
1303 // a child of a folder already in the list, we must not add it. Otherwise
1304 // that path could show up twice in the list.
1305 bool bHasParentInList
= false;
1306 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1308 if (m_pathList
[i
].IsAncestorOf(path
))
1310 bHasParentInList
= true;
1314 if (!bHasParentInList
)
1316 m_pathList
.AddPath(path
);
1317 m_pathList
.RemoveDuplicates();
1318 m_updatedPathList
.AddPath(path
);
1319 m_updatedPathList
.RemoveDuplicates();
1324 // Always start the timer, since the status of an existing item might have changed
1325 SetTimer(REFRESHTIMER
, 200, NULL
);
1326 ATLTRACE(_T("Item %s dropped, timer started\n"), path
.GetWinPath());
1331 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1333 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1337 //////////////////////////////////////////////////////////////////////////
1338 // functions which run in the status thread
1339 //////////////////////////////////////////////////////////////////////////
1341 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1346 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1347 while (m_bRunThread
&& file
.ReadString(strLine
))
1349 int eqpos
= strLine
.Find('=');
1351 rgx
= strLine
.Mid(eqpos
+1).Trim();
1354 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1356 mapRegex
[strLine
.Left(pos
)] = rgx
;
1357 strLine
= strLine
.Mid(pos
+1).Trim();
1359 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1363 catch (CFileException
* pE
)
1365 TRACE("CFileException loading auto list regex file\n");
1370 void CCommitDlg::GetAutocompletionList()
1372 // the auto completion list is made of strings from each selected files.
1373 // the strings used are extracted from the files with regexes found
1374 // in the file "autolist.txt".
1375 // the format of that file is:
1376 // file extensions separated with commas '=' regular expression to use
1378 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1379 // .cpp = (?<=[^\s]::)\b\w+\b
1381 std::map
<CString
, CString
> mapRegex
;
1382 CString sRegexFile
= CPathUtils::GetAppDirectory();
1383 CRegDWORD regtimeout
= CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1384 DWORD timeoutvalue
= regtimeout
*1000;
1385 sRegexFile
+= _T("autolist.txt");
1388 ParseRegexFile(sRegexFile
, mapRegex
);
1389 SHGetFolderPath(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, sRegexFile
.GetBuffer(MAX_PATH
+1));
1390 sRegexFile
.ReleaseBuffer();
1391 sRegexFile
+= _T("\\TortoiseGit\\autolist.txt");
1392 if (PathFileExists(sRegexFile
))
1394 ParseRegexFile(sRegexFile
, mapRegex
);
1396 DWORD starttime
= GetTickCount();
1398 // now we have two arrays of strings, where the first array contains all
1399 // file extensions we can use and the second the corresponding regex strings
1400 // to apply to those files.
1402 // the next step is to go over all files shown in the commit dialog
1403 // and scan them for strings we can use
1404 int nListItems
= m_ListCtrl
.GetItemCount();
1406 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1408 // stop parsing after timeout
1409 if ((!m_bRunThread
) || (GetTickCount() - starttime
> timeoutvalue
))
1412 CTGitPath
*path
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1417 CString sPartPath
=path
->GetGitPathString();
1418 m_autolist
.insert(sPartPath
);
1420 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1424 // add the path parts to the auto completion list too
1425 // CString sPartPath = entry->GetRelativeGitPath();
1426 // m_autolist.insert(sPartPath);
1431 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1435 m_autolist
.insert(sPartPath
.Mid(pos
));
1438 // Last inserted entry is a file name.
1439 // Some users prefer to also list file name without extension.
1440 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE
))
1442 int dotPos
= sPartPath
.ReverseFind('.');
1443 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1444 m_autolist
.insert(sPartPath
.Mid(lastPos
, dotPos
- lastPos
));
1447 if ((entry
->status
<= Git_wc_status_normal
)||(entry
->status
== Git_wc_status_ignored
))
1450 CString sExt
= entry
->GetPath().GetFileExtension();
1452 // find the regex string which corresponds to the file extension
1453 CString rdata
= mapRegex
[sExt
];
1454 if (rdata
.IsEmpty())
1457 ScanFile(entry
->GetPath().GetWinPathString(), rdata
);
1458 if ((entry
->textstatus
!= Git_wc_status_unversioned
) &&
1459 (entry
->textstatus
!= Git_wc_status_none
) &&
1460 (entry
->textstatus
!= Git_wc_status_ignored
) &&
1461 (entry
->textstatus
!= Git_wc_status_added
) &&
1462 (entry
->textstatus
!= Git_wc_status_normal
))
1464 CTGitPath basePath
= Git::GetPristinePath(entry
->GetPath());
1465 if (!basePath
.IsEmpty())
1466 ScanFile(basePath
.GetWinPathString(), rdata
);
1470 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime
);
1473 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
)
1475 wstring sFileContent
;
1476 HANDLE hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
1477 if (hFile
!= INVALID_HANDLE_VALUE
)
1479 DWORD size
= GetFileSize(hFile
, NULL
);
1480 if (size
> 1000000L)
1482 // no files bigger than 1 Meg
1486 // allocate memory to hold file contents
1487 char * buffer
= new char[size
];
1489 ReadFile(hFile
, buffer
, size
, &readbytes
, NULL
);
1492 IsTextUnicode(buffer
, readbytes
, &opts
);
1493 if (opts
& IS_TEXT_UNICODE_NULL_BYTES
)
1498 if (opts
& IS_TEXT_UNICODE_UNICODE_MASK
)
1500 sFileContent
= wstring((wchar_t*)buffer
, readbytes
/sizeof(WCHAR
));
1502 if ((opts
& IS_TEXT_UNICODE_NOT_UNICODE_MASK
)||(opts
== 0))
1504 int ret
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, NULL
, 0);
1505 wchar_t * pWideBuf
= new wchar_t[ret
];
1506 int ret2
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, pWideBuf
, ret
);
1508 sFileContent
= wstring(pWideBuf
, ret
);
1513 if (sFileContent
.empty()|| !m_bRunThread
)
1520 const tr1::wregex
regCheck(sRegex
, tr1::regex_constants::icase
| tr1::regex_constants::ECMAScript
);
1521 const tr1::wsregex_iterator end
;
1522 wstring s
= sFileContent
;
1523 for (tr1::wsregex_iterator
it(s
.begin(), s
.end(), regCheck
); it
!= end
; ++it
)
1525 const tr1::wsmatch match
= *it
;
1526 for (size_t i
=1; i
<match
.size(); ++i
)
1528 if (match
[i
].second
-match
[i
].first
)
1530 ATLTRACE(_T("matched keyword : %s\n"), wstring(match
[i
]).c_str());
1531 m_autolist
.insert(wstring(match
[i
]).c_str());
1536 catch (exception
) {}
1539 // CSciEditContextMenuInterface
1540 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1542 CString
sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST
));
1543 m_nPopupPasteListCmd
= nCmd
++;
1544 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
1546 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1547 if(m_History
.GetCount() > 0)
1549 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
1550 m_nPopupPasteLastMessage
= nCmd
++;
1551 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
1553 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
1554 m_nPopupRecentMessage
= nCmd
++;
1555 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
1561 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
1566 if (cmd
== m_nPopupPasteListCmd
)
1569 int nListItems
= m_ListCtrl
.GetItemCount();
1570 for (int i
=0; i
<nListItems
; ++i
)
1572 CTGitPath
* entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1573 if (entry
&&entry
->m_Checked
)
1576 CString status
= entry
->GetActionName();
1577 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1580 //git_wc_status_kind status = entry->status;
1581 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1582 if (m_ProjectProperties
.bFileListInEnglish
)
1585 line
.Format(_T("%-10s %s\r\n"),status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
,0));
1589 pSciEdit
->InsertText(logmsg
);
1593 if(cmd
== m_nPopupPasteLastMessage
)
1595 if(m_History
.GetCount() ==0 )
1599 logmsg
+=m_History
.GetEntry(0);
1600 pSciEdit
->InsertText(logmsg
);
1604 if(cmd
== m_nPopupRecentMessage
)
1606 OnBnClickedHistory();
1612 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
1616 case ENDDIALOGTIMER
:
1617 KillTimer(ENDDIALOGTIMER
);
1621 if (m_bThreadRunning
)
1623 SetTimer(REFRESHTIMER
, 200, NULL
);
1624 ATLTRACE("Wait some more before refreshing\n");
1628 KillTimer(REFRESHTIMER
);
1629 ATLTRACE("Refreshing after items dropped\n");
1634 __super::OnTimer(nIDEvent
);
1637 void CCommitDlg::OnBnClickedHistory()
1639 m_tooltips
.Pop(); // hide the tooltips
1640 if (m_pathList
.GetCount() == 0)
1643 CHistoryDlg historyDlg
;
1644 historyDlg
.SetHistory(m_History
);
1645 if (historyDlg
.DoModal() != IDOK
)
1648 CString sMsg
= historyDlg
.GetSelectedText();
1649 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
1651 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(sMsg
);
1652 if (!sBugID
.IsEmpty())
1654 SetDlgItemText(IDC_BUGID
, sBugID
);
1656 if (m_ProjectProperties
.sLogTemplate
.Compare(m_cLogMessage
.GetText())!=0)
1657 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
1659 m_cLogMessage
.SetText(sMsg
);
1663 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1667 void CCommitDlg::OnBnClickedBugtraqbutton()
1669 m_tooltips
.Pop(); // hide the tooltips
1670 CString sMsg
= m_cLogMessage
.GetText();
1672 if (m_BugTraqProvider
== NULL
)
1675 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
1676 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
1677 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_pathList
.GetCount());
1679 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
1680 SafeArrayPutElement(pathList
, &index
, m_pathList
[index
].GetGitPathString().AllocSysString());
1682 BSTR originalMessage
= sMsg
.AllocSysString();
1684 // m_revProps.clear();
1686 // first try the IBugTraqProvider2 interface
1687 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
1688 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
1691 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1692 BSTR repositoryRoot
= g_Git
.m_CurrentDir
.AllocSysString();
1693 BSTR bugIDOut
= NULL
;
1694 GetDlgItemText(IDC_BUGID
, m_sBugID
);
1695 BSTR bugID
= m_sBugID
.AllocSysString();
1696 SAFEARRAY
* revPropNames
= NULL
;
1697 SAFEARRAY
* revPropValues
= NULL
;
1698 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
1701 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1702 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1708 m_sBugID
= bugIDOut
;
1709 SysFreeString(bugIDOut
);
1710 SetDlgItemText(IDC_BUGID
, m_sBugID
);
1712 SysFreeString(bugID
);
1713 SysFreeString(repositoryRoot
);
1714 m_cLogMessage
.SetText(temp
);
1715 BSTR HUGEP
*pbRevNames
;
1716 BSTR HUGEP
*pbRevValues
;
1718 HRESULT hr1
= SafeArrayAccessData(revPropNames
, (void HUGEP
**)&pbRevNames
);
1721 HRESULT hr2
= SafeArrayAccessData(revPropValues
, (void HUGEP
**)&pbRevValues
);
1724 if (revPropNames
->rgsabound
->cElements
== revPropValues
->rgsabound
->cElements
)
1726 for (ULONG i
= 0; i
< revPropNames
->rgsabound
->cElements
; i
++)
1728 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1731 SafeArrayUnaccessData(revPropValues
);
1733 SafeArrayUnaccessData(revPropNames
);
1736 SafeArrayDestroy(revPropNames
);
1738 SafeArrayDestroy(revPropValues
);
1743 // if IBugTraqProvider2 failed, try IBugTraqProvider
1744 CComPtr
<IBugTraqProvider
> pProvider
= NULL
;
1745 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
1749 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1750 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1754 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
1757 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1758 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1761 m_cLogMessage
.SetText(temp
);
1763 m_sLogMessage
= m_cLogMessage
.GetText();
1764 if (!m_ProjectProperties
.sMessage
.IsEmpty())
1766 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
1767 if (!sBugID
.IsEmpty())
1769 SetDlgItemText(IDC_BUGID
, sBugID
);
1773 m_cLogMessage
.SetFocus();
1775 SysFreeString(parameters
);
1776 SysFreeString(commonRoot
);
1777 SafeArrayDestroy(pathList
);
1778 SysFreeString(originalMessage
);
1779 SysFreeString(temp
);
1783 void CCommitDlg::FillPatchView()
1785 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
1787 m_patchViewdlg
.m_ctrlPatchView
.SetText(CString());
1789 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
1790 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, FALSE
);
1795 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
1796 CTGitPath
* p
=(CTGitPath
*)m_ListCtrl
.GetItemData(nSelect
);
1797 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
1799 CString head
= _T("HEAD");
1800 if(m_bCommitAmend
==TRUE
&& m_bAmendDiffToLastCommit
==FALSE
)
1801 head
= _T("HEAD~1");
1802 cmd
.Format(_T("git.exe diff %s -- \"%s\""), head
, p
->GetGitPathString());
1803 g_Git
.Run(cmd
,&out
,CP_ACP
);
1807 m_patchViewdlg
.m_ctrlPatchView
.SetText(out
);
1808 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, TRUE
);
1809 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_GOTOPOS
, 0);
1812 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM
/*wparam*/, LPARAM
/*lparam*/)
1814 this->FillPatchView();
1819 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
1825 void CCommitDlg::UpdateOKButton()
1830 bool bValidLogSize
= m_cLogMessage
.GetText().GetLength() >= m_ProjectProperties
.nMinLogSize
&& m_cLogMessage
.GetText().GetLength() > 0;
1831 bool bAmendOrSelectFilesOrMerge
= m_ListCtrl
.GetSelected() > 0 || (m_bCommitAmend
&& m_bAmendDiffToLastCommit
) || CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1833 DialogEnableWindow(IDOK
, bValidLogSize
&& bAmendOrSelectFilesOrMerge
);
1836 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
1840 if (wParam
== IDC_SPLITTER
)
1842 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
1843 DoSize(pHdr
->delta
);
1848 return __super::DefWindowProc(message
, wParam
, lParam
);
1851 void CCommitDlg::SetSplitterRange()
1853 if ((m_ListCtrl
)&&(m_cLogMessage
))
1856 m_cLogMessage
.GetWindowRect(rcTop
);
1857 ScreenToClient(rcTop
);
1859 m_ListCtrl
.GetWindowRect(rcMiddle
);
1860 ScreenToClient(rcMiddle
);
1861 if (rcMiddle
.Height() && rcMiddle
.Width())
1862 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
1866 void CCommitDlg::DoSize(int delta
)
1868 RemoveAnchor(IDC_MESSAGEGROUP
);
1869 RemoveAnchor(IDC_LOGMESSAGE
);
1870 RemoveAnchor(IDC_SPLITTER
);
1871 RemoveAnchor(IDC_SIGNOFF
);
1872 RemoveAnchor(IDC_COMMIT_AMEND
);
1873 RemoveAnchor(IDC_COMMIT_AMENDDIFF
);
1874 RemoveAnchor(IDC_COMMIT_SETDATETIME
);
1875 RemoveAnchor(IDC_COMMIT_DATEPICKER
);
1876 RemoveAnchor(IDC_COMMIT_TIMEPICKER
);
1877 RemoveAnchor(IDC_LISTGROUP
);
1878 RemoveAnchor(IDC_FILELIST
);
1879 RemoveAnchor(IDC_TEXT_INFO
);
1881 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
1882 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
1883 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
1884 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
1885 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
1886 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
1887 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF
),0,delta
);
1888 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME
),0,delta
);
1889 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER
),0,delta
);
1890 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER
),0,delta
);
1891 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
1893 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
1894 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
1895 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
1896 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
1897 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
1898 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
1899 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
1900 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
1901 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
1902 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
1903 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
1904 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
1906 // adjust the minimum size of the dialog to prevent the resizing from
1907 // moving the list control too far down.
1909 m_cLogMessage
.GetClientRect(rcLogMsg
);
1910 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
1913 m_cLogMessage
.Invalidate();
1914 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
1917 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
1919 // first, let the resizing take place
1920 __super::OnSize(nType
, cx
, cy
);
1926 CString
CCommitDlg::GetSignedOffByLine()
1930 CString username
= g_Git
.GetUserName();
1931 CString email
= g_Git
.GetUserEmail();
1932 username
.Remove(_T('\n'));
1933 email
.Remove(_T('\n'));
1935 str
.Format(_T("Signed-off-by: %s <%s>"), username
, email
);
1940 void CCommitDlg::OnBnClickedSignOff()
1942 CString str
= GetSignedOffByLine();
1944 if (m_cLogMessage
.GetText().Find(str
) == -1) {
1945 m_cLogMessage
.SetText(m_cLogMessage
.GetText().TrimRight());
1946 int lastNewline
= m_cLogMessage
.GetText().ReverseFind(_T('\n'));
1947 int foundByLine
= -1;
1948 if (lastNewline
> 0)
1949 foundByLine
= m_cLogMessage
.GetText().Find(_T("-by: "), lastNewline
);
1951 if (foundByLine
== -1 || foundByLine
< lastNewline
)
1952 str
= _T("\r\n") + str
;
1954 m_cLogMessage
.SetText(m_cLogMessage
.GetText()+_T("\r\n")+str
+_T("\r\n"));
1958 void CCommitDlg::OnBnClickedCommitAmend()
1961 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
1964 rev
.GetCommit(CString(_T("HEAD")));
1965 m_AmendStr
=rev
.GetSubject()+_T("\n")+rev
.GetBody();
1968 if(this->m_bCommitAmend
)
1970 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
1971 m_cLogMessage
.SetText(m_AmendStr
);
1972 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
1976 this->m_AmendStr
=this->m_cLogMessage
.GetText();
1977 m_cLogMessage
.SetText(m_NoAmendStr
);
1978 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
1981 OnBnClickedCommitSetDateTime(); // to update the commit date and time
1986 void CCommitDlg::OnBnClickedWholeProject()
1988 m_tooltips
.Pop(); // hide the tooltips
1994 m_ListCtrl
.GetStatus(NULL
,true,false,true);
1996 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
1998 DWORD dwShow
= (DWORD
)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWUNVERSIONED
| GITSLC_SHOWLOCKS
);
1999 m_ListCtrl
.Show(m_ListCtrl
.GetShowFlags(), dwShow
& (~CTGitPath::LOGACTIONS_UNVER
|~CTGitPath::LOGACTIONS_IGNORE
));
2005 void CCommitDlg::OnFocusMessage()
2007 m_cLogMessage
.SetFocus();
2010 void CCommitDlg::OnScnUpdateUI(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2012 UNREFERENCED_PARAMETER(pNMHDR
);
2013 int pos
=this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
2014 int line
=this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
2015 int column
=this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
2018 str
.Format(_T("%d/%d"),line
+1,column
+1);
2019 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
2024 void CCommitDlg::OnStnClickedViewPatch()
2026 m_patchViewdlg
.m_pProjectProperties
= &this->m_ProjectProperties
;
2027 m_patchViewdlg
.m_ParentCommitDlg
= this;
2028 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
2030 BOOL viewPatchEnabled
= FALSE
;
2031 m_ProjectProperties
.GetBOOLProps(viewPatchEnabled
, _T("tgit.commitshowpatch"));
2032 if (viewPatchEnabled
== FALSE
)
2033 g_Git
.SetConfigValue(_T("tgit.showpatch"), _T("true"));
2034 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
2036 this->GetWindowRect(&rect
);
2038 m_patchViewdlg
.ShowWindow(SW_SHOW
);
2040 m_patchViewdlg
.SetWindowPos(NULL
,rect
.right
,rect
.top
,rect
.Width(),rect
.Height(),
2041 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
2043 ShowViewPatchText(false);
2048 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2049 m_patchViewdlg
.ShowWindow(SW_HIDE
);
2050 m_patchViewdlg
.DestroyWindow();
2051 ShowViewPatchText(true);
2053 this->m_ctrlShowPatch
.Invalidate();
2056 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
2058 __super::OnMoving(fwSide
, pRect
);
2060 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
2063 m_patchViewdlg
.GetWindowRect(&patchrect
);
2064 if (::IsWindow(m_hWnd
))
2067 GetWindowRect(&thisrect
);
2068 if (patchrect
.left
== thisrect
.right
)
2070 m_patchViewdlg
.SetWindowPos(NULL
, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
2071 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
2078 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
2080 __super::OnSizing(fwSide
, pRect
);
2082 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2084 CRect thisrect
, patchrect
;
2085 this->GetWindowRect(thisrect
);
2086 this->m_patchViewdlg
.GetWindowRect(patchrect
);
2087 if(thisrect
.right
==patchrect
.left
)
2089 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
2090 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
2092 if( patchrect
.bottom
== thisrect
.bottom
)
2094 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
2096 if( patchrect
.top
== thisrect
.top
)
2098 patchrect
.top
-= thisrect
.top
-pRect
->top
;
2100 m_patchViewdlg
.MoveWindow(patchrect
);
2105 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2107 UNREFERENCED_PARAMETER(pNMHDR
);
2109 TRACE("Item Changed\r\n");
2112 int CCommitDlg::CheckHeadDetach()
2115 if(g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
,output
))
2117 if(CMessageBox::Show(NULL
,_T("<ct=0x0000FF>Current HEAD Detached</ct>, you are working on (no branch)\nDo you want create branch now?"),
2118 _T("TortoiseGit"),MB_YESNO
|MB_ICONWARNING
) == IDYES
)
2120 CAppUtils::CreateBranchTag(FALSE
,NULL
,true);
2126 void CCommitDlg::OnBnClickedCommitAmenddiff()
2132 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2138 void CCommitDlg::OnBnClickedCommitSetDateTime()
2142 if (m_bSetCommitDateTime
)
2144 CTime authordate
= CTime::GetCurrentTime();
2147 GitRev headRevision
;
2148 headRevision
.GetCommit(_T("HEAD"));
2149 authordate
= headRevision
.GetAuthorDate();
2152 m_CommitDate
.SetTime(&authordate
);
2153 m_CommitTime
.SetTime(&authordate
);
2155 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_SHOW
);
2156 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_SHOW
);
2160 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_HIDE
);
2161 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_HIDE
);