warn user if signed-off-by line is missing
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob16006cb67dce42674db9881f3eff2f389f1a1cd5
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.
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"
43 #ifdef _DEBUG
44 #define new DEBUG_NEW
45 #undef THIS_FILE
46 static char THIS_FILE[] = __FILE__;
47 #endif
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)
54 , m_bRecursive(FALSE)
55 , m_bShowUnversioned(FALSE)
56 , m_bBlock(FALSE)
57 , m_bThreadRunning(FALSE)
58 , m_bRunThread(FALSE)
59 , m_pThread(NULL)
60 , m_bWholeProject(FALSE)
61 , m_bKeepChangeList(TRUE)
62 , m_bDoNotAutoselectSubmodules(FALSE)
63 , m_itemsCount(0)
64 , m_bSelectFilesForCommit(TRUE)
65 , m_bNoPostActions(FALSE)
66 , m_bAutoClose(false)
68 this->m_bCommitAmend=FALSE;
69 m_bPushAfterCommit = FALSE;
72 CCommitDlg::~CCommitDlg()
74 if(m_pThread != NULL)
76 delete m_pThread;
80 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
82 CResizableStandAloneDialog::DoDataExchange(pDX);
83 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
84 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
85 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
86 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
87 DDX_Text(pDX, IDC_BUGID, m_sBugID);
88 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
89 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
90 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
91 DDX_Check(pDX, IDC_NOAUTOSELECTSUBMODULES, m_bDoNotAutoselectSubmodules);
92 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
93 DDX_Check(pDX,IDC_COMMIT_AMENDDIFF,m_bAmendDiffToLastCommit);
94 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
97 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
98 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
99 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
100 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
101 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
102 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
103 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
104 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
105 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
106 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
107 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE, OnFileDropped)
108 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
109 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
111 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
112 ON_WM_TIMER()
113 ON_WM_SIZE()
114 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
115 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
116 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
117 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
118 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
119 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
120 ON_WM_MOVE()
121 ON_WM_MOVING()
122 ON_WM_SIZING()
123 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
124 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF, &CCommitDlg::OnBnClickedCommitAmenddiff)
125 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES, &CCommitDlg::OnBnClickedNoautoselectsubmodules)
126 END_MESSAGE_MAP()
128 BOOL CCommitDlg::OnInitDialog()
130 CResizableStandAloneDialog::OnInitDialog();
131 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
133 CAppUtils::GetCommitTemplate(this->m_sLogMessage);
135 if(PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_MSG")))
137 CStdioFile file;
138 if(file.Open(g_Git.m_CurrentDir+_T("\\.git\\MERGE_MSG"), CFile::modeRead))
140 CString str;
141 while(file.ReadString(str))
143 m_sLogMessage += str;
144 str.Empty();
145 m_sLogMessage += _T("\n");
149 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
150 m_bShowUnversioned = m_regAddBeforeCommit;
152 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
154 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
155 m_bKeepChangeList = m_regKeepChangelists;
157 m_regDoNotAutoselectSubmodules = CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE);
158 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
160 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
162 // GitConfig config;
163 // m_bWholeProject = config.KeepLocks();
165 if(this->m_pathList.GetCount() == 0)
166 m_bWholeProject =true;
168 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
169 m_bWholeProject =true;
171 UpdateData(FALSE);
173 m_ListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS | SVNSLC_COLADD |SVNSLC_COLDEL, _T("CommitDlg"),(SVNSLC_POPALL ^ (SVNSLC_POPCOMMIT | SVNSLC_POPSAVEAS)));
174 m_ListCtrl.SetSelectButton(&m_SelectAll);
175 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
176 m_ListCtrl.SetCancelBool(&m_bCancelled);
177 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
178 m_ListCtrl.EnableFileDrop();
179 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
181 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
182 m_ProjectProperties.ReadPropsPathList(m_pathList);
184 m_cLogMessage.Init(m_ProjectProperties);
185 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
186 m_cLogMessage.RegisterContextMenuHandler(this);
188 OnEnChangeLogmessage();
190 m_tooltips.Create(this);
191 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
192 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
193 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
195 m_SelectAll.SetCheck(BST_INDETERMINATE);
197 CBugTraqAssociations bugtraq_associations;
198 bugtraq_associations.Load();
200 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
202 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
203 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
205 CComPtr<IBugTraqProvider> pProvider;
206 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
207 if (SUCCEEDED(hr))
209 m_BugTraqProvider = pProvider;
210 BSTR temp = NULL;
211 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
213 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
214 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
215 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
218 SysFreeString(temp);
221 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
223 else if (!m_ProjectProperties.sMessage.IsEmpty())
225 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
226 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
227 if (!m_ProjectProperties.sLabel.IsEmpty())
228 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
229 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
230 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
231 GetDlgItem(IDC_BUGID)->SetFocus();
232 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
233 if (!sBugID.IsEmpty())
235 SetDlgItemText(IDC_BUGID, sBugID);
238 else
240 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
241 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
242 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
243 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
244 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
247 if (!m_sLogMessage.IsEmpty())
248 m_cLogMessage.SetText(m_sLogMessage);
250 GetWindowText(m_sWindowTitle);
252 AdjustControlSize(IDC_SHOWUNVERSIONED);
253 AdjustControlSize(IDC_SELECTALL);
254 AdjustControlSize(IDC_WHOLE_PROJECT);
256 GetClientRect(m_DlgOrigRect);
257 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
259 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
260 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
261 AddAnchor(IDC_BUGID, TOP_RIGHT);
262 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
263 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
264 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
265 // AddAnchor(IDC_HISTORY, TOP_LEFT);
266 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
267 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
268 AddAnchor(IDC_VIEW_PATCH,TOP_RIGHT);
269 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
270 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
271 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
272 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
273 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
274 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
275 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
276 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
277 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
278 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
279 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
280 AddAnchor(IDOK, BOTTOM_RIGHT);
281 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
282 AddAnchor(IDHELP, BOTTOM_RIGHT);
283 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
284 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
286 if (hWndExplorer)
287 CenterWindow(CWnd::FromHandle(hWndExplorer));
288 EnableSaveRestore(_T("CommitDlg"));
289 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
290 RECT rcDlg, rcLogMsg, rcFileList;
291 GetClientRect(&rcDlg);
292 m_cLogMessage.GetWindowRect(&rcLogMsg);
293 ScreenToClient(&rcLogMsg);
294 m_ListCtrl.GetWindowRect(&rcFileList);
295 ScreenToClient(&rcFileList);
296 if (yPos)
298 RECT rectSplitter;
299 m_wndSplitter.GetWindowRect(&rectSplitter);
300 ScreenToClient(&rectSplitter);
301 int delta = yPos - rectSplitter.top;
302 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
304 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
305 DoSize(delta);
309 // add all directories to the watcher
311 for (int i=0; i<m_pathList.GetCount(); ++i)
313 if (m_pathList[i].IsDirectory())
314 m_pathwatcher.AddPath(m_pathList[i]);
317 m_updatedPathList = m_pathList;
319 //first start a thread to obtain the file list with the status without
320 //blocking the dialog
321 InterlockedExchange(&m_bBlock, TRUE);
322 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
323 if (m_pThread==NULL)
325 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
326 InterlockedExchange(&m_bBlock, FALSE);
328 else
330 m_pThread->m_bAutoDelete = FALSE;
331 m_pThread->ResumeThread();
333 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
334 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
335 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
337 historyhint = TRUE;
338 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
340 err = FALSE;
342 if(m_bCommitAmend)
344 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(FALSE);
345 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
348 CGitHash hash = g_Git.GetHash(_T("HEAD"));
349 GitRev headRevision;
350 headRevision.GetParentFromHash(hash);
351 if (headRevision.ParentsCount() != 1)
353 m_bAmendDiffToLastCommit = true;
354 UpdateData(FALSE);
355 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(FALSE);
358 this->m_ctrlShowPatch.SetURL(CString());
360 return FALSE; // return TRUE unless you set the focus to a control
361 // EXCEPTION: OCX Property Pages should return FALSE
364 void CCommitDlg::OnOK()
366 if (m_bBlock)
367 return;
368 if (m_bThreadRunning)
370 m_bCancelled = true;
371 InterlockedExchange(&m_bRunThread, FALSE);
372 WaitForSingleObject(m_pThread->m_hThread, 1000);
373 if (m_bThreadRunning)
375 // we gave the thread a chance to quit. Since the thread didn't
376 // listen to us we have to kill it.
377 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
378 InterlockedExchange(&m_bThreadRunning, FALSE);
381 this->UpdateData();
383 CString id;
384 GetDlgItemText(IDC_BUGID, id);
385 if (!m_ProjectProperties.CheckBugID(id))
387 ShowBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDI_EXCLAMATION);
388 return;
390 m_sLogMessage = m_cLogMessage.GetText();
391 if ( m_sLogMessage.IsEmpty() )
393 // no message entered, go round again
394 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
395 return;
397 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
399 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
400 return;
403 BOOL bWarnNoSignedOffBy = FALSE;
404 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy, _T("tgit.warnnosignedoffby"));
405 if (bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
407 if (CMessageBox::Show(this->m_hWnd, _T("You haven't entered a Signed-Off-By line!\nAre you sure you want to commit without this line?"), _T("TortoiseGit"), MB_YESNO | MB_ICONWARNING) != IDYES)
408 return;
411 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
412 #if 0
413 CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);
414 if (!(DWORD)regUnversionedRecurse)
416 // Find unversioned directories which are marked for commit. The user might expect them
417 // to be added recursively since he cannot the the files. Let's ask the user if he knows
418 // what he is doing.
419 int nListItems = m_ListCtrl.GetItemCount();
420 for (int j=0; j<nListItems; j++)
422 const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
423 if (entry->IsChecked() && (entry->status == Git_wc_status_unversioned) && entry->IsFolder() )
425 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
426 return;
430 #endif
431 m_pathwatcher.Stop();
432 InterlockedExchange(&m_bBlock, TRUE);
433 CDWordArray arDeleted;
434 //first add all the unversioned files the user selected
435 //and check if all versioned files are selected
436 int nchecked = 0;
437 m_bRecursive = true;
438 int nListItems = m_ListCtrl.GetItemCount();
440 CTGitPathList itemsToAdd;
441 CTGitPathList itemsToRemove;
442 //std::set<CString> checkedLists;
443 //std::set<CString> uncheckedLists;
445 // now let the bugtraq plugin check the commit message
446 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
447 if (m_BugTraqProvider)
449 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
450 if (SUCCEEDED(hr))
452 BSTR temp = NULL;
453 CString common = g_Git.m_CurrentDir;
454 BSTR repositoryRoot = common.AllocSysString();
455 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
456 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
457 BSTR commitMessage = m_sLogMessage.AllocSysString();
458 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
460 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
461 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
463 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
465 COMError ce(hr);
466 CString sErr;
467 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
468 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
470 else
472 CString sError = temp;
473 if (!sError.IsEmpty())
475 CMessageBox::Show(m_hWnd, sError, _T("TortoiseGit"), MB_ICONERROR);
476 return;
478 SysFreeString(temp);
483 //CString checkedfiles;
484 //CString uncheckedfiles;
486 CString cmd;
487 CString out;
489 bool bAddSuccess=true;
490 bool bCloseCommitDlg=false;
492 for (int j=0; j<nListItems; j++)
494 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
495 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
496 if (entry->m_Checked)
498 #if 0
499 if (entry->status == Git_wc_status_unversioned)
501 itemsToAdd.AddPath(entry->GetPath());
503 if (entry->status == Git_wc_status_conflicted)
505 bHasConflicted = true;
507 if (entry->status == Git_wc_status_missing)
509 itemsToRemove.AddPath(entry->GetPath());
511 if (entry->status == Git_wc_status_deleted)
513 arDeleted.Add(j);
515 if (entry->IsInExternal())
517 bCheckedInExternal = true;
519 #endif
520 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
521 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
522 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
523 cmd.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry->GetGitPathString());
524 else
525 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
527 if(g_Git.Run(cmd,&out,CP_ACP))
529 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
530 bAddSuccess = false ;
531 break;
534 if( entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
535 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
537 g_Git.Run(cmd,&out,CP_ACP);
539 nchecked++;
541 //checkedLists.insert(entry->GetGitPathString());
542 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
544 else
546 //uncheckedLists.insert(entry->GetGitPathString());
547 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)
548 { //To init git repository, there are not HEAD, so we can use git reset command
549 cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString());
550 if(g_Git.Run(cmd,&out,CP_ACP))
552 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
553 bAddSuccess = false ;
554 bCloseCommitDlg=false;
555 break;
559 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
561 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
563 cmd.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry->GetGitPathString());
565 else
567 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitPathString());
569 if(g_Git.Run(cmd,&out,CP_ACP))
571 /* when reset a unstage file will report error.
572 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
573 bAddSuccess = false ;
574 bCloseCommitDlg=false;
575 break;
578 // && !entry->IsDirectory()
579 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
580 continue;
583 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
584 #if 0
585 if ((entry->status != Git_wc_status_unversioned) &&
586 (entry->status != Git_wc_status_ignored))
588 nUnchecked++;
589 uncheckedLists.insert(entry->GetChangeList());
590 if (m_bRecursive)
592 // This algorithm is for the sake of simplicity of the complexity O(N?
593 for (int k=0; k<nListItems; k++)
595 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);
596 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath()) )
598 // Fall back to a non-recursive commit to prevent items being
599 // committed which aren't checked although its parent is checked
600 // (property change, directory deletion, ... )
601 m_bRecursive = false;
602 break;
607 #endif
610 CShellUpdater::Instance().AddPathForUpdate(*entry);
613 //if(uncheckedfiles.GetLength()>0)
615 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
616 // g_Git.Run(cmd,&out);
619 m_sBugID.Trim();
620 if (!m_sBugID.IsEmpty())
622 m_sBugID.Replace(_T(", "), _T(","));
623 m_sBugID.Replace(_T(" ,"), _T(","));
624 CString sBugID = m_ProjectProperties.sMessage;
625 sBugID.Replace(_T("%BUGID%"), m_sBugID);
626 if (m_ProjectProperties.bAppend)
627 m_sLogMessage += _T("\n") + sBugID + _T("\n");
628 else
629 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
632 BOOL bIsMerge=false;
633 if(PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
635 bIsMerge=true;
637 //if(checkedfiles.GetLength()>0)
638 if( bAddSuccess && (nchecked||m_bCommitAmend||bIsMerge) )
640 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
641 // g_Git.Run(cmd,&out);
643 bCloseCommitDlg = true;
645 CString tempfile=::GetTempFile();
647 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
648 //file.WriteString(m_sLogMessage);
650 CTGitPath path=g_Git.m_CurrentDir;
652 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
654 out =_T("");
655 CString amend;
656 if(this->m_bCommitAmend)
658 amend=_T("--amend");
660 cmd.Format(_T("git.exe commit %s -F \"%s\""),amend, tempfile);
662 CheckHeadDetach();
664 CCommitProgressDlg progress;
665 progress.m_bBufferAll=true; // improve show speed when there are many file added.
666 progress.m_GitCmd=cmd;
667 progress.m_bShowCommand = FALSE; // don't show the commit command
668 progress.m_PreText = out; // show any output already generated in log window
669 progress.m_bAutoCloseOnSuccess = m_bAutoClose;
671 if (!m_bNoPostActions && !m_bAutoClose)
673 progress.m_PostCmdList.Add( IsGitSVN? _T("&DCommit"): _T("&Push"));
674 progress.m_PostCmdList.Add(_T("&ReCommit"));
677 m_PostCmd = IsGitSVN? GIT_POST_CMD_DCOMMIT:GIT_POST_CMD_PUSH;
679 DWORD userResponse = progress.DoModal();
681 if(progress.m_GitStatus || userResponse == (IDC_PROGRESS_BUTTON1+1))
683 bCloseCommitDlg = false;
684 if( userResponse == (IDC_PROGRESS_BUTTON1+1 ))
686 this->m_sLogMessage.Empty();
687 m_cLogMessage.SetText(m_sLogMessage);
690 this->Refresh();
692 else if(userResponse == IDC_PROGRESS_BUTTON1)
694 //User pressed 'Push' button after successful commit.
695 m_bPushAfterCommit=true;
698 CFile::Remove(tempfile);
700 if (m_BugTraqProvider && progress.m_GitStatus == 0)
702 CComPtr<IBugTraqProvider2> pProvider = NULL;
703 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
704 if (SUCCEEDED(hr))
706 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
707 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
709 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
710 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
712 BSTR logMessage = m_sLogMessage.AllocSysString();
714 CGitHash hash=g_Git.GetHash(_T("HEAD"));
715 LONG version = g_Git.Hash2int(hash);
717 BSTR temp = NULL;
718 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
719 commonRoot,
720 pathList,
721 logMessage,
722 (LONG)version,
723 &temp)))
725 CString sErr = temp;
726 if (!sErr.IsEmpty())
727 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
728 else
730 COMError ce(hr);
731 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
732 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
736 SysFreeString(temp);
740 }else if(bAddSuccess)
742 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
743 bCloseCommitDlg=false;
745 #if 0
746 if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)
748 // There are paths which got changed (touched at least).
749 // We have to find out if this affects the selection in the commit dialog
750 // If it could affect the selection, revert back to a non-recursive commit
751 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();
752 changedList.RemoveDuplicates();
753 for (int i=0; i<changedList.GetCount(); ++i)
755 if (changedList[i].IsAdminDir())
757 // something inside an admin dir was changed.
758 // if it's the entries file, then we have to fully refresh because
759 // files may have been added/removed from version control
760 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
761 (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))
763 m_bRecursive = false;
764 break;
767 else if (!m_ListCtrl.IsPathShown(changedList[i]))
769 // a path which is not shown in the list has changed
770 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);
771 if (entry)
773 // check if the changed path would get committed by a recursive commit
774 if ((!entry->IsFromDifferentRepository()) &&
775 (!entry->IsInExternal()) &&
776 (!entry->IsNested()) &&
777 (!entry->IsChecked()))
779 m_bRecursive = false;
780 break;
788 // Now, do all the adds - make sure that the list is sorted so that parents
789 // are added before their children
790 itemsToAdd.SortByPathname();
791 Git Git;
792 if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))
794 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
795 InterlockedExchange(&m_bBlock, FALSE);
796 Refresh();
797 return;
800 // Remove any missing items
801 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
802 itemsToRemove.SortByPathname();
803 Git.Remove(itemsToRemove, TRUE);
805 //the next step: find all deleted files and check if they're
806 //inside a deleted folder. If that's the case, then remove those
807 //files from the list since they'll get deleted by the parent
808 //folder automatically.
809 m_ListCtrl.Block(TRUE, FALSE);
810 INT_PTR nDeleted = arDeleted.GetCount();
811 for (INT_PTR i=0; i<arDeleted.GetCount(); i++)
813 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))
815 const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();
816 if (path.IsDirectory())
818 //now find all children of this directory
819 for (int j=0; j<arDeleted.GetCount(); j++)
821 if (i!=j)
823 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));
824 if (childEntry->IsChecked())
826 if (path.IsAncestorOf(childEntry->GetPath()))
828 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);
829 nDeleted--;
837 m_ListCtrl.Block(FALSE, FALSE);
839 if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))
841 //save only the files the user has checked into the temporary file
842 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);
845 // the item count is used in the progress dialog to show the overall commit
846 // progress.
847 // deleted items only send one notification event, all others send two
848 m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();
850 if ((m_bRecursive)&&(checkedLists.size() == 1))
852 // all checked items belong to the same changelist
853 // find out if there are any unchecked items which belong to that changelist
854 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())
855 m_sChangeList = *checkedLists.begin();
857 #endif
858 UpdateData();
859 m_regAddBeforeCommit = m_bShowUnversioned;
860 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
861 m_bWholeProject = FALSE;
862 m_regKeepChangelists = m_bKeepChangeList;
863 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
864 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
865 m_bKeepChangeList = FALSE;
866 InterlockedExchange(&m_bBlock, FALSE);
868 m_History.AddEntry(m_sLogMessage);
869 m_History.Save();
871 SaveSplitterPos();
873 if( bCloseCommitDlg )
874 CResizableStandAloneDialog::OnOK();
876 CShellUpdater::Instance().Flush();
879 void CCommitDlg::SaveSplitterPos()
881 if (!IsIconic())
883 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
884 RECT rectSplitter;
885 m_wndSplitter.GetWindowRect(&rectSplitter);
886 ScreenToClient(&rectSplitter);
887 regPos = rectSplitter.top;
891 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
893 return ((CCommitDlg*)pVoid)->StatusThread();
896 UINT CCommitDlg::StatusThread()
898 //get the status of all selected file/folders recursively
899 //and show the ones which have to be committed to the user
900 //in a list control.
901 InterlockedExchange(&m_bBlock, TRUE);
902 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
903 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
905 m_pathwatcher.Stop();
907 g_Git.RefreshGitIndex();
909 m_bCancelled = false;
911 DialogEnableWindow(IDOK, false);
912 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
913 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
914 DialogEnableWindow(IDC_SELECTALL, false);
915 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
916 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
917 DialogEnableWindow(IDC_EXTERNALWARNING, false);
918 // read the list of recent log entries before querying the WC for status
919 // -> the user may select one and modify / update it while we are crawling the WC
921 if (m_History.GetCount()==0)
923 CString reg;
924 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
925 reg.Replace(_T(':'),_T('_'));
926 m_History.Load(reg, _T("logmsgs"));
929 // Initialise the list control with the status of the files/folders below us
930 m_ListCtrl.Clear();
931 BOOL success;
932 CTGitPathList *pList;
933 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE) && (m_bAmendDiffToLastCommit==FALSE);
934 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
936 if(m_bWholeProject)
937 pList=NULL;
938 else
939 pList = &m_pathList;
941 success=m_ListCtrl.GetStatus(pList);
943 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
944 if(this->m_bShowUnversioned)
945 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
947 m_ListCtrl.CheckIfChangelistsArePresent(false);
949 DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWINCHANGELIST;
950 dwShow |= DWORD(m_regAddBeforeCommit) ? SVNSLC_SHOWUNVERSIONED : 0;
951 if (success)
953 if (m_checkedPathList.GetCount())
954 m_ListCtrl.Show(dwShow, m_checkedPathList);
955 else
957 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
958 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
959 m_ListCtrl.Show(dwShow, dwCheck);
960 m_bSelectFilesForCommit = true;
963 if (m_ListCtrl.HasExternalsFromDifferentRepos())
965 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
966 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
969 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
970 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
972 if (!success)
974 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
975 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
976 m_ListCtrl.Show(dwShow);
978 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
979 && !PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
981 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
983 m_bShowUnversioned = TRUE;
984 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
985 DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);
986 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
987 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
991 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
993 if(this->m_bWholeProject)
994 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString() + CString(_T(" (Whole Project)")));
995 else
996 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
998 m_autolist.clear();
999 // we don't have to block the commit dialog while we fetch the
1000 // auto completion list.
1001 m_pathwatcher.ClearChangedPaths();
1002 InterlockedExchange(&m_bBlock, FALSE);
1003 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
1005 m_ListCtrl.Block(TRUE, TRUE);
1006 GetAutocompletionList();
1007 m_ListCtrl.Block(FALSE, FALSE);
1009 UpdateOKButton();
1010 if (m_bRunThread)
1012 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1013 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1014 DialogEnableWindow(IDC_SELECTALL, true);
1015 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1016 if (m_ListCtrl.HasChangeLists())
1017 DialogEnableWindow(IDC_KEEPLISTS, true);
1018 if (m_ListCtrl.HasLocks())
1019 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1020 // we have the list, now signal the main thread about it
1021 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1024 InterlockedExchange(&m_bRunThread, FALSE);
1025 InterlockedExchange(&m_bThreadRunning, FALSE);
1026 // force the cursor to normal
1027 RefreshCursor();
1029 return 0;
1032 void CCommitDlg::OnCancel()
1034 m_bCancelled = true;
1035 m_pathwatcher.Stop();
1037 if (m_bBlock)
1038 return;
1040 if (m_bThreadRunning)
1042 InterlockedExchange(&m_bRunThread, FALSE);
1043 WaitForSingleObject(m_pThread->m_hThread, 1000);
1044 if (m_bThreadRunning)
1046 // we gave the thread a chance to quit. Since the thread didn't
1047 // listen to us we have to kill it.
1048 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1049 InterlockedExchange(&m_bThreadRunning, FALSE);
1052 UpdateData();
1053 m_sBugID.Trim();
1054 m_sLogMessage = m_cLogMessage.GetText();
1055 if (!m_sBugID.IsEmpty())
1057 m_sBugID.Replace(_T(", "), _T(","));
1058 m_sBugID.Replace(_T(" ,"), _T(","));
1059 CString sBugID = m_ProjectProperties.sMessage;
1060 sBugID.Replace(_T("%BUGID%"), m_sBugID);
1061 if (m_ProjectProperties.bAppend)
1062 m_sLogMessage += _T("\n") + sBugID + _T("\n");
1063 else
1064 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1066 if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)
1067 m_History.AddEntry(m_sLogMessage);
1068 m_History.Save();
1069 SaveSplitterPos();
1070 CResizableStandAloneDialog::OnCancel();
1073 void CCommitDlg::OnBnClickedSelectall()
1075 m_tooltips.Pop(); // hide the tooltips
1076 UINT state = (m_SelectAll.GetState() & 0x0003);
1077 if (state == BST_INDETERMINATE)
1079 // It is not at all useful to manually place the checkbox into the indeterminate state...
1080 // We will force this on to the unchecked state
1081 state = BST_UNCHECKED;
1082 m_SelectAll.SetCheck(state);
1084 m_ListCtrl.SelectAll(state == BST_CHECKED);
1087 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1089 if (!m_bBlock)
1090 m_tooltips.RelayEvent(pMsg);
1092 if (m_hAccel)
1094 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1095 if (ret)
1096 return TRUE;
1099 if (pMsg->message == WM_KEYDOWN)
1101 switch (pMsg->wParam)
1103 case VK_F5:
1105 if (m_bBlock)
1106 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1107 Refresh();
1109 break;
1110 case VK_RETURN:
1112 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1114 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1116 PostMessage(WM_COMMAND, IDOK);
1118 return TRUE;
1120 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1122 // Pressing RETURN in the bug id control
1123 // moves the focus to the message
1124 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1125 return TRUE;
1128 break;
1132 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1135 void CCommitDlg::Refresh()
1137 if (m_bThreadRunning)
1138 return;
1140 InterlockedExchange(&m_bBlock, TRUE);
1141 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1142 if (m_pThread==NULL)
1144 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1145 InterlockedExchange(&m_bBlock, FALSE);
1147 else
1149 m_pThread->m_bAutoDelete = FALSE;
1150 m_pThread->ResumeThread();
1154 void CCommitDlg::OnBnClickedHelp()
1156 OnHelp();
1159 void CCommitDlg::OnBnClickedShowunversioned()
1161 m_tooltips.Pop(); // hide the tooltips
1162 UpdateData();
1163 m_regAddBeforeCommit = m_bShowUnversioned;
1164 if (!m_bBlock)
1166 DWORD dwShow = m_ListCtrl.GetShowFlags();
1167 if (DWORD(m_regAddBeforeCommit))
1168 dwShow |= SVNSLC_SHOWUNVERSIONED;
1169 else
1170 dwShow &= ~SVNSLC_SHOWUNVERSIONED;
1171 if(dwShow & SVNSLC_SHOWUNVERSIONED)
1173 if(m_bWholeProject)
1174 m_ListCtrl.GetStatus(NULL,false,false,true);
1175 else
1176 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1178 m_ListCtrl.Show(dwShow,0,true,0,true);
1182 void CCommitDlg::OnStnClickedExternalwarning()
1184 m_tooltips.Popup();
1187 void CCommitDlg::OnEnChangeLogmessage()
1189 UpdateOKButton();
1192 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1194 #if 0
1195 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1197 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1199 m_bShowUnversioned = TRUE;
1200 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1201 m_ListCtrl.Show(dwShow);
1202 UpdateData(FALSE);
1205 #endif
1206 return 0;
1209 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1211 Refresh();
1212 return 0;
1215 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1217 #if 0
1218 BringWindowToTop();
1219 SetForegroundWindow();
1220 SetActiveWindow();
1221 // if multiple files/folders are dropped
1222 // this handler is called for every single item
1223 // separately.
1224 // To avoid creating multiple refresh threads and
1225 // causing crashes, we only add the items to the
1226 // list control and start a timer.
1227 // When the timer expires, we start the refresh thread,
1228 // but only if it isn't already running - otherwise we
1229 // restart the timer.
1230 CTGitPath path;
1231 path.SetFromWin((LPCTSTR)lParam);
1233 // just add all the items we get here.
1234 // if the item is versioned, the add will fail but nothing
1235 // more will happen.
1236 Git Git;
1237 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1239 if (!m_ListCtrl.HasPath(path))
1241 if (m_pathList.AreAllPathsFiles())
1243 m_pathList.AddPath(path);
1244 m_pathList.RemoveDuplicates();
1245 m_updatedPathList.AddPath(path);
1246 m_updatedPathList.RemoveDuplicates();
1248 else
1250 // if the path list contains folders, we have to check whether
1251 // our just (maybe) added path is a child of one of those. If it is
1252 // a child of a folder already in the list, we must not add it. Otherwise
1253 // that path could show up twice in the list.
1254 bool bHasParentInList = false;
1255 for (int i=0; i<m_pathList.GetCount(); ++i)
1257 if (m_pathList[i].IsAncestorOf(path))
1259 bHasParentInList = true;
1260 break;
1263 if (!bHasParentInList)
1265 m_pathList.AddPath(path);
1266 m_pathList.RemoveDuplicates();
1267 m_updatedPathList.AddPath(path);
1268 m_updatedPathList.RemoveDuplicates();
1273 // Always start the timer, since the status of an existing item might have changed
1274 SetTimer(REFRESHTIMER, 200, NULL);
1275 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1276 #endif
1277 return 0;
1280 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1282 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1283 return 0;
1286 //////////////////////////////////////////////////////////////////////////
1287 // functions which run in the status thread
1288 //////////////////////////////////////////////////////////////////////////
1290 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1292 CString strLine;
1295 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1296 while (m_bRunThread && file.ReadString(strLine))
1298 int eqpos = strLine.Find('=');
1299 CString rgx;
1300 rgx = strLine.Mid(eqpos+1).Trim();
1302 int pos = -1;
1303 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1305 mapRegex[strLine.Left(pos)] = rgx;
1306 strLine = strLine.Mid(pos+1).Trim();
1308 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1310 file.Close();
1312 catch (CFileException* pE)
1314 TRACE("CFileException loading auto list regex file\n");
1315 pE->Delete();
1316 return;
1319 void CCommitDlg::GetAutocompletionList()
1321 // the auto completion list is made of strings from each selected files.
1322 // the strings used are extracted from the files with regexes found
1323 // in the file "autolist.txt".
1324 // the format of that file is:
1325 // file extensions separated with commas '=' regular expression to use
1326 // example:
1327 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1328 // .cpp = (?<=[^\s]::)\b\w+\b
1330 std::map<CString, CString> mapRegex;
1331 CString sRegexFile = CPathUtils::GetAppDirectory();
1332 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1333 DWORD timeoutvalue = regtimeout*1000;
1334 sRegexFile += _T("autolist.txt");
1335 if (!m_bRunThread)
1336 return;
1337 ParseRegexFile(sRegexFile, mapRegex);
1338 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1339 sRegexFile.ReleaseBuffer();
1340 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1341 if (PathFileExists(sRegexFile))
1343 ParseRegexFile(sRegexFile, mapRegex);
1345 DWORD starttime = GetTickCount();
1347 // now we have two arrays of strings, where the first array contains all
1348 // file extensions we can use and the second the corresponding regex strings
1349 // to apply to those files.
1351 // the next step is to go over all files shown in the commit dialog
1352 // and scan them for strings we can use
1353 int nListItems = m_ListCtrl.GetItemCount();
1355 for (int i=0; i<nListItems && m_bRunThread; ++i)
1357 // stop parsing after timeout
1358 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1359 return;
1361 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1363 if(path == NULL)
1364 continue;
1366 CString sPartPath =path->GetGitPathString();
1367 m_autolist.insert(sPartPath);
1369 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1370 // if (!entry)
1371 // continue;
1373 // add the path parts to the auto completion list too
1374 // CString sPartPath = entry->GetRelativeGitPath();
1375 // m_autolist.insert(sPartPath);
1378 int pos = 0;
1379 int lastPos = 0;
1380 while ((pos = sPartPath.Find('/', pos)) >= 0)
1382 pos++;
1383 lastPos = pos;
1384 m_autolist.insert(sPartPath.Mid(pos));
1387 // Last inserted entry is a file name.
1388 // Some users prefer to also list file name without extension.
1389 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1391 int dotPos = sPartPath.ReverseFind('.');
1392 if ((dotPos >= 0) && (dotPos > lastPos))
1393 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1395 #if 0
1396 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1397 continue;
1399 CString sExt = entry->GetPath().GetFileExtension();
1400 sExt.MakeLower();
1401 // find the regex string which corresponds to the file extension
1402 CString rdata = mapRegex[sExt];
1403 if (rdata.IsEmpty())
1404 continue;
1406 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1407 if ((entry->textstatus != Git_wc_status_unversioned) &&
1408 (entry->textstatus != Git_wc_status_none) &&
1409 (entry->textstatus != Git_wc_status_ignored) &&
1410 (entry->textstatus != Git_wc_status_added) &&
1411 (entry->textstatus != Git_wc_status_normal))
1413 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1414 if (!basePath.IsEmpty())
1415 ScanFile(basePath.GetWinPathString(), rdata);
1417 #endif
1419 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1422 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1424 wstring sFileContent;
1425 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1426 if (hFile != INVALID_HANDLE_VALUE)
1428 DWORD size = GetFileSize(hFile, NULL);
1429 if (size > 1000000L)
1431 // no files bigger than 1 Meg
1432 CloseHandle(hFile);
1433 return;
1435 // allocate memory to hold file contents
1436 char * buffer = new char[size];
1437 DWORD readbytes;
1438 ReadFile(hFile, buffer, size, &readbytes, NULL);
1439 CloseHandle(hFile);
1440 int opts = 0;
1441 IsTextUnicode(buffer, readbytes, &opts);
1442 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1444 delete [] buffer;
1445 return;
1447 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1449 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1451 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1453 int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1454 wchar_t * pWideBuf = new wchar_t[ret];
1455 int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1456 if (ret2 == ret)
1457 sFileContent = wstring(pWideBuf, ret);
1458 delete [] pWideBuf;
1460 delete [] buffer;
1462 if (sFileContent.empty()|| !m_bRunThread)
1464 return;
1469 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1470 const tr1::wsregex_iterator end;
1471 wstring s = sFileContent;
1472 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1474 const tr1::wsmatch match = *it;
1475 for (size_t i=1; i<match.size(); ++i)
1477 if (match[i].second-match[i].first)
1479 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1480 m_autolist.insert(wstring(match[i]).c_str());
1485 catch (exception) {}
1488 // CSciEditContextMenuInterface
1489 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1491 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1492 m_nPopupPasteListCmd = nCmd++;
1493 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1495 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1496 if(m_History.GetCount() > 0)
1498 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1499 m_nPopupPasteLastMessage = nCmd++;
1500 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1502 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1503 m_nPopupRecentMessage = nCmd++;
1504 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1510 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1513 if (m_bBlock)
1514 return false;
1515 if (cmd == m_nPopupPasteListCmd)
1517 CString logmsg;
1518 int nListItems = m_ListCtrl.GetItemCount();
1519 for (int i=0; i<nListItems; ++i)
1521 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1522 if (entry&&entry->m_Checked)
1524 CString line;
1525 CString status = entry->GetActionName();
1526 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1527 status = _T("Add");
1529 //git_wc_status_kind status = entry->status;
1530 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1531 if (m_ProjectProperties.bFileListInEnglish)
1532 langID = 1033;
1534 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1535 logmsg += line;
1538 pSciEdit->InsertText(logmsg);
1539 return true;
1542 if(cmd == m_nPopupPasteLastMessage)
1544 if(m_History.GetCount() ==0 )
1545 return false;
1547 CString logmsg;
1548 logmsg +=m_History.GetEntry(0);
1549 pSciEdit->InsertText(logmsg);
1550 return true;
1553 if(cmd == m_nPopupRecentMessage )
1555 OnBnClickedHistory();
1556 return true;
1558 return false;
1561 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1563 switch (nIDEvent)
1565 case ENDDIALOGTIMER:
1566 KillTimer(ENDDIALOGTIMER);
1567 EndDialog(0);
1568 break;
1569 case REFRESHTIMER:
1570 if (m_bThreadRunning)
1572 SetTimer(REFRESHTIMER, 200, NULL);
1573 ATLTRACE("Wait some more before refreshing\n");
1575 else
1577 KillTimer(REFRESHTIMER);
1578 ATLTRACE("Refreshing after items dropped\n");
1579 Refresh();
1581 break;
1583 __super::OnTimer(nIDEvent);
1586 void CCommitDlg::OnBnClickedHistory()
1588 m_tooltips.Pop(); // hide the tooltips
1589 if (m_pathList.GetCount() == 0)
1590 return;
1592 CHistoryDlg historyDlg;
1593 historyDlg.SetHistory(m_History);
1594 if (historyDlg.DoModal() != IDOK)
1595 return;
1597 CString sMsg = historyDlg.GetSelectedText();
1598 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1600 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);
1601 if (!sBugID.IsEmpty())
1603 SetDlgItemText(IDC_BUGID, sBugID);
1605 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1606 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1607 else
1608 m_cLogMessage.SetText(sMsg);
1611 UpdateOKButton();
1612 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1616 void CCommitDlg::OnBnClickedBugtraqbutton()
1618 m_tooltips.Pop(); // hide the tooltips
1619 CString sMsg = m_cLogMessage.GetText();
1621 if (m_BugTraqProvider == NULL)
1622 return;
1624 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1625 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1626 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1628 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1629 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1631 BSTR originalMessage = sMsg.AllocSysString();
1632 BSTR temp = NULL;
1633 // m_revProps.clear();
1635 // first try the IBugTraqProvider2 interface
1636 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1637 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1638 if (SUCCEEDED(hr))
1640 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1641 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1642 BSTR bugIDOut = NULL;
1643 GetDlgItemText(IDC_BUGID, m_sBugID);
1644 BSTR bugID = m_sBugID.AllocSysString();
1645 SAFEARRAY * revPropNames = NULL;
1646 SAFEARRAY * revPropValues = NULL;
1647 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1649 CString sErr;
1650 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1651 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1653 else
1655 if (bugIDOut)
1657 m_sBugID = bugIDOut;
1658 SysFreeString(bugIDOut);
1659 SetDlgItemText(IDC_BUGID, m_sBugID);
1661 SysFreeString(bugID);
1662 SysFreeString(repositoryRoot);
1663 m_cLogMessage.SetText(temp);
1664 BSTR HUGEP *pbRevNames;
1665 BSTR HUGEP *pbRevValues;
1667 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1668 if (SUCCEEDED(hr1))
1670 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1671 if (SUCCEEDED(hr2))
1673 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1675 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)
1677 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1680 SafeArrayUnaccessData(revPropValues);
1682 SafeArrayUnaccessData(revPropNames);
1684 if (revPropNames)
1685 SafeArrayDestroy(revPropNames);
1686 if (revPropValues)
1687 SafeArrayDestroy(revPropValues);
1690 else
1692 // if IBugTraqProvider2 failed, try IBugTraqProvider
1693 CComPtr<IBugTraqProvider> pProvider = NULL;
1694 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1695 if (FAILED(hr))
1697 CString sErr;
1698 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1699 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1700 return;
1703 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1705 CString sErr;
1706 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1707 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1709 else
1710 m_cLogMessage.SetText(temp);
1712 m_sLogMessage = m_cLogMessage.GetText();
1713 if (!m_ProjectProperties.sMessage.IsEmpty())
1715 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1716 if (!sBugID.IsEmpty())
1718 SetDlgItemText(IDC_BUGID, sBugID);
1722 m_cLogMessage.SetFocus();
1724 SysFreeString(parameters);
1725 SysFreeString(commonRoot);
1726 SafeArrayDestroy(pathList);
1727 SysFreeString(originalMessage);
1728 SysFreeString(temp);
1732 void CCommitDlg::FillPatchView()
1734 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1736 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
1738 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
1739 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
1740 CString cmd,out;
1742 while(pos)
1744 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
1745 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
1746 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
1748 CString head;
1749 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
1750 head = _T("HEAD~1 ");
1751 cmd.Format(_T("git.exe diff %s-- \"%s\""), head, p->GetGitPathString());
1752 g_Git.Run(cmd,&out,CP_ACP);
1756 m_patchViewdlg.m_ctrlPatchView.SetText(out);
1757 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
1758 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
1761 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1763 this->FillPatchView();
1764 return 0;
1768 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1770 UpdateOKButton();
1771 return 0;
1774 void CCommitDlg::UpdateOKButton()
1776 if (m_bBlock)
1777 return;
1779 bool bValidLogSize = m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize && m_cLogMessage.GetText().GetLength() > 0;
1780 bool bAmendOrSelectFiles = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit);
1782 DialogEnableWindow(IDOK, bValidLogSize && bAmendOrSelectFiles);
1785 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1787 switch (message) {
1788 case WM_NOTIFY:
1789 if (wParam == IDC_SPLITTER)
1791 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1792 DoSize(pHdr->delta);
1794 break;
1797 return __super::DefWindowProc(message, wParam, lParam);
1800 void CCommitDlg::SetSplitterRange()
1802 if ((m_ListCtrl)&&(m_cLogMessage))
1804 CRect rcTop;
1805 m_cLogMessage.GetWindowRect(rcTop);
1806 ScreenToClient(rcTop);
1807 CRect rcMiddle;
1808 m_ListCtrl.GetWindowRect(rcMiddle);
1809 ScreenToClient(rcMiddle);
1810 if (rcMiddle.Height() && rcMiddle.Width())
1811 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
1815 void CCommitDlg::DoSize(int delta)
1817 RemoveAnchor(IDC_MESSAGEGROUP);
1818 RemoveAnchor(IDC_LOGMESSAGE);
1819 RemoveAnchor(IDC_SPLITTER);
1820 RemoveAnchor(IDC_SIGNOFF);
1821 RemoveAnchor(IDC_COMMIT_AMEND);
1822 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
1823 RemoveAnchor(IDC_LISTGROUP);
1824 RemoveAnchor(IDC_FILELIST);
1825 RemoveAnchor(IDC_TEXT_INFO);
1826 RemoveAnchor(IDC_VIEW_PATCH);
1828 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
1829 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
1830 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
1831 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
1832 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
1833 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
1834 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
1835 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
1836 CSplitterControl::ChangePos(GetDlgItem(IDC_VIEW_PATCH),0,delta);
1838 AddAnchor(IDC_VIEW_PATCH,TOP_RIGHT);
1839 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
1840 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
1841 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
1842 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
1843 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
1844 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
1845 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
1846 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
1847 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
1848 ArrangeLayout();
1849 // adjust the minimum size of the dialog to prevent the resizing from
1850 // moving the list control too far down.
1851 CRect rcLogMsg;
1852 m_cLogMessage.GetClientRect(rcLogMsg);
1853 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
1855 SetSplitterRange();
1856 m_cLogMessage.Invalidate();
1857 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
1860 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
1862 // first, let the resizing take place
1863 __super::OnSize(nType, cx, cy);
1865 //set range
1866 SetSplitterRange();
1869 CString CCommitDlg::GetSignedOffByLine()
1871 CString str;
1873 CString username = g_Git.GetUserName();
1874 CString email = g_Git.GetUserEmail();
1875 username.Remove(_T('\n'));
1876 email.Remove(_T('\n'));
1878 str.Format(_T("Signed-off-by: %s <%s>"), username, email);
1880 return str;
1883 void CCommitDlg::OnBnClickedSignOff()
1885 CString str = GetSignedOffByLine();
1887 if (m_cLogMessage.GetText().Find(str) == -1) {
1888 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
1889 int lastNewline = m_cLogMessage.GetText().ReverseFind(_T('\n'));
1890 int foundByLine = -1;
1891 if (lastNewline > 0)
1892 foundByLine = m_cLogMessage.GetText().Find(_T("-by: "), lastNewline);
1894 if (foundByLine == -1 || foundByLine < lastNewline)
1895 str = _T("\r\n") + str;
1897 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n")+str+_T("\r\n"));
1901 void CCommitDlg::OnBnClickedCommitAmend()
1903 this->UpdateData();
1904 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
1906 GitRev rev;
1907 rev.GetCommit(CString(_T("HEAD")));
1908 m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody();
1911 if(this->m_bCommitAmend)
1913 this->m_NoAmendStr=this->m_cLogMessage.GetText();
1914 m_cLogMessage.SetText(m_AmendStr);
1915 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
1917 else
1919 this->m_AmendStr=this->m_cLogMessage.GetText();
1920 m_cLogMessage.SetText(m_NoAmendStr);
1921 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
1923 Refresh();
1926 void CCommitDlg::OnBnClickedWholeProject()
1928 m_tooltips.Pop(); // hide the tooltips
1929 UpdateData();
1930 m_ListCtrl.Clear();
1931 if (!m_bBlock)
1933 if(m_bWholeProject)
1934 m_ListCtrl.GetStatus(NULL,true,false,true);
1935 else
1936 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
1938 DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);
1939 m_ListCtrl.Show(m_ListCtrl.GetShowFlags(), dwShow & (~CTGitPath::LOGACTIONS_UNVER));
1942 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
1944 if(this->m_bWholeProject)
1945 SetWindowText(m_sWindowTitle + _T(" - ") + CString(_T("Whole Project")));
1946 else
1947 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
1951 void CCommitDlg::OnFocusMessage()
1953 m_cLogMessage.SetFocus();
1956 void CCommitDlg::OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult)
1958 UNREFERENCED_PARAMETER(pNMHDR);
1959 int pos=this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
1960 int line=this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
1961 int column=this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
1963 CString str;
1964 str.Format(_T("%d/%d"),line+1,column+1);
1965 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
1967 if(*pResult)
1968 *pResult=0;
1970 void CCommitDlg::OnStnClickedViewPatch()
1972 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
1973 m_patchViewdlg.m_ParentCommitDlg = this;
1974 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
1976 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
1977 CRect rect;
1978 this->GetWindowRect(&rect);
1980 m_patchViewdlg.ShowWindow(SW_SHOW);
1982 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
1983 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
1985 ShowViewPatchText(false);
1986 FillPatchView();
1988 else
1990 m_patchViewdlg.ShowWindow(SW_HIDE);
1991 m_patchViewdlg.DestroyWindow();
1992 ShowViewPatchText(true);
1994 this->m_ctrlShowPatch.Invalidate();
1997 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
1999 __super::OnMoving(fwSide, pRect);
2001 if (::IsWindow(m_patchViewdlg.m_hWnd))
2003 RECT patchrect;
2004 m_patchViewdlg.GetWindowRect(&patchrect);
2005 if (::IsWindow(m_hWnd))
2007 RECT thisrect;
2008 GetWindowRect(&thisrect);
2009 if (patchrect.left == thisrect.right)
2011 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2012 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2019 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2021 __super::OnSizing(fwSide, pRect);
2023 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2025 CRect thisrect, patchrect;
2026 this->GetWindowRect(thisrect);
2027 this->m_patchViewdlg.GetWindowRect(patchrect);
2028 if(thisrect.right==patchrect.left)
2030 patchrect.left -= (thisrect.right - pRect->right);
2031 patchrect.right-= (thisrect.right - pRect->right);
2033 if( patchrect.bottom == thisrect.bottom)
2035 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2037 if( patchrect.top == thisrect.top)
2039 patchrect.top -= thisrect.top-pRect->top;
2041 m_patchViewdlg.MoveWindow(patchrect);
2046 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult)
2048 UNREFERENCED_PARAMETER(pNMHDR);
2049 *pResult = 0;
2050 TRACE("Item Changed\r\n");
2053 int CCommitDlg::CheckHeadDetach()
2055 CString output;
2056 if(g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir,output))
2058 if(CMessageBox::Show(NULL,_T("<ct=0x0000FF>Current HEAD Detached</ct>, you are working on (no branch)\nDo you want create branch now?"),
2059 _T("TortoiseGit"),MB_YESNO|MB_ICONWARNING) == IDYES)
2061 CAppUtils::CreateBranchTag(FALSE,NULL,true);
2064 return 0;
2067 void CCommitDlg::OnBnClickedCommitAmenddiff()
2069 UpdateData();
2070 Refresh();
2073 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2075 UpdateData();
2076 Refresh();