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 ShowEditBalloon(IDC_BUGID
, IDS_COMMITDLG_ONLYNUMBERS
, TTI_ERROR
);
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
);
443 m_pathwatcher
.Stop();
444 InterlockedExchange(&m_bBlock
, TRUE
);
445 CDWordArray arDeleted
;
446 //first add all the unversioned files the user selected
447 //and check if all versioned files are selected
450 int nListItems
= m_ListCtrl
.GetItemCount();
452 CTGitPathList itemsToAdd
;
453 CTGitPathList itemsToRemove
;
454 //std::set<CString> checkedLists;
455 //std::set<CString> uncheckedLists;
457 // now let the bugtraq plugin check the commit message
458 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
459 if (m_BugTraqProvider
)
461 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
465 CString common
= g_Git
.m_CurrentDir
;
466 BSTR repositoryRoot
= common
.AllocSysString();
467 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
468 BSTR commonRoot
= SysAllocString(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
469 BSTR commitMessage
= m_sLogMessage
.AllocSysString();
470 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_selectedPathList
.GetCount());
472 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
473 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
475 if (FAILED(hr
= pProvider2
->CheckCommit(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, commitMessage
, &temp
)))
479 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), ce
.GetMessageAndDescription().c_str());
480 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
484 CString sError
= temp
;
485 if (!sError
.IsEmpty())
487 CMessageBox::Show(m_hWnd
, sError
, _T("TortoiseGit"), MB_ICONERROR
);
495 //CString checkedfiles;
496 //CString uncheckedfiles;
501 bool bAddSuccess
=true;
502 bool bCloseCommitDlg
=false;
504 for (int j
=0; j
<nListItems
; j
++)
506 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
507 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
508 if (entry
->m_Checked
)
511 if (entry
->status
== Git_wc_status_unversioned
)
513 itemsToAdd
.AddPath(entry
->GetPath());
515 if (entry
->status
== Git_wc_status_conflicted
)
517 bHasConflicted
= true;
519 if (entry
->status
== Git_wc_status_missing
)
521 itemsToRemove
.AddPath(entry
->GetPath());
523 if (entry
->status
== Git_wc_status_deleted
)
527 if (entry
->IsInExternal())
529 bCheckedInExternal
= true;
532 if( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
533 cmd
.Format(_T("git.exe add -f -- \"%s\""),entry
->GetGitPathString());
534 else if ( entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
535 cmd
.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry
->GetGitPathString());
537 cmd
.Format(_T("git.exe update-index -- \"%s\""),entry
->GetGitPathString());
539 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
541 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
542 bAddSuccess
= false ;
546 if( entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
547 cmd
.Format(_T("git.exe rm -- \"%s\""), entry
->GetGitOldPathString());
549 g_Git
.Run(cmd
,&out
,CP_ACP
);
553 //checkedLists.insert(entry->GetGitPathString());
554 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
558 //uncheckedLists.insert(entry->GetGitPathString());
559 if(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
560 { //To init git repository, there are not HEAD, so we can use git reset command
561 cmd
.Format(_T("git.exe rm -f --cache -- \"%s\""),entry
->GetGitPathString());
562 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
564 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
565 bAddSuccess
= false ;
566 bCloseCommitDlg
=false;
571 else if(!( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
) )
573 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
575 cmd
.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry
->GetGitPathString());
579 cmd
.Format(_T("git.exe reset -- \"%s\""), entry
->GetGitPathString());
581 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
583 /* when reset a unstage file will report error.
584 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
585 bAddSuccess = false ;
586 bCloseCommitDlg=false;
590 // && !entry->IsDirectory()
591 if (m_bCommitAmend
&& !m_bAmendDiffToLastCommit
)
595 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
597 if ((entry
->status
!= Git_wc_status_unversioned
) &&
598 (entry
->status
!= Git_wc_status_ignored
))
601 uncheckedLists
.insert(entry
->GetChangeList());
604 // This algorithm is for the sake of simplicity of the complexity O(N?
605 for (int k
=0; k
<nListItems
; k
++)
607 const CGitStatusListCtrl::FileEntry
* entryK
= m_ListCtrl
.GetListEntry(k
);
608 if (entryK
->IsChecked() && entryK
->GetPath().IsAncestorOf(entry
->GetPath()) )
610 // Fall back to a non-recursive commit to prevent items being
611 // committed which aren't checked although its parent is checked
612 // (property change, directory deletion, ... )
613 m_bRecursive
= false;
622 CShellUpdater::Instance().AddPathForUpdate(*entry
);
625 //if(uncheckedfiles.GetLength()>0)
627 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
628 // g_Git.Run(cmd,&out);
632 if (!m_sBugID
.IsEmpty())
634 m_sBugID
.Replace(_T(", "), _T(","));
635 m_sBugID
.Replace(_T(" ,"), _T(","));
636 CString sBugID
= m_ProjectProperties
.sMessage
;
637 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
638 if (m_ProjectProperties
.bAppend
)
639 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
641 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
645 if(PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_HEAD")))
649 //if(checkedfiles.GetLength()>0)
650 if( bAddSuccess
&& (nchecked
||m_bCommitAmend
||bIsMerge
) )
652 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
653 // g_Git.Run(cmd,&out);
655 bCloseCommitDlg
= true;
657 CString tempfile
=::GetTempFile();
659 CAppUtils::SaveCommitUnicodeFile(tempfile
,m_sLogMessage
);
660 //file.WriteString(m_sLogMessage);
662 CTGitPath path
=g_Git
.m_CurrentDir
;
664 BOOL IsGitSVN
= path
.GetAdminDirMask() & ITEMIS_GITSVN
;
668 if(this->m_bCommitAmend
)
673 if (m_bSetCommitDateTime
)
676 m_CommitDate
.GetTime(date
);
677 m_CommitTime
.GetTime(time
);
678 dateTime
.Format(_T("--date=%sT%s"), date
.Format(_T("%Y-%m-%d")), time
.Format(_T("%H:%M:%S")));
680 cmd
.Format(_T("git.exe commit %s %s -F \"%s\""), dateTime
, amend
, tempfile
);
684 CCommitProgressDlg progress
;
685 progress
.m_bBufferAll
=true; // improve show speed when there are many file added.
686 progress
.m_GitCmd
=cmd
;
687 progress
.m_bShowCommand
= FALSE
; // don't show the commit command
688 progress
.m_PreText
= out
; // show any output already generated in log window
689 progress
.m_bAutoCloseOnSuccess
= m_bAutoClose
;
691 if (!m_bNoPostActions
&& !m_bAutoClose
)
693 progress
.m_PostCmdList
.Add( IsGitSVN
? _T("&DCommit"): _T("&Push"));
694 progress
.m_PostCmdList
.Add(_T("&ReCommit"));
697 m_PostCmd
= IsGitSVN
? GIT_POST_CMD_DCOMMIT
:GIT_POST_CMD_PUSH
;
699 DWORD userResponse
= progress
.DoModal();
701 if(progress
.m_GitStatus
|| userResponse
== (IDC_PROGRESS_BUTTON1
+1))
703 bCloseCommitDlg
= false;
704 if( userResponse
== (IDC_PROGRESS_BUTTON1
+1 ))
706 this->m_sLogMessage
.Empty();
707 m_cLogMessage
.SetText(m_sLogMessage
);
712 else if(userResponse
== IDC_PROGRESS_BUTTON1
)
714 //User pressed 'Push' button after successful commit.
715 m_bPushAfterCommit
=true;
718 CFile::Remove(tempfile
);
720 if (m_BugTraqProvider
&& progress
.m_GitStatus
== 0)
722 CComPtr
<IBugTraqProvider2
> pProvider
= NULL
;
723 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
726 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
727 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0,this->m_selectedPathList
.GetCount());
729 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
730 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
732 BSTR logMessage
= m_sLogMessage
.AllocSysString();
734 CGitHash hash
=g_Git
.GetHash(_T("HEAD"));
735 LONG version
= g_Git
.Hash2int(hash
);
738 if (FAILED(hr
= pProvider
->OnCommitFinished(GetSafeHwnd(),
747 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
751 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, ce
.GetSource().c_str(), ce
.GetMessageAndDescription().c_str());
752 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
763 CMessageBox::Show(this->m_hWnd
, IDS_ERROR_NOTHING_COMMIT
, IDS_COMMIT_FINISH
, MB_OK
| MB_ICONINFORMATION
);
764 bCloseCommitDlg
=false;
767 if (m_pathwatcher
.GetNumberOfChangedPaths() && m_bRecursive
)
769 // There are paths which got changed (touched at least).
770 // We have to find out if this affects the selection in the commit dialog
771 // If it could affect the selection, revert back to a non-recursive commit
772 CTGitPathList changedList
= m_pathwatcher
.GetChangedPaths();
773 changedList
.RemoveDuplicates();
774 for (int i
=0; i
<changedList
.GetCount(); ++i
)
776 if (changedList
[i
].IsAdminDir())
778 // something inside an admin dir was changed.
779 // if it's the entries file, then we have to fully refresh because
780 // files may have been added/removed from version control
781 if ((changedList
[i
].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
782 (changedList
[i
].GetWinPathString().Find(_T("\\tmp\\"))<0))
784 m_bRecursive
= false;
788 else if (!m_ListCtrl
.IsPathShown(changedList
[i
]))
790 // a path which is not shown in the list has changed
791 CGitStatusListCtrl::FileEntry
* entry
= m_ListCtrl
.GetListEntry(changedList
[i
]);
794 // check if the changed path would get committed by a recursive commit
795 if ((!entry
->IsFromDifferentRepository()) &&
796 (!entry
->IsInExternal()) &&
797 (!entry
->IsNested()) &&
798 (!entry
->IsChecked()))
800 m_bRecursive
= false;
809 // Now, do all the adds - make sure that the list is sorted so that parents
810 // are added before their children
811 itemsToAdd
.SortByPathname();
813 if (!Git
.Add(itemsToAdd
, &m_ProjectProperties
, Git_depth_empty
, FALSE
, FALSE
, TRUE
))
815 CMessageBox::Show(m_hWnd
, Git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
816 InterlockedExchange(&m_bBlock
, FALSE
);
821 // Remove any missing items
822 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
823 itemsToRemove
.SortByPathname();
824 Git
.Remove(itemsToRemove
, TRUE
);
826 //the next step: find all deleted files and check if they're
827 //inside a deleted folder. If that's the case, then remove those
828 //files from the list since they'll get deleted by the parent
829 //folder automatically.
830 m_ListCtrl
.Block(TRUE
, FALSE
);
831 INT_PTR nDeleted
= arDeleted
.GetCount();
832 for (INT_PTR i
=0; i
<arDeleted
.GetCount(); i
++)
834 if (m_ListCtrl
.GetCheck(arDeleted
.GetAt(i
)))
836 const CTGitPath
& path
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(i
))->GetPath();
837 if (path
.IsDirectory())
839 //now find all children of this directory
840 for (int j
=0; j
<arDeleted
.GetCount(); j
++)
844 CGitStatusListCtrl::FileEntry
* childEntry
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(j
));
845 if (childEntry
->IsChecked())
847 if (path
.IsAncestorOf(childEntry
->GetPath()))
849 m_ListCtrl
.SetEntryCheck(childEntry
, arDeleted
.GetAt(j
), false);
858 m_ListCtrl
.Block(FALSE
, FALSE
);
860 if ((nUnchecked
!= 0)||(bCheckedInExternal
)||(bHasConflicted
)||(!m_bRecursive
))
862 //save only the files the user has checked into the temporary file
863 m_ListCtrl
.WriteCheckedNamesToPathList(m_pathList
);
866 // the item count is used in the progress dialog to show the overall commit
868 // deleted items only send one notification event, all others send two
869 m_itemsCount
= ((m_selectedPathList
.GetCount() - nDeleted
- itemsToRemove
.GetCount()) * 2) + nDeleted
+ itemsToRemove
.GetCount();
871 if ((m_bRecursive
)&&(checkedLists
.size() == 1))
873 // all checked items belong to the same changelist
874 // find out if there are any unchecked items which belong to that changelist
875 if (uncheckedLists
.find(*checkedLists
.begin()) == uncheckedLists
.end())
876 m_sChangeList
= *checkedLists
.begin();
880 m_regAddBeforeCommit
= m_bShowUnversioned
;
881 if (!GetDlgItem(IDC_WHOLE_PROJECT
)->IsWindowEnabled())
882 m_bWholeProject
= FALSE
;
883 m_regKeepChangelists
= m_bKeepChangeList
;
884 m_regDoNotAutoselectSubmodules
= m_bDoNotAutoselectSubmodules
;
885 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
886 m_bKeepChangeList
= FALSE
;
887 InterlockedExchange(&m_bBlock
, FALSE
);
889 m_History
.AddEntry(m_sLogMessage
);
894 if( bCloseCommitDlg
)
895 CResizableStandAloneDialog::OnOK();
897 CShellUpdater::Instance().Flush();
900 void CCommitDlg::SaveSplitterPos()
904 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
906 m_wndSplitter
.GetWindowRect(&rectSplitter
);
907 ScreenToClient(&rectSplitter
);
908 regPos
= rectSplitter
.top
;
912 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
914 return ((CCommitDlg
*)pVoid
)->StatusThread();
917 UINT
CCommitDlg::StatusThread()
919 //get the status of all selected file/folders recursively
920 //and show the ones which have to be committed to the user
922 InterlockedExchange(&m_bBlock
, TRUE
);
923 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
924 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
926 m_pathwatcher
.Stop();
928 g_Git
.RefreshGitIndex();
930 m_bCancelled
= false;
932 DialogEnableWindow(IDOK
, false);
933 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
934 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
935 DialogEnableWindow(IDC_SELECTALL
, false);
936 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, false);
937 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
938 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
939 // read the list of recent log entries before querying the WC for status
940 // -> the user may select one and modify / update it while we are crawling the WC
942 if (m_History
.GetCount()==0)
945 reg
.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR
)m_ListCtrl
.m_sUUID
);
946 reg
.Replace(_T(':'),_T('_'));
947 m_History
.Load(reg
, _T("logmsgs"));
950 // Initialise the list control with the status of the files/folders below us
953 CTGitPathList
*pList
;
954 m_ListCtrl
.m_amend
= (m_bCommitAmend
==TRUE
) && (m_bAmendDiffToLastCommit
==FALSE
);
955 m_ListCtrl
.m_bDoNotAutoselectSubmodules
= (m_bDoNotAutoselectSubmodules
== TRUE
);
962 success
=m_ListCtrl
.GetStatus(pList
);
964 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
965 if(this->m_bShowUnversioned
)
966 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
968 m_ListCtrl
.CheckIfChangelistsArePresent(false);
970 DWORD dwShow
= GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWLOCKS
| GITSLC_SHOWINCHANGELIST
;
971 dwShow
|= DWORD(m_regAddBeforeCommit
) ? GITSLC_SHOWUNVERSIONED
: 0;
974 if (m_checkedPathList
.GetCount())
975 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
978 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
979 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
980 m_ListCtrl
.Show(dwShow
, dwCheck
);
981 m_bSelectFilesForCommit
= true;
984 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
986 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
987 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
990 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
991 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
995 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
996 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
997 m_ListCtrl
.Show(dwShow
);
999 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
1000 && !PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_HEAD")))
1002 if (CMessageBox::Show(m_hWnd
, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1004 m_bShowUnversioned
= TRUE
;
1005 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
1006 DWORD dwShow
= (DWORD
)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWUNVERSIONED
| GITSLC_SHOWLOCKS
);
1007 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
1008 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
1015 // we don't have to block the commit dialog while we fetch the
1016 // auto completion list.
1017 m_pathwatcher
.ClearChangedPaths();
1018 InterlockedExchange(&m_bBlock
, FALSE
);
1019 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE
)==TRUE
)
1021 m_ListCtrl
.Block(TRUE
, TRUE
);
1022 GetAutocompletionList();
1023 m_ListCtrl
.Block(FALSE
, FALSE
);
1028 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
1029 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1030 DialogEnableWindow(IDC_SELECTALL
, true);
1031 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES
, true);
1032 if (m_ListCtrl
.HasChangeLists())
1033 DialogEnableWindow(IDC_KEEPLISTS
, true);
1034 if (m_ListCtrl
.HasLocks())
1035 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
1036 // we have the list, now signal the main thread about it
1037 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
1040 InterlockedExchange(&m_bRunThread
, FALSE
);
1041 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1042 // force the cursor to normal
1048 void CCommitDlg::SetDlgTitle()
1050 if (m_sTitle
.IsEmpty())
1051 GetWindowText(m_sTitle
);
1053 if (m_bWholeProject
)
1054 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
1057 if (m_pathList
.GetCount() == 1)
1058 CAppUtils::SetWindowTitle(m_hWnd
, (g_Git
.m_CurrentDir
+ _T("\\") + m_pathList
[0].GetUIPathString()).TrimRight('\\'), m_sTitle
);
1060 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
+ _T("\\") + m_ListCtrl
.GetCommonDirectory(false), m_sTitle
);
1064 void CCommitDlg::OnCancel()
1066 m_bCancelled
= true;
1067 m_pathwatcher
.Stop();
1072 if (m_bThreadRunning
)
1074 InterlockedExchange(&m_bRunThread
, FALSE
);
1075 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
1076 if (m_bThreadRunning
)
1078 // we gave the thread a chance to quit. Since the thread didn't
1079 // listen to us we have to kill it.
1080 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
1081 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1086 m_sLogMessage
= m_cLogMessage
.GetText();
1087 if (!m_sBugID
.IsEmpty())
1089 m_sBugID
.Replace(_T(", "), _T(","));
1090 m_sBugID
.Replace(_T(" ,"), _T(","));
1091 CString sBugID
= m_ProjectProperties
.sMessage
;
1092 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
1093 if (m_ProjectProperties
.bAppend
)
1094 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
1096 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
1098 if (m_ProjectProperties
.sLogTemplate
.Compare(m_sLogMessage
) != 0)
1099 m_History
.AddEntry(m_sLogMessage
);
1102 CResizableStandAloneDialog::OnCancel();
1105 void CCommitDlg::OnBnClickedSelectall()
1107 m_tooltips
.Pop(); // hide the tooltips
1108 UINT state
= (m_SelectAll
.GetState() & 0x0003);
1109 if (state
== BST_INDETERMINATE
)
1111 // It is not at all useful to manually place the checkbox into the indeterminate state...
1112 // We will force this on to the unchecked state
1113 state
= BST_UNCHECKED
;
1114 m_SelectAll
.SetCheck(state
);
1116 m_ListCtrl
.SelectAll(state
== BST_CHECKED
);
1119 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1122 m_tooltips
.RelayEvent(pMsg
);
1126 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1131 if (pMsg
->message
== WM_KEYDOWN
)
1133 switch (pMsg
->wParam
)
1138 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1144 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1146 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1148 PostMessage(WM_COMMAND
, IDOK
);
1152 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1154 // Pressing RETURN in the bug id control
1155 // moves the focus to the message
1156 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1164 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1167 void CCommitDlg::Refresh()
1169 if (m_bThreadRunning
)
1172 InterlockedExchange(&m_bBlock
, TRUE
);
1173 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1174 if (m_pThread
==NULL
)
1176 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1177 InterlockedExchange(&m_bBlock
, FALSE
);
1181 m_pThread
->m_bAutoDelete
= FALSE
;
1182 m_pThread
->ResumeThread();
1186 void CCommitDlg::OnBnClickedHelp()
1191 void CCommitDlg::OnBnClickedShowunversioned()
1193 m_tooltips
.Pop(); // hide the tooltips
1195 m_regAddBeforeCommit
= m_bShowUnversioned
;
1198 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1199 if (DWORD(m_regAddBeforeCommit
))
1200 dwShow
|= GITSLC_SHOWUNVERSIONED
;
1202 dwShow
&= ~GITSLC_SHOWUNVERSIONED
;
1203 if(dwShow
& GITSLC_SHOWUNVERSIONED
)
1206 m_ListCtrl
.GetStatus(NULL
,false,false,true);
1208 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1210 m_ListCtrl
.Show(dwShow
,0,true,0,true);
1214 void CCommitDlg::OnStnClickedExternalwarning()
1219 void CCommitDlg::OnEnChangeLogmessage()
1224 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1227 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1229 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1231 m_bShowUnversioned
= TRUE
;
1232 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1233 m_ListCtrl
.Show(dwShow
);
1241 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1247 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM
/*lParam*/)
1251 SetForegroundWindow();
1253 // if multiple files/folders are dropped
1254 // this handler is called for every single item
1256 // To avoid creating multiple refresh threads and
1257 // causing crashes, we only add the items to the
1258 // list control and start a timer.
1259 // When the timer expires, we start the refresh thread,
1260 // but only if it isn't already running - otherwise we
1261 // restart the timer.
1263 path
.SetFromWin((LPCTSTR
)lParam
);
1265 // just add all the items we get here.
1266 // if the item is versioned, the add will fail but nothing
1267 // more will happen.
1269 Git
.Add(CTGitPathList(path
), &m_ProjectProperties
, Git_depth_empty
, false, true, true);
1271 if (!m_ListCtrl
.HasPath(path
))
1273 if (m_pathList
.AreAllPathsFiles())
1275 m_pathList
.AddPath(path
);
1276 m_pathList
.RemoveDuplicates();
1277 m_updatedPathList
.AddPath(path
);
1278 m_updatedPathList
.RemoveDuplicates();
1282 // if the path list contains folders, we have to check whether
1283 // our just (maybe) added path is a child of one of those. If it is
1284 // a child of a folder already in the list, we must not add it. Otherwise
1285 // that path could show up twice in the list.
1286 bool bHasParentInList
= false;
1287 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1289 if (m_pathList
[i
].IsAncestorOf(path
))
1291 bHasParentInList
= true;
1295 if (!bHasParentInList
)
1297 m_pathList
.AddPath(path
);
1298 m_pathList
.RemoveDuplicates();
1299 m_updatedPathList
.AddPath(path
);
1300 m_updatedPathList
.RemoveDuplicates();
1305 // Always start the timer, since the status of an existing item might have changed
1306 SetTimer(REFRESHTIMER
, 200, NULL
);
1307 ATLTRACE(_T("Item %s dropped, timer started\n"), path
.GetWinPath());
1312 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1314 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1318 //////////////////////////////////////////////////////////////////////////
1319 // functions which run in the status thread
1320 //////////////////////////////////////////////////////////////////////////
1322 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1327 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1328 while (m_bRunThread
&& file
.ReadString(strLine
))
1330 int eqpos
= strLine
.Find('=');
1332 rgx
= strLine
.Mid(eqpos
+1).Trim();
1335 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1337 mapRegex
[strLine
.Left(pos
)] = rgx
;
1338 strLine
= strLine
.Mid(pos
+1).Trim();
1340 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1344 catch (CFileException
* pE
)
1346 TRACE("CFileException loading auto list regex file\n");
1351 void CCommitDlg::GetAutocompletionList()
1353 // the auto completion list is made of strings from each selected files.
1354 // the strings used are extracted from the files with regexes found
1355 // in the file "autolist.txt".
1356 // the format of that file is:
1357 // file extensions separated with commas '=' regular expression to use
1359 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1360 // .cpp = (?<=[^\s]::)\b\w+\b
1362 std::map
<CString
, CString
> mapRegex
;
1363 CString sRegexFile
= CPathUtils::GetAppDirectory();
1364 CRegDWORD regtimeout
= CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1365 DWORD timeoutvalue
= regtimeout
*1000;
1366 sRegexFile
+= _T("autolist.txt");
1369 ParseRegexFile(sRegexFile
, mapRegex
);
1370 SHGetFolderPath(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, sRegexFile
.GetBuffer(MAX_PATH
+1));
1371 sRegexFile
.ReleaseBuffer();
1372 sRegexFile
+= _T("\\TortoiseGit\\autolist.txt");
1373 if (PathFileExists(sRegexFile
))
1375 ParseRegexFile(sRegexFile
, mapRegex
);
1377 DWORD starttime
= GetTickCount();
1379 // now we have two arrays of strings, where the first array contains all
1380 // file extensions we can use and the second the corresponding regex strings
1381 // to apply to those files.
1383 // the next step is to go over all files shown in the commit dialog
1384 // and scan them for strings we can use
1385 int nListItems
= m_ListCtrl
.GetItemCount();
1387 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1389 // stop parsing after timeout
1390 if ((!m_bRunThread
) || (GetTickCount() - starttime
> timeoutvalue
))
1393 CTGitPath
*path
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1398 CString sPartPath
=path
->GetGitPathString();
1399 m_autolist
.insert(sPartPath
);
1401 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1405 // add the path parts to the auto completion list too
1406 // CString sPartPath = entry->GetRelativeGitPath();
1407 // m_autolist.insert(sPartPath);
1412 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1416 m_autolist
.insert(sPartPath
.Mid(pos
));
1419 // Last inserted entry is a file name.
1420 // Some users prefer to also list file name without extension.
1421 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE
))
1423 int dotPos
= sPartPath
.ReverseFind('.');
1424 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1425 m_autolist
.insert(sPartPath
.Mid(lastPos
, dotPos
- lastPos
));
1428 if ((entry
->status
<= Git_wc_status_normal
)||(entry
->status
== Git_wc_status_ignored
))
1431 CString sExt
= entry
->GetPath().GetFileExtension();
1433 // find the regex string which corresponds to the file extension
1434 CString rdata
= mapRegex
[sExt
];
1435 if (rdata
.IsEmpty())
1438 ScanFile(entry
->GetPath().GetWinPathString(), rdata
);
1439 if ((entry
->textstatus
!= Git_wc_status_unversioned
) &&
1440 (entry
->textstatus
!= Git_wc_status_none
) &&
1441 (entry
->textstatus
!= Git_wc_status_ignored
) &&
1442 (entry
->textstatus
!= Git_wc_status_added
) &&
1443 (entry
->textstatus
!= Git_wc_status_normal
))
1445 CTGitPath basePath
= Git::GetPristinePath(entry
->GetPath());
1446 if (!basePath
.IsEmpty())
1447 ScanFile(basePath
.GetWinPathString(), rdata
);
1451 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime
);
1454 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
)
1456 wstring sFileContent
;
1457 HANDLE hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
1458 if (hFile
!= INVALID_HANDLE_VALUE
)
1460 DWORD size
= GetFileSize(hFile
, NULL
);
1461 if (size
> 1000000L)
1463 // no files bigger than 1 Meg
1467 // allocate memory to hold file contents
1468 char * buffer
= new char[size
];
1470 ReadFile(hFile
, buffer
, size
, &readbytes
, NULL
);
1473 IsTextUnicode(buffer
, readbytes
, &opts
);
1474 if (opts
& IS_TEXT_UNICODE_NULL_BYTES
)
1479 if (opts
& IS_TEXT_UNICODE_UNICODE_MASK
)
1481 sFileContent
= wstring((wchar_t*)buffer
, readbytes
/sizeof(WCHAR
));
1483 if ((opts
& IS_TEXT_UNICODE_NOT_UNICODE_MASK
)||(opts
== 0))
1485 int ret
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, NULL
, 0);
1486 wchar_t * pWideBuf
= new wchar_t[ret
];
1487 int ret2
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, pWideBuf
, ret
);
1489 sFileContent
= wstring(pWideBuf
, ret
);
1494 if (sFileContent
.empty()|| !m_bRunThread
)
1501 const tr1::wregex
regCheck(sRegex
, tr1::regex_constants::icase
| tr1::regex_constants::ECMAScript
);
1502 const tr1::wsregex_iterator end
;
1503 wstring s
= sFileContent
;
1504 for (tr1::wsregex_iterator
it(s
.begin(), s
.end(), regCheck
); it
!= end
; ++it
)
1506 const tr1::wsmatch match
= *it
;
1507 for (size_t i
=1; i
<match
.size(); ++i
)
1509 if (match
[i
].second
-match
[i
].first
)
1511 ATLTRACE(_T("matched keyword : %s\n"), wstring(match
[i
]).c_str());
1512 m_autolist
.insert(wstring(match
[i
]).c_str());
1517 catch (exception
) {}
1520 // CSciEditContextMenuInterface
1521 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1523 CString
sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST
));
1524 m_nPopupPasteListCmd
= nCmd
++;
1525 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
1527 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1528 if(m_History
.GetCount() > 0)
1530 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
1531 m_nPopupPasteLastMessage
= nCmd
++;
1532 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
1534 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
1535 m_nPopupRecentMessage
= nCmd
++;
1536 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
1542 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
1547 if (cmd
== m_nPopupPasteListCmd
)
1550 int nListItems
= m_ListCtrl
.GetItemCount();
1551 for (int i
=0; i
<nListItems
; ++i
)
1553 CTGitPath
* entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1554 if (entry
&&entry
->m_Checked
)
1557 CString status
= entry
->GetActionName();
1558 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1561 //git_wc_status_kind status = entry->status;
1562 WORD langID
= (WORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1563 if (m_ProjectProperties
.bFileListInEnglish
)
1566 line
.Format(_T("%-10s %s\r\n"),status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
,0));
1570 pSciEdit
->InsertText(logmsg
);
1574 if(cmd
== m_nPopupPasteLastMessage
)
1576 if(m_History
.GetCount() ==0 )
1580 logmsg
+=m_History
.GetEntry(0);
1581 pSciEdit
->InsertText(logmsg
);
1585 if(cmd
== m_nPopupRecentMessage
)
1587 OnBnClickedHistory();
1593 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
1597 case ENDDIALOGTIMER
:
1598 KillTimer(ENDDIALOGTIMER
);
1602 if (m_bThreadRunning
)
1604 SetTimer(REFRESHTIMER
, 200, NULL
);
1605 ATLTRACE("Wait some more before refreshing\n");
1609 KillTimer(REFRESHTIMER
);
1610 ATLTRACE("Refreshing after items dropped\n");
1615 __super::OnTimer(nIDEvent
);
1618 void CCommitDlg::OnBnClickedHistory()
1620 m_tooltips
.Pop(); // hide the tooltips
1621 if (m_pathList
.GetCount() == 0)
1624 CHistoryDlg historyDlg
;
1625 historyDlg
.SetHistory(m_History
);
1626 if (historyDlg
.DoModal() != IDOK
)
1629 CString sMsg
= historyDlg
.GetSelectedText();
1630 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
1632 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(sMsg
);
1633 if (!sBugID
.IsEmpty())
1635 SetDlgItemText(IDC_BUGID
, sBugID
);
1637 if (m_ProjectProperties
.sLogTemplate
.Compare(m_cLogMessage
.GetText())!=0)
1638 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
1640 m_cLogMessage
.SetText(sMsg
);
1644 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1648 void CCommitDlg::OnBnClickedBugtraqbutton()
1650 m_tooltips
.Pop(); // hide the tooltips
1651 CString sMsg
= m_cLogMessage
.GetText();
1653 if (m_BugTraqProvider
== NULL
)
1656 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
1657 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
1658 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_pathList
.GetCount());
1660 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
1661 SafeArrayPutElement(pathList
, &index
, m_pathList
[index
].GetGitPathString().AllocSysString());
1663 BSTR originalMessage
= sMsg
.AllocSysString();
1665 // m_revProps.clear();
1667 // first try the IBugTraqProvider2 interface
1668 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
1669 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
1672 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1673 BSTR repositoryRoot
= g_Git
.m_CurrentDir
.AllocSysString();
1674 BSTR bugIDOut
= NULL
;
1675 GetDlgItemText(IDC_BUGID
, m_sBugID
);
1676 BSTR bugID
= m_sBugID
.AllocSysString();
1677 SAFEARRAY
* revPropNames
= NULL
;
1678 SAFEARRAY
* revPropValues
= NULL
;
1679 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
1682 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1683 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1689 m_sBugID
= bugIDOut
;
1690 SysFreeString(bugIDOut
);
1691 SetDlgItemText(IDC_BUGID
, m_sBugID
);
1693 SysFreeString(bugID
);
1694 SysFreeString(repositoryRoot
);
1695 m_cLogMessage
.SetText(temp
);
1696 BSTR HUGEP
*pbRevNames
;
1697 BSTR HUGEP
*pbRevValues
;
1699 HRESULT hr1
= SafeArrayAccessData(revPropNames
, (void HUGEP
**)&pbRevNames
);
1702 HRESULT hr2
= SafeArrayAccessData(revPropValues
, (void HUGEP
**)&pbRevValues
);
1705 if (revPropNames
->rgsabound
->cElements
== revPropValues
->rgsabound
->cElements
)
1707 for (ULONG i
= 0; i
< revPropNames
->rgsabound
->cElements
; i
++)
1709 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1712 SafeArrayUnaccessData(revPropValues
);
1714 SafeArrayUnaccessData(revPropNames
);
1717 SafeArrayDestroy(revPropNames
);
1719 SafeArrayDestroy(revPropValues
);
1724 // if IBugTraqProvider2 failed, try IBugTraqProvider
1725 CComPtr
<IBugTraqProvider
> pProvider
= NULL
;
1726 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
1730 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1731 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1735 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
1738 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1739 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1742 m_cLogMessage
.SetText(temp
);
1744 m_sLogMessage
= m_cLogMessage
.GetText();
1745 if (!m_ProjectProperties
.sMessage
.IsEmpty())
1747 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
1748 if (!sBugID
.IsEmpty())
1750 SetDlgItemText(IDC_BUGID
, sBugID
);
1754 m_cLogMessage
.SetFocus();
1756 SysFreeString(parameters
);
1757 SysFreeString(commonRoot
);
1758 SafeArrayDestroy(pathList
);
1759 SysFreeString(originalMessage
);
1760 SysFreeString(temp
);
1764 void CCommitDlg::FillPatchView()
1766 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
1768 m_patchViewdlg
.m_ctrlPatchView
.SetText(CString());
1770 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
1771 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, FALSE
);
1776 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
1777 CTGitPath
* p
=(CTGitPath
*)m_ListCtrl
.GetItemData(nSelect
);
1778 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
1780 CString head
= _T("HEAD");
1781 if(m_bCommitAmend
==TRUE
&& m_bAmendDiffToLastCommit
==FALSE
)
1782 head
= _T("HEAD~1");
1783 cmd
.Format(_T("git.exe diff %s -- \"%s\""), head
, p
->GetGitPathString());
1784 g_Git
.Run(cmd
,&out
,CP_ACP
);
1788 m_patchViewdlg
.m_ctrlPatchView
.SetText(out
);
1789 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, TRUE
);
1790 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_GOTOPOS
, 0);
1793 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM
/*wparam*/, LPARAM
/*lparam*/)
1795 this->FillPatchView();
1800 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
1806 void CCommitDlg::UpdateOKButton()
1811 bool bValidLogSize
= m_cLogMessage
.GetText().GetLength() >= m_ProjectProperties
.nMinLogSize
&& m_cLogMessage
.GetText().GetLength() > 0;
1812 bool bAmendOrSelectFilesOrMerge
= m_ListCtrl
.GetSelected() > 0 || (m_bCommitAmend
&& m_bAmendDiffToLastCommit
) || CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1814 DialogEnableWindow(IDOK
, bValidLogSize
&& bAmendOrSelectFilesOrMerge
);
1817 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
1821 if (wParam
== IDC_SPLITTER
)
1823 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
1824 DoSize(pHdr
->delta
);
1829 return __super::DefWindowProc(message
, wParam
, lParam
);
1832 void CCommitDlg::SetSplitterRange()
1834 if ((m_ListCtrl
)&&(m_cLogMessage
))
1837 m_cLogMessage
.GetWindowRect(rcTop
);
1838 ScreenToClient(rcTop
);
1840 m_ListCtrl
.GetWindowRect(rcMiddle
);
1841 ScreenToClient(rcMiddle
);
1842 if (rcMiddle
.Height() && rcMiddle
.Width())
1843 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
1847 void CCommitDlg::DoSize(int delta
)
1849 RemoveAnchor(IDC_MESSAGEGROUP
);
1850 RemoveAnchor(IDC_LOGMESSAGE
);
1851 RemoveAnchor(IDC_SPLITTER
);
1852 RemoveAnchor(IDC_SIGNOFF
);
1853 RemoveAnchor(IDC_COMMIT_AMEND
);
1854 RemoveAnchor(IDC_COMMIT_AMENDDIFF
);
1855 RemoveAnchor(IDC_COMMIT_SETDATETIME
);
1856 RemoveAnchor(IDC_COMMIT_DATEPICKER
);
1857 RemoveAnchor(IDC_COMMIT_TIMEPICKER
);
1858 RemoveAnchor(IDC_LISTGROUP
);
1859 RemoveAnchor(IDC_FILELIST
);
1860 RemoveAnchor(IDC_TEXT_INFO
);
1862 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
1863 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
1864 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
1865 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
1866 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
1867 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
1868 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF
),0,delta
);
1869 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME
),0,delta
);
1870 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER
),0,delta
);
1871 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER
),0,delta
);
1872 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
1874 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
1875 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
1876 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
1877 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
1878 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
1879 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
1880 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
1881 AddAnchor(IDC_COMMIT_AMENDDIFF
,TOP_LEFT
);
1882 AddAnchor(IDC_COMMIT_SETDATETIME
,TOP_LEFT
);
1883 AddAnchor(IDC_COMMIT_DATEPICKER
,TOP_LEFT
);
1884 AddAnchor(IDC_COMMIT_TIMEPICKER
,TOP_LEFT
);
1885 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
1887 // adjust the minimum size of the dialog to prevent the resizing from
1888 // moving the list control too far down.
1890 m_cLogMessage
.GetClientRect(rcLogMsg
);
1891 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
1894 m_cLogMessage
.Invalidate();
1895 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
1898 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
1900 // first, let the resizing take place
1901 __super::OnSize(nType
, cx
, cy
);
1907 CString
CCommitDlg::GetSignedOffByLine()
1911 CString username
= g_Git
.GetUserName();
1912 CString email
= g_Git
.GetUserEmail();
1913 username
.Remove(_T('\n'));
1914 email
.Remove(_T('\n'));
1916 str
.Format(_T("Signed-off-by: %s <%s>"), username
, email
);
1921 void CCommitDlg::OnBnClickedSignOff()
1923 CString str
= GetSignedOffByLine();
1925 if (m_cLogMessage
.GetText().Find(str
) == -1) {
1926 m_cLogMessage
.SetText(m_cLogMessage
.GetText().TrimRight());
1927 int lastNewline
= m_cLogMessage
.GetText().ReverseFind(_T('\n'));
1928 int foundByLine
= -1;
1929 if (lastNewline
> 0)
1930 foundByLine
= m_cLogMessage
.GetText().Find(_T("-by: "), lastNewline
);
1932 if (foundByLine
== -1 || foundByLine
< lastNewline
)
1933 str
= _T("\r\n") + str
;
1935 m_cLogMessage
.SetText(m_cLogMessage
.GetText()+_T("\r\n")+str
+_T("\r\n"));
1939 void CCommitDlg::OnBnClickedCommitAmend()
1942 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
1945 rev
.GetCommit(CString(_T("HEAD")));
1946 m_AmendStr
=rev
.GetSubject()+_T("\n")+rev
.GetBody();
1949 if(this->m_bCommitAmend
)
1951 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
1952 m_cLogMessage
.SetText(m_AmendStr
);
1953 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_SHOW
);
1957 this->m_AmendStr
=this->m_cLogMessage
.GetText();
1958 m_cLogMessage
.SetText(m_NoAmendStr
);
1959 GetDlgItem(IDC_COMMIT_AMENDDIFF
)->ShowWindow(SW_HIDE
);
1962 OnBnClickedCommitSetDateTime(); // to update the commit date and time
1967 void CCommitDlg::OnBnClickedWholeProject()
1969 m_tooltips
.Pop(); // hide the tooltips
1975 m_ListCtrl
.GetStatus(NULL
,true,false,true);
1977 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
1979 DWORD dwShow
= (DWORD
)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GITSLC_SHOWUNVERSIONED
| GITSLC_SHOWLOCKS
);
1980 m_ListCtrl
.Show(m_ListCtrl
.GetShowFlags(), dwShow
& (~CTGitPath::LOGACTIONS_UNVER
|~CTGitPath::LOGACTIONS_IGNORE
));
1986 void CCommitDlg::OnFocusMessage()
1988 m_cLogMessage
.SetFocus();
1991 void CCommitDlg::OnScnUpdateUI(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1993 UNREFERENCED_PARAMETER(pNMHDR
);
1994 int pos
=this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
1995 int line
=this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
1996 int column
=this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
1999 str
.Format(_T("%d/%d"),line
+1,column
+1);
2000 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
2005 void CCommitDlg::OnStnClickedViewPatch()
2007 m_patchViewdlg
.m_pProjectProperties
= &this->m_ProjectProperties
;
2008 m_patchViewdlg
.m_ParentCommitDlg
= this;
2009 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
2011 BOOL viewPatchEnabled
= FALSE
;
2012 m_ProjectProperties
.GetBOOLProps(viewPatchEnabled
, _T("tgit.commitshowpatch"));
2013 if (viewPatchEnabled
== FALSE
)
2014 g_Git
.SetConfigValue(_T("tgit.showpatch"), _T("true"));
2015 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
2017 this->GetWindowRect(&rect
);
2019 m_patchViewdlg
.ShowWindow(SW_SHOW
);
2021 m_patchViewdlg
.SetWindowPos(NULL
,rect
.right
,rect
.top
,rect
.Width(),rect
.Height(),
2022 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
2024 ShowViewPatchText(false);
2029 g_Git
.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2030 m_patchViewdlg
.ShowWindow(SW_HIDE
);
2031 m_patchViewdlg
.DestroyWindow();
2032 ShowViewPatchText(true);
2034 this->m_ctrlShowPatch
.Invalidate();
2037 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
2039 __super::OnMoving(fwSide
, pRect
);
2041 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
2044 m_patchViewdlg
.GetWindowRect(&patchrect
);
2045 if (::IsWindow(m_hWnd
))
2048 GetWindowRect(&thisrect
);
2049 if (patchrect
.left
== thisrect
.right
)
2051 m_patchViewdlg
.SetWindowPos(NULL
, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
2052 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
2059 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
2061 __super::OnSizing(fwSide
, pRect
);
2063 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
2065 CRect thisrect
, patchrect
;
2066 this->GetWindowRect(thisrect
);
2067 this->m_patchViewdlg
.GetWindowRect(patchrect
);
2068 if(thisrect
.right
==patchrect
.left
)
2070 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
2071 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
2073 if( patchrect
.bottom
== thisrect
.bottom
)
2075 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
2077 if( patchrect
.top
== thisrect
.top
)
2079 patchrect
.top
-= thisrect
.top
-pRect
->top
;
2081 m_patchViewdlg
.MoveWindow(patchrect
);
2086 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2088 UNREFERENCED_PARAMETER(pNMHDR
);
2090 TRACE("Item Changed\r\n");
2093 int CCommitDlg::CheckHeadDetach()
2096 if(g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
,output
))
2098 if(CMessageBox::Show(NULL
,_T("<ct=0x0000FF>Current HEAD Detached</ct>, you are working on (no branch)\nDo you want create branch now?"),
2099 _T("TortoiseGit"),MB_YESNO
|MB_ICONWARNING
) == IDYES
)
2101 CAppUtils::CreateBranchTag(FALSE
,NULL
,true);
2107 void CCommitDlg::OnBnClickedCommitAmenddiff()
2113 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2119 void CCommitDlg::OnBnClickedCommitSetDateTime()
2123 if (m_bSetCommitDateTime
)
2125 CTime authordate
= CTime::GetCurrentTime();
2128 GitRev headRevision
;
2129 headRevision
.GetCommit(_T("HEAD"));
2130 authordate
= headRevision
.GetAuthorDate();
2133 m_CommitDate
.SetTime(&authordate
);
2134 m_CommitTime
.SetTime(&authordate
);
2136 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_SHOW
);
2137 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_SHOW
);
2141 GetDlgItem(IDC_COMMIT_DATEPICKER
)->ShowWindow(SW_HIDE
);
2142 GetDlgItem(IDC_COMMIT_TIMEPICKER
)->ShowWindow(SW_HIDE
);