CommitDlg: do not provide a default value for the new branch name
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob54a16ed63c816e82b646c30582e9b47903f97726
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2012 - 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.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "CommitDlg.h"
23 #include "DirFileEnum.h"
24 //#include "GitConfig.h"
25 #include "ProjectProperties.h"
26 #include "MessageBox.h"
27 #include "AppUtils.h"
28 #include "PathUtils.h"
29 #include "Git.h"
30 #include "Registry.h"
31 #include "GitStatus.h"
32 #include "HistoryDlg.h"
33 #include "Hooks.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"
40 #include "COMError.h"
41 #include "Globals.h"
42 #include "SysProgressDlg.h"
44 #ifdef _DEBUG
45 #define new DEBUG_NEW
46 #undef THIS_FILE
47 static char THIS_FILE[] = __FILE__;
48 #endif
50 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
52 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)
53 CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)
54 : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)
55 , m_bRecursive(FALSE)
56 , m_bShowUnversioned(FALSE)
57 , m_bBlock(FALSE)
58 , m_bThreadRunning(FALSE)
59 , m_bRunThread(FALSE)
60 , m_pThread(NULL)
61 , m_bWholeProject(FALSE)
62 , m_bKeepChangeList(TRUE)
63 , m_bDoNotAutoselectSubmodules(FALSE)
64 , m_itemsCount(0)
65 , m_bSelectFilesForCommit(TRUE)
66 , m_bNoPostActions(FALSE)
67 , m_bAutoClose(false)
68 , m_bSetCommitDateTime(FALSE)
69 , m_bCreateNewBranch(FALSE)
71 this->m_bCommitAmend=FALSE;
72 m_bPushAfterCommit = FALSE;
75 CCommitDlg::~CCommitDlg()
77 if(m_pThread != NULL)
79 delete m_pThread;
83 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
85 CResizableStandAloneDialog::DoDataExchange(pDX);
86 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
87 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
88 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
89 DDX_Check(pDX, IDC_COMMIT_SETDATETIME, m_bSetCommitDateTime);
90 DDX_Check(pDX, IDC_CHECK_NEWBRANCH, m_bCreateNewBranch);
91 DDX_Text(pDX, IDC_NEWBRANCH, m_sCreateNewBranch);
92 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
93 DDX_Text(pDX, IDC_BUGID, m_sBugID);
94 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
95 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
96 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
97 DDX_Check(pDX, IDC_NOAUTOSELECTSUBMODULES, m_bDoNotAutoselectSubmodules);
98 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
99 DDX_Check(pDX,IDC_COMMIT_AMENDDIFF,m_bAmendDiffToLastCommit);
100 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
101 DDX_Control(pDX, IDC_COMMIT_DATEPICKER, m_CommitDate);
102 DDX_Control(pDX, IDC_COMMIT_TIMEPICKER, m_CommitTime);
105 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
106 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
107 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
108 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
109 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
110 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
111 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
112 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
113 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
114 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
115 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE, OnFileDropped)
116 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
117 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
119 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
120 ON_WM_TIMER()
121 ON_WM_SIZE()
122 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
123 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
124 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
125 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
126 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
127 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
128 ON_WM_MOVE()
129 ON_WM_MOVING()
130 ON_WM_SIZING()
131 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
132 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF, &CCommitDlg::OnBnClickedCommitAmenddiff)
133 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES, &CCommitDlg::OnBnClickedNoautoselectsubmodules)
134 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME, &CCommitDlg::OnBnClickedCommitSetDateTime)
135 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH, &CCommitDlg::OnBnClickedCheckNewBranch)
136 END_MESSAGE_MAP()
138 BOOL CCommitDlg::OnInitDialog()
140 CResizableStandAloneDialog::OnInitDialog();
141 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
143 CAppUtils::GetCommitTemplate(this->m_sLogMessage);
145 CString dotGitPath;
146 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
147 if(PathFileExists(dotGitPath + _T("MERGE_MSG")))
149 CStdioFile file;
150 if(file.Open(dotGitPath + _T("MERGE_MSG"), CFile::modeRead))
152 CString str;
153 while(file.ReadString(str))
155 m_sLogMessage += str;
156 str.Empty();
157 m_sLogMessage += _T("\n");
162 if (CTGitPath(g_Git.m_CurrentDir).IsMergeActive())
163 DialogEnableWindow(IDC_CHECK_NEWBRANCH, FALSE);
165 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
166 m_bShowUnversioned = m_regAddBeforeCommit;
168 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
170 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
171 m_bKeepChangeList = m_regKeepChangelists;
173 m_regDoNotAutoselectSubmodules = CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE);
174 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
176 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
178 // GitConfig config;
179 // m_bWholeProject = config.KeepLocks();
181 if(this->m_pathList.GetCount() == 0)
182 m_bWholeProject =true;
184 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
185 m_bWholeProject =true;
187 SetDlgTitle();
189 UpdateData(FALSE);
191 m_ListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD |GITSLC_COLDEL, _T("CommitDlg"),(GITSLC_POPALL ^ (GITSLC_POPCOMMIT | GITSLC_POPSAVEAS)));
192 m_ListCtrl.SetSelectButton(&m_SelectAll);
193 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
194 m_ListCtrl.SetCancelBool(&m_bCancelled);
195 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
196 m_ListCtrl.EnableFileDrop();
197 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
199 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
200 m_ProjectProperties.ReadPropsPathList(m_pathList);
202 m_cLogMessage.Init(m_ProjectProperties);
203 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
204 m_cLogMessage.RegisterContextMenuHandler(this);
206 OnEnChangeLogmessage();
208 m_tooltips.Create(this);
209 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
210 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
211 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
213 m_SelectAll.SetCheck(BST_INDETERMINATE);
215 CBugTraqAssociations bugtraq_associations;
216 bugtraq_associations.Load();
218 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
220 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
221 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
223 CComPtr<IBugTraqProvider> pProvider;
224 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
225 if (SUCCEEDED(hr))
227 m_BugTraqProvider = pProvider;
228 BSTR temp = NULL;
229 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
231 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
232 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
233 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
236 SysFreeString(temp);
239 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
241 else if (!m_ProjectProperties.sMessage.IsEmpty())
243 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
244 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
245 if (!m_ProjectProperties.sLabel.IsEmpty())
246 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
247 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
248 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
249 GetDlgItem(IDC_BUGID)->SetFocus();
250 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
251 if (!sBugID.IsEmpty())
253 SetDlgItemText(IDC_BUGID, sBugID);
256 else
258 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
259 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
260 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
261 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
262 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
265 if (!m_sLogMessage.IsEmpty())
266 m_cLogMessage.SetText(m_sLogMessage);
268 GetWindowText(m_sWindowTitle);
270 AdjustControlSize(IDC_SHOWUNVERSIONED);
271 AdjustControlSize(IDC_SELECTALL);
272 AdjustControlSize(IDC_WHOLE_PROJECT);
274 GetClientRect(m_DlgOrigRect);
275 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
277 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
278 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
279 AddAnchor(IDC_BUGID, TOP_RIGHT);
280 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
281 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
282 AddAnchor(IDC_CHECK_NEWBRANCH, TOP_RIGHT);
283 AddAnchor(IDC_NEWBRANCH, TOP_LEFT, TOP_RIGHT);
284 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
285 // AddAnchor(IDC_HISTORY, TOP_LEFT);
286 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
287 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
288 AddAnchor(IDC_VIEW_PATCH, BOTTOM_RIGHT);
289 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
290 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
291 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
292 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
293 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
294 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
295 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
296 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
297 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
298 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
299 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
300 AddAnchor(IDOK, BOTTOM_RIGHT);
301 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
302 AddAnchor(IDHELP, BOTTOM_RIGHT);
303 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
304 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
305 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
306 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
307 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
309 if (hWndExplorer)
310 CenterWindow(CWnd::FromHandle(hWndExplorer));
311 EnableSaveRestore(_T("CommitDlg"));
312 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
313 RECT rcDlg, rcLogMsg, rcFileList;
314 GetClientRect(&rcDlg);
315 m_cLogMessage.GetWindowRect(&rcLogMsg);
316 ScreenToClient(&rcLogMsg);
317 m_ListCtrl.GetWindowRect(&rcFileList);
318 ScreenToClient(&rcFileList);
319 if (yPos)
321 RECT rectSplitter;
322 m_wndSplitter.GetWindowRect(&rectSplitter);
323 ScreenToClient(&rectSplitter);
324 int delta = yPos - rectSplitter.top;
325 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
327 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
328 DoSize(delta);
332 // add all directories to the watcher
334 for (int i=0; i<m_pathList.GetCount(); ++i)
336 if (m_pathList[i].IsDirectory())
337 m_pathwatcher.AddPath(m_pathList[i]);
340 m_updatedPathList = m_pathList;
342 //first start a thread to obtain the file list with the status without
343 //blocking the dialog
344 InterlockedExchange(&m_bBlock, TRUE);
345 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
346 if (m_pThread==NULL)
348 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
349 InterlockedExchange(&m_bBlock, FALSE);
351 else
353 m_pThread->m_bAutoDelete = FALSE;
354 m_pThread->ResumeThread();
356 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
357 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
358 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
360 historyhint = TRUE;
361 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
363 err = FALSE;
365 if (g_Git.IsInitRepos())
367 m_bCommitAmend = FALSE;
368 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(FALSE);
369 UpdateData(FALSE);
371 else
373 if(m_bCommitAmend)
375 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(FALSE);
376 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
379 CGitHash hash = g_Git.GetHash(_T("HEAD"));
380 GitRev headRevision;
381 headRevision.GetParentFromHash(hash);
382 // do not allow to show diff to "last" revision if it has more that one parent
383 if (headRevision.ParentsCount() != 1)
385 m_bAmendDiffToLastCommit = true;
386 UpdateData(FALSE);
387 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(FALSE);
391 this->m_ctrlShowPatch.SetURL(CString());
393 BOOL viewPatchEnabled = FALSE;
394 m_ProjectProperties.GetBOOLProps(viewPatchEnabled, _T("tgit.commitshowpatch"));
395 if (viewPatchEnabled)
396 OnStnClickedViewPatch();
398 return FALSE; // return TRUE unless you set the focus to a control
399 // EXCEPTION: OCX Property Pages should return FALSE
402 void CCommitDlg::OnOK()
404 if (m_bBlock)
405 return;
406 if (m_bThreadRunning)
408 m_bCancelled = true;
409 InterlockedExchange(&m_bRunThread, FALSE);
410 WaitForSingleObject(m_pThread->m_hThread, 1000);
411 if (m_bThreadRunning)
413 // we gave the thread a chance to quit. Since the thread didn't
414 // listen to us we have to kill it.
415 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
416 InterlockedExchange(&m_bThreadRunning, FALSE);
419 this->UpdateData();
421 if (m_bCreateNewBranch && !g_Git.IsBranchNameValid(m_sCreateNewBranch))
423 ShowEditBalloon(IDC_NEWBRANCH, IDS_B_T_NOTEMPTY, TTI_ERROR);
424 return;
427 CString id;
428 GetDlgItemText(IDC_BUGID, id);
429 if (!m_ProjectProperties.CheckBugID(id))
431 ShowEditBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, TTI_ERROR);
432 return;
434 m_sLogMessage = m_cLogMessage.GetText();
435 if ( m_sLogMessage.IsEmpty() )
437 // no message entered, go round again
438 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
439 return;
441 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
443 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
444 return;
447 BOOL bWarnNoSignedOffBy = FALSE;
448 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy, _T("tgit.warnnosignedoffby"));
449 if (bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
451 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"));
452 if (retval == 1)
454 OnBnClickedSignOff();
455 m_sLogMessage = m_cLogMessage.GetText();
457 else if (retval == 3)
458 return;
461 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
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
467 int nchecked = 0;
468 m_bRecursive = true;
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);
481 if (SUCCEEDED(hr))
483 BSTR temp = NULL;
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)))
496 COMError ce(hr);
497 CString sErr;
498 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
499 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
501 else
503 CString sError = temp;
504 if (!sError.IsEmpty())
506 CMessageBox::Show(m_hWnd, sError, _T("TortoiseGit"), MB_ICONERROR);
507 return;
509 SysFreeString(temp);
514 //CString checkedfiles;
515 //CString uncheckedfiles;
517 CString cmd;
518 CString out;
520 bool bAddSuccess=true;
521 bool bCloseCommitDlg=false;
523 CSysProgressDlg sysProgressDlg;
524 if (nListItems >= 10 && sysProgressDlg.IsValid())
526 sysProgressDlg.SetTitle(_T("Preparing commit..."));
527 sysProgressDlg.SetLine(1, _T("Updating index"));
528 sysProgressDlg.SetTime(true);
529 sysProgressDlg.SetShowProgressBar(true);
530 sysProgressDlg.ShowModal(this, true);
533 for (int j=0; j<nListItems; j++)
535 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
536 if (sysProgressDlg.IsValid())
538 sysProgressDlg.SetLine(2, entry->GetGitPathString(), true);
539 sysProgressDlg.SetProgress(j, nListItems);
540 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing
542 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
543 if (entry->m_Checked)
545 #if 0
546 if (entry->status == Git_wc_status_unversioned)
548 itemsToAdd.AddPath(entry->GetPath());
550 if (entry->status == Git_wc_status_conflicted)
552 bHasConflicted = true;
554 if (entry->status == Git_wc_status_missing)
556 itemsToRemove.AddPath(entry->GetPath());
558 if (entry->status == Git_wc_status_deleted)
560 arDeleted.Add(j);
562 if (entry->IsInExternal())
564 bCheckedInExternal = true;
566 #endif
567 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
568 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
569 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
570 cmd.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry->GetGitPathString());
571 else
572 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
574 if(g_Git.Run(cmd,&out,CP_ACP))
576 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
577 bAddSuccess = false ;
578 break;
581 if( entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
582 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
584 g_Git.Run(cmd,&out,CP_ACP);
586 nchecked++;
588 //checkedLists.insert(entry->GetGitPathString());
589 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
591 else
593 //uncheckedLists.insert(entry->GetGitPathString());
594 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)
595 { //To init git repository, there are not HEAD, so we can use git reset command
596 cmd.Format(_T("git.exe rm -f --cache -- \"%s\""),entry->GetGitPathString());
597 if(g_Git.Run(cmd,&out,CP_ACP))
599 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
600 bAddSuccess = false ;
601 bCloseCommitDlg=false;
602 break;
606 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
608 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
610 cmd.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry->GetGitPathString());
612 else
614 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitPathString());
616 if(g_Git.Run(cmd,&out,CP_ACP))
618 /* when reset a unstage file will report error.
619 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
620 bAddSuccess = false ;
621 bCloseCommitDlg=false;
622 break;
625 // && !entry->IsDirectory()
626 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
627 continue;
630 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
631 #if 0
632 if ((entry->status != Git_wc_status_unversioned) &&
633 (entry->status != Git_wc_status_ignored))
635 nUnchecked++;
636 uncheckedLists.insert(entry->GetChangeList());
637 if (m_bRecursive)
639 // This algorithm is for the sake of simplicity of the complexity O(N?
640 for (int k=0; k<nListItems; k++)
642 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);
643 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath()) )
645 // Fall back to a non-recursive commit to prevent items being
646 // committed which aren't checked although its parent is checked
647 // (property change, directory deletion, ... )
648 m_bRecursive = false;
649 break;
654 #endif
657 if (sysProgressDlg.IsValid() && sysProgressDlg.HasUserCancelled())
659 bAddSuccess = false;
660 break;
663 CShellUpdater::Instance().AddPathForUpdate(*entry);
666 if (sysProgressDlg.IsValid())
667 sysProgressDlg.Stop();
669 if (m_bCreateNewBranch)
671 if (g_Git.Run(_T("git branch ") + m_sCreateNewBranch, &out, CP_ACP))
673 MessageBox(_T("Creating branch failed:\n") + out, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
674 bAddSuccess = false;
676 if (g_Git.Run(_T("git checkout ") + m_sCreateNewBranch, &out, CP_ACP))
678 MessageBox(_T("Switching to new branch failed:\n") + out, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
679 bAddSuccess = false;
683 //if(uncheckedfiles.GetLength()>0)
685 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
686 // g_Git.Run(cmd,&out);
689 m_sBugID.Trim();
690 if (!m_sBugID.IsEmpty())
692 m_sBugID.Replace(_T(", "), _T(","));
693 m_sBugID.Replace(_T(" ,"), _T(","));
694 CString sBugID = m_ProjectProperties.sMessage;
695 sBugID.Replace(_T("%BUGID%"), m_sBugID);
696 if (m_ProjectProperties.bAppend)
697 m_sLogMessage += _T("\n") + sBugID + _T("\n");
698 else
699 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
702 //if(checkedfiles.GetLength()>0)
703 if (bAddSuccess && (nchecked || m_bCommitAmend || CTGitPath(g_Git.m_CurrentDir).IsMergeActive()))
705 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
706 // g_Git.Run(cmd,&out);
708 bCloseCommitDlg = true;
710 CString tempfile=::GetTempFile();
712 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
713 //file.WriteString(m_sLogMessage);
715 CTGitPath path=g_Git.m_CurrentDir;
717 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
719 out =_T("");
720 CString amend;
721 if(this->m_bCommitAmend)
723 amend=_T("--amend");
725 CString dateTime;
726 if (m_bSetCommitDateTime)
728 CTime date, time;
729 m_CommitDate.GetTime(date);
730 m_CommitTime.GetTime(time);
731 dateTime.Format(_T("--date=%sT%s"), date.Format(_T("%Y-%m-%d")), time.Format(_T("%H:%M:%S")));
733 cmd.Format(_T("git.exe commit %s %s -F \"%s\""), dateTime, amend, tempfile);
735 CheckHeadDetach();
737 CCommitProgressDlg progress;
738 progress.m_bBufferAll=true; // improve show speed when there are many file added.
739 progress.m_GitCmd=cmd;
740 progress.m_bShowCommand = FALSE; // don't show the commit command
741 progress.m_PreText = out; // show any output already generated in log window
742 progress.m_bAutoCloseOnSuccess = m_bAutoClose;
744 if (!m_bNoPostActions && !m_bAutoClose)
746 progress.m_PostCmdList.Add( IsGitSVN? _T("&DCommit"): _T("&Push"));
747 progress.m_PostCmdList.Add(_T("&ReCommit"));
750 m_PostCmd = IsGitSVN? GIT_POST_CMD_DCOMMIT:GIT_POST_CMD_PUSH;
752 DWORD userResponse = progress.DoModal();
754 if(progress.m_GitStatus || userResponse == (IDC_PROGRESS_BUTTON1+1))
756 bCloseCommitDlg = false;
757 if( userResponse == (IDC_PROGRESS_BUTTON1+1 ))
759 this->m_sLogMessage.Empty();
760 m_cLogMessage.SetText(m_sLogMessage);
763 this->Refresh();
765 else if(userResponse == IDC_PROGRESS_BUTTON1)
767 //User pressed 'Push' button after successful commit.
768 m_bPushAfterCommit=true;
771 CFile::Remove(tempfile);
773 if (m_BugTraqProvider && progress.m_GitStatus == 0)
775 CComPtr<IBugTraqProvider2> pProvider = NULL;
776 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
777 if (SUCCEEDED(hr))
779 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
780 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
782 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
783 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
785 BSTR logMessage = m_sLogMessage.AllocSysString();
787 CGitHash hash=g_Git.GetHash(_T("HEAD"));
788 LONG version = g_Git.Hash2int(hash);
790 BSTR temp = NULL;
791 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
792 commonRoot,
793 pathList,
794 logMessage,
795 (LONG)version,
796 &temp)))
798 CString sErr = temp;
799 if (!sErr.IsEmpty())
800 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
801 else
803 COMError ce(hr);
804 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
805 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
809 SysFreeString(temp);
814 else if(bAddSuccess)
816 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
817 bCloseCommitDlg=false;
819 #if 0
820 if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)
822 // There are paths which got changed (touched at least).
823 // We have to find out if this affects the selection in the commit dialog
824 // If it could affect the selection, revert back to a non-recursive commit
825 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();
826 changedList.RemoveDuplicates();
827 for (int i=0; i<changedList.GetCount(); ++i)
829 if (changedList[i].IsAdminDir())
831 // something inside an admin dir was changed.
832 // if it's the entries file, then we have to fully refresh because
833 // files may have been added/removed from version control
834 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
835 (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))
837 m_bRecursive = false;
838 break;
841 else if (!m_ListCtrl.IsPathShown(changedList[i]))
843 // a path which is not shown in the list has changed
844 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);
845 if (entry)
847 // check if the changed path would get committed by a recursive commit
848 if ((!entry->IsFromDifferentRepository()) &&
849 (!entry->IsInExternal()) &&
850 (!entry->IsNested()) &&
851 (!entry->IsChecked()))
853 m_bRecursive = false;
854 break;
862 // Now, do all the adds - make sure that the list is sorted so that parents
863 // are added before their children
864 itemsToAdd.SortByPathname();
865 Git Git;
866 if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))
868 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
869 InterlockedExchange(&m_bBlock, FALSE);
870 Refresh();
871 return;
874 // Remove any missing items
875 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
876 itemsToRemove.SortByPathname();
877 Git.Remove(itemsToRemove, TRUE);
879 //the next step: find all deleted files and check if they're
880 //inside a deleted folder. If that's the case, then remove those
881 //files from the list since they'll get deleted by the parent
882 //folder automatically.
883 m_ListCtrl.Block(TRUE, FALSE);
884 INT_PTR nDeleted = arDeleted.GetCount();
885 for (INT_PTR i=0; i<arDeleted.GetCount(); i++)
887 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))
889 const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();
890 if (path.IsDirectory())
892 //now find all children of this directory
893 for (int j=0; j<arDeleted.GetCount(); j++)
895 if (i!=j)
897 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));
898 if (childEntry->IsChecked())
900 if (path.IsAncestorOf(childEntry->GetPath()))
902 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);
903 nDeleted--;
911 m_ListCtrl.Block(FALSE, FALSE);
913 if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))
915 //save only the files the user has checked into the temporary file
916 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);
919 // the item count is used in the progress dialog to show the overall commit
920 // progress.
921 // deleted items only send one notification event, all others send two
922 m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();
924 if ((m_bRecursive)&&(checkedLists.size() == 1))
926 // all checked items belong to the same changelist
927 // find out if there are any unchecked items which belong to that changelist
928 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())
929 m_sChangeList = *checkedLists.begin();
931 #endif
932 UpdateData();
933 m_regAddBeforeCommit = m_bShowUnversioned;
934 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
935 m_bWholeProject = FALSE;
936 m_regKeepChangelists = m_bKeepChangeList;
937 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
938 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
939 m_bKeepChangeList = FALSE;
940 InterlockedExchange(&m_bBlock, FALSE);
942 m_History.AddEntry(m_sLogMessage);
943 m_History.Save();
945 SaveSplitterPos();
947 if( bCloseCommitDlg )
948 CResizableStandAloneDialog::OnOK();
950 CShellUpdater::Instance().Flush();
953 void CCommitDlg::SaveSplitterPos()
955 if (!IsIconic())
957 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
958 RECT rectSplitter;
959 m_wndSplitter.GetWindowRect(&rectSplitter);
960 ScreenToClient(&rectSplitter);
961 regPos = rectSplitter.top;
965 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
967 return ((CCommitDlg*)pVoid)->StatusThread();
970 UINT CCommitDlg::StatusThread()
972 //get the status of all selected file/folders recursively
973 //and show the ones which have to be committed to the user
974 //in a list control.
975 InterlockedExchange(&m_bBlock, TRUE);
976 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
977 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
979 m_pathwatcher.Stop();
981 g_Git.RefreshGitIndex();
983 m_bCancelled = false;
985 DialogEnableWindow(IDOK, false);
986 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
987 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
988 DialogEnableWindow(IDC_SELECTALL, false);
989 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
990 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
991 DialogEnableWindow(IDC_EXTERNALWARNING, false);
992 // read the list of recent log entries before querying the WC for status
993 // -> the user may select one and modify / update it while we are crawling the WC
995 if (m_History.GetCount()==0)
997 CString reg;
998 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
999 reg.Replace(_T(':'),_T('_'));
1000 m_History.Load(reg, _T("logmsgs"));
1003 // Initialise the list control with the status of the files/folders below us
1004 m_ListCtrl.Clear();
1005 BOOL success;
1006 CTGitPathList *pList;
1007 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE) && (m_bAmendDiffToLastCommit==FALSE);
1008 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
1010 if(m_bWholeProject)
1011 pList=NULL;
1012 else
1013 pList = &m_pathList;
1015 success=m_ListCtrl.GetStatus(pList);
1017 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1018 if(this->m_bShowUnversioned)
1019 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
1021 m_ListCtrl.CheckIfChangelistsArePresent(false);
1023 DWORD dwShow = GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWLOCKS | GITSLC_SHOWINCHANGELIST;
1024 dwShow |= DWORD(m_regAddBeforeCommit) ? GITSLC_SHOWUNVERSIONED : 0;
1025 if (success)
1027 if (m_checkedPathList.GetCount())
1028 m_ListCtrl.Show(dwShow, m_checkedPathList);
1029 else
1031 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
1032 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
1033 m_ListCtrl.Show(dwShow, dwCheck);
1034 m_bSelectFilesForCommit = true;
1037 if (m_ListCtrl.HasExternalsFromDifferentRepos())
1039 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
1040 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
1043 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
1044 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
1046 if (!success)
1048 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
1049 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
1050 m_ListCtrl.Show(dwShow);
1053 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
1054 && !PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
1056 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1058 m_bShowUnversioned = TRUE;
1059 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
1060 DWORD dwShow = (DWORD)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWUNVERSIONED | GITSLC_SHOWLOCKS);
1061 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
1062 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
1066 SetDlgTitle();
1068 m_autolist.clear();
1069 // we don't have to block the commit dialog while we fetch the
1070 // auto completion list.
1071 m_pathwatcher.ClearChangedPaths();
1072 InterlockedExchange(&m_bBlock, FALSE);
1073 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
1075 m_ListCtrl.Block(TRUE, TRUE);
1076 GetAutocompletionList();
1077 m_ListCtrl.Block(FALSE, FALSE);
1079 UpdateOKButton();
1080 if (m_bRunThread)
1082 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1083 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1084 DialogEnableWindow(IDC_SELECTALL, true);
1085 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1086 if (m_ListCtrl.HasChangeLists())
1087 DialogEnableWindow(IDC_KEEPLISTS, true);
1088 if (m_ListCtrl.HasLocks())
1089 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1090 // we have the list, now signal the main thread about it
1091 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1094 InterlockedExchange(&m_bRunThread, FALSE);
1095 InterlockedExchange(&m_bThreadRunning, FALSE);
1096 // force the cursor to normal
1097 RefreshCursor();
1099 return 0;
1102 void CCommitDlg::SetDlgTitle()
1104 if (m_sTitle.IsEmpty())
1105 GetWindowText(m_sTitle);
1107 if (m_bWholeProject)
1108 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
1109 else
1111 if (m_pathList.GetCount() == 1)
1112 CAppUtils::SetWindowTitle(m_hWnd, (g_Git.m_CurrentDir + _T("\\") + m_pathList[0].GetUIPathString()).TrimRight('\\'), m_sTitle);
1113 else
1114 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir + _T("\\") + m_ListCtrl.GetCommonDirectory(false), m_sTitle);
1118 void CCommitDlg::OnCancel()
1120 m_bCancelled = true;
1121 m_pathwatcher.Stop();
1123 if (m_bBlock)
1124 return;
1126 if (m_bThreadRunning)
1128 InterlockedExchange(&m_bRunThread, FALSE);
1129 WaitForSingleObject(m_pThread->m_hThread, 1000);
1130 if (m_bThreadRunning)
1132 // we gave the thread a chance to quit. Since the thread didn't
1133 // listen to us we have to kill it.
1134 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1135 InterlockedExchange(&m_bThreadRunning, FALSE);
1138 UpdateData();
1139 m_sBugID.Trim();
1140 m_sLogMessage = m_cLogMessage.GetText();
1141 if (!m_sBugID.IsEmpty())
1143 m_sBugID.Replace(_T(", "), _T(","));
1144 m_sBugID.Replace(_T(" ,"), _T(","));
1145 CString sBugID = m_ProjectProperties.sMessage;
1146 sBugID.Replace(_T("%BUGID%"), m_sBugID);
1147 if (m_ProjectProperties.bAppend)
1148 m_sLogMessage += _T("\n") + sBugID + _T("\n");
1149 else
1150 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1152 if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)
1153 m_History.AddEntry(m_sLogMessage);
1154 m_History.Save();
1155 SaveSplitterPos();
1156 CResizableStandAloneDialog::OnCancel();
1159 void CCommitDlg::OnBnClickedSelectall()
1161 m_tooltips.Pop(); // hide the tooltips
1162 UINT state = (m_SelectAll.GetState() & 0x0003);
1163 if (state == BST_INDETERMINATE)
1165 // It is not at all useful to manually place the checkbox into the indeterminate state...
1166 // We will force this on to the unchecked state
1167 state = BST_UNCHECKED;
1168 m_SelectAll.SetCheck(state);
1170 m_ListCtrl.SelectAll(state == BST_CHECKED);
1173 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1175 if (!m_bBlock)
1176 m_tooltips.RelayEvent(pMsg);
1178 if (m_hAccel)
1180 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1181 if (ret)
1182 return TRUE;
1185 if (pMsg->message == WM_KEYDOWN)
1187 switch (pMsg->wParam)
1189 case VK_F5:
1191 if (m_bBlock)
1192 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1193 Refresh();
1195 break;
1196 case VK_RETURN:
1198 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1200 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1202 PostMessage(WM_COMMAND, IDOK);
1204 return TRUE;
1206 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1208 // Pressing RETURN in the bug id control
1209 // moves the focus to the message
1210 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1211 return TRUE;
1214 break;
1218 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1221 void CCommitDlg::Refresh()
1223 if (m_bThreadRunning)
1224 return;
1226 InterlockedExchange(&m_bBlock, TRUE);
1227 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1228 if (m_pThread==NULL)
1230 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1231 InterlockedExchange(&m_bBlock, FALSE);
1233 else
1235 m_pThread->m_bAutoDelete = FALSE;
1236 m_pThread->ResumeThread();
1240 void CCommitDlg::OnBnClickedHelp()
1242 OnHelp();
1245 void CCommitDlg::OnBnClickedShowunversioned()
1247 m_tooltips.Pop(); // hide the tooltips
1248 UpdateData();
1249 m_regAddBeforeCommit = m_bShowUnversioned;
1250 if (!m_bBlock)
1252 DWORD dwShow = m_ListCtrl.GetShowFlags();
1253 if (DWORD(m_regAddBeforeCommit))
1254 dwShow |= GITSLC_SHOWUNVERSIONED;
1255 else
1256 dwShow &= ~GITSLC_SHOWUNVERSIONED;
1257 if(dwShow & GITSLC_SHOWUNVERSIONED)
1259 if(m_bWholeProject)
1260 m_ListCtrl.GetStatus(NULL,false,false,true);
1261 else
1262 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1264 m_ListCtrl.Show(dwShow,0,true,0,true);
1268 void CCommitDlg::OnStnClickedExternalwarning()
1270 m_tooltips.Popup();
1273 void CCommitDlg::OnEnChangeLogmessage()
1275 UpdateOKButton();
1278 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1280 #if 0
1281 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1283 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1285 m_bShowUnversioned = TRUE;
1286 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1287 m_ListCtrl.Show(dwShow);
1288 UpdateData(FALSE);
1291 #endif
1292 return 0;
1295 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1297 Refresh();
1298 return 0;
1301 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1303 #if 0
1304 BringWindowToTop();
1305 SetForegroundWindow();
1306 SetActiveWindow();
1307 // if multiple files/folders are dropped
1308 // this handler is called for every single item
1309 // separately.
1310 // To avoid creating multiple refresh threads and
1311 // causing crashes, we only add the items to the
1312 // list control and start a timer.
1313 // When the timer expires, we start the refresh thread,
1314 // but only if it isn't already running - otherwise we
1315 // restart the timer.
1316 CTGitPath path;
1317 path.SetFromWin((LPCTSTR)lParam);
1319 // just add all the items we get here.
1320 // if the item is versioned, the add will fail but nothing
1321 // more will happen.
1322 Git Git;
1323 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1325 if (!m_ListCtrl.HasPath(path))
1327 if (m_pathList.AreAllPathsFiles())
1329 m_pathList.AddPath(path);
1330 m_pathList.RemoveDuplicates();
1331 m_updatedPathList.AddPath(path);
1332 m_updatedPathList.RemoveDuplicates();
1334 else
1336 // if the path list contains folders, we have to check whether
1337 // our just (maybe) added path is a child of one of those. If it is
1338 // a child of a folder already in the list, we must not add it. Otherwise
1339 // that path could show up twice in the list.
1340 bool bHasParentInList = false;
1341 for (int i=0; i<m_pathList.GetCount(); ++i)
1343 if (m_pathList[i].IsAncestorOf(path))
1345 bHasParentInList = true;
1346 break;
1349 if (!bHasParentInList)
1351 m_pathList.AddPath(path);
1352 m_pathList.RemoveDuplicates();
1353 m_updatedPathList.AddPath(path);
1354 m_updatedPathList.RemoveDuplicates();
1359 // Always start the timer, since the status of an existing item might have changed
1360 SetTimer(REFRESHTIMER, 200, NULL);
1361 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1362 #endif
1363 return 0;
1366 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1368 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1369 return 0;
1372 //////////////////////////////////////////////////////////////////////////
1373 // functions which run in the status thread
1374 //////////////////////////////////////////////////////////////////////////
1376 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1378 CString strLine;
1381 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1382 while (m_bRunThread && file.ReadString(strLine))
1384 int eqpos = strLine.Find('=');
1385 CString rgx;
1386 rgx = strLine.Mid(eqpos+1).Trim();
1388 int pos = -1;
1389 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1391 mapRegex[strLine.Left(pos)] = rgx;
1392 strLine = strLine.Mid(pos+1).Trim();
1394 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1396 file.Close();
1398 catch (CFileException* pE)
1400 TRACE("CFileException loading auto list regex file\n");
1401 pE->Delete();
1402 return;
1405 void CCommitDlg::GetAutocompletionList()
1407 // the auto completion list is made of strings from each selected files.
1408 // the strings used are extracted from the files with regexes found
1409 // in the file "autolist.txt".
1410 // the format of that file is:
1411 // file extensions separated with commas '=' regular expression to use
1412 // example:
1413 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1414 // .cpp = (?<=[^\s]::)\b\w+\b
1416 std::map<CString, CString> mapRegex;
1417 CString sRegexFile = CPathUtils::GetAppDirectory();
1418 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1419 DWORD timeoutvalue = regtimeout*1000;
1420 sRegexFile += _T("autolist.txt");
1421 if (!m_bRunThread)
1422 return;
1423 ParseRegexFile(sRegexFile, mapRegex);
1424 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1425 sRegexFile.ReleaseBuffer();
1426 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1427 if (PathFileExists(sRegexFile))
1429 ParseRegexFile(sRegexFile, mapRegex);
1431 DWORD starttime = GetTickCount();
1433 // now we have two arrays of strings, where the first array contains all
1434 // file extensions we can use and the second the corresponding regex strings
1435 // to apply to those files.
1437 // the next step is to go over all files shown in the commit dialog
1438 // and scan them for strings we can use
1439 int nListItems = m_ListCtrl.GetItemCount();
1441 for (int i=0; i<nListItems && m_bRunThread; ++i)
1443 // stop parsing after timeout
1444 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1445 return;
1447 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1449 if(path == NULL)
1450 continue;
1452 CString sPartPath =path->GetGitPathString();
1453 m_autolist.insert(sPartPath);
1455 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1456 // if (!entry)
1457 // continue;
1459 // add the path parts to the auto completion list too
1460 // CString sPartPath = entry->GetRelativeGitPath();
1461 // m_autolist.insert(sPartPath);
1464 int pos = 0;
1465 int lastPos = 0;
1466 while ((pos = sPartPath.Find('/', pos)) >= 0)
1468 pos++;
1469 lastPos = pos;
1470 m_autolist.insert(sPartPath.Mid(pos));
1473 // Last inserted entry is a file name.
1474 // Some users prefer to also list file name without extension.
1475 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1477 int dotPos = sPartPath.ReverseFind('.');
1478 if ((dotPos >= 0) && (dotPos > lastPos))
1479 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1481 #if 0
1482 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1483 continue;
1485 CString sExt = entry->GetPath().GetFileExtension();
1486 sExt.MakeLower();
1487 // find the regex string which corresponds to the file extension
1488 CString rdata = mapRegex[sExt];
1489 if (rdata.IsEmpty())
1490 continue;
1492 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1493 if ((entry->textstatus != Git_wc_status_unversioned) &&
1494 (entry->textstatus != Git_wc_status_none) &&
1495 (entry->textstatus != Git_wc_status_ignored) &&
1496 (entry->textstatus != Git_wc_status_added) &&
1497 (entry->textstatus != Git_wc_status_normal))
1499 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1500 if (!basePath.IsEmpty())
1501 ScanFile(basePath.GetWinPathString(), rdata);
1503 #endif
1505 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1508 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1510 wstring sFileContent;
1511 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1512 if (hFile != INVALID_HANDLE_VALUE)
1514 DWORD size = GetFileSize(hFile, NULL);
1515 if (size > 1000000L)
1517 // no files bigger than 1 Meg
1518 CloseHandle(hFile);
1519 return;
1521 // allocate memory to hold file contents
1522 char * buffer = new char[size];
1523 DWORD readbytes;
1524 ReadFile(hFile, buffer, size, &readbytes, NULL);
1525 CloseHandle(hFile);
1526 int opts = 0;
1527 IsTextUnicode(buffer, readbytes, &opts);
1528 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1530 delete [] buffer;
1531 return;
1533 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1535 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1537 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1539 int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1540 wchar_t * pWideBuf = new wchar_t[ret];
1541 int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1542 if (ret2 == ret)
1543 sFileContent = wstring(pWideBuf, ret);
1544 delete [] pWideBuf;
1546 delete [] buffer;
1548 if (sFileContent.empty()|| !m_bRunThread)
1550 return;
1555 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1556 const tr1::wsregex_iterator end;
1557 wstring s = sFileContent;
1558 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1560 const tr1::wsmatch match = *it;
1561 for (size_t i=1; i<match.size(); ++i)
1563 if (match[i].second-match[i].first)
1565 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1566 m_autolist.insert(wstring(match[i]).c_str());
1571 catch (exception) {}
1574 // CSciEditContextMenuInterface
1575 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1577 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1578 m_nPopupPasteListCmd = nCmd++;
1579 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1581 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1582 if(m_History.GetCount() > 0)
1584 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1585 m_nPopupPasteLastMessage = nCmd++;
1586 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1588 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1589 m_nPopupRecentMessage = nCmd++;
1590 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1596 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1599 if (m_bBlock)
1600 return false;
1601 if (cmd == m_nPopupPasteListCmd)
1603 CString logmsg;
1604 int nListItems = m_ListCtrl.GetItemCount();
1605 for (int i=0; i<nListItems; ++i)
1607 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1608 if (entry&&entry->m_Checked)
1610 CString line;
1611 CString status = entry->GetActionName();
1612 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1613 status = _T("Add");
1615 //git_wc_status_kind status = entry->status;
1616 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1617 if (m_ProjectProperties.bFileListInEnglish)
1618 langID = 1033;
1620 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1621 logmsg += line;
1624 pSciEdit->InsertText(logmsg);
1625 return true;
1628 if(cmd == m_nPopupPasteLastMessage)
1630 if(m_History.GetCount() ==0 )
1631 return false;
1633 CString logmsg;
1634 logmsg +=m_History.GetEntry(0);
1635 pSciEdit->InsertText(logmsg);
1636 return true;
1639 if(cmd == m_nPopupRecentMessage )
1641 OnBnClickedHistory();
1642 return true;
1644 return false;
1647 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1649 switch (nIDEvent)
1651 case ENDDIALOGTIMER:
1652 KillTimer(ENDDIALOGTIMER);
1653 EndDialog(0);
1654 break;
1655 case REFRESHTIMER:
1656 if (m_bThreadRunning)
1658 SetTimer(REFRESHTIMER, 200, NULL);
1659 ATLTRACE("Wait some more before refreshing\n");
1661 else
1663 KillTimer(REFRESHTIMER);
1664 ATLTRACE("Refreshing after items dropped\n");
1665 Refresh();
1667 break;
1669 __super::OnTimer(nIDEvent);
1672 void CCommitDlg::OnBnClickedHistory()
1674 m_tooltips.Pop(); // hide the tooltips
1675 if (m_pathList.GetCount() == 0)
1676 return;
1678 CHistoryDlg historyDlg;
1679 historyDlg.SetHistory(m_History);
1680 if (historyDlg.DoModal() != IDOK)
1681 return;
1683 CString sMsg = historyDlg.GetSelectedText();
1684 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1686 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);
1687 if (!sBugID.IsEmpty())
1689 SetDlgItemText(IDC_BUGID, sBugID);
1691 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1692 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1693 else
1694 m_cLogMessage.SetText(sMsg);
1697 UpdateOKButton();
1698 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1702 void CCommitDlg::OnBnClickedBugtraqbutton()
1704 m_tooltips.Pop(); // hide the tooltips
1705 CString sMsg = m_cLogMessage.GetText();
1707 if (m_BugTraqProvider == NULL)
1708 return;
1710 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1711 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1712 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1714 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1715 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1717 BSTR originalMessage = sMsg.AllocSysString();
1718 BSTR temp = NULL;
1719 // m_revProps.clear();
1721 // first try the IBugTraqProvider2 interface
1722 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1723 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1724 if (SUCCEEDED(hr))
1726 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1727 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1728 BSTR bugIDOut = NULL;
1729 GetDlgItemText(IDC_BUGID, m_sBugID);
1730 BSTR bugID = m_sBugID.AllocSysString();
1731 SAFEARRAY * revPropNames = NULL;
1732 SAFEARRAY * revPropValues = NULL;
1733 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1735 CString sErr;
1736 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1737 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1739 else
1741 if (bugIDOut)
1743 m_sBugID = bugIDOut;
1744 SysFreeString(bugIDOut);
1745 SetDlgItemText(IDC_BUGID, m_sBugID);
1747 SysFreeString(bugID);
1748 SysFreeString(repositoryRoot);
1749 m_cLogMessage.SetText(temp);
1750 BSTR HUGEP *pbRevNames;
1751 BSTR HUGEP *pbRevValues;
1753 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1754 if (SUCCEEDED(hr1))
1756 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1757 if (SUCCEEDED(hr2))
1759 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1761 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)
1763 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1766 SafeArrayUnaccessData(revPropValues);
1768 SafeArrayUnaccessData(revPropNames);
1770 if (revPropNames)
1771 SafeArrayDestroy(revPropNames);
1772 if (revPropValues)
1773 SafeArrayDestroy(revPropValues);
1776 else
1778 // if IBugTraqProvider2 failed, try IBugTraqProvider
1779 CComPtr<IBugTraqProvider> pProvider = NULL;
1780 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1781 if (FAILED(hr))
1783 CString sErr;
1784 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1785 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1786 return;
1789 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1791 CString sErr;
1792 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1793 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1795 else
1796 m_cLogMessage.SetText(temp);
1798 m_sLogMessage = m_cLogMessage.GetText();
1799 if (!m_ProjectProperties.sMessage.IsEmpty())
1801 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1802 if (!sBugID.IsEmpty())
1804 SetDlgItemText(IDC_BUGID, sBugID);
1808 m_cLogMessage.SetFocus();
1810 SysFreeString(parameters);
1811 SysFreeString(commonRoot);
1812 SafeArrayDestroy(pathList);
1813 SysFreeString(originalMessage);
1814 SysFreeString(temp);
1818 void CCommitDlg::FillPatchView()
1820 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1822 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
1824 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
1825 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
1826 CString cmd,out;
1828 while(pos)
1830 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
1831 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
1832 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
1834 CString head = _T("HEAD");
1835 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
1836 head = _T("HEAD~1");
1837 cmd.Format(_T("git.exe diff %s -- \"%s\""), head, p->GetGitPathString());
1838 g_Git.Run(cmd,&out,CP_ACP);
1842 m_patchViewdlg.m_ctrlPatchView.SetText(out);
1843 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
1844 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
1847 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1849 this->FillPatchView();
1850 return 0;
1854 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1856 UpdateOKButton();
1857 return 0;
1860 void CCommitDlg::UpdateOKButton()
1862 if (m_bBlock)
1863 return;
1865 bool bValidLogSize = m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize && m_cLogMessage.GetText().GetLength() > 0;
1866 bool bAmendOrSelectFilesOrMerge = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit) || CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1868 DialogEnableWindow(IDOK, bValidLogSize && bAmendOrSelectFilesOrMerge);
1871 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1873 switch (message) {
1874 case WM_NOTIFY:
1875 if (wParam == IDC_SPLITTER)
1877 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1878 DoSize(pHdr->delta);
1880 break;
1883 return __super::DefWindowProc(message, wParam, lParam);
1886 void CCommitDlg::SetSplitterRange()
1888 if ((m_ListCtrl)&&(m_cLogMessage))
1890 CRect rcTop;
1891 m_cLogMessage.GetWindowRect(rcTop);
1892 ScreenToClient(rcTop);
1893 CRect rcMiddle;
1894 m_ListCtrl.GetWindowRect(rcMiddle);
1895 ScreenToClient(rcMiddle);
1896 if (rcMiddle.Height() && rcMiddle.Width())
1897 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
1901 void CCommitDlg::DoSize(int delta)
1903 RemoveAnchor(IDC_MESSAGEGROUP);
1904 RemoveAnchor(IDC_LOGMESSAGE);
1905 RemoveAnchor(IDC_SPLITTER);
1906 RemoveAnchor(IDC_SIGNOFF);
1907 RemoveAnchor(IDC_COMMIT_AMEND);
1908 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
1909 RemoveAnchor(IDC_COMMIT_SETDATETIME);
1910 RemoveAnchor(IDC_COMMIT_DATEPICKER);
1911 RemoveAnchor(IDC_COMMIT_TIMEPICKER);
1912 RemoveAnchor(IDC_LISTGROUP);
1913 RemoveAnchor(IDC_FILELIST);
1914 RemoveAnchor(IDC_TEXT_INFO);
1916 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
1917 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
1918 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
1919 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
1920 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
1921 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
1922 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
1923 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME),0,delta);
1924 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER),0,delta);
1925 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER),0,delta);
1926 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
1928 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
1929 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
1930 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
1931 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
1932 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
1933 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
1934 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
1935 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
1936 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
1937 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
1938 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
1939 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
1940 ArrangeLayout();
1941 // adjust the minimum size of the dialog to prevent the resizing from
1942 // moving the list control too far down.
1943 CRect rcLogMsg;
1944 m_cLogMessage.GetClientRect(rcLogMsg);
1945 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
1947 SetSplitterRange();
1948 m_cLogMessage.Invalidate();
1949 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
1952 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
1954 // first, let the resizing take place
1955 __super::OnSize(nType, cx, cy);
1957 //set range
1958 SetSplitterRange();
1961 CString CCommitDlg::GetSignedOffByLine()
1963 CString str;
1965 CString username = g_Git.GetUserName();
1966 CString email = g_Git.GetUserEmail();
1967 username.Remove(_T('\n'));
1968 email.Remove(_T('\n'));
1970 str.Format(_T("Signed-off-by: %s <%s>"), username, email);
1972 return str;
1975 void CCommitDlg::OnBnClickedSignOff()
1977 CString str = GetSignedOffByLine();
1979 if (m_cLogMessage.GetText().Find(str) == -1) {
1980 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
1981 int lastNewline = m_cLogMessage.GetText().ReverseFind(_T('\n'));
1982 int foundByLine = -1;
1983 if (lastNewline > 0)
1984 foundByLine = m_cLogMessage.GetText().Find(_T("-by: "), lastNewline);
1986 if (foundByLine == -1 || foundByLine < lastNewline)
1987 str = _T("\r\n") + str;
1989 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n")+str+_T("\r\n"));
1993 void CCommitDlg::OnBnClickedCommitAmend()
1995 this->UpdateData();
1996 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
1998 GitRev rev;
1999 rev.GetCommit(CString(_T("HEAD")));
2000 m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody();
2003 if(this->m_bCommitAmend)
2005 this->m_NoAmendStr=this->m_cLogMessage.GetText();
2006 m_cLogMessage.SetText(m_AmendStr);
2007 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
2009 else
2011 this->m_AmendStr=this->m_cLogMessage.GetText();
2012 m_cLogMessage.SetText(m_NoAmendStr);
2013 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
2016 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2018 Refresh();
2021 void CCommitDlg::OnBnClickedWholeProject()
2023 m_tooltips.Pop(); // hide the tooltips
2024 UpdateData();
2025 m_ListCtrl.Clear();
2026 if (!m_bBlock)
2028 if(m_bWholeProject)
2029 m_ListCtrl.GetStatus(NULL,true,false,true);
2030 else
2031 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
2033 DWORD dwShow = (DWORD)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWUNVERSIONED | GITSLC_SHOWLOCKS);
2034 m_ListCtrl.Show(m_ListCtrl.GetShowFlags(), dwShow & (~CTGitPath::LOGACTIONS_UNVER|~CTGitPath::LOGACTIONS_IGNORE));
2037 SetDlgTitle();
2040 void CCommitDlg::OnFocusMessage()
2042 m_cLogMessage.SetFocus();
2045 void CCommitDlg::OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult)
2047 UNREFERENCED_PARAMETER(pNMHDR);
2048 int pos=this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
2049 int line=this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
2050 int column=this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
2052 CString str;
2053 str.Format(_T("%d/%d"),line+1,column+1);
2054 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
2056 if(*pResult)
2057 *pResult=0;
2059 void CCommitDlg::OnStnClickedViewPatch()
2061 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
2062 m_patchViewdlg.m_ParentCommitDlg = this;
2063 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
2065 BOOL viewPatchEnabled = FALSE;
2066 m_ProjectProperties.GetBOOLProps(viewPatchEnabled, _T("tgit.commitshowpatch"));
2067 if (viewPatchEnabled == FALSE)
2068 g_Git.SetConfigValue(_T("tgit.showpatch"), _T("true"));
2069 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
2070 CRect rect;
2071 this->GetWindowRect(&rect);
2073 m_patchViewdlg.ShowWindow(SW_SHOW);
2075 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
2076 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
2078 ShowViewPatchText(false);
2079 FillPatchView();
2081 else
2083 g_Git.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2084 m_patchViewdlg.ShowWindow(SW_HIDE);
2085 m_patchViewdlg.DestroyWindow();
2086 ShowViewPatchText(true);
2088 this->m_ctrlShowPatch.Invalidate();
2091 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
2093 __super::OnMoving(fwSide, pRect);
2095 if (::IsWindow(m_patchViewdlg.m_hWnd))
2097 RECT patchrect;
2098 m_patchViewdlg.GetWindowRect(&patchrect);
2099 if (::IsWindow(m_hWnd))
2101 RECT thisrect;
2102 GetWindowRect(&thisrect);
2103 if (patchrect.left == thisrect.right)
2105 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2106 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2113 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2115 __super::OnSizing(fwSide, pRect);
2117 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2119 CRect thisrect, patchrect;
2120 this->GetWindowRect(thisrect);
2121 this->m_patchViewdlg.GetWindowRect(patchrect);
2122 if(thisrect.right==patchrect.left)
2124 patchrect.left -= (thisrect.right - pRect->right);
2125 patchrect.right-= (thisrect.right - pRect->right);
2127 if( patchrect.bottom == thisrect.bottom)
2129 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2131 if( patchrect.top == thisrect.top)
2133 patchrect.top -= thisrect.top-pRect->top;
2135 m_patchViewdlg.MoveWindow(patchrect);
2140 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult)
2142 UNREFERENCED_PARAMETER(pNMHDR);
2143 *pResult = 0;
2144 TRACE("Item Changed\r\n");
2147 int CCommitDlg::CheckHeadDetach()
2149 CString output;
2150 if(g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir,output))
2152 if(CMessageBox::Show(NULL,_T("<ct=0x0000FF>Current HEAD Detached</ct>, you are working on (no branch)\nDo you want create branch now?"),
2153 _T("TortoiseGit"),MB_YESNO|MB_ICONWARNING) == IDYES)
2155 CAppUtils::CreateBranchTag(FALSE,NULL,true);
2158 return 0;
2161 void CCommitDlg::OnBnClickedCommitAmenddiff()
2163 UpdateData();
2164 Refresh();
2167 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2169 UpdateData();
2170 Refresh();
2173 void CCommitDlg::OnBnClickedCommitSetDateTime()
2175 UpdateData();
2177 if (m_bSetCommitDateTime)
2179 CTime authordate = CTime::GetCurrentTime();
2180 if (m_bCommitAmend)
2182 GitRev headRevision;
2183 headRevision.GetCommit(_T("HEAD"));
2184 authordate = headRevision.GetAuthorDate();
2187 m_CommitDate.SetTime(&authordate);
2188 m_CommitTime.SetTime(&authordate);
2190 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
2191 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
2193 else
2195 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_HIDE);
2196 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_HIDE);
2200 void CCommitDlg::OnBnClickedCheckNewBranch()
2202 UpdateData();
2203 if (m_bCreateNewBranch)
2205 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_HIDE);
2206 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_SHOW);
2208 else
2210 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
2211 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);