CommitDlg: Do not use libgit2 index manipulation for commit by default any more
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
bloba8977ee74579f2cb138b9cbde9158e650f478c1f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2013 - 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 "UnicodeUtils.h"
35 #include "../TGitCache/CacheInterface.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"
43 #include "MassiveGitTask.h"
45 #ifdef _DEBUG
46 #define new DEBUG_NEW
47 #undef THIS_FILE
48 static char THIS_FILE[] = __FILE__;
49 #endif
51 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
52 UINT CCommitDlg::WM_UPDATEOKBUTTON = RegisterWindowMessage(_T("TORTOISEGIT_COMMIT_UPDATEOKBUTTON"));
53 UINT CCommitDlg::WM_UPDATEDATAFALSE = RegisterWindowMessage(_T("TORTOISEGIT_COMMIT_UPDATEDATAFALSE"));
55 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)
56 CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)
57 : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)
58 , m_bRecursive(FALSE)
59 , m_bShowUnversioned(FALSE)
60 , m_bBlock(FALSE)
61 , m_bThreadRunning(FALSE)
62 , m_bRunThread(FALSE)
63 , m_pThread(NULL)
64 , m_bWholeProject(FALSE)
65 , m_bKeepChangeList(TRUE)
66 , m_bDoNotAutoselectSubmodules(FALSE)
67 , m_itemsCount(0)
68 , m_bSelectFilesForCommit(TRUE)
69 , m_bNoPostActions(FALSE)
70 , m_bAutoClose(false)
71 , m_bSetCommitDateTime(FALSE)
72 , m_bCreateNewBranch(FALSE)
73 , m_bCreateTagAfterCommit(FALSE)
74 , m_bForceCommitAmend(false)
75 , m_bCommitMessageOnly(FALSE)
76 , m_bSetAuthor(FALSE)
78 this->m_bCommitAmend=FALSE;
79 m_bPushAfterCommit = FALSE;
82 CCommitDlg::~CCommitDlg()
84 if(m_pThread != NULL)
86 delete m_pThread;
90 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
92 CResizableStandAloneDialog::DoDataExchange(pDX);
93 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
94 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
95 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
96 DDX_Check(pDX, IDC_COMMIT_SETDATETIME, m_bSetCommitDateTime);
97 DDX_Check(pDX, IDC_CHECK_NEWBRANCH, m_bCreateNewBranch);
98 DDX_Text(pDX, IDC_NEWBRANCH, m_sCreateNewBranch);
99 DDX_Text(pDX, IDC_BUGID, m_sBugID);
100 DDX_Text(pDX, IDC_COMMIT_AUTHORDATA, m_sAuthor);
101 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
102 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
103 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
104 DDX_Check(pDX, IDC_NOAUTOSELECTSUBMODULES, m_bDoNotAutoselectSubmodules);
105 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
106 DDX_Check(pDX, IDC_COMMIT_MESSAGEONLY, m_bCommitMessageOnly);
107 DDX_Check(pDX,IDC_COMMIT_AMENDDIFF,m_bAmendDiffToLastCommit);
108 DDX_Check(pDX, IDC_COMMIT_SETAUTHOR, m_bSetAuthor);
109 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
110 DDX_Control(pDX, IDC_COMMIT_DATEPICKER, m_CommitDate);
111 DDX_Control(pDX, IDC_COMMIT_TIMEPICKER, m_CommitTime);
114 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
115 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
116 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
117 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
118 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
119 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
120 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
121 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
122 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
123 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE, OnFileDropped)
124 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
125 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
127 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED, &CCommitDlg::OnCheck)
128 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
129 ON_REGISTERED_MESSAGE(WM_UPDATEOKBUTTON, OnUpdateOKButton)
130 ON_REGISTERED_MESSAGE(WM_UPDATEDATAFALSE, OnUpdateDataFalse)
131 ON_WM_TIMER()
132 ON_WM_SIZE()
133 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
134 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
135 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
136 ON_BN_CLICKED(IDC_COMMIT_MESSAGEONLY, &CCommitDlg::OnBnClickedCommitMessageOnly)
137 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
138 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
139 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
140 ON_WM_MOVE()
141 ON_WM_MOVING()
142 ON_WM_SIZING()
143 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
144 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF, &CCommitDlg::OnBnClickedCommitAmenddiff)
145 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES, &CCommitDlg::OnBnClickedNoautoselectsubmodules)
146 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME, &CCommitDlg::OnBnClickedCommitSetDateTime)
147 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH, &CCommitDlg::OnBnClickedCheckNewBranch)
148 ON_BN_CLICKED(IDC_COMMIT_SETAUTHOR, &CCommitDlg::OnBnClickedCommitSetauthor)
149 END_MESSAGE_MAP()
151 BOOL CCommitDlg::OnInitDialog()
153 CResizableStandAloneDialog::OnInitDialog();
154 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
156 CAppUtils::GetCommitTemplate(this->m_sLogMessage);
158 CString dotGitPath;
159 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
160 if(PathFileExists(dotGitPath + _T("MERGE_MSG")))
162 CStdioFile file;
163 if(file.Open(dotGitPath + _T("MERGE_MSG"), CFile::modeRead))
165 CString str;
166 while(file.ReadString(str))
168 m_sLogMessage += str;
169 str.Empty();
170 m_sLogMessage += _T("\n");
175 if (CTGitPath(g_Git.m_CurrentDir).IsMergeActive())
176 DialogEnableWindow(IDC_CHECK_NEWBRANCH, FALSE);
178 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
179 m_bShowUnversioned = m_regAddBeforeCommit;
181 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
183 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
184 m_bKeepChangeList = m_regKeepChangelists;
186 m_regDoNotAutoselectSubmodules = CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE);
187 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
189 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
191 // GitConfig config;
192 // m_bWholeProject = config.KeepLocks();
194 if(this->m_pathList.GetCount() == 0)
195 m_bWholeProject =true;
197 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
198 m_bWholeProject =true;
200 SetDlgTitle();
202 UpdateData(FALSE);
204 m_ListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD | GITSLC_COLDEL, _T("CommitDlg"),(GITSLC_POPALL ^ (GITSLC_POPCOMMIT | GITSLC_POPSAVEAS)), true, true);
205 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
206 m_ListCtrl.SetCancelBool(&m_bCancelled);
207 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
208 m_ListCtrl.EnableFileDrop();
209 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
211 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
212 m_ProjectProperties.ReadPropsPathList(m_pathList);
214 m_cLogMessage.Init(m_ProjectProperties);
215 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
216 m_cLogMessage.RegisterContextMenuHandler(this);
218 OnEnChangeLogmessage();
220 m_tooltips.Create(this);
221 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
222 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
223 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
225 CBugTraqAssociations bugtraq_associations;
226 bugtraq_associations.Load();
228 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
230 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
231 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
233 CComPtr<IBugTraqProvider> pProvider;
234 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
235 if (SUCCEEDED(hr))
237 m_BugTraqProvider = pProvider;
238 BSTR temp = NULL;
239 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
241 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
242 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
243 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
246 SysFreeString(temp);
249 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
251 else if (!m_ProjectProperties.sMessage.IsEmpty())
253 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
254 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
255 if (!m_ProjectProperties.sLabel.IsEmpty())
256 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
257 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
258 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
259 GetDlgItem(IDC_BUGID)->SetFocus();
260 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
261 if (!sBugID.IsEmpty())
263 SetDlgItemText(IDC_BUGID, sBugID);
266 else
268 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
269 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
270 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
271 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
272 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
275 if (!m_sLogMessage.IsEmpty())
276 m_cLogMessage.SetText(m_sLogMessage);
278 GetWindowText(m_sWindowTitle);
280 AdjustControlSize(IDC_SHOWUNVERSIONED);
281 AdjustControlSize(IDC_WHOLE_PROJECT);
282 AdjustControlSize(IDC_CHECK_NEWBRANCH);
283 AdjustControlSize(IDC_COMMIT_AMEND);
284 AdjustControlSize(IDC_COMMIT_MESSAGEONLY);
285 AdjustControlSize(IDC_COMMIT_AMENDDIFF);
286 AdjustControlSize(IDC_COMMIT_SETDATETIME);
287 AdjustControlSize(IDC_COMMIT_SETAUTHOR);
288 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES);
289 AdjustControlSize(IDC_KEEPLISTS);
291 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKALL);
292 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKNONE);
293 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKUNVERSIONED);
294 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKVERSIONED);
295 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKADDED);
296 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKDELETED);
297 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKMODIFIED);
298 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKFILES);
299 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKSUBMODULES);
301 // line up all controls and adjust their sizes.
302 #define LINKSPACING 9
303 RECT rc = AdjustControlSize(IDC_SELECTLABEL);
304 rc.right -= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
305 rc = AdjustStaticSize(IDC_CHECKALL, rc, LINKSPACING);
306 rc = AdjustStaticSize(IDC_CHECKNONE, rc, LINKSPACING);
307 rc = AdjustStaticSize(IDC_CHECKUNVERSIONED, rc, LINKSPACING);
308 rc = AdjustStaticSize(IDC_CHECKVERSIONED, rc, LINKSPACING);
309 rc = AdjustStaticSize(IDC_CHECKADDED, rc, LINKSPACING);
310 rc = AdjustStaticSize(IDC_CHECKDELETED, rc, LINKSPACING);
311 rc = AdjustStaticSize(IDC_CHECKMODIFIED, rc, LINKSPACING);
312 rc = AdjustStaticSize(IDC_CHECKFILES, rc, LINKSPACING);
313 rc = AdjustStaticSize(IDC_CHECKSUBMODULES, rc, LINKSPACING);
315 GetClientRect(m_DlgOrigRect);
316 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
318 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
319 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
320 AddAnchor(IDC_BUGID, TOP_RIGHT);
321 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
322 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
323 AddAnchor(IDC_CHECK_NEWBRANCH, TOP_RIGHT);
324 AddAnchor(IDC_NEWBRANCH, TOP_LEFT, TOP_RIGHT);
325 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
326 // AddAnchor(IDC_HISTORY, TOP_LEFT);
327 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
328 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
329 AddAnchor(IDC_VIEW_PATCH, BOTTOM_RIGHT);
330 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
331 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
332 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
333 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
334 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
335 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
336 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
337 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
338 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
339 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
340 AddAnchor(IDOK, BOTTOM_RIGHT);
341 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
342 AddAnchor(IDHELP, BOTTOM_RIGHT);
343 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
344 AddAnchor(IDC_COMMIT_MESSAGEONLY, BOTTOM_LEFT);
345 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
346 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
347 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
348 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
349 AddAnchor(IDC_COMMIT_SETAUTHOR, TOP_LEFT);
350 AddAnchor(IDC_COMMIT_AUTHORDATA, TOP_LEFT, TOP_RIGHT);
352 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
353 AddAnchor(IDC_CHECKALL, TOP_LEFT);
354 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
355 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
356 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
357 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
358 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
359 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
360 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
361 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
363 if (hWndExplorer)
364 CenterWindow(CWnd::FromHandle(hWndExplorer));
365 EnableSaveRestore(_T("CommitDlg"));
366 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
367 RECT rcDlg, rcLogMsg, rcFileList;
368 GetClientRect(&rcDlg);
369 m_cLogMessage.GetWindowRect(&rcLogMsg);
370 ScreenToClient(&rcLogMsg);
371 m_ListCtrl.GetWindowRect(&rcFileList);
372 ScreenToClient(&rcFileList);
373 if (yPos)
375 RECT rectSplitter;
376 m_wndSplitter.GetWindowRect(&rectSplitter);
377 ScreenToClient(&rectSplitter);
378 int delta = yPos - rectSplitter.top;
379 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
381 m_wndSplitter.SetWindowPos(NULL, rectSplitter.left, yPos, 0, 0, SWP_NOSIZE);
382 DoSize(delta);
386 SetSplitterRange();
388 // add all directories to the watcher
390 for (int i=0; i<m_pathList.GetCount(); ++i)
392 if (m_pathList[i].IsDirectory())
393 m_pathwatcher.AddPath(m_pathList[i]);
396 m_updatedPathList = m_pathList;
398 //first start a thread to obtain the file list with the status without
399 //blocking the dialog
400 InterlockedExchange(&m_bBlock, TRUE);
401 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
402 if (m_pThread==NULL)
404 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
405 InterlockedExchange(&m_bBlock, FALSE);
407 else
409 m_pThread->m_bAutoDelete = FALSE;
410 m_pThread->ResumeThread();
412 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
413 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
414 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
416 historyhint = TRUE;
417 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
419 err = FALSE;
421 this->m_ctrlShowPatch.SetURL(CString());
423 BOOL viewPatchEnabled = FALSE;
424 m_ProjectProperties.GetBOOLProps(viewPatchEnabled, _T("tgit.commitshowpatch"));
425 if (viewPatchEnabled)
426 OnStnClickedViewPatch();
428 return FALSE; // return TRUE unless you set the focus to a control
429 // EXCEPTION: OCX Property Pages should return FALSE
432 void CCommitDlg::OnOK()
434 if (m_bBlock)
435 return;
436 if (m_bThreadRunning)
438 m_bCancelled = true;
439 InterlockedExchange(&m_bRunThread, FALSE);
440 WaitForSingleObject(m_pThread->m_hThread, 1000);
441 if (m_bThreadRunning)
443 // we gave the thread a chance to quit. Since the thread didn't
444 // listen to us we have to kill it.
445 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
446 InterlockedExchange(&m_bThreadRunning, FALSE);
449 this->UpdateData();
451 if (m_bCreateNewBranch)
453 if (!g_Git.IsBranchNameValid(m_sCreateNewBranch))
455 ShowEditBalloon(IDC_NEWBRANCH, IDS_B_T_NOTEMPTY, TTI_ERROR);
456 return;
458 if (g_Git.BranchTagExists(m_sCreateNewBranch))
460 // branch already exists
461 CString msg;
462 msg.LoadString(IDS_B_EXISTS);
463 msg += _T(" ") + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME));
464 ShowEditBalloon(IDC_NEWBRANCH, msg, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
465 return;
467 if (g_Git.BranchTagExists(m_sCreateNewBranch, false))
469 // tag with the same name exists -> shortref is ambiguous
470 if (CMessageBox::Show(m_hWnd, IDS_B_SAMETAGNAMEEXISTS, IDS_APPNAME, 2, IDI_EXCLAMATION, IDS_CONTINUEBUTTON, IDS_ABORTBUTTON) == 2)
471 return;
475 CString id;
476 GetDlgItemText(IDC_BUGID, id);
477 if (!m_ProjectProperties.CheckBugID(id))
479 ShowEditBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, TTI_ERROR);
480 return;
482 m_sLogMessage = m_cLogMessage.GetText();
483 if ( m_sLogMessage.IsEmpty() )
485 // no message entered, go round again
486 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
487 return;
489 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
491 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
492 return;
495 BOOL bWarnNoSignedOffBy = FALSE;
496 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy, _T("tgit.warnnosignedoffby"));
497 if (bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
499 UINT retval = CMessageBox::Show(this->m_hWnd, IDS_PROC_COMMIT_NOSIGNOFFLINE, IDS_APPNAME, 1, IDI_WARNING, IDS_PROC_COMMIT_ADDSIGNOFFBUTTON, IDS_PROC_COMMIT_NOADDSIGNOFFBUTTON, IDS_ABORTBUTTON);
500 if (retval == 1)
502 OnBnClickedSignOff();
503 m_sLogMessage = m_cLogMessage.GetText();
505 else if (retval == 3)
506 return;
509 int nListItems = m_ListCtrl.GetItemCount();
510 bool needResetIndex = false;
511 for (int i = 0; i < nListItems && !m_bCommitMessageOnly; ++i)
513 CTGitPath *entry = (CTGitPath *)m_ListCtrl.GetItemData(i);
514 if (!entry->m_Checked && !(entry->m_Action & CTGitPath::LOGACTIONS_UNVER))
515 needResetIndex = true;
516 if (!entry->m_Checked || !entry->IsDirectory())
517 continue;
519 bool dirty = false;
520 if (entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
522 CGit subgit;
523 subgit.m_CurrentDir = g_Git.m_CurrentDir + _T("\\") + entry->GetWinPathString();
524 CString subcmdout;
525 subgit.Run(_T("git.exe status --porcelain"), &subcmdout, CP_UTF8);
526 dirty = !subcmdout.IsEmpty();
528 else
530 CString cmd, cmdout;
531 cmd.Format(_T("git.exe diff -- \"%s\""), entry->GetWinPathString());
532 g_Git.Run(cmd, &cmdout, CP_UTF8);
533 dirty = cmdout.Right(7) == _T("-dirty\n");
536 if (dirty)
538 CString message;
539 message.Format(CString(MAKEINTRESOURCE(IDS_COMMITDLG_SUBMODULEDIRTY)), entry->GetGitPathString());
540 int result = CMessageBox::Show(m_hWnd, message, _T("TortoiseGit"), 1, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_COMMIT)), CString(MAKEINTRESOURCE(IDS_MSGBOX_IGNORE)), CString(MAKEINTRESOURCE(IDS_MSGBOX_CANCEL)));
541 if (result == 1)
543 CString cmdCommit;
544 cmdCommit.Format(_T("/command:commit /path:\"%s\\%s\""), g_Git.m_CurrentDir, entry->GetWinPathString());
545 CAppUtils::RunTortoiseGitProc(cmdCommit);
546 return;
548 else if (result == 2)
549 continue;
550 else
551 return;
555 if (!m_bCommitMessageOnly)
556 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
557 m_pathwatcher.Stop();
558 InterlockedExchange(&m_bBlock, TRUE);
559 CDWordArray arDeleted;
560 //first add all the unversioned files the user selected
561 //and check if all versioned files are selected
562 int nchecked = 0;
563 m_bRecursive = true;
565 CTGitPathList itemsToAdd;
566 CTGitPathList itemsToRemove;
567 CMassiveGitTask mgtReAddAfterCommit(_T("add --ignore-errors -f"));
569 CString cmd;
570 CString out;
572 bool bAddSuccess=true;
573 bool bCloseCommitDlg=false;
575 CSysProgressDlg sysProgressDlg;
576 if (nListItems >= 25)
578 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
579 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
580 sysProgressDlg.SetTime(true);
581 sysProgressDlg.SetShowProgressBar(true);
582 sysProgressDlg.ShowModal(this, true);
585 CBlockCacheForPath cacheBlock(g_Git.m_CurrentDir);
586 DWORD currentTicks = GetTickCount();
588 if (g_Git.UsingLibGit2(CGit::GIT_CMD_COMMIT_UPDATE_INDEX))
591 Do not use the libgit2 implementation right now, since it has several flaws:
592 * https://github.com/libgit2/libgit2/issues/1397: crlf issue
593 * http://code.google.com/p/tortoisegit/issues/detail?id=1690: possible access denied problem
594 * https://github.com/libgit2/libgit2/pull/1291: git.exe path is searched again and again
595 * changes to x-bit are not correctly committed
597 bAddSuccess = false;
600 git_repository *repository = nullptr;
601 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8);
602 if (git_repository_open(&repository, gitdir.GetBuffer()))
604 gitdir.ReleaseBuffer();
605 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
606 break;
608 gitdir.ReleaseBuffer();
610 git_config *config;
611 git_config_new(&config);
613 CStringA projectConfigA = CUnicodeUtils::GetMulti(g_Git.GetGitLocalConfig(), CP_UTF8);
614 if (git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), 4, FALSE))
616 projectConfigA.ReleaseBuffer();
617 git_config_free(config);
618 git_repository_free(repository);
619 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open project config.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
620 break;
622 projectConfigA.ReleaseBuffer();
623 CString globalConfig = g_Git.GetGitGlobalConfig();
624 if (PathFileExists(globalConfig))
626 CStringA globalConfigA = CUnicodeUtils::GetMulti(globalConfig, CP_UTF8);
627 if (git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), 3, FALSE))
629 globalConfigA.ReleaseBuffer();
630 git_config_free(config);
631 git_repository_free(repository);
632 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open global config.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
633 break;
635 globalConfigA.ReleaseBuffer();
637 CString globalXDGConfig = g_Git.GetGitGlobalXDGConfig();
638 if (PathFileExists(globalXDGConfig))
640 CStringA globalXDGConfigA = CUnicodeUtils::GetMulti(globalXDGConfig, CP_UTF8);
641 if (git_config_add_file_ondisk(config, globalXDGConfigA.GetBuffer(), 2, FALSE))
643 globalXDGConfigA.ReleaseBuffer();
644 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open xdg config config.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
645 git_config_free(config);
646 git_repository_free(repository);
647 break;
649 globalXDGConfigA.ReleaseBuffer();
651 CString systemConfig = g_Git.GetGitSystemConfig();
652 if (!systemConfig.IsEmpty())
654 CStringA systemConfigA = CUnicodeUtils::GetMulti(systemConfig, CP_UTF8);
655 if (git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), 1, FALSE))
657 systemConfigA.ReleaseBuffer();
658 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open system config.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
659 git_config_free(config);
660 git_repository_free(repository);
661 break;
663 systemConfigA.ReleaseBuffer();
666 git_repository_set_config(repository, config);
667 git_config_free(config);
668 config = nullptr;
670 CGitHash revHash;
671 CString revRef = _T("HEAD");
672 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
673 revRef = _T("HEAD~1");
674 if (g_Git.GetHash(revHash, revRef))
676 git_repository_free(repository);
677 MessageBox(g_Git.GetLibGit2LastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR);
678 break;
681 git_commit *commit = nullptr;
682 if (!revHash.IsEmpty() && needResetIndex && git_commit_lookup(&commit, repository, (const git_oid*)revHash.m_hash))
684 git_repository_free(repository);
685 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not get last commit.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
686 break;
689 git_tree *tree = nullptr;
690 if (!revHash.IsEmpty() && needResetIndex && git_commit_tree(&tree, commit))
692 git_commit_free(commit);
693 git_repository_free(repository);
694 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not read tree of commit.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
695 break;
698 git_index *index = nullptr;
699 if (git_repository_index(&index, repository))
701 if (tree != nullptr)
702 git_tree_free(tree);
703 if (commit != nullptr)
704 git_commit_free(commit);
705 git_repository_free(repository);
706 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not get the repository index.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
707 break;
710 // reset index to the one of the reference commit (HEAD or HEAD~1)
711 if (!revHash.IsEmpty() && needResetIndex && git_index_read_tree(index, tree))
713 git_index_free(index);
714 git_tree_free(tree);
715 git_commit_free(commit);
716 git_repository_free(repository);
717 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not read the tree into the index.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
718 break;
720 else if (!revHash.IsEmpty() && !needResetIndex)
722 git_index_read(index);
725 bAddSuccess = true;
727 for (int j = 0; j < nListItems; ++j)
729 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
731 if (sysProgressDlg.IsVisible())
733 if (GetTickCount() - currentTicks > 1000 || j == nListItems - 1 || j == 0)
735 sysProgressDlg.SetLine(2, entry->GetGitPathString(), true);
736 sysProgressDlg.SetProgress(j, nListItems);
737 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too often: this takes time!
738 currentTicks = GetTickCount();
742 CStringA filePathA = CUnicodeUtils::GetMulti(entry->GetGitPathString(), CP_UTF8);
744 if (entry->m_Checked && !m_bCommitMessageOnly)
746 if (entry->IsDirectory())
748 git_submodule *submodule = nullptr;
749 if (git_submodule_lookup(&submodule, repository, filePathA.GetBuffer()))
751 filePathA.ReleaseBuffer();
752 bAddSuccess = false;
753 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open submodule \"") + entry->GetGitPathString() + _T("\".")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
754 break;
756 filePathA.ReleaseBuffer();
757 if (git_submodule_add_to_index(submodule, FALSE))
759 bAddSuccess = false;
760 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not add submodule \"") + entry->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
761 break;
764 else if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
766 git_index_remove_bypath(index, filePathA.GetBuffer()); // ignore error
767 filePathA.ReleaseBuffer();
769 else
771 if (git_index_add_bypath(index, filePathA.GetBuffer()))
773 filePathA.ReleaseBuffer();
774 bAddSuccess = false;
775 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not add \"") + entry->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
776 break;
778 filePathA.ReleaseBuffer();
781 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
783 git_index_remove_bypath(index, filePathA.GetBuffer()); // ignore error
784 filePathA.ReleaseBuffer();
787 ++nchecked;
789 else if (entry->m_Action & CTGitPath::LOGACTIONS_ADDED || entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
790 mgtReAddAfterCommit.AddFile(*entry);
792 if (sysProgressDlg.HasUserCancelled())
794 bAddSuccess = false;
795 break;
798 CShellUpdater::Instance().AddPathForUpdate(*entry);
800 if (bAddSuccess && git_index_write(index))
801 bAddSuccess = false;
803 git_index_free(index);
804 if (tree != nullptr)
805 git_tree_free(tree);
806 if (commit != nullptr)
807 git_commit_free(commit);
808 git_repository_free(repository);
809 } while (0);
811 else
813 // ***************************************************
814 // ATTENTION: Similar code in RebaseDlg.cpp!!!
815 // ***************************************************
816 for (int j = 0; j < nListItems; ++j)
818 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
819 if (sysProgressDlg.IsVisible())
821 if (GetTickCount() - currentTicks > 1000 || j == nListItems - 1 || j == 0)
823 sysProgressDlg.SetLine(2, entry->GetGitPathString(), true);
824 sysProgressDlg.SetProgress(j, nListItems);
825 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too often: this takes time!
826 currentTicks = GetTickCount();
829 if (entry->m_Checked && !m_bCommitMessageOnly)
831 if (entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
832 cmd.Format(_T("git.exe add -f -- \"%s\""), entry->GetGitPathString());
833 else if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
834 cmd.Format(_T("git.exe update-index --force-remove -- \"%s\""), entry->GetGitPathString());
835 else
836 cmd.Format(_T("git.exe update-index -- \"%s\""), entry->GetGitPathString());
838 if (g_Git.Run(cmd, &out, CP_UTF8))
840 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
841 bAddSuccess = false ;
842 break;
845 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
846 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
848 g_Git.Run(cmd, &out, CP_UTF8);
850 ++nchecked;
852 else
854 if (entry->m_Action & CTGitPath::LOGACTIONS_ADDED || entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
855 { //To init git repository, there are not HEAD, so we can use git reset command
856 cmd.Format(_T("git.exe rm -f --cache -- \"%s\""), entry->GetGitPathString());
857 if (g_Git.Run(cmd, &out, CP_UTF8))
859 CMessageBox::Show(NULL, out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
860 bAddSuccess = false ;
861 bCloseCommitDlg=false;
862 break;
864 mgtReAddAfterCommit.AddFile(*entry);
866 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED && !entry->GetGitOldPathString().IsEmpty())
868 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
869 cmd.Format(_T("git.exe reset HEAD~1 -- \"%s\""), entry->GetGitOldPathString());
870 else
871 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitOldPathString());
872 g_Git.Run(cmd, &out, CP_UTF8);
875 else if (!(entry->m_Action & CTGitPath::LOGACTIONS_UNVER))
877 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
879 cmd.Format(_T("git.exe reset HEAD~1 -- \"%s\""), entry->GetGitPathString());
881 else
883 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitPathString());
885 g_Git.Run(cmd, &out, CP_UTF8);
886 if (m_bCommitAmend && !m_bAmendDiffToLastCommit && !sysProgressDlg.HasUserCancelled())
887 continue;
891 if (sysProgressDlg.HasUserCancelled())
893 bAddSuccess = false;
894 break;
897 CShellUpdater::Instance().AddPathForUpdate(*entry);
901 sysProgressDlg.Stop();
903 if (bAddSuccess && m_bCreateNewBranch)
905 if (g_Git.Run(_T("git branch ") + m_sCreateNewBranch, &out, CP_UTF8))
907 MessageBox(_T("Creating new branch failed:\n") + out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
908 bAddSuccess = false;
910 if (g_Git.Run(_T("git checkout ") + m_sCreateNewBranch, &out, CP_UTF8))
912 MessageBox(_T("Switching to new branch failed:\n") + out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
913 bAddSuccess = false;
917 if (bAddSuccess && CheckHeadDetach())
918 bAddSuccess = false;
920 m_sBugID.Trim();
921 CString sExistingBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
922 sExistingBugID.Trim();
923 if (!m_sBugID.IsEmpty() && m_sBugID.Compare(sExistingBugID))
925 m_sBugID.Replace(_T(", "), _T(","));
926 m_sBugID.Replace(_T(" ,"), _T(","));
927 CString sBugID = m_ProjectProperties.sMessage;
928 sBugID.Replace(_T("%BUGID%"), m_sBugID);
929 if (m_ProjectProperties.bAppend)
930 m_sLogMessage += _T("\n") + sBugID + _T("\n");
931 else
932 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
935 // now let the bugtraq plugin check the commit message
936 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
937 if (m_BugTraqProvider)
939 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
940 if (SUCCEEDED(hr))
942 BSTR temp = NULL;
943 CString common = g_Git.m_CurrentDir;
944 BSTR repositoryRoot = common.AllocSysString();
945 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
946 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
947 BSTR commitMessage = m_sLogMessage.AllocSysString();
948 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
950 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
951 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
953 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
955 COMError ce(hr);
956 CString sErr;
957 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
958 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
960 else
962 CString sError = temp;
963 if (!sError.IsEmpty())
965 CMessageBox::Show(m_hWnd, sError, _T("TortoiseGit"), MB_ICONERROR);
966 return;
968 SysFreeString(temp);
973 if (m_bCommitMessageOnly || bAddSuccess && (nchecked || m_bCommitAmend || CTGitPath(g_Git.m_CurrentDir).IsMergeActive()))
975 bCloseCommitDlg = true;
977 CString tempfile=::GetTempFile();
979 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
981 CTGitPath path=g_Git.m_CurrentDir;
983 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
985 out =_T("");
986 CString amend;
987 if(this->m_bCommitAmend)
989 amend=_T("--amend");
991 CString dateTime;
992 if (m_bSetCommitDateTime)
994 CTime date, time;
995 m_CommitDate.GetTime(date);
996 m_CommitTime.GetTime(time);
997 dateTime.Format(_T("--date=%sT%s"), date.Format(_T("%Y-%m-%d")), time.Format(_T("%H:%M:%S")));
999 CString author;
1000 if (m_bSetAuthor)
1001 author.Format(_T("--author=\"%s\""), m_sAuthor);
1002 CString allowEmpty = m_bCommitMessageOnly ? _T("--allow-empty") : _T("");
1003 cmd.Format(_T("git.exe commit %s %s %s %s -F \"%s\""), author, dateTime, amend, allowEmpty, tempfile);
1005 CCommitProgressDlg progress;
1006 progress.m_bBufferAll=true; // improve show speed when there are many file added.
1007 progress.m_GitCmd=cmd;
1008 progress.m_bShowCommand = FALSE; // don't show the commit command
1009 progress.m_PreText = out; // show any output already generated in log window
1010 progress.m_bAutoCloseOnSuccess = m_bAutoClose;
1012 int indexReCommit = -1;
1013 int indexTag = -1;
1015 if (!m_bNoPostActions && !m_bAutoClose)
1017 if (IsGitSVN)
1018 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUSVNDCOMMIT)));
1019 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH)));
1020 indexReCommit = (int)progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_RECOMMIT)));
1021 indexTag = (int)progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUTAG)));
1024 INT_PTR userResponse = progress.DoModal();
1026 if(progress.m_GitStatus || userResponse == (IDC_PROGRESS_BUTTON1 + indexReCommit))
1028 bCloseCommitDlg = false;
1029 if (userResponse == IDC_PROGRESS_BUTTON1 + indexReCommit)
1031 this->m_sLogMessage.Empty();
1032 m_cLogMessage.SetText(m_sLogMessage);
1035 m_bCommitAmend = FALSE;
1036 UpdateData(FALSE);
1037 this->Refresh();
1039 else if (userResponse == IDC_PROGRESS_BUTTON1 + indexTag)
1041 m_bCreateTagAfterCommit=true;
1043 else if (userResponse >= IDC_PROGRESS_BUTTON1 && userResponse < IDC_PROGRESS_BUTTON1 + indexReCommit)
1045 // User pressed 'DCommit' or 'Push' button after successful commit.
1046 m_bPushAfterCommit=true;
1047 if (userResponse == IDC_PROGRESS_BUTTON1 && IsGitSVN)
1048 m_PostCmd = GIT_POST_CMD_DCOMMIT;
1049 else
1050 m_PostCmd = GIT_POST_CMD_PUSH;
1053 CFile::Remove(tempfile);
1055 if (m_BugTraqProvider && progress.m_GitStatus == 0)
1057 CComPtr<IBugTraqProvider2> pProvider = NULL;
1058 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
1059 if (SUCCEEDED(hr))
1061 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1062 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
1064 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
1065 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
1067 BSTR logMessage = m_sLogMessage.AllocSysString();
1069 CGitHash hash;
1070 if (g_Git.GetHash(hash, _T("HEAD")))
1071 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR);
1072 LONG version = g_Git.Hash2int(hash);
1074 BSTR temp = NULL;
1075 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
1076 commonRoot,
1077 pathList,
1078 logMessage,
1079 (LONG)version,
1080 &temp)))
1082 CString sErr = temp;
1083 if (!sErr.IsEmpty())
1084 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1085 else
1087 COMError ce(hr);
1088 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
1089 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1093 SysFreeString(temp);
1096 RestoreFiles(progress.m_GitStatus == 0);
1097 if (((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit"), TRUE)) == TRUE)
1099 BOOL cancel = FALSE;
1100 mgtReAddAfterCommit.Execute(cancel);
1103 else if(bAddSuccess)
1105 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
1106 bCloseCommitDlg=false;
1109 UpdateData();
1110 m_regAddBeforeCommit = m_bShowUnversioned;
1111 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
1112 m_bWholeProject = FALSE;
1113 m_regKeepChangelists = m_bKeepChangeList;
1114 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
1115 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
1116 m_bKeepChangeList = FALSE;
1117 InterlockedExchange(&m_bBlock, FALSE);
1119 if (!m_sLogMessage.IsEmpty())
1121 m_History.AddEntry(m_sLogMessage);
1122 m_History.Save();
1125 SaveSplitterPos();
1127 if( bCloseCommitDlg )
1128 CResizableStandAloneDialog::OnOK();
1130 CShellUpdater::Instance().Flush();
1133 void CCommitDlg::SaveSplitterPos()
1135 if (!IsIconic())
1137 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
1138 RECT rectSplitter;
1139 m_wndSplitter.GetWindowRect(&rectSplitter);
1140 ScreenToClient(&rectSplitter);
1141 regPos = rectSplitter.top;
1145 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
1147 return ((CCommitDlg*)pVoid)->StatusThread();
1150 UINT CCommitDlg::StatusThread()
1152 //get the status of all selected file/folders recursively
1153 //and show the ones which have to be committed to the user
1154 //in a list control.
1155 InterlockedExchange(&m_bBlock, TRUE);
1156 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
1157 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
1159 m_pathwatcher.Stop();
1161 m_ListCtrl.SetBusy(true);
1162 g_Git.RefreshGitIndex();
1164 m_bCancelled = false;
1166 DialogEnableWindow(IDOK, false);
1167 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
1168 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
1169 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
1170 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
1171 DialogEnableWindow(IDC_EXTERNALWARNING, false);
1172 DialogEnableWindow(IDC_COMMIT_AMEND, FALSE);
1173 DialogEnableWindow(IDC_COMMIT_AMENDDIFF, FALSE);
1174 // read the list of recent log entries before querying the WC for status
1175 // -> the user may select one and modify / update it while we are crawling the WC
1177 DialogEnableWindow(IDC_CHECKALL, false);
1178 DialogEnableWindow(IDC_CHECKNONE, false);
1179 DialogEnableWindow(IDC_CHECKUNVERSIONED, false);
1180 DialogEnableWindow(IDC_CHECKVERSIONED, false);
1181 DialogEnableWindow(IDC_CHECKADDED, false);
1182 DialogEnableWindow(IDC_CHECKDELETED, false);
1183 DialogEnableWindow(IDC_CHECKMODIFIED, false);
1184 DialogEnableWindow(IDC_CHECKFILES, false);
1185 DialogEnableWindow(IDC_CHECKSUBMODULES, false);
1187 if (m_History.GetCount()==0)
1189 CString reg;
1190 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
1191 reg.Replace(_T(':'),_T('_'));
1192 m_History.Load(reg, _T("logmsgs"));
1195 // Initialise the list control with the status of the files/folders below us
1196 m_ListCtrl.Clear();
1197 BOOL success;
1198 CTGitPathList *pList;
1199 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE || m_bForceCommitAmend) && (m_bAmendDiffToLastCommit==FALSE);
1200 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
1202 if(m_bWholeProject)
1203 pList=NULL;
1204 else
1205 pList = &m_pathList;
1207 success=m_ListCtrl.GetStatus(pList);
1209 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1210 if(this->m_bShowUnversioned)
1211 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
1213 m_ListCtrl.CheckIfChangelistsArePresent(false);
1215 DWORD dwShow = GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWLOCKS | GITSLC_SHOWINCHANGELIST;
1216 dwShow |= DWORD(m_regAddBeforeCommit) ? GITSLC_SHOWUNVERSIONED : 0;
1217 if (success)
1219 if (m_checkedPathList.GetCount())
1220 m_ListCtrl.Show(dwShow, m_checkedPathList);
1221 else
1223 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
1224 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
1225 m_ListCtrl.Show(dwShow, dwCheck);
1226 m_bSelectFilesForCommit = true;
1229 if (m_ListCtrl.HasExternalsFromDifferentRepos())
1231 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
1232 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
1235 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
1236 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
1238 if (!success)
1240 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
1241 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
1242 m_ListCtrl.Show(dwShow);
1245 CString dotGitPath;
1246 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
1247 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
1248 && !PathFileExists(dotGitPath + _T("MERGE_HEAD")))
1250 CString temp;
1251 temp.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED);
1252 if (CMessageBox::ShowCheck(m_hWnd, temp, _T("TortoiseGit"), MB_ICONINFORMATION | MB_YESNO, _T("NothingToCommitShowUnversioned"), NULL)==IDYES)
1254 m_bShowUnversioned = TRUE;
1255 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
1256 DWORD dwShow = (DWORD)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWUNVERSIONED | GITSLC_SHOWLOCKS);
1257 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
1258 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
1262 SetDlgTitle();
1264 m_autolist.clear();
1265 // we don't have to block the commit dialog while we fetch the
1266 // auto completion list.
1267 m_pathwatcher.ClearChangedPaths();
1268 InterlockedExchange(&m_bBlock, FALSE);
1269 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
1271 m_ListCtrl.Block(TRUE, TRUE);
1272 GetAutocompletionList();
1273 m_ListCtrl.Block(FALSE, FALSE);
1275 SendMessage(WM_UPDATEOKBUTTON);
1276 if (m_bRunThread)
1278 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1279 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1280 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1281 if (m_ListCtrl.HasChangeLists())
1282 DialogEnableWindow(IDC_KEEPLISTS, true);
1283 if (m_ListCtrl.HasLocks())
1284 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1286 // activate amend checkbox (if necessary)
1287 if (g_Git.IsInitRepos())
1289 m_bCommitAmend = FALSE;
1290 SendMessage(WM_UPDATEDATAFALSE);
1292 else
1294 if (m_bForceCommitAmend)
1296 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
1297 m_bCommitAmend = TRUE;
1298 SendMessage(WM_UPDATEDATAFALSE);
1300 else
1301 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(TRUE);
1303 CGitHash hash;
1304 if (g_Git.GetHash(hash, _T("HEAD")))
1306 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR);
1308 if (!hash.IsEmpty())
1310 GitRev headRevision;
1313 headRevision.GetParentFromHash(hash);
1315 catch (char* msg)
1317 CString err(msg);
1318 MessageBox(_T("Could not get parent from HEAD.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
1320 // do not allow to show diff to "last" revision if it has more that one parent
1321 if (headRevision.ParentsCount() != 1)
1323 m_bAmendDiffToLastCommit = true;
1324 SendMessage(WM_UPDATEDATAFALSE);
1326 else
1327 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(TRUE);
1331 UpdateCheckLinks();
1333 // we have the list, now signal the main thread about it
1334 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1337 InterlockedExchange(&m_bRunThread, FALSE);
1338 InterlockedExchange(&m_bThreadRunning, FALSE);
1339 // force the cursor to normal
1340 RefreshCursor();
1342 return 0;
1345 void CCommitDlg::SetDlgTitle()
1347 if (m_sTitle.IsEmpty())
1348 GetWindowText(m_sTitle);
1350 if (m_bWholeProject)
1351 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
1352 else
1354 if (m_pathList.GetCount() == 1)
1355 CAppUtils::SetWindowTitle(m_hWnd, (g_Git.m_CurrentDir + _T("\\") + m_pathList[0].GetUIPathString()).TrimRight('\\'), m_sTitle);
1356 else
1357 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir + _T("\\") + m_ListCtrl.GetCommonDirectory(false), m_sTitle);
1361 void CCommitDlg::OnCancel()
1363 m_bCancelled = true;
1364 m_pathwatcher.Stop();
1366 if (m_bThreadRunning)
1368 InterlockedExchange(&m_bRunThread, FALSE);
1369 WaitForSingleObject(m_pThread->m_hThread, 1000);
1370 if (m_bThreadRunning)
1372 // we gave the thread a chance to quit. Since the thread didn't
1373 // listen to us we have to kill it.
1374 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1375 InterlockedExchange(&m_bThreadRunning, FALSE);
1378 UpdateData();
1379 m_sBugID.Trim();
1380 m_sLogMessage = m_cLogMessage.GetText();
1381 if (!m_sBugID.IsEmpty())
1383 m_sBugID.Replace(_T(", "), _T(","));
1384 m_sBugID.Replace(_T(" ,"), _T(","));
1385 CString sBugID = m_ProjectProperties.sMessage;
1386 sBugID.Replace(_T("%BUGID%"), m_sBugID);
1387 if (m_ProjectProperties.bAppend)
1388 m_sLogMessage += _T("\n") + sBugID + _T("\n");
1389 else
1390 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1392 if ((m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0) && !m_sLogMessage.IsEmpty())
1394 m_History.AddEntry(m_sLogMessage);
1395 m_History.Save();
1397 RestoreFiles();
1398 SaveSplitterPos();
1399 CResizableStandAloneDialog::OnCancel();
1402 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1404 if (!m_bBlock)
1405 m_tooltips.RelayEvent(pMsg);
1407 if (m_hAccel)
1409 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1410 if (ret)
1411 return TRUE;
1414 if (pMsg->message == WM_KEYDOWN)
1416 switch (pMsg->wParam)
1418 case VK_F5:
1420 if (m_bBlock)
1421 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1422 Refresh();
1424 break;
1425 case VK_RETURN:
1427 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1429 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1431 PostMessage(WM_COMMAND, IDOK);
1433 return TRUE;
1435 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1437 // Pressing RETURN in the bug id control
1438 // moves the focus to the message
1439 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1440 return TRUE;
1443 break;
1447 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1450 void CCommitDlg::Refresh()
1452 if (m_bThreadRunning)
1453 return;
1455 InterlockedExchange(&m_bBlock, TRUE);
1456 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1457 if (m_pThread==NULL)
1459 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1460 InterlockedExchange(&m_bBlock, FALSE);
1462 else
1464 m_pThread->m_bAutoDelete = FALSE;
1465 m_pThread->ResumeThread();
1469 void CCommitDlg::OnBnClickedHelp()
1471 OnHelp();
1474 void CCommitDlg::OnBnClickedShowunversioned()
1476 m_tooltips.Pop(); // hide the tooltips
1477 UpdateData();
1478 m_regAddBeforeCommit = m_bShowUnversioned;
1479 if (!m_bBlock)
1481 DWORD dwShow = m_ListCtrl.GetShowFlags();
1482 if (DWORD(m_regAddBeforeCommit))
1483 dwShow |= GITSLC_SHOWUNVERSIONED;
1484 else
1485 dwShow &= ~GITSLC_SHOWUNVERSIONED;
1486 if(dwShow & GITSLC_SHOWUNVERSIONED)
1488 if(m_bWholeProject)
1489 m_ListCtrl.GetStatus(NULL,false,false,true);
1490 else
1491 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1493 m_ListCtrl.Show(dwShow, 0, true, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
1494 UpdateCheckLinks();
1498 void CCommitDlg::OnStnClickedExternalwarning()
1500 m_tooltips.Popup();
1503 void CCommitDlg::OnEnChangeLogmessage()
1505 SendMessage(WM_UPDATEOKBUTTON);
1508 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1510 #if 0
1511 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1513 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1515 m_bShowUnversioned = TRUE;
1516 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1517 m_ListCtrl.Show(dwShow);
1518 UpdateData(FALSE);
1521 #endif
1522 return 0;
1525 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1527 Refresh();
1528 return 0;
1531 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1533 #if 0
1534 BringWindowToTop();
1535 SetForegroundWindow();
1536 SetActiveWindow();
1537 // if multiple files/folders are dropped
1538 // this handler is called for every single item
1539 // separately.
1540 // To avoid creating multiple refresh threads and
1541 // causing crashes, we only add the items to the
1542 // list control and start a timer.
1543 // When the timer expires, we start the refresh thread,
1544 // but only if it isn't already running - otherwise we
1545 // restart the timer.
1546 CTGitPath path;
1547 path.SetFromWin((LPCTSTR)lParam);
1549 // just add all the items we get here.
1550 // if the item is versioned, the add will fail but nothing
1551 // more will happen.
1552 Git Git;
1553 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1555 if (!m_ListCtrl.HasPath(path))
1557 if (m_pathList.AreAllPathsFiles())
1559 m_pathList.AddPath(path);
1560 m_pathList.RemoveDuplicates();
1561 m_updatedPathList.AddPath(path);
1562 m_updatedPathList.RemoveDuplicates();
1564 else
1566 // if the path list contains folders, we have to check whether
1567 // our just (maybe) added path is a child of one of those. If it is
1568 // a child of a folder already in the list, we must not add it. Otherwise
1569 // that path could show up twice in the list.
1570 bool bHasParentInList = false;
1571 for (int i=0; i<m_pathList.GetCount(); ++i)
1573 if (m_pathList[i].IsAncestorOf(path))
1575 bHasParentInList = true;
1576 break;
1579 if (!bHasParentInList)
1581 m_pathList.AddPath(path);
1582 m_pathList.RemoveDuplicates();
1583 m_updatedPathList.AddPath(path);
1584 m_updatedPathList.RemoveDuplicates();
1589 // Always start the timer, since the status of an existing item might have changed
1590 SetTimer(REFRESHTIMER, 200, NULL);
1591 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1592 #endif
1593 return 0;
1596 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1598 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1599 return 0;
1602 //////////////////////////////////////////////////////////////////////////
1603 // functions which run in the status thread
1604 //////////////////////////////////////////////////////////////////////////
1606 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1608 CString strLine;
1611 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1612 while (m_bRunThread && file.ReadString(strLine))
1614 int eqpos = strLine.Find('=');
1615 CString rgx;
1616 rgx = strLine.Mid(eqpos+1).Trim();
1618 int pos = -1;
1619 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1621 mapRegex[strLine.Left(pos)] = rgx;
1622 strLine = strLine.Mid(pos+1).Trim();
1624 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1626 file.Close();
1628 catch (CFileException* pE)
1630 TRACE("CFileException loading auto list regex file\n");
1631 pE->Delete();
1632 return;
1635 void CCommitDlg::GetAutocompletionList()
1637 // the auto completion list is made of strings from each selected files.
1638 // the strings used are extracted from the files with regexes found
1639 // in the file "autolist.txt".
1640 // the format of that file is:
1641 // file extensions separated with commas '=' regular expression to use
1642 // example:
1643 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1644 // .cpp = (?<=[^\s]::)\b\w+\b
1646 std::map<CString, CString> mapRegex;
1647 CString sRegexFile = CPathUtils::GetAppDirectory();
1648 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1649 DWORD timeoutvalue = regtimeout*1000;
1650 sRegexFile += _T("autolist.txt");
1651 if (!m_bRunThread)
1652 return;
1653 ParseRegexFile(sRegexFile, mapRegex);
1654 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1655 sRegexFile.ReleaseBuffer();
1656 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1657 if (PathFileExists(sRegexFile))
1659 ParseRegexFile(sRegexFile, mapRegex);
1661 DWORD starttime = GetTickCount();
1663 // now we have two arrays of strings, where the first array contains all
1664 // file extensions we can use and the second the corresponding regex strings
1665 // to apply to those files.
1667 // the next step is to go over all files shown in the commit dialog
1668 // and scan them for strings we can use
1669 int nListItems = m_ListCtrl.GetItemCount();
1671 for (int i=0; i<nListItems && m_bRunThread; ++i)
1673 // stop parsing after timeout
1674 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1675 return;
1677 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1679 if(path == NULL)
1680 continue;
1682 CString sPartPath =path->GetGitPathString();
1683 m_autolist.insert(sPartPath);
1685 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1686 // if (!entry)
1687 // continue;
1689 // add the path parts to the auto completion list too
1690 // CString sPartPath = entry->GetRelativeGitPath();
1691 // m_autolist.insert(sPartPath);
1694 int pos = 0;
1695 int lastPos = 0;
1696 while ((pos = sPartPath.Find('/', pos)) >= 0)
1698 ++pos;
1699 lastPos = pos;
1700 m_autolist.insert(sPartPath.Mid(pos));
1703 // Last inserted entry is a file name.
1704 // Some users prefer to also list file name without extension.
1705 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1707 int dotPos = sPartPath.ReverseFind('.');
1708 if ((dotPos >= 0) && (dotPos > lastPos))
1709 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1711 #if 0
1712 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1713 continue;
1715 CString sExt = entry->GetPath().GetFileExtension();
1716 sExt.MakeLower();
1717 // find the regex string which corresponds to the file extension
1718 CString rdata = mapRegex[sExt];
1719 if (rdata.IsEmpty())
1720 continue;
1722 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1723 if ((entry->textstatus != Git_wc_status_unversioned) &&
1724 (entry->textstatus != Git_wc_status_none) &&
1725 (entry->textstatus != Git_wc_status_ignored) &&
1726 (entry->textstatus != Git_wc_status_added) &&
1727 (entry->textstatus != Git_wc_status_normal))
1729 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1730 if (!basePath.IsEmpty())
1731 ScanFile(basePath.GetWinPathString(), rdata);
1733 #endif
1735 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1738 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1740 wstring sFileContent;
1741 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1742 if (hFile != INVALID_HANDLE_VALUE)
1744 DWORD size = GetFileSize(hFile, NULL);
1745 if (size > 1000000L)
1747 // no files bigger than 1 Meg
1748 CloseHandle(hFile);
1749 return;
1751 // allocate memory to hold file contents
1752 char * buffer = new char[size];
1753 DWORD readbytes;
1754 ReadFile(hFile, buffer, size, &readbytes, NULL);
1755 CloseHandle(hFile);
1756 int opts = 0;
1757 IsTextUnicode(buffer, readbytes, &opts);
1758 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1760 delete [] buffer;
1761 return;
1763 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1765 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1767 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1769 int ret = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1770 wchar_t * pWideBuf = new wchar_t[ret];
1771 int ret2 = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1772 if (ret2 == ret)
1773 sFileContent = wstring(pWideBuf, ret);
1774 delete [] pWideBuf;
1776 delete [] buffer;
1778 if (sFileContent.empty()|| !m_bRunThread)
1780 return;
1785 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1786 const tr1::wsregex_iterator end;
1787 wstring s = sFileContent;
1788 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1790 const tr1::wsmatch match = *it;
1791 for (size_t i=1; i<match.size(); ++i)
1793 if (match[i].second-match[i].first)
1795 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1796 m_autolist.insert(wstring(match[i]).c_str());
1801 catch (exception) {}
1804 // CSciEditContextMenuInterface
1805 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1807 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1808 m_nPopupPasteListCmd = nCmd++;
1809 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1811 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1812 if(m_History.GetCount() > 0)
1814 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1815 m_nPopupPasteLastMessage = nCmd++;
1816 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1818 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1819 m_nPopupRecentMessage = nCmd++;
1820 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1826 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1829 if (m_bBlock)
1830 return false;
1831 if (cmd == m_nPopupPasteListCmd)
1833 CString logmsg;
1834 int nListItems = m_ListCtrl.GetItemCount();
1835 for (int i=0; i<nListItems; ++i)
1837 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1838 if (entry&&entry->m_Checked)
1840 CString line;
1841 CString status = entry->GetActionName();
1842 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1843 status = _T("Add"); // I18N TODO
1845 //git_wc_status_kind status = entry->status;
1846 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1847 if (m_ProjectProperties.bFileListInEnglish)
1848 langID = 1033;
1850 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1851 logmsg += line;
1854 pSciEdit->InsertText(logmsg);
1855 return true;
1858 if(cmd == m_nPopupPasteLastMessage)
1860 if(m_History.GetCount() ==0 )
1861 return false;
1863 CString logmsg;
1864 logmsg +=m_History.GetEntry(0);
1865 pSciEdit->InsertText(logmsg);
1866 return true;
1869 if(cmd == m_nPopupRecentMessage )
1871 OnBnClickedHistory();
1872 return true;
1874 return false;
1877 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1879 switch (nIDEvent)
1881 case ENDDIALOGTIMER:
1882 KillTimer(ENDDIALOGTIMER);
1883 EndDialog(0);
1884 break;
1885 case REFRESHTIMER:
1886 if (m_bThreadRunning)
1888 SetTimer(REFRESHTIMER, 200, NULL);
1889 ATLTRACE("Wait some more before refreshing\n");
1891 else
1893 KillTimer(REFRESHTIMER);
1894 ATLTRACE("Refreshing after items dropped\n");
1895 Refresh();
1897 break;
1898 case FILLPATCHVTIMER:
1899 FillPatchView();
1900 break;
1902 __super::OnTimer(nIDEvent);
1905 void CCommitDlg::OnBnClickedHistory()
1907 m_tooltips.Pop(); // hide the tooltips
1908 if (m_pathList.GetCount() == 0)
1909 return;
1911 CHistoryDlg historyDlg;
1912 historyDlg.SetHistory(m_History);
1913 if (historyDlg.DoModal() != IDOK)
1914 return;
1916 CString sMsg = historyDlg.GetSelectedText();
1917 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1919 CString sBugID = m_ProjectProperties.FindBugID(sMsg);
1920 if ((!sBugID.IsEmpty()) && ((GetDlgItem(IDC_BUGID)->IsWindowVisible())))
1922 SetDlgItemText(IDC_BUGID, sBugID);
1924 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1925 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1926 else
1927 m_cLogMessage.SetText(sMsg);
1930 SendMessage(WM_UPDATEOKBUTTON);
1931 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1935 void CCommitDlg::OnBnClickedBugtraqbutton()
1937 m_tooltips.Pop(); // hide the tooltips
1938 CString sMsg = m_cLogMessage.GetText();
1940 if (m_BugTraqProvider == NULL)
1941 return;
1943 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1944 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1945 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1947 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1948 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1950 BSTR originalMessage = sMsg.AllocSysString();
1951 BSTR temp = NULL;
1952 // m_revProps.clear();
1954 // first try the IBugTraqProvider2 interface
1955 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1956 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1957 bool bugIdOutSet = false;
1958 if (SUCCEEDED(hr))
1960 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1961 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1962 BSTR bugIDOut = NULL;
1963 GetDlgItemText(IDC_BUGID, m_sBugID);
1964 BSTR bugID = m_sBugID.AllocSysString();
1965 SAFEARRAY * revPropNames = NULL;
1966 SAFEARRAY * revPropValues = NULL;
1967 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1969 CString sErr;
1970 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1971 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1973 else
1975 if (bugIDOut)
1977 bugIdOutSet = true;
1978 m_sBugID = bugIDOut;
1979 SysFreeString(bugIDOut);
1980 SetDlgItemText(IDC_BUGID, m_sBugID);
1982 SysFreeString(bugID);
1983 SysFreeString(repositoryRoot);
1984 m_cLogMessage.SetText(temp);
1985 BSTR HUGEP *pbRevNames;
1986 BSTR HUGEP *pbRevValues;
1988 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1989 if (SUCCEEDED(hr1))
1991 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1992 if (SUCCEEDED(hr2))
1994 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1996 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; ++i)
1998 // m_revProps[pbRevNames[i]] = pbRevValues[i];
2001 SafeArrayUnaccessData(revPropValues);
2003 SafeArrayUnaccessData(revPropNames);
2005 if (revPropNames)
2006 SafeArrayDestroy(revPropNames);
2007 if (revPropValues)
2008 SafeArrayDestroy(revPropValues);
2011 else
2013 // if IBugTraqProvider2 failed, try IBugTraqProvider
2014 CComPtr<IBugTraqProvider> pProvider = NULL;
2015 hr = m_BugTraqProvider.QueryInterface(&pProvider);
2016 if (FAILED(hr))
2018 CString sErr;
2019 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2020 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
2021 return;
2024 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
2026 CString sErr;
2027 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2028 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
2030 else
2031 m_cLogMessage.SetText(temp);
2033 m_sLogMessage = m_cLogMessage.GetText();
2034 if (!m_ProjectProperties.sMessage.IsEmpty())
2036 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
2037 if (!sBugID.IsEmpty() && !bugIdOutSet)
2039 SetDlgItemText(IDC_BUGID, sBugID);
2043 m_cLogMessage.SetFocus();
2045 SysFreeString(parameters);
2046 SysFreeString(commonRoot);
2047 SafeArrayDestroy(pathList);
2048 SysFreeString(originalMessage);
2049 SysFreeString(temp);
2052 void CCommitDlg::FillPatchView(bool onlySetTimer)
2054 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2056 KillTimer(FILLPATCHVTIMER);
2057 if (onlySetTimer)
2059 SetTimer(FILLPATCHVTIMER, 100, NULL);
2060 return;
2062 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
2064 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
2065 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
2066 CString cmd,out;
2068 while(pos)
2070 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
2071 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
2072 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
2074 CString head = _T("HEAD");
2075 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
2076 head = _T("HEAD~1");
2077 cmd.Format(_T("git.exe diff %s -- \"%s\""), head, p->GetGitPathString());
2078 g_Git.Run(cmd, &out, CP_UTF8);
2082 m_patchViewdlg.m_ctrlPatchView.SetText(out);
2083 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
2084 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
2085 CRect rect;
2086 m_patchViewdlg.m_ctrlPatchView.GetClientRect(rect);
2087 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTH, rect.Width() - 4);
2090 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
2092 this->FillPatchView(true);
2093 return 0;
2097 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
2099 SendMessage(WM_UPDATEOKBUTTON);
2100 return 0;
2103 LRESULT CCommitDlg::OnCheck(WPARAM wnd, LPARAM)
2105 HWND hwnd = (HWND)wnd;
2106 bool check = !(GetAsyncKeyState(VK_SHIFT) & 0x8000);
2107 if (hwnd == GetDlgItem(IDC_CHECKALL)->GetSafeHwnd())
2108 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, check);
2109 else if (hwnd == GetDlgItem(IDC_CHECKNONE)->GetSafeHwnd())
2110 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, !check);
2111 else if (hwnd == GetDlgItem(IDC_CHECKUNVERSIONED)->GetSafeHwnd())
2112 m_ListCtrl.Check(GITSLC_SHOWUNVERSIONED, check);
2113 else if (hwnd == GetDlgItem(IDC_CHECKVERSIONED)->GetSafeHwnd())
2114 m_ListCtrl.Check(GITSLC_SHOWVERSIONED, check);
2115 else if (hwnd == GetDlgItem(IDC_CHECKADDED)->GetSafeHwnd())
2116 m_ListCtrl.Check(GITSLC_SHOWADDED, check);
2117 else if (hwnd == GetDlgItem(IDC_CHECKDELETED)->GetSafeHwnd())
2118 m_ListCtrl.Check(GITSLC_SHOWREMOVED, check);
2119 else if (hwnd == GetDlgItem(IDC_CHECKMODIFIED)->GetSafeHwnd())
2120 m_ListCtrl.Check(GITSLC_SHOWMODIFIED, check);
2121 else if (hwnd == GetDlgItem(IDC_CHECKFILES)->GetSafeHwnd())
2122 m_ListCtrl.Check(GITSLC_SHOWFILES, check);
2123 else if (hwnd == GetDlgItem(IDC_CHECKSUBMODULES)->GetSafeHwnd())
2124 m_ListCtrl.Check(GITSLC_SHOWSUBMODULES, check);
2126 return 0;
2129 LRESULT CCommitDlg::OnUpdateOKButton(WPARAM, LPARAM)
2131 if (m_bBlock)
2132 return 0;
2134 bool bValidLogSize = m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize && m_cLogMessage.GetText().GetLength() > 0;
2135 bool bAmendOrSelectFilesOrMerge = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit) || CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
2137 DialogEnableWindow(IDOK, bValidLogSize && (m_bCommitMessageOnly || bAmendOrSelectFilesOrMerge));
2139 return 0;
2142 LRESULT CCommitDlg::OnUpdateDataFalse(WPARAM, LPARAM)
2144 UpdateData(FALSE);
2145 return 0;
2148 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
2150 switch (message) {
2151 case WM_NOTIFY:
2152 if (wParam == IDC_SPLITTER)
2154 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2155 DoSize(pHdr->delta);
2157 break;
2160 return __super::DefWindowProc(message, wParam, lParam);
2163 void CCommitDlg::SetSplitterRange()
2165 if ((m_ListCtrl)&&(m_cLogMessage))
2167 CRect rcTop;
2168 m_cLogMessage.GetWindowRect(rcTop);
2169 ScreenToClient(rcTop);
2170 CRect rcMiddle;
2171 m_ListCtrl.GetWindowRect(rcMiddle);
2172 ScreenToClient(rcMiddle);
2173 if (rcMiddle.Height() && rcMiddle.Width())
2174 m_wndSplitter.SetRange(rcTop.top + 100, rcMiddle.bottom - 80);
2178 void CCommitDlg::DoSize(int delta)
2180 RemoveAnchor(IDC_MESSAGEGROUP);
2181 RemoveAnchor(IDC_LOGMESSAGE);
2182 RemoveAnchor(IDC_SPLITTER);
2183 RemoveAnchor(IDC_SIGNOFF);
2184 RemoveAnchor(IDC_COMMIT_AMEND);
2185 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
2186 RemoveAnchor(IDC_COMMIT_SETDATETIME);
2187 RemoveAnchor(IDC_COMMIT_DATEPICKER);
2188 RemoveAnchor(IDC_COMMIT_TIMEPICKER);
2189 RemoveAnchor(IDC_COMMIT_SETAUTHOR);
2190 RemoveAnchor(IDC_COMMIT_AUTHORDATA);
2191 RemoveAnchor(IDC_LISTGROUP);
2192 RemoveAnchor(IDC_FILELIST);
2193 RemoveAnchor(IDC_TEXT_INFO);
2194 RemoveAnchor(IDC_SELECTLABEL);
2195 RemoveAnchor(IDC_CHECKALL);
2196 RemoveAnchor(IDC_CHECKNONE);
2197 RemoveAnchor(IDC_CHECKUNVERSIONED);
2198 RemoveAnchor(IDC_CHECKVERSIONED);
2199 RemoveAnchor(IDC_CHECKADDED);
2200 RemoveAnchor(IDC_CHECKDELETED);
2201 RemoveAnchor(IDC_CHECKMODIFIED);
2202 RemoveAnchor(IDC_CHECKFILES);
2203 RemoveAnchor(IDC_CHECKSUBMODULES);
2205 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
2206 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
2207 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
2208 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
2209 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
2210 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
2211 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
2212 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME),0,delta);
2213 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER),0,delta);
2214 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER),0,delta);
2215 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETAUTHOR), 0, delta);
2216 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AUTHORDATA), 0, delta);
2217 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
2218 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL), 0, delta);
2219 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL), 0, delta);
2220 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE), 0, delta);
2221 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED), 0, delta);
2222 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED), 0, delta);
2223 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED), 0, delta);
2224 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED), 0, delta);
2225 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED), 0, delta);
2226 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES), 0, delta);
2227 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES), 0, delta);
2229 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
2230 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
2231 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
2232 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
2233 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
2234 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
2235 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
2236 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
2237 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
2238 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
2239 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
2240 AddAnchor(IDC_COMMIT_SETAUTHOR, TOP_LEFT);
2241 AddAnchor(IDC_COMMIT_AUTHORDATA, TOP_LEFT, TOP_RIGHT);
2242 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
2243 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
2244 AddAnchor(IDC_CHECKALL, TOP_LEFT);
2245 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
2246 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
2247 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
2248 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
2249 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
2250 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
2251 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
2252 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
2253 ArrangeLayout();
2254 // adjust the minimum size of the dialog to prevent the resizing from
2255 // moving the list control too far down.
2256 CRect rcLogMsg;
2257 m_cLogMessage.GetClientRect(rcLogMsg);
2258 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
2260 SetSplitterRange();
2261 m_cLogMessage.Invalidate();
2262 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
2265 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
2267 // first, let the resizing take place
2268 __super::OnSize(nType, cx, cy);
2270 //set range
2271 SetSplitterRange();
2274 CString CCommitDlg::GetSignedOffByLine()
2276 CString str;
2278 CString username = g_Git.GetUserName();
2279 CString email = g_Git.GetUserEmail();
2280 username.Remove(_T('\n'));
2281 email.Remove(_T('\n'));
2283 str.Format(_T("Signed-off-by: %s <%s>"), username, email);
2285 return str;
2288 void CCommitDlg::OnBnClickedSignOff()
2290 CString str = GetSignedOffByLine();
2292 if (m_cLogMessage.GetText().Find(str) == -1) {
2293 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
2294 int lastNewline = m_cLogMessage.GetText().ReverseFind(_T('\n'));
2295 int foundByLine = -1;
2296 if (lastNewline > 0)
2297 foundByLine = m_cLogMessage.GetText().Find(_T("-by: "), lastNewline);
2299 if (foundByLine == -1 || foundByLine < lastNewline)
2300 str = _T("\r\n") + str;
2302 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n")+str+_T("\r\n"));
2306 void CCommitDlg::OnBnClickedCommitAmend()
2308 this->UpdateData();
2309 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
2311 GitRev rev;
2312 rev.GetCommit(CString(_T("HEAD")));
2313 m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody();
2316 if(this->m_bCommitAmend)
2318 this->m_NoAmendStr=this->m_cLogMessage.GetText();
2319 m_cLogMessage.SetText(m_AmendStr);
2320 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
2322 else
2324 this->m_AmendStr=this->m_cLogMessage.GetText();
2325 m_cLogMessage.SetText(m_NoAmendStr);
2326 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
2329 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2330 OnBnClickedCommitSetauthor(); // to update the commit author
2332 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2333 Refresh();
2336 void CCommitDlg::OnBnClickedCommitMessageOnly()
2338 this->UpdateData();
2339 this->m_ListCtrl.EnableWindow(m_bCommitMessageOnly ? FALSE : TRUE);
2340 SendMessage(WM_UPDATEOKBUTTON);
2343 void CCommitDlg::OnBnClickedWholeProject()
2345 m_tooltips.Pop(); // hide the tooltips
2346 UpdateData();
2347 m_ListCtrl.Clear();
2348 if (!m_bBlock)
2350 if(m_bWholeProject)
2351 m_ListCtrl.GetStatus(NULL,true,false,true);
2352 else
2353 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
2355 DWORD dwShow = m_ListCtrl.GetShowFlags();
2356 if (DWORD(m_regAddBeforeCommit))
2357 dwShow |= GITSLC_SHOWUNVERSIONED;
2358 else
2359 dwShow &= ~GITSLC_SHOWUNVERSIONED;
2361 m_ListCtrl.Show(dwShow, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
2362 UpdateCheckLinks();
2365 SetDlgTitle();
2368 void CCommitDlg::OnFocusMessage()
2370 m_cLogMessage.SetFocus();
2373 void CCommitDlg::OnScnUpdateUI(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2375 int pos = (int)this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
2376 int line = (int)this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
2377 int column = (int)this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
2379 CString str;
2380 str.Format(_T("%d/%d"),line+1,column+1);
2381 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
2383 if(*pResult)
2384 *pResult=0;
2386 void CCommitDlg::OnStnClickedViewPatch()
2388 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
2389 m_patchViewdlg.m_ParentCommitDlg = this;
2390 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
2392 BOOL viewPatchEnabled = FALSE;
2393 m_ProjectProperties.GetBOOLProps(viewPatchEnabled, _T("tgit.commitshowpatch"));
2394 if (viewPatchEnabled == FALSE)
2395 g_Git.SetConfigValue(_T("tgit.commitshowpatch"), _T("true"));
2396 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
2397 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2398 CRect rect;
2399 this->GetWindowRect(&rect);
2401 m_patchViewdlg.ShowWindow(SW_SHOW);
2403 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
2404 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
2406 ShowViewPatchText(false);
2407 FillPatchView();
2409 else
2411 g_Git.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2412 m_patchViewdlg.ShowWindow(SW_HIDE);
2413 m_patchViewdlg.DestroyWindow();
2414 ShowViewPatchText(true);
2416 this->m_ctrlShowPatch.Invalidate();
2419 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
2421 __super::OnMoving(fwSide, pRect);
2423 if (::IsWindow(m_patchViewdlg.m_hWnd))
2425 RECT patchrect;
2426 m_patchViewdlg.GetWindowRect(&patchrect);
2427 if (::IsWindow(m_hWnd))
2429 RECT thisrect;
2430 GetWindowRect(&thisrect);
2431 if (patchrect.left == thisrect.right)
2433 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2434 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2441 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2443 __super::OnSizing(fwSide, pRect);
2445 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2447 CRect thisrect, patchrect;
2448 this->GetWindowRect(thisrect);
2449 this->m_patchViewdlg.GetWindowRect(patchrect);
2450 if(thisrect.right==patchrect.left)
2452 patchrect.left -= (thisrect.right - pRect->right);
2453 patchrect.right-= (thisrect.right - pRect->right);
2455 if( patchrect.bottom == thisrect.bottom)
2457 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2459 if( patchrect.top == thisrect.top)
2461 patchrect.top -= thisrect.top-pRect->top;
2463 m_patchViewdlg.MoveWindow(patchrect);
2468 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2470 *pResult = 0;
2471 TRACE("Item Changed\r\n");
2474 int CCommitDlg::CheckHeadDetach()
2476 CString output;
2477 if(g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir,output))
2479 int retval = CMessageBox::Show(NULL, IDS_PROC_COMMIT_DETACHEDWARNING, IDS_APPNAME, MB_YESNOCANCEL | MB_ICONWARNING);
2480 if(retval == IDYES)
2482 if (CAppUtils::CreateBranchTag(FALSE, NULL, true) == FALSE)
2483 return 1;
2485 else if (retval == IDCANCEL)
2486 return 1;
2488 return 0;
2491 void CCommitDlg::OnBnClickedCommitAmenddiff()
2493 UpdateData();
2494 Refresh();
2497 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2499 UpdateData();
2500 Refresh();
2503 void CCommitDlg::OnBnClickedCommitSetDateTime()
2505 UpdateData();
2507 if (m_bSetCommitDateTime)
2509 CTime authordate = CTime::GetCurrentTime();
2510 if (m_bCommitAmend)
2512 GitRev headRevision;
2513 headRevision.GetCommit(_T("HEAD"));
2514 authordate = headRevision.GetAuthorDate();
2517 m_CommitDate.SetTime(&authordate);
2518 m_CommitTime.SetTime(&authordate);
2520 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
2521 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
2523 else
2525 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_HIDE);
2526 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_HIDE);
2530 void CCommitDlg::OnBnClickedCheckNewBranch()
2532 UpdateData();
2533 if (m_bCreateNewBranch)
2535 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_HIDE);
2536 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_SHOW);
2538 else
2540 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
2541 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);
2545 void CCommitDlg::RestoreFiles(bool doNotAsk)
2547 if (!m_ListCtrl.m_restorepaths.empty() && (doNotAsk || CMessageBox::Show(m_hWnd, IDS_PROC_COMMIT_RESTOREFILES, IDS_APPNAME, 2, IDI_QUESTION, IDS_PROC_COMMIT_RESTOREFILES_RESTORE, IDS_PROC_COMMIT_RESTOREFILES_KEEP) == 1))
2549 for (std::map<CString, CString>::iterator it = m_ListCtrl.m_restorepaths.begin(); it != m_ListCtrl.m_restorepaths.end(); ++it)
2550 CopyFile(it->second, g_Git.m_CurrentDir + _T("\\") + it->first, FALSE);
2551 m_ListCtrl.m_restorepaths.clear();
2555 void CCommitDlg::UpdateCheckLinks()
2557 DialogEnableWindow(IDC_CHECKALL, true);
2558 DialogEnableWindow(IDC_CHECKNONE, true);
2559 DialogEnableWindow(IDC_CHECKUNVERSIONED, m_ListCtrl.GetUnversionedCount() > 0);
2560 DialogEnableWindow(IDC_CHECKVERSIONED, m_ListCtrl.GetItemCount() > m_ListCtrl.GetUnversionedCount());
2561 DialogEnableWindow(IDC_CHECKADDED, m_ListCtrl.GetAddedCount() > 0);
2562 DialogEnableWindow(IDC_CHECKDELETED, m_ListCtrl.GetDeletedCount() > 0);
2563 DialogEnableWindow(IDC_CHECKMODIFIED, m_ListCtrl.GetModifiedCount() > 0);
2564 DialogEnableWindow(IDC_CHECKFILES, m_ListCtrl.GetFileCount() > 0);
2565 DialogEnableWindow(IDC_CHECKSUBMODULES, m_ListCtrl.GetSubmoduleCount() > 0);
2568 void CCommitDlg::OnBnClickedCommitSetauthor()
2570 UpdateData();
2572 if (m_bSetAuthor)
2574 m_sAuthor.Format(_T("%s <%s>"), g_Git.GetUserName(), g_Git.GetUserEmail());
2575 if (m_bCommitAmend)
2577 GitRev headRevision;
2578 headRevision.GetCommit(_T("HEAD"));
2579 m_sAuthor.Format(_T("%s <%s>"), headRevision.GetAuthorName(), headRevision.GetAuthorEmail());
2582 UpdateData(FALSE);
2584 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_SHOW);
2586 else
2587 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_HIDE);