Add support for "project" config level
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob5ebd01a3c521d2ce0d69ef4bb3a564fbebbf03e5
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 "MessageBox.h"
25 #include "AppUtils.h"
26 #include "PathUtils.h"
27 #include "Git.h"
28 #include "registry.h"
29 #include "GitStatus.h"
30 #include "HistoryDlg.h"
31 #include "Hooks.h"
32 #include "UnicodeUtils.h"
33 #include "../TGitCache/CacheInterface.h"
34 #include "ProgressDlg.h"
35 #include "ShellUpdater.h"
36 #include "Commands/PushCommand.h"
37 #include "PatchViewDlg.h"
38 #include "COMError.h"
39 #include "Globals.h"
40 #include "SysProgressDlg.h"
41 #include "MassiveGitTask.h"
42 #include "LogDlg.h"
44 #ifdef _DEBUG
45 #define new DEBUG_NEW
46 #undef THIS_FILE
47 static char THIS_FILE[] = __FILE__;
48 #endif
50 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
51 UINT CCommitDlg::WM_UPDATEOKBUTTON = RegisterWindowMessage(_T("TORTOISEGIT_COMMIT_UPDATEOKBUTTON"));
52 UINT CCommitDlg::WM_UPDATEDATAFALSE = RegisterWindowMessage(_T("TORTOISEGIT_COMMIT_UPDATEDATAFALSE"));
54 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)
55 CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)
56 : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)
57 , m_bRecursive(FALSE)
58 , m_bShowUnversioned(FALSE)
59 , m_bBlock(FALSE)
60 , m_bThreadRunning(FALSE)
61 , m_bRunThread(FALSE)
62 , m_pThread(NULL)
63 , m_bWholeProject(FALSE)
64 , m_bKeepChangeList(TRUE)
65 , m_bDoNotAutoselectSubmodules(FALSE)
66 , m_itemsCount(0)
67 , m_bSelectFilesForCommit(TRUE)
68 , m_bNoPostActions(FALSE)
69 , m_bAutoClose(false)
70 , m_bSetCommitDateTime(FALSE)
71 , m_bCreateNewBranch(FALSE)
72 , m_bCreateTagAfterCommit(FALSE)
73 , m_bForceCommitAmend(false)
74 , m_bCommitMessageOnly(FALSE)
75 , m_bSetAuthor(FALSE)
76 , m_bCancelled(false)
77 , m_PostCmd(-1)
78 , m_bAmendDiffToLastCommit(FALSE)
79 , m_nPopupPasteListCmd(0)
80 , m_nPopupPasteLastMessage(0)
81 , m_nPopupRecentMessage(0)
82 , m_hAccel(nullptr)
84 this->m_bCommitAmend=FALSE;
85 m_bPushAfterCommit = FALSE;
88 CCommitDlg::~CCommitDlg()
90 if(m_pThread != NULL)
92 delete m_pThread;
96 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
98 CResizableStandAloneDialog::DoDataExchange(pDX);
99 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
100 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
101 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
102 DDX_Check(pDX, IDC_COMMIT_SETDATETIME, m_bSetCommitDateTime);
103 DDX_Check(pDX, IDC_CHECK_NEWBRANCH, m_bCreateNewBranch);
104 DDX_Text(pDX, IDC_NEWBRANCH, m_sCreateNewBranch);
105 DDX_Text(pDX, IDC_BUGID, m_sBugID);
106 DDX_Text(pDX, IDC_COMMIT_AUTHORDATA, m_sAuthor);
107 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
108 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
109 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
110 DDX_Check(pDX, IDC_NOAUTOSELECTSUBMODULES, m_bDoNotAutoselectSubmodules);
111 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
112 DDX_Check(pDX, IDC_COMMIT_MESSAGEONLY, m_bCommitMessageOnly);
113 DDX_Check(pDX,IDC_COMMIT_AMENDDIFF,m_bAmendDiffToLastCommit);
114 DDX_Check(pDX, IDC_COMMIT_SETAUTHOR, m_bSetAuthor);
115 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
116 DDX_Control(pDX, IDC_COMMIT_DATEPICKER, m_CommitDate);
117 DDX_Control(pDX, IDC_COMMIT_TIMEPICKER, m_CommitTime);
120 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
121 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
122 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
123 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
124 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
125 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
126 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
127 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
128 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE, OnFileDropped)
129 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
130 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
132 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED, &CCommitDlg::OnCheck)
133 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
134 ON_REGISTERED_MESSAGE(WM_UPDATEOKBUTTON, OnUpdateOKButton)
135 ON_REGISTERED_MESSAGE(WM_UPDATEDATAFALSE, OnUpdateDataFalse)
136 ON_WM_TIMER()
137 ON_WM_SIZE()
138 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
139 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
140 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
141 ON_BN_CLICKED(IDC_COMMIT_MESSAGEONLY, &CCommitDlg::OnBnClickedCommitMessageOnly)
142 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
143 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
144 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
145 ON_WM_MOVE()
146 ON_WM_MOVING()
147 ON_WM_SIZING()
148 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
149 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF, &CCommitDlg::OnBnClickedCommitAmenddiff)
150 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES, &CCommitDlg::OnBnClickedNoautoselectsubmodules)
151 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME, &CCommitDlg::OnBnClickedCommitSetDateTime)
152 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH, &CCommitDlg::OnBnClickedCheckNewBranch)
153 ON_BN_CLICKED(IDC_COMMIT_SETAUTHOR, &CCommitDlg::OnBnClickedCommitSetauthor)
154 END_MESSAGE_MAP()
156 bool PrefillMessage(const CString &filename, CString &msg)
158 if (PathFileExists(filename))
160 CStdioFile file;
161 if (file.Open(filename, CFile::modeRead))
163 CString str;
164 while(file.ReadString(str))
166 msg += str;
167 str.Empty();
168 msg += _T("\n");
171 else
172 ::MessageBox(nullptr, _T("Could not open ") + filename, _T("TortoiseGit"), MB_ICONERROR);
173 return true; // load no further files
175 return false;
178 BOOL CCommitDlg::OnInitDialog()
180 CResizableStandAloneDialog::OnInitDialog();
181 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
183 CAppUtils::GetCommitTemplate(this->m_sLogMessage);
185 CString dotGitPath;
186 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
187 bool loadedMsg = !PrefillMessage(dotGitPath + _T("MERGE_MSG"), m_sLogMessage);
188 loadedMsg = loadedMsg && !PrefillMessage(dotGitPath + _T("SQUASH_MSG"), m_sLogMessage);
190 if (CTGitPath(g_Git.m_CurrentDir).IsMergeActive())
192 DialogEnableWindow(IDC_CHECK_NEWBRANCH, FALSE);
193 m_bCreateNewBranch = FALSE;
194 GetDlgItem(IDC_MERGEACTIVE)->ShowWindow(SW_SHOW);
197 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
198 m_bShowUnversioned = m_regAddBeforeCommit;
200 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
202 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
203 m_bKeepChangeList = m_regKeepChangelists;
205 m_regDoNotAutoselectSubmodules = CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE);
206 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
208 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
210 // GitConfig config;
211 // m_bWholeProject = config.KeepLocks();
213 if(this->m_pathList.GetCount() == 0)
214 m_bWholeProject =true;
216 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
217 m_bWholeProject =true;
219 SetDlgTitle();
221 UpdateData(FALSE);
223 m_ListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD | GITSLC_COLDEL, _T("CommitDlg"),(GITSLC_POPALL ^ (GITSLC_POPCOMMIT | GITSLC_POPSAVEAS)), true, true);
224 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
225 m_ListCtrl.SetCancelBool(&m_bCancelled);
226 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
227 m_ListCtrl.EnableFileDrop();
228 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
230 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
231 m_ProjectProperties.ReadPropsPathList(m_pathList);
233 m_cLogMessage.Init(m_ProjectProperties);
234 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
235 m_cLogMessage.RegisterContextMenuHandler(this);
237 OnEnChangeLogmessage();
239 m_tooltips.Create(this);
240 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
241 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
242 m_tooltips.AddTool(IDC_MERGEACTIVE, IDC_MERGEACTIVE_TT);
243 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
245 CBugTraqAssociations bugtraq_associations;
246 bugtraq_associations.Load(m_ProjectProperties.GetProviderUUID(), m_ProjectProperties.sProviderParams);
248 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
250 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
251 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
253 CComPtr<IBugTraqProvider> pProvider;
254 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
255 if (SUCCEEDED(hr))
257 m_BugTraqProvider = pProvider;
258 BSTR temp = NULL;
259 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
261 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
262 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
263 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
266 SysFreeString(temp);
269 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
271 else if (!m_ProjectProperties.sMessage.IsEmpty())
273 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
274 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
275 if (!m_ProjectProperties.sLabel.IsEmpty())
276 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
277 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
278 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
279 GetDlgItem(IDC_BUGID)->SetFocus();
280 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
281 if (!sBugID.IsEmpty())
283 SetDlgItemText(IDC_BUGID, sBugID);
286 else
288 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
289 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
290 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
291 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
292 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
295 if (!m_sLogMessage.IsEmpty())
296 m_cLogMessage.SetText(m_sLogMessage);
298 GetWindowText(m_sWindowTitle);
300 AdjustControlSize(IDC_SHOWUNVERSIONED);
301 AdjustControlSize(IDC_WHOLE_PROJECT);
302 AdjustControlSize(IDC_CHECK_NEWBRANCH);
303 AdjustControlSize(IDC_COMMIT_AMEND);
304 AdjustControlSize(IDC_COMMIT_MESSAGEONLY);
305 AdjustControlSize(IDC_COMMIT_AMENDDIFF);
306 AdjustControlSize(IDC_COMMIT_SETDATETIME);
307 AdjustControlSize(IDC_COMMIT_SETAUTHOR);
308 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES);
309 AdjustControlSize(IDC_KEEPLISTS);
311 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKALL);
312 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKNONE);
313 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKUNVERSIONED);
314 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKVERSIONED);
315 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKADDED);
316 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKDELETED);
317 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKMODIFIED);
318 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKFILES);
319 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKSUBMODULES);
321 // line up all controls and adjust their sizes.
322 #define LINKSPACING 9
323 RECT rc = AdjustControlSize(IDC_SELECTLABEL);
324 rc.right -= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
325 rc = AdjustStaticSize(IDC_CHECKALL, rc, LINKSPACING);
326 rc = AdjustStaticSize(IDC_CHECKNONE, rc, LINKSPACING);
327 rc = AdjustStaticSize(IDC_CHECKUNVERSIONED, rc, LINKSPACING);
328 rc = AdjustStaticSize(IDC_CHECKVERSIONED, rc, LINKSPACING);
329 rc = AdjustStaticSize(IDC_CHECKADDED, rc, LINKSPACING);
330 rc = AdjustStaticSize(IDC_CHECKDELETED, rc, LINKSPACING);
331 rc = AdjustStaticSize(IDC_CHECKMODIFIED, rc, LINKSPACING);
332 rc = AdjustStaticSize(IDC_CHECKFILES, rc, LINKSPACING);
333 rc = AdjustStaticSize(IDC_CHECKSUBMODULES, rc, LINKSPACING);
335 GetClientRect(m_DlgOrigRect);
336 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
338 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
339 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
340 AddAnchor(IDC_BUGID, TOP_RIGHT);
341 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
342 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
343 AddAnchor(IDC_CHECK_NEWBRANCH, TOP_RIGHT);
344 AddAnchor(IDC_NEWBRANCH, TOP_LEFT, TOP_RIGHT);
345 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
346 // AddAnchor(IDC_HISTORY, TOP_LEFT);
347 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
348 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
349 AddAnchor(IDC_VIEW_PATCH, BOTTOM_RIGHT);
350 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
351 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
352 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
353 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
354 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
355 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
356 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
357 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
358 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
359 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
360 AddAnchor(IDOK, BOTTOM_RIGHT);
361 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
362 AddAnchor(IDHELP, BOTTOM_RIGHT);
363 AddAnchor(IDC_MERGEACTIVE, BOTTOM_RIGHT);
364 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
365 AddAnchor(IDC_COMMIT_MESSAGEONLY, BOTTOM_LEFT);
366 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
367 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
368 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
369 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
370 AddAnchor(IDC_COMMIT_SETAUTHOR, TOP_LEFT);
371 AddAnchor(IDC_COMMIT_AUTHORDATA, TOP_LEFT, TOP_RIGHT);
373 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
374 AddAnchor(IDC_CHECKALL, TOP_LEFT);
375 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
376 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
377 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
378 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
379 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
380 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
381 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
382 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
384 if (hWndExplorer)
385 CenterWindow(CWnd::FromHandle(hWndExplorer));
386 EnableSaveRestore(_T("CommitDlg"));
387 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
388 RECT rcDlg, rcLogMsg, rcFileList;
389 GetClientRect(&rcDlg);
390 m_cLogMessage.GetWindowRect(&rcLogMsg);
391 ScreenToClient(&rcLogMsg);
392 m_ListCtrl.GetWindowRect(&rcFileList);
393 ScreenToClient(&rcFileList);
394 if (yPos)
396 RECT rectSplitter;
397 m_wndSplitter.GetWindowRect(&rectSplitter);
398 ScreenToClient(&rectSplitter);
399 int delta = yPos - rectSplitter.top;
400 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
402 m_wndSplitter.SetWindowPos(NULL, rectSplitter.left, yPos, 0, 0, SWP_NOSIZE);
403 DoSize(delta);
407 SetSplitterRange();
409 // add all directories to the watcher
411 for (int i=0; i<m_pathList.GetCount(); ++i)
413 if (m_pathList[i].IsDirectory())
414 m_pathwatcher.AddPath(m_pathList[i]);
417 m_updatedPathList = m_pathList;
419 //first start a thread to obtain the file list with the status without
420 //blocking the dialog
421 InterlockedExchange(&m_bBlock, TRUE);
422 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
423 if (m_pThread==NULL)
425 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
426 InterlockedExchange(&m_bBlock, FALSE);
428 else
430 m_pThread->m_bAutoDelete = FALSE;
431 m_pThread->ResumeThread();
433 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
434 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
435 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
437 historyhint = TRUE;
438 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
440 err = FALSE;
442 this->m_ctrlShowPatch.SetURL(CString());
444 if (g_Git.GetConfigValueBool(_T("tgit.commitshowpatch")))
445 OnStnClickedViewPatch();
447 return FALSE; // return TRUE unless you set the focus to a control
448 // EXCEPTION: OCX Property Pages should return FALSE
451 static bool UpdateIndex(CMassiveGitTask &mgt, CSysProgressDlg &sysProgressDlg, int progress, int maxProgress)
453 if (sysProgressDlg.HasUserCancelled())
454 return false;
456 if (sysProgressDlg.IsVisible())
458 sysProgressDlg.SetTitle(IDS_APPNAME);
459 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
460 sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
461 sysProgressDlg.SetProgress(progress, maxProgress);
462 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing
465 BOOL cancel = FALSE;
466 return mgt.Execute(cancel);
469 void CCommitDlg::OnOK()
471 if (m_bBlock)
472 return;
473 if (m_bThreadRunning)
475 m_bCancelled = true;
476 InterlockedExchange(&m_bRunThread, FALSE);
477 WaitForSingleObject(m_pThread->m_hThread, 1000);
478 if (m_bThreadRunning)
480 // we gave the thread a chance to quit. Since the thread didn't
481 // listen to us we have to kill it.
482 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
483 InterlockedExchange(&m_bThreadRunning, FALSE);
486 this->UpdateData();
488 if (m_bCreateNewBranch)
490 if (!g_Git.IsBranchNameValid(m_sCreateNewBranch))
492 ShowEditBalloon(IDC_NEWBRANCH, IDS_B_T_NOTEMPTY, TTI_ERROR);
493 return;
495 if (g_Git.BranchTagExists(m_sCreateNewBranch))
497 // branch already exists
498 CString msg;
499 msg.LoadString(IDS_B_EXISTS);
500 msg += _T(" ") + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME));
501 ShowEditBalloon(IDC_NEWBRANCH, msg, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
502 return;
504 if (g_Git.BranchTagExists(m_sCreateNewBranch, false))
506 // tag with the same name exists -> shortref is ambiguous
507 if (CMessageBox::Show(m_hWnd, IDS_B_SAMETAGNAMEEXISTS, IDS_APPNAME, 2, IDI_EXCLAMATION, IDS_CONTINUEBUTTON, IDS_ABORTBUTTON) == 2)
508 return;
512 CString id;
513 GetDlgItemText(IDC_BUGID, id);
514 if (!m_ProjectProperties.CheckBugID(id))
516 ShowEditBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, TTI_ERROR);
517 return;
519 m_sLogMessage = m_cLogMessage.GetText();
520 if ( m_sLogMessage.IsEmpty() )
522 // no message entered, go round again
523 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
524 return;
526 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
528 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
529 return;
532 if (m_ProjectProperties.bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
534 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);
535 if (retval == 1)
537 OnBnClickedSignOff();
538 m_sLogMessage = m_cLogMessage.GetText();
540 else if (retval == 3)
541 return;
544 int nListItems = m_ListCtrl.GetItemCount();
545 bool needResetIndex = false;
546 for (int i = 0; i < nListItems && !m_bCommitMessageOnly; ++i)
548 CTGitPath *entry = (CTGitPath *)m_ListCtrl.GetItemData(i);
549 if (!entry->m_Checked && !(entry->m_Action & CTGitPath::LOGACTIONS_UNVER))
550 needResetIndex = true;
551 if (!entry->m_Checked || !entry->IsDirectory())
552 continue;
554 bool dirty = false;
555 if (entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
557 CGit subgit;
558 subgit.m_CurrentDir = g_Git.m_CurrentDir + _T("\\") + entry->GetWinPathString();
559 CString subcmdout;
560 subgit.Run(_T("git.exe status --porcelain"), &subcmdout, CP_UTF8);
561 dirty = !subcmdout.IsEmpty();
563 else
565 CString cmd, cmdout;
566 cmd.Format(_T("git.exe diff -- \"%s\""), entry->GetWinPathString());
567 g_Git.Run(cmd, &cmdout, CP_UTF8);
568 dirty = cmdout.Right(7) == _T("-dirty\n");
571 if (dirty)
573 CString message;
574 message.Format(CString(MAKEINTRESOURCE(IDS_COMMITDLG_SUBMODULEDIRTY)), entry->GetGitPathString());
575 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)));
576 if (result == 1)
578 CString cmdCommit;
579 cmdCommit.Format(_T("/command:commit /path:\"%s\\%s\""), g_Git.m_CurrentDir, entry->GetWinPathString());
580 CAppUtils::RunTortoiseGitProc(cmdCommit);
581 return;
583 else if (result == 2)
584 continue;
585 else
586 return;
590 if (!m_bCommitMessageOnly)
591 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
592 m_pathwatcher.Stop();
593 InterlockedExchange(&m_bBlock, TRUE);
594 CDWordArray arDeleted;
595 //first add all the unversioned files the user selected
596 //and check if all versioned files are selected
597 int nchecked = 0;
598 m_bRecursive = true;
600 CTGitPathList itemsToAdd;
601 CTGitPathList itemsToRemove;
602 CMassiveGitTask mgtReAddAfterCommit(_T("add --ignore-errors -f"));
604 CString cmd;
605 CString out;
607 bool bAddSuccess=true;
608 bool bCloseCommitDlg=false;
610 CSysProgressDlg sysProgressDlg;
611 if (nListItems >= 25)
613 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
614 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
615 sysProgressDlg.SetTime(true);
616 sysProgressDlg.SetShowProgressBar(true);
617 sysProgressDlg.ShowModal(this, true);
620 CBlockCacheForPath cacheBlock(g_Git.m_CurrentDir);
621 DWORD currentTicks = GetTickCount();
623 if (g_Git.UsingLibGit2(CGit::GIT_CMD_COMMIT_UPDATE_INDEX))
626 Do not use the libgit2 implementation right now, since it has several flaws:
627 * https://github.com/libgit2/libgit2/issues/1397: crlf issue
628 * http://code.google.com/p/tortoisegit/issues/detail?id=1690: possible access denied problem
629 * https://github.com/libgit2/libgit2/pull/1291: git.exe path is searched again and again
630 * changes to x-bit are not correctly committed
632 bAddSuccess = false;
635 git_repository *repository = nullptr;
636 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8);
637 if (git_repository_open(&repository, gitdir.GetBuffer()))
639 gitdir.ReleaseBuffer();
640 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
641 break;
643 gitdir.ReleaseBuffer();
645 CGitHash revHash;
646 CString revRef = _T("HEAD");
647 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
648 revRef = _T("HEAD~1");
649 if (g_Git.GetHash(revHash, revRef))
651 git_repository_free(repository);
652 MessageBox(g_Git.GetLibGit2LastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR);
653 break;
656 git_commit *commit = nullptr;
657 if (!revHash.IsEmpty() && needResetIndex && git_commit_lookup(&commit, repository, (const git_oid*)revHash.m_hash))
659 git_repository_free(repository);
660 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not get last commit.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
661 break;
664 git_tree *tree = nullptr;
665 if (!revHash.IsEmpty() && needResetIndex && git_commit_tree(&tree, commit))
667 git_commit_free(commit);
668 git_repository_free(repository);
669 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not read tree of commit.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
670 break;
673 git_index *index = nullptr;
674 if (git_repository_index(&index, repository))
676 if (tree != nullptr)
677 git_tree_free(tree);
678 if (commit != nullptr)
679 git_commit_free(commit);
680 git_repository_free(repository);
681 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not get the repository index.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
682 break;
685 // reset index to the one of the reference commit (HEAD or HEAD~1)
686 if (!revHash.IsEmpty() && needResetIndex && git_index_read_tree(index, tree))
688 git_index_free(index);
689 git_tree_free(tree);
690 git_commit_free(commit);
691 git_repository_free(repository);
692 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not read the tree into the index.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
693 break;
695 else if (!revHash.IsEmpty() && !needResetIndex)
697 git_index_read(index);
700 bAddSuccess = true;
702 for (int j = 0; j < nListItems; ++j)
704 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
706 if (sysProgressDlg.IsVisible())
708 if (GetTickCount() - currentTicks > 1000 || j == nListItems - 1 || j == 0)
710 sysProgressDlg.SetLine(2, entry->GetGitPathString(), true);
711 sysProgressDlg.SetProgress(j, nListItems);
712 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too often: this takes time!
713 currentTicks = GetTickCount();
717 CStringA filePathA = CUnicodeUtils::GetMulti(entry->GetGitPathString(), CP_UTF8);
719 if (entry->m_Checked && !m_bCommitMessageOnly)
721 if (entry->IsDirectory())
723 git_submodule *submodule = nullptr;
724 if (git_submodule_lookup(&submodule, repository, filePathA.GetBuffer()))
726 filePathA.ReleaseBuffer();
727 bAddSuccess = false;
728 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open submodule \"") + entry->GetGitPathString() + _T("\".")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
729 break;
731 filePathA.ReleaseBuffer();
732 if (git_submodule_add_to_index(submodule, FALSE))
734 bAddSuccess = false;
735 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not add submodule \"") + entry->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
736 break;
739 else if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
741 git_index_remove_bypath(index, filePathA.GetBuffer()); // ignore error
742 filePathA.ReleaseBuffer();
744 else
746 if (git_index_add_bypath(index, filePathA.GetBuffer()))
748 filePathA.ReleaseBuffer();
749 bAddSuccess = false;
750 CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not add \"") + entry->GetGitPathString() + _T("\" to index.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
751 break;
753 filePathA.ReleaseBuffer();
756 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
758 git_index_remove_bypath(index, filePathA.GetBuffer()); // ignore error
759 filePathA.ReleaseBuffer();
762 ++nchecked;
764 else if (entry->m_Action & CTGitPath::LOGACTIONS_ADDED || entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
765 mgtReAddAfterCommit.AddFile(*entry);
767 if (sysProgressDlg.HasUserCancelled())
769 bAddSuccess = false;
770 break;
773 CShellUpdater::Instance().AddPathForUpdate(*entry);
775 if (bAddSuccess && git_index_write(index))
776 bAddSuccess = false;
778 git_index_free(index);
779 if (tree != nullptr)
780 git_tree_free(tree);
781 if (commit != nullptr)
782 git_commit_free(commit);
783 git_repository_free(repository);
784 } while (0);
786 else
788 // ***************************************************
789 // ATTENTION: Similar code in RebaseDlg.cpp!!!
790 // ***************************************************
791 CMassiveGitTask mgtAdd(_T("add -f"));
792 CMassiveGitTask mgtUpdateIndexForceRemove(_T("update-index --force-remove"));
793 CMassiveGitTask mgtUpdateIndex(_T("update-index"));
794 CMassiveGitTask mgtRm(_T("rm --ignore-unmatch"));
795 CMassiveGitTask mgtRmFCache(_T("rm -f --cache"));
796 CString resetCmd = _T("reset");
797 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
798 resetCmd += _T(" HEAD~1");;
799 CMassiveGitTask mgtReset(resetCmd, TRUE, true);
800 for (int j = 0; j < nListItems; ++j)
802 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
804 if (entry->m_Checked && !m_bCommitMessageOnly)
806 if (entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
807 mgtAdd.AddFile(entry->GetGitPathString());
808 else if (entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
809 mgtUpdateIndexForceRemove.AddFile(entry->GetGitPathString());
810 else
811 mgtUpdateIndex.AddFile(entry->GetGitPathString());
813 if ((entry->m_Action & CTGitPath::LOGACTIONS_REPLACED) && !entry->GetGitOldPathString().IsEmpty())
814 mgtRm.AddFile(entry->GetGitOldPathString());
816 ++nchecked;
818 else
820 if (entry->m_Action & CTGitPath::LOGACTIONS_ADDED || entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
821 { //To init git repository, there are not HEAD, so we can use git reset command
822 mgtRmFCache.AddFile(entry->GetGitPathString());
823 mgtReAddAfterCommit.AddFile(*entry);
825 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED && !entry->GetGitOldPathString().IsEmpty())
826 mgtReset.AddFile(entry->GetGitOldPathString());
828 else if (!(entry->m_Action & CTGitPath::LOGACTIONS_UNVER))
829 mgtReset.AddFile(entry->GetGitPathString());
832 if (sysProgressDlg.HasUserCancelled())
834 bAddSuccess = false;
835 break;
839 CMassiveGitTask tasks[] = { mgtAdd, mgtUpdateIndexForceRemove, mgtUpdateIndex, mgtRm, mgtRmFCache, mgtReset };
840 int progress = 0, maxProgress = 0;
841 for (int j = 0; j < _countof(tasks); ++j)
842 maxProgress += tasks[j].GetListCount();
843 for (int j = 0; j < _countof(tasks); ++j)
844 bAddSuccess = bAddSuccess && UpdateIndex(tasks[j], sysProgressDlg, progress += tasks[j].GetListCount(), maxProgress);
846 if (sysProgressDlg.HasUserCancelled())
847 bAddSuccess = false;
849 for (int j = 0; bAddSuccess && j < nListItems; ++j)
850 CShellUpdater::Instance().AddPathForUpdate(*(CTGitPath*)m_ListCtrl.GetItemData(j));
853 if (sysProgressDlg.HasUserCancelled())
854 bAddSuccess = false;
856 //sysProgressDlg.Stop();
858 if (bAddSuccess && m_bCreateNewBranch)
860 if (g_Git.Run(_T("git branch ") + m_sCreateNewBranch, &out, CP_UTF8))
862 MessageBox(_T("Creating new branch failed:\n") + out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
863 bAddSuccess = false;
865 if (g_Git.Run(_T("git checkout ") + m_sCreateNewBranch, &out, CP_UTF8))
867 MessageBox(_T("Switching to new branch failed:\n") + out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
868 bAddSuccess = false;
872 if (bAddSuccess && CheckHeadDetach())
873 bAddSuccess = false;
875 m_sBugID.Trim();
876 CString sExistingBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
877 sExistingBugID.Trim();
878 if (!m_sBugID.IsEmpty() && m_sBugID.Compare(sExistingBugID))
880 m_sBugID.Replace(_T(", "), _T(","));
881 m_sBugID.Replace(_T(" ,"), _T(","));
882 CString sBugID = m_ProjectProperties.sMessage;
883 sBugID.Replace(_T("%BUGID%"), m_sBugID);
884 if (m_ProjectProperties.bAppend)
885 m_sLogMessage += _T("\n") + sBugID + _T("\n");
886 else
887 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
890 // now let the bugtraq plugin check the commit message
891 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
892 if (m_BugTraqProvider)
894 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
895 if (SUCCEEDED(hr))
897 BSTR temp = NULL;
898 CString common = g_Git.m_CurrentDir;
899 BSTR repositoryRoot = common.AllocSysString();
900 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
901 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
902 BSTR commitMessage = m_sLogMessage.AllocSysString();
903 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
905 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
906 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
908 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
910 COMError ce(hr);
911 CString sErr;
912 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
913 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
915 else
917 CString sError = temp;
918 if (!sError.IsEmpty())
920 CMessageBox::Show(m_hWnd, sError, _T("TortoiseGit"), MB_ICONERROR);
921 return;
923 SysFreeString(temp);
928 if (m_bCommitMessageOnly || bAddSuccess && (nchecked || m_bCommitAmend || CTGitPath(g_Git.m_CurrentDir).IsMergeActive()))
930 bCloseCommitDlg = true;
932 CString tempfile=::GetTempFile();
934 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
936 CTGitPath path=g_Git.m_CurrentDir;
938 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
940 out =_T("");
941 CString amend;
942 if(this->m_bCommitAmend)
944 amend=_T("--amend");
946 CString dateTime;
947 if (m_bSetCommitDateTime)
949 CTime date, time;
950 m_CommitDate.GetTime(date);
951 m_CommitTime.GetTime(time);
952 dateTime.Format(_T("--date=%sT%s"), date.Format(_T("%Y-%m-%d")), time.Format(_T("%H:%M:%S")));
954 CString author;
955 if (m_bSetAuthor)
956 author.Format(_T("--author=\"%s\""), m_sAuthor);
957 CString allowEmpty = m_bCommitMessageOnly ? _T("--allow-empty") : _T("");
958 cmd.Format(_T("git.exe commit %s %s %s %s -F \"%s\""), author, dateTime, amend, allowEmpty, tempfile);
960 CCommitProgressDlg progress;
961 progress.m_bBufferAll=true; // improve show speed when there are many file added.
962 progress.m_GitCmd=cmd;
963 progress.m_bShowCommand = FALSE; // don't show the commit command
964 progress.m_PreText = out; // show any output already generated in log window
965 progress.m_bAutoCloseOnSuccess = m_bAutoClose;
967 int indexReCommit = -1;
968 int indexTag = -1;
970 if (!m_bNoPostActions && !m_bAutoClose)
972 if (IsGitSVN)
973 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUSVNDCOMMIT)));
974 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH)));
975 indexReCommit = (int)progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_RECOMMIT)));
976 indexTag = (int)progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUTAG)));
979 INT_PTR userResponse = progress.DoModal();
981 if(progress.m_GitStatus || userResponse == (IDC_PROGRESS_BUTTON1 + indexReCommit))
983 bCloseCommitDlg = false;
984 if (userResponse == IDC_PROGRESS_BUTTON1 + indexReCommit)
986 this->m_sLogMessage.Empty();
987 m_cLogMessage.SetText(m_sLogMessage);
988 m_bCreateNewBranch = FALSE;
991 m_bCommitAmend = FALSE;
992 UpdateData(FALSE);
993 this->Refresh();
994 this->BringWindowToTop();
996 else if (userResponse == IDC_PROGRESS_BUTTON1 + indexTag)
998 m_bCreateTagAfterCommit=true;
1000 else if (userResponse >= IDC_PROGRESS_BUTTON1 && userResponse < IDC_PROGRESS_BUTTON1 + indexReCommit)
1002 // User pressed 'DCommit' or 'Push' button after successful commit.
1003 m_bPushAfterCommit=true;
1004 if (userResponse == IDC_PROGRESS_BUTTON1 && IsGitSVN)
1005 m_PostCmd = GIT_POST_CMD_DCOMMIT;
1006 else
1007 m_PostCmd = GIT_POST_CMD_PUSH;
1010 CFile::Remove(tempfile);
1012 if (m_BugTraqProvider && progress.m_GitStatus == 0)
1014 CComPtr<IBugTraqProvider2> pProvider = NULL;
1015 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
1016 if (SUCCEEDED(hr))
1018 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1019 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
1021 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
1022 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
1024 BSTR logMessage = m_sLogMessage.AllocSysString();
1026 CGitHash hash;
1027 if (g_Git.GetHash(hash, _T("HEAD")))
1028 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR);
1029 LONG version = g_Git.Hash2int(hash);
1031 BSTR temp = NULL;
1032 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
1033 commonRoot,
1034 pathList,
1035 logMessage,
1036 (LONG)version,
1037 &temp)))
1039 CString sErr = temp;
1040 if (!sErr.IsEmpty())
1041 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1042 else
1044 COMError ce(hr);
1045 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
1046 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1050 SysFreeString(temp);
1053 RestoreFiles(progress.m_GitStatus == 0);
1054 if (((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit"), TRUE)) == TRUE)
1056 BOOL cancel = FALSE;
1057 mgtReAddAfterCommit.Execute(cancel);
1060 else if(bAddSuccess)
1062 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
1063 bCloseCommitDlg=false;
1066 UpdateData();
1067 m_regAddBeforeCommit = m_bShowUnversioned;
1068 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
1069 m_bWholeProject = FALSE;
1070 m_regKeepChangelists = m_bKeepChangeList;
1071 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
1072 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
1073 m_bKeepChangeList = FALSE;
1074 InterlockedExchange(&m_bBlock, FALSE);
1076 if (!m_sLogMessage.IsEmpty())
1078 m_History.AddEntry(m_sLogMessage);
1079 m_History.Save();
1082 SaveSplitterPos();
1084 if( bCloseCommitDlg )
1085 CResizableStandAloneDialog::OnOK();
1087 CShellUpdater::Instance().Flush();
1090 void CCommitDlg::SaveSplitterPos()
1092 if (!IsIconic())
1094 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
1095 RECT rectSplitter;
1096 m_wndSplitter.GetWindowRect(&rectSplitter);
1097 ScreenToClient(&rectSplitter);
1098 regPos = rectSplitter.top;
1102 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
1104 return ((CCommitDlg*)pVoid)->StatusThread();
1107 UINT CCommitDlg::StatusThread()
1109 //get the status of all selected file/folders recursively
1110 //and show the ones which have to be committed to the user
1111 //in a list control.
1112 InterlockedExchange(&m_bBlock, TRUE);
1113 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
1114 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
1116 m_pathwatcher.Stop();
1118 m_ListCtrl.SetBusy(true);
1119 g_Git.RefreshGitIndex();
1121 m_bCancelled = false;
1123 DialogEnableWindow(IDOK, false);
1124 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
1125 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
1126 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
1127 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
1128 DialogEnableWindow(IDC_EXTERNALWARNING, false);
1129 DialogEnableWindow(IDC_COMMIT_AMEND, FALSE);
1130 DialogEnableWindow(IDC_COMMIT_AMENDDIFF, FALSE);
1131 // read the list of recent log entries before querying the WC for status
1132 // -> the user may select one and modify / update it while we are crawling the WC
1134 DialogEnableWindow(IDC_CHECKALL, false);
1135 DialogEnableWindow(IDC_CHECKNONE, false);
1136 DialogEnableWindow(IDC_CHECKUNVERSIONED, false);
1137 DialogEnableWindow(IDC_CHECKVERSIONED, false);
1138 DialogEnableWindow(IDC_CHECKADDED, false);
1139 DialogEnableWindow(IDC_CHECKDELETED, false);
1140 DialogEnableWindow(IDC_CHECKMODIFIED, false);
1141 DialogEnableWindow(IDC_CHECKFILES, false);
1142 DialogEnableWindow(IDC_CHECKSUBMODULES, false);
1144 if (m_History.GetCount()==0)
1146 CString reg;
1147 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
1148 reg.Replace(_T(':'),_T('_'));
1149 m_History.Load(reg, _T("logmsgs"));
1152 // Initialise the list control with the status of the files/folders below us
1153 m_ListCtrl.Clear();
1154 BOOL success;
1155 CTGitPathList *pList;
1156 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE || m_bForceCommitAmend) && (m_bAmendDiffToLastCommit==FALSE);
1157 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
1159 if(m_bWholeProject)
1160 pList=NULL;
1161 else
1162 pList = &m_pathList;
1164 success=m_ListCtrl.GetStatus(pList);
1166 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1167 if(this->m_bShowUnversioned)
1168 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
1170 m_ListCtrl.CheckIfChangelistsArePresent(false);
1172 DWORD dwShow = GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWLOCKS | GITSLC_SHOWINCHANGELIST | GITSLC_SHOWDIRECTFILES;
1173 dwShow |= DWORD(m_regAddBeforeCommit) ? GITSLC_SHOWUNVERSIONED : 0;
1174 if (success)
1176 if (m_checkedPathList.GetCount())
1177 m_ListCtrl.Show(dwShow, m_checkedPathList);
1178 else
1180 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
1181 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
1182 m_ListCtrl.Show(dwShow, dwCheck);
1183 m_bSelectFilesForCommit = true;
1186 if (m_ListCtrl.HasExternalsFromDifferentRepos())
1188 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
1189 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
1192 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
1193 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
1195 if (!success)
1197 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
1198 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
1199 m_ListCtrl.Show(dwShow);
1202 CString dotGitPath;
1203 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
1204 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
1205 && !PathFileExists(dotGitPath + _T("MERGE_HEAD")))
1207 CString temp;
1208 temp.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED);
1209 if (CMessageBox::ShowCheck(m_hWnd, temp, _T("TortoiseGit"), MB_ICONINFORMATION | MB_YESNO, _T("NothingToCommitShowUnversioned"), NULL)==IDYES)
1211 m_bShowUnversioned = TRUE;
1212 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
1213 DWORD dwShow = (DWORD)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWUNVERSIONED | GITSLC_SHOWLOCKS);
1214 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
1215 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
1219 SetDlgTitle();
1221 m_autolist.clear();
1222 // we don't have to block the commit dialog while we fetch the
1223 // auto completion list.
1224 m_pathwatcher.ClearChangedPaths();
1225 InterlockedExchange(&m_bBlock, FALSE);
1226 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
1228 m_ListCtrl.Block(TRUE, TRUE);
1229 GetAutocompletionList();
1230 m_ListCtrl.Block(FALSE, FALSE);
1232 SendMessage(WM_UPDATEOKBUTTON);
1233 if (m_bRunThread)
1235 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1236 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1237 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1238 if (m_ListCtrl.HasChangeLists())
1239 DialogEnableWindow(IDC_KEEPLISTS, true);
1240 if (m_ListCtrl.HasLocks())
1241 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1243 // activate amend checkbox (if necessary)
1244 if (g_Git.IsInitRepos())
1246 m_bCommitAmend = FALSE;
1247 SendMessage(WM_UPDATEDATAFALSE);
1249 else
1251 if (m_bForceCommitAmend)
1253 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
1254 m_bCommitAmend = TRUE;
1255 SendMessage(WM_UPDATEDATAFALSE);
1257 else
1258 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(TRUE);
1260 CGitHash hash;
1261 if (g_Git.GetHash(hash, _T("HEAD")))
1263 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR);
1265 if (!hash.IsEmpty())
1267 GitRev headRevision;
1270 headRevision.GetParentFromHash(hash);
1272 catch (char* msg)
1274 CString err(msg);
1275 MessageBox(_T("Could not get parent from HEAD.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
1277 // do not allow to show diff to "last" revision if it has more that one parent
1278 if (headRevision.ParentsCount() != 1)
1280 m_bAmendDiffToLastCommit = TRUE;
1281 SendMessage(WM_UPDATEDATAFALSE);
1283 else
1284 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(TRUE);
1288 UpdateCheckLinks();
1290 // we have the list, now signal the main thread about it
1291 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1294 InterlockedExchange(&m_bRunThread, FALSE);
1295 InterlockedExchange(&m_bThreadRunning, FALSE);
1296 // force the cursor to normal
1297 RefreshCursor();
1299 return 0;
1302 void CCommitDlg::SetDlgTitle()
1304 if (m_sTitle.IsEmpty())
1305 GetWindowText(m_sTitle);
1307 if (m_bWholeProject)
1308 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
1309 else
1311 if (m_pathList.GetCount() == 1)
1312 CAppUtils::SetWindowTitle(m_hWnd, (g_Git.m_CurrentDir + _T("\\") + m_pathList[0].GetUIPathString()).TrimRight('\\'), m_sTitle);
1313 else
1314 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir + _T("\\") + m_ListCtrl.GetCommonDirectory(false), m_sTitle);
1318 void CCommitDlg::OnCancel()
1320 m_bCancelled = true;
1321 m_pathwatcher.Stop();
1323 if (m_bThreadRunning)
1325 InterlockedExchange(&m_bRunThread, FALSE);
1326 WaitForSingleObject(m_pThread->m_hThread, 1000);
1327 if (m_bThreadRunning)
1329 // we gave the thread a chance to quit. Since the thread didn't
1330 // listen to us we have to kill it.
1331 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1332 InterlockedExchange(&m_bThreadRunning, FALSE);
1335 UpdateData();
1336 m_sBugID.Trim();
1337 m_sLogMessage = m_cLogMessage.GetText();
1338 if (!m_sBugID.IsEmpty())
1340 m_sBugID.Replace(_T(", "), _T(","));
1341 m_sBugID.Replace(_T(" ,"), _T(","));
1342 CString sBugID = m_ProjectProperties.sMessage;
1343 sBugID.Replace(_T("%BUGID%"), m_sBugID);
1344 if (m_ProjectProperties.bAppend)
1345 m_sLogMessage += _T("\n") + sBugID + _T("\n");
1346 else
1347 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1349 if ((m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0) && !m_sLogMessage.IsEmpty())
1351 m_History.AddEntry(m_sLogMessage);
1352 m_History.Save();
1354 RestoreFiles();
1355 SaveSplitterPos();
1356 CResizableStandAloneDialog::OnCancel();
1359 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1361 if (!m_bBlock)
1362 m_tooltips.RelayEvent(pMsg);
1364 if (m_hAccel)
1366 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1367 if (ret)
1368 return TRUE;
1371 if (pMsg->message == WM_KEYDOWN)
1373 switch (pMsg->wParam)
1375 case VK_F5:
1377 if (m_bBlock)
1378 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1379 Refresh();
1381 break;
1382 case VK_RETURN:
1384 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1386 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1388 PostMessage(WM_COMMAND, IDOK);
1390 return TRUE;
1392 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1394 // Pressing RETURN in the bug id control
1395 // moves the focus to the message
1396 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1397 return TRUE;
1400 break;
1404 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1407 void CCommitDlg::Refresh()
1409 if (m_bThreadRunning)
1410 return;
1412 InterlockedExchange(&m_bBlock, TRUE);
1413 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1414 if (m_pThread==NULL)
1416 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1417 InterlockedExchange(&m_bBlock, FALSE);
1419 else
1421 m_pThread->m_bAutoDelete = FALSE;
1422 m_pThread->ResumeThread();
1426 void CCommitDlg::OnBnClickedShowunversioned()
1428 m_tooltips.Pop(); // hide the tooltips
1429 UpdateData();
1430 m_regAddBeforeCommit = m_bShowUnversioned;
1431 if (!m_bBlock)
1433 DWORD dwShow = m_ListCtrl.GetShowFlags();
1434 if (DWORD(m_regAddBeforeCommit))
1435 dwShow |= GITSLC_SHOWUNVERSIONED;
1436 else
1437 dwShow &= ~GITSLC_SHOWUNVERSIONED;
1438 if(dwShow & GITSLC_SHOWUNVERSIONED)
1440 if(m_bWholeProject)
1441 m_ListCtrl.GetStatus(NULL,false,false,true);
1442 else
1443 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1445 m_ListCtrl.Show(dwShow, 0, true, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
1446 UpdateCheckLinks();
1450 void CCommitDlg::OnStnClickedExternalwarning()
1452 m_tooltips.Popup();
1455 void CCommitDlg::OnEnChangeLogmessage()
1457 SendMessage(WM_UPDATEOKBUTTON);
1460 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1462 #if 0
1463 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1465 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1467 m_bShowUnversioned = TRUE;
1468 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1469 m_ListCtrl.Show(dwShow);
1470 UpdateData(FALSE);
1473 #endif
1474 return 0;
1477 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1479 Refresh();
1480 return 0;
1483 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1485 #if 0
1486 BringWindowToTop();
1487 SetForegroundWindow();
1488 SetActiveWindow();
1489 // if multiple files/folders are dropped
1490 // this handler is called for every single item
1491 // separately.
1492 // To avoid creating multiple refresh threads and
1493 // causing crashes, we only add the items to the
1494 // list control and start a timer.
1495 // When the timer expires, we start the refresh thread,
1496 // but only if it isn't already running - otherwise we
1497 // restart the timer.
1498 CTGitPath path;
1499 path.SetFromWin((LPCTSTR)lParam);
1501 // just add all the items we get here.
1502 // if the item is versioned, the add will fail but nothing
1503 // more will happen.
1504 Git Git;
1505 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1507 if (!m_ListCtrl.HasPath(path))
1509 if (m_pathList.AreAllPathsFiles())
1511 m_pathList.AddPath(path);
1512 m_pathList.RemoveDuplicates();
1513 m_updatedPathList.AddPath(path);
1514 m_updatedPathList.RemoveDuplicates();
1516 else
1518 // if the path list contains folders, we have to check whether
1519 // our just (maybe) added path is a child of one of those. If it is
1520 // a child of a folder already in the list, we must not add it. Otherwise
1521 // that path could show up twice in the list.
1522 bool bHasParentInList = false;
1523 for (int i=0; i<m_pathList.GetCount(); ++i)
1525 if (m_pathList[i].IsAncestorOf(path))
1527 bHasParentInList = true;
1528 break;
1531 if (!bHasParentInList)
1533 m_pathList.AddPath(path);
1534 m_pathList.RemoveDuplicates();
1535 m_updatedPathList.AddPath(path);
1536 m_updatedPathList.RemoveDuplicates();
1541 // Always start the timer, since the status of an existing item might have changed
1542 SetTimer(REFRESHTIMER, 200, NULL);
1543 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": Item %s dropped, timer started\n"), path.GetWinPath());
1544 #endif
1545 return 0;
1548 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1550 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1551 return 0;
1554 //////////////////////////////////////////////////////////////////////////
1555 // functions which run in the status thread
1556 //////////////////////////////////////////////////////////////////////////
1558 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1560 CString strLine;
1563 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1564 while (m_bRunThread && file.ReadString(strLine))
1566 int eqpos = strLine.Find('=');
1567 CString rgx;
1568 rgx = strLine.Mid(eqpos+1).Trim();
1570 int pos = -1;
1571 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1573 mapRegex[strLine.Left(pos)] = rgx;
1574 strLine = strLine.Mid(pos+1).Trim();
1576 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1578 file.Close();
1580 catch (CFileException* pE)
1582 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException loading auto list regex file\n");
1583 pE->Delete();
1584 return;
1587 void CCommitDlg::GetAutocompletionList()
1589 // the auto completion list is made of strings from each selected files.
1590 // the strings used are extracted from the files with regexes found
1591 // in the file "autolist.txt".
1592 // the format of that file is:
1593 // file extensions separated with commas '=' regular expression to use
1594 // example:
1595 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1596 // .cpp = (?<=[^\s]::)\b\w+\b
1598 std::map<CString, CString> mapRegex;
1599 CString sRegexFile = CPathUtils::GetAppDirectory();
1600 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1601 DWORD timeoutvalue = regtimeout*1000;
1602 sRegexFile += _T("autolist.txt");
1603 if (!m_bRunThread)
1604 return;
1605 ParseRegexFile(sRegexFile, mapRegex);
1606 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1607 sRegexFile.ReleaseBuffer();
1608 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1609 if (PathFileExists(sRegexFile))
1611 ParseRegexFile(sRegexFile, mapRegex);
1613 DWORD starttime = GetTickCount();
1615 // now we have two arrays of strings, where the first array contains all
1616 // file extensions we can use and the second the corresponding regex strings
1617 // to apply to those files.
1619 // the next step is to go over all files shown in the commit dialog
1620 // and scan them for strings we can use
1621 int nListItems = m_ListCtrl.GetItemCount();
1623 for (int i=0; i<nListItems && m_bRunThread; ++i)
1625 // stop parsing after timeout
1626 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1627 return;
1629 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1631 if(path == NULL)
1632 continue;
1634 CString sPartPath =path->GetGitPathString();
1635 m_autolist.insert(sPartPath);
1637 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1638 // if (!entry)
1639 // continue;
1641 // add the path parts to the auto completion list too
1642 // CString sPartPath = entry->GetRelativeGitPath();
1643 // m_autolist.insert(sPartPath);
1646 int pos = 0;
1647 int lastPos = 0;
1648 while ((pos = sPartPath.Find('/', pos)) >= 0)
1650 ++pos;
1651 lastPos = pos;
1652 m_autolist.insert(sPartPath.Mid(pos));
1655 // Last inserted entry is a file name.
1656 // Some users prefer to also list file name without extension.
1657 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1659 int dotPos = sPartPath.ReverseFind('.');
1660 if ((dotPos >= 0) && (dotPos > lastPos))
1661 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1663 #if 0
1664 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1665 continue;
1667 CString sExt = entry->GetPath().GetFileExtension();
1668 sExt.MakeLower();
1669 // find the regex string which corresponds to the file extension
1670 CString rdata = mapRegex[sExt];
1671 if (rdata.IsEmpty())
1672 continue;
1674 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1675 if ((entry->textstatus != Git_wc_status_unversioned) &&
1676 (entry->textstatus != Git_wc_status_none) &&
1677 (entry->textstatus != Git_wc_status_ignored) &&
1678 (entry->textstatus != Git_wc_status_added) &&
1679 (entry->textstatus != Git_wc_status_normal))
1681 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1682 if (!basePath.IsEmpty())
1683 ScanFile(basePath.GetWinPathString(), rdata);
1685 #endif
1687 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1690 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1692 std::wstring sFileContent;
1693 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1694 if (hFile != INVALID_HANDLE_VALUE)
1696 DWORD size = GetFileSize(hFile, NULL);
1697 if (size > 1000000L)
1699 // no files bigger than 1 Meg
1700 CloseHandle(hFile);
1701 return;
1703 // allocate memory to hold file contents
1704 char * buffer = new char[size];
1705 DWORD readbytes;
1706 ReadFile(hFile, buffer, size, &readbytes, NULL);
1707 CloseHandle(hFile);
1708 int opts = 0;
1709 IsTextUnicode(buffer, readbytes, &opts);
1710 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1712 delete [] buffer;
1713 return;
1715 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1717 sFileContent = std::wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1719 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1721 int ret = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1722 wchar_t * pWideBuf = new wchar_t[ret];
1723 int ret2 = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1724 if (ret2 == ret)
1725 sFileContent = std::wstring(pWideBuf, ret);
1726 delete [] pWideBuf;
1728 delete [] buffer;
1730 if (sFileContent.empty()|| !m_bRunThread)
1732 return;
1737 const std::tr1::wregex regCheck(sRegex, std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript);
1738 const std::tr1::wsregex_iterator end;
1739 std::wstring s = sFileContent;
1740 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1742 const std::tr1::wsmatch match = *it;
1743 for (size_t i=1; i<match.size(); ++i)
1745 if (match[i].second-match[i].first)
1747 ATLTRACE(_T("matched keyword : %s\n"), std::wstring(match[i]).c_str());
1748 m_autolist.insert(std::wstring(match[i]).c_str());
1753 catch (std::exception) {}
1756 // CSciEditContextMenuInterface
1757 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1759 CString sMenuItemText;
1760 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITHASH);
1761 m_nPopupPickCommitHash = nCmd++;
1762 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPickCommitHash, sMenuItemText);
1764 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PICKCOMMITMESSAGE);
1765 m_nPopupPickCommitMessage = nCmd++;
1766 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPickCommitMessage, sMenuItemText);
1768 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTEFILELIST);
1769 m_nPopupPasteListCmd = nCmd++;
1770 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1772 if (m_History.GetCount() > 0)
1774 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1775 m_nPopupPasteLastMessage = nCmd++;
1776 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1778 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1779 m_nPopupRecentMessage = nCmd++;
1780 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1784 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1786 if (cmd == m_nPopupPickCommitHash)
1788 // use the git log to allow selection of a version
1789 CLogDlg dlg;
1790 // tell the dialog to use mode for selecting revisions
1791 dlg.SetSelect(true);
1792 // only one revision must be selected however
1793 dlg.SingleSelection(true);
1794 if (dlg.DoModal() == IDOK)
1796 // get selected hash if any
1797 CString selectedHash = dlg.GetSelectedHash();
1798 pSciEdit->InsertText(selectedHash);
1800 return true;
1803 if (cmd == m_nPopupPickCommitMessage)
1805 // use the git log to allow selection of a version
1806 CLogDlg dlg;
1807 // tell the dialog to use mode for selecting revisions
1808 dlg.SetSelect(true);
1809 // only one revision must be selected however
1810 dlg.SingleSelection(true);
1811 if (dlg.DoModal() == IDOK)
1813 // get selected hash if any
1814 CString selectedHash = dlg.GetSelectedHash();
1815 GitRev rev;
1816 rev.GetCommit(selectedHash);
1817 CString message = rev.GetSubject() + _T("\r\n") + rev.GetBody();
1818 pSciEdit->InsertText(message);
1820 return true;
1823 if (cmd == m_nPopupPasteListCmd)
1825 CString logmsg;
1826 int nListItems = m_ListCtrl.GetItemCount();
1827 for (int i=0; i<nListItems; ++i)
1829 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1830 if (entry&&entry->m_Checked)
1832 CString line;
1833 CString status = entry->GetActionName();
1834 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1835 status = _T("Add"); // I18N TODO
1837 //git_wc_status_kind status = entry->status;
1838 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1839 if (m_ProjectProperties.bFileListInEnglish)
1840 langID = 1033;
1842 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1843 logmsg += line;
1846 pSciEdit->InsertText(logmsg);
1847 return true;
1850 if(cmd == m_nPopupPasteLastMessage)
1852 if(m_History.GetCount() ==0 )
1853 return false;
1855 CString logmsg;
1856 logmsg +=m_History.GetEntry(0);
1857 pSciEdit->InsertText(logmsg);
1858 return true;
1861 if(cmd == m_nPopupRecentMessage )
1863 OnBnClickedHistory();
1864 return true;
1866 return false;
1869 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1871 switch (nIDEvent)
1873 case ENDDIALOGTIMER:
1874 KillTimer(ENDDIALOGTIMER);
1875 EndDialog(0);
1876 break;
1877 case REFRESHTIMER:
1878 if (m_bThreadRunning)
1880 SetTimer(REFRESHTIMER, 200, NULL);
1881 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Wait some more before refreshing\n");
1883 else
1885 KillTimer(REFRESHTIMER);
1886 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Refreshing after items dropped\n");
1887 Refresh();
1889 break;
1890 case FILLPATCHVTIMER:
1891 FillPatchView();
1892 break;
1894 __super::OnTimer(nIDEvent);
1897 void CCommitDlg::OnBnClickedHistory()
1899 m_tooltips.Pop(); // hide the tooltips
1900 if (m_pathList.GetCount() == 0)
1901 return;
1903 CHistoryDlg historyDlg;
1904 historyDlg.SetHistory(m_History);
1905 if (historyDlg.DoModal() != IDOK)
1906 return;
1908 CString sMsg = historyDlg.GetSelectedText();
1909 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1911 CString sBugID = m_ProjectProperties.FindBugID(sMsg);
1912 if ((!sBugID.IsEmpty()) && ((GetDlgItem(IDC_BUGID)->IsWindowVisible())))
1914 SetDlgItemText(IDC_BUGID, sBugID);
1916 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1917 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1918 else
1919 m_cLogMessage.SetText(sMsg);
1922 SendMessage(WM_UPDATEOKBUTTON);
1923 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1927 void CCommitDlg::OnBnClickedBugtraqbutton()
1929 m_tooltips.Pop(); // hide the tooltips
1930 CString sMsg = m_cLogMessage.GetText();
1932 if (m_BugTraqProvider == NULL)
1933 return;
1935 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1936 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1937 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1939 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1940 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1942 BSTR originalMessage = sMsg.AllocSysString();
1943 BSTR temp = NULL;
1944 // m_revProps.clear();
1946 // first try the IBugTraqProvider2 interface
1947 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1948 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1949 bool bugIdOutSet = false;
1950 if (SUCCEEDED(hr))
1952 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1953 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1954 BSTR bugIDOut = NULL;
1955 GetDlgItemText(IDC_BUGID, m_sBugID);
1956 BSTR bugID = m_sBugID.AllocSysString();
1957 SAFEARRAY * revPropNames = NULL;
1958 SAFEARRAY * revPropValues = NULL;
1959 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1961 CString sErr;
1962 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1963 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1965 else
1967 if (bugIDOut)
1969 bugIdOutSet = true;
1970 m_sBugID = bugIDOut;
1971 SysFreeString(bugIDOut);
1972 SetDlgItemText(IDC_BUGID, m_sBugID);
1974 SysFreeString(bugID);
1975 SysFreeString(repositoryRoot);
1976 m_cLogMessage.SetText(temp);
1977 BSTR HUGEP *pbRevNames;
1978 BSTR HUGEP *pbRevValues;
1980 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1981 if (SUCCEEDED(hr1))
1983 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1984 if (SUCCEEDED(hr2))
1986 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1988 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; ++i)
1990 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1993 SafeArrayUnaccessData(revPropValues);
1995 SafeArrayUnaccessData(revPropNames);
1997 if (revPropNames)
1998 SafeArrayDestroy(revPropNames);
1999 if (revPropValues)
2000 SafeArrayDestroy(revPropValues);
2003 else
2005 // if IBugTraqProvider2 failed, try IBugTraqProvider
2006 CComPtr<IBugTraqProvider> pProvider = NULL;
2007 hr = m_BugTraqProvider.QueryInterface(&pProvider);
2008 if (FAILED(hr))
2010 CString sErr;
2011 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2012 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
2013 SysFreeString(parameters);
2014 SysFreeString(commonRoot);
2015 SafeArrayDestroy(pathList);
2016 SysFreeString(originalMessage);
2017 return;
2020 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
2022 CString sErr;
2023 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
2024 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
2026 else
2027 m_cLogMessage.SetText(temp);
2029 m_sLogMessage = m_cLogMessage.GetText();
2030 if (!m_ProjectProperties.sMessage.IsEmpty())
2032 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
2033 if (!sBugID.IsEmpty() && !bugIdOutSet)
2035 SetDlgItemText(IDC_BUGID, sBugID);
2039 m_cLogMessage.SetFocus();
2041 SysFreeString(parameters);
2042 SysFreeString(commonRoot);
2043 SafeArrayDestroy(pathList);
2044 SysFreeString(originalMessage);
2045 SysFreeString(temp);
2048 void CCommitDlg::FillPatchView(bool onlySetTimer)
2050 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2052 KillTimer(FILLPATCHVTIMER);
2053 if (onlySetTimer)
2055 SetTimer(FILLPATCHVTIMER, 100, NULL);
2056 return;
2058 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
2060 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
2061 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
2062 CString cmd,out;
2064 while(pos)
2066 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
2067 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
2068 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
2070 CString head = _T("HEAD");
2071 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
2072 head = _T("HEAD~1");
2073 cmd.Format(_T("git.exe diff %s -- \"%s\""), head, p->GetGitPathString());
2074 g_Git.Run(cmd, &out, CP_UTF8);
2078 m_patchViewdlg.m_ctrlPatchView.SetText(out);
2079 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
2080 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
2081 CRect rect;
2082 m_patchViewdlg.m_ctrlPatchView.GetClientRect(rect);
2083 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTH, rect.Width() - 4);
2086 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
2088 this->FillPatchView(true);
2089 return 0;
2093 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
2095 SendMessage(WM_UPDATEOKBUTTON);
2096 return 0;
2099 LRESULT CCommitDlg::OnCheck(WPARAM wnd, LPARAM)
2101 HWND hwnd = (HWND)wnd;
2102 bool check = !(GetAsyncKeyState(VK_SHIFT) & 0x8000);
2103 if (hwnd == GetDlgItem(IDC_CHECKALL)->GetSafeHwnd())
2104 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, check);
2105 else if (hwnd == GetDlgItem(IDC_CHECKNONE)->GetSafeHwnd())
2106 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, !check);
2107 else if (hwnd == GetDlgItem(IDC_CHECKUNVERSIONED)->GetSafeHwnd())
2108 m_ListCtrl.Check(GITSLC_SHOWUNVERSIONED, check);
2109 else if (hwnd == GetDlgItem(IDC_CHECKVERSIONED)->GetSafeHwnd())
2110 m_ListCtrl.Check(GITSLC_SHOWVERSIONED, check);
2111 else if (hwnd == GetDlgItem(IDC_CHECKADDED)->GetSafeHwnd())
2112 m_ListCtrl.Check(GITSLC_SHOWADDED, check);
2113 else if (hwnd == GetDlgItem(IDC_CHECKDELETED)->GetSafeHwnd())
2114 m_ListCtrl.Check(GITSLC_SHOWREMOVED, check);
2115 else if (hwnd == GetDlgItem(IDC_CHECKMODIFIED)->GetSafeHwnd())
2116 m_ListCtrl.Check(GITSLC_SHOWMODIFIED, check);
2117 else if (hwnd == GetDlgItem(IDC_CHECKFILES)->GetSafeHwnd())
2118 m_ListCtrl.Check(GITSLC_SHOWFILES, check);
2119 else if (hwnd == GetDlgItem(IDC_CHECKSUBMODULES)->GetSafeHwnd())
2120 m_ListCtrl.Check(GITSLC_SHOWSUBMODULES, check);
2122 return 0;
2125 LRESULT CCommitDlg::OnUpdateOKButton(WPARAM, LPARAM)
2127 if (m_bBlock)
2128 return 0;
2130 bool bValidLogSize = m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize && m_cLogMessage.GetText().GetLength() > 0;
2131 bool bAmendOrSelectFilesOrMerge = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit) || CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
2133 DialogEnableWindow(IDOK, bValidLogSize && (m_bCommitMessageOnly || bAmendOrSelectFilesOrMerge));
2135 return 0;
2138 LRESULT CCommitDlg::OnUpdateDataFalse(WPARAM, LPARAM)
2140 UpdateData(FALSE);
2141 return 0;
2144 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
2146 switch (message) {
2147 case WM_NOTIFY:
2148 if (wParam == IDC_SPLITTER)
2150 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2151 DoSize(pHdr->delta);
2153 break;
2156 return __super::DefWindowProc(message, wParam, lParam);
2159 void CCommitDlg::SetSplitterRange()
2161 if ((m_ListCtrl)&&(m_cLogMessage))
2163 CRect rcTop;
2164 m_cLogMessage.GetWindowRect(rcTop);
2165 ScreenToClient(rcTop);
2166 CRect rcMiddle;
2167 m_ListCtrl.GetWindowRect(rcMiddle);
2168 ScreenToClient(rcMiddle);
2169 if (rcMiddle.Height() && rcMiddle.Width())
2170 m_wndSplitter.SetRange(rcTop.top + 100, rcMiddle.bottom - 80);
2174 void CCommitDlg::DoSize(int delta)
2176 RemoveAnchor(IDC_MESSAGEGROUP);
2177 RemoveAnchor(IDC_LOGMESSAGE);
2178 RemoveAnchor(IDC_SPLITTER);
2179 RemoveAnchor(IDC_SIGNOFF);
2180 RemoveAnchor(IDC_COMMIT_AMEND);
2181 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
2182 RemoveAnchor(IDC_COMMIT_SETDATETIME);
2183 RemoveAnchor(IDC_COMMIT_DATEPICKER);
2184 RemoveAnchor(IDC_COMMIT_TIMEPICKER);
2185 RemoveAnchor(IDC_COMMIT_SETAUTHOR);
2186 RemoveAnchor(IDC_COMMIT_AUTHORDATA);
2187 RemoveAnchor(IDC_LISTGROUP);
2188 RemoveAnchor(IDC_FILELIST);
2189 RemoveAnchor(IDC_TEXT_INFO);
2190 RemoveAnchor(IDC_SELECTLABEL);
2191 RemoveAnchor(IDC_CHECKALL);
2192 RemoveAnchor(IDC_CHECKNONE);
2193 RemoveAnchor(IDC_CHECKUNVERSIONED);
2194 RemoveAnchor(IDC_CHECKVERSIONED);
2195 RemoveAnchor(IDC_CHECKADDED);
2196 RemoveAnchor(IDC_CHECKDELETED);
2197 RemoveAnchor(IDC_CHECKMODIFIED);
2198 RemoveAnchor(IDC_CHECKFILES);
2199 RemoveAnchor(IDC_CHECKSUBMODULES);
2201 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
2202 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
2203 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
2204 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
2205 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
2206 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
2207 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
2208 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME),0,delta);
2209 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER),0,delta);
2210 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER),0,delta);
2211 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETAUTHOR), 0, delta);
2212 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AUTHORDATA), 0, delta);
2213 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
2214 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL), 0, delta);
2215 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL), 0, delta);
2216 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE), 0, delta);
2217 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED), 0, delta);
2218 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED), 0, delta);
2219 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED), 0, delta);
2220 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED), 0, delta);
2221 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED), 0, delta);
2222 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES), 0, delta);
2223 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES), 0, delta);
2225 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
2226 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
2227 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
2228 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
2229 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
2230 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
2231 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
2232 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
2233 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
2234 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
2235 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
2236 AddAnchor(IDC_COMMIT_SETAUTHOR, TOP_LEFT);
2237 AddAnchor(IDC_COMMIT_AUTHORDATA, TOP_LEFT, TOP_RIGHT);
2238 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
2239 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
2240 AddAnchor(IDC_CHECKALL, TOP_LEFT);
2241 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
2242 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
2243 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
2244 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
2245 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
2246 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
2247 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
2248 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
2249 ArrangeLayout();
2250 // adjust the minimum size of the dialog to prevent the resizing from
2251 // moving the list control too far down.
2252 CRect rcLogMsg;
2253 m_cLogMessage.GetClientRect(rcLogMsg);
2254 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
2256 SetSplitterRange();
2257 m_cLogMessage.Invalidate();
2258 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
2261 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
2263 // first, let the resizing take place
2264 __super::OnSize(nType, cx, cy);
2266 //set range
2267 SetSplitterRange();
2270 CString CCommitDlg::GetSignedOffByLine()
2272 CString str;
2274 CString username = g_Git.GetUserName();
2275 CString email = g_Git.GetUserEmail();
2276 username.Remove(_T('\n'));
2277 email.Remove(_T('\n'));
2279 str.Format(_T("Signed-off-by: %s <%s>"), username, email);
2281 return str;
2284 void CCommitDlg::OnBnClickedSignOff()
2286 CString str = GetSignedOffByLine();
2288 if (m_cLogMessage.GetText().Find(str) == -1) {
2289 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
2290 int lastNewline = m_cLogMessage.GetText().ReverseFind(_T('\n'));
2291 int foundByLine = -1;
2292 if (lastNewline > 0)
2293 foundByLine = m_cLogMessage.GetText().Find(_T("-by: "), lastNewline);
2295 if (foundByLine == -1 || foundByLine < lastNewline)
2296 str = _T("\r\n") + str;
2298 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n")+str+_T("\r\n"));
2302 void CCommitDlg::OnBnClickedCommitAmend()
2304 this->UpdateData();
2305 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
2307 GitRev rev;
2310 rev.GetCommit(CString(_T("HEAD")));
2312 catch (const char *msg)
2314 CMessageBox::Show(m_hWnd, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
2316 m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody();
2319 if(this->m_bCommitAmend)
2321 this->m_NoAmendStr=this->m_cLogMessage.GetText();
2322 m_cLogMessage.SetText(m_AmendStr);
2323 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
2325 else
2327 this->m_AmendStr=this->m_cLogMessage.GetText();
2328 m_cLogMessage.SetText(m_NoAmendStr);
2329 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
2332 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2333 OnBnClickedCommitSetauthor(); // to update the commit author
2335 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2336 Refresh();
2339 void CCommitDlg::OnBnClickedCommitMessageOnly()
2341 this->UpdateData();
2342 this->m_ListCtrl.EnableWindow(m_bCommitMessageOnly ? FALSE : TRUE);
2343 SendMessage(WM_UPDATEOKBUTTON);
2346 void CCommitDlg::OnBnClickedWholeProject()
2348 m_tooltips.Pop(); // hide the tooltips
2349 UpdateData();
2350 m_ListCtrl.Clear();
2351 if (!m_bBlock)
2353 if(m_bWholeProject)
2354 m_ListCtrl.GetStatus(NULL,true,false,true);
2355 else
2356 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
2358 DWORD dwShow = m_ListCtrl.GetShowFlags();
2359 if (DWORD(m_regAddBeforeCommit))
2360 dwShow |= GITSLC_SHOWUNVERSIONED;
2361 else
2362 dwShow &= ~GITSLC_SHOWUNVERSIONED;
2364 m_ListCtrl.Show(dwShow, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
2365 UpdateCheckLinks();
2368 SetDlgTitle();
2371 void CCommitDlg::OnFocusMessage()
2373 m_cLogMessage.SetFocus();
2376 void CCommitDlg::OnScnUpdateUI(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2378 int pos = (int)this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
2379 int line = (int)this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
2380 int column = (int)this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
2382 CString str;
2383 str.Format(_T("%d/%d"),line+1,column+1);
2384 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
2386 if(*pResult)
2387 *pResult=0;
2389 void CCommitDlg::OnStnClickedViewPatch()
2391 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
2392 m_patchViewdlg.m_ParentCommitDlg = this;
2393 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
2395 BOOL viewPatchEnabled = FALSE;
2396 viewPatchEnabled = g_Git.GetConfigValueBool(_T("tgit.commitshowpatch"));
2397 if (viewPatchEnabled == FALSE)
2398 g_Git.SetConfigValue(_T("tgit.commitshowpatch"), _T("true"));
2399 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
2400 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2401 CRect rect;
2402 this->GetWindowRect(&rect);
2404 m_patchViewdlg.ShowWindow(SW_SHOW);
2406 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
2407 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
2409 ShowViewPatchText(false);
2410 FillPatchView();
2412 else
2414 g_Git.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2415 m_patchViewdlg.ShowWindow(SW_HIDE);
2416 m_patchViewdlg.DestroyWindow();
2417 ShowViewPatchText(true);
2419 this->m_ctrlShowPatch.Invalidate();
2422 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
2424 __super::OnMoving(fwSide, pRect);
2426 if (::IsWindow(m_patchViewdlg.m_hWnd))
2428 RECT patchrect;
2429 m_patchViewdlg.GetWindowRect(&patchrect);
2430 if (::IsWindow(m_hWnd))
2432 RECT thisrect;
2433 GetWindowRect(&thisrect);
2434 if (patchrect.left == thisrect.right)
2436 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2437 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2444 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2446 __super::OnSizing(fwSide, pRect);
2448 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2450 CRect thisrect, patchrect;
2451 this->GetWindowRect(thisrect);
2452 this->m_patchViewdlg.GetWindowRect(patchrect);
2453 if(thisrect.right==patchrect.left)
2455 patchrect.left -= (thisrect.right - pRect->right);
2456 patchrect.right-= (thisrect.right - pRect->right);
2458 if( patchrect.bottom == thisrect.bottom)
2460 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2462 if( patchrect.top == thisrect.top)
2464 patchrect.top -= thisrect.top-pRect->top;
2466 m_patchViewdlg.MoveWindow(patchrect);
2471 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2473 *pResult = 0;
2474 TRACE("Item Changed\r\n");
2477 int CCommitDlg::CheckHeadDetach()
2479 CString output;
2480 if(g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir,output))
2482 int retval = CMessageBox::Show(NULL, IDS_PROC_COMMIT_DETACHEDWARNING, IDS_APPNAME, MB_YESNOCANCEL | MB_ICONWARNING);
2483 if(retval == IDYES)
2485 if (CAppUtils::CreateBranchTag(FALSE, NULL, true) == FALSE)
2486 return 1;
2488 else if (retval == IDCANCEL)
2489 return 1;
2491 return 0;
2494 void CCommitDlg::OnBnClickedCommitAmenddiff()
2496 UpdateData();
2497 Refresh();
2500 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2502 UpdateData();
2503 Refresh();
2506 void CCommitDlg::OnBnClickedCommitSetDateTime()
2508 UpdateData();
2510 if (m_bSetCommitDateTime)
2512 CTime authordate = CTime::GetCurrentTime();
2513 if (m_bCommitAmend)
2515 GitRev headRevision;
2518 headRevision.GetCommit(_T("HEAD"));
2520 catch (const char *msg)
2522 CMessageBox::Show(m_hWnd, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
2524 authordate = headRevision.GetAuthorDate();
2527 m_CommitDate.SetTime(&authordate);
2528 m_CommitTime.SetTime(&authordate);
2530 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
2531 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
2533 else
2535 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_HIDE);
2536 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_HIDE);
2540 void CCommitDlg::OnBnClickedCheckNewBranch()
2542 UpdateData();
2543 if (m_bCreateNewBranch)
2545 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_HIDE);
2546 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_SHOW);
2548 else
2550 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
2551 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);
2555 void CCommitDlg::RestoreFiles(bool doNotAsk)
2557 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))
2559 for (std::map<CString, CString>::iterator it = m_ListCtrl.m_restorepaths.begin(); it != m_ListCtrl.m_restorepaths.end(); ++it)
2560 CopyFile(it->second, g_Git.m_CurrentDir + _T("\\") + it->first, FALSE);
2561 m_ListCtrl.m_restorepaths.clear();
2565 void CCommitDlg::UpdateCheckLinks()
2567 DialogEnableWindow(IDC_CHECKALL, true);
2568 DialogEnableWindow(IDC_CHECKNONE, true);
2569 DialogEnableWindow(IDC_CHECKUNVERSIONED, m_ListCtrl.GetUnversionedCount() > 0);
2570 DialogEnableWindow(IDC_CHECKVERSIONED, m_ListCtrl.GetItemCount() > m_ListCtrl.GetUnversionedCount());
2571 DialogEnableWindow(IDC_CHECKADDED, m_ListCtrl.GetAddedCount() > 0);
2572 DialogEnableWindow(IDC_CHECKDELETED, m_ListCtrl.GetDeletedCount() > 0);
2573 DialogEnableWindow(IDC_CHECKMODIFIED, m_ListCtrl.GetModifiedCount() > 0);
2574 DialogEnableWindow(IDC_CHECKFILES, m_ListCtrl.GetFileCount() > 0);
2575 DialogEnableWindow(IDC_CHECKSUBMODULES, m_ListCtrl.GetSubmoduleCount() > 0);
2578 void CCommitDlg::OnBnClickedCommitSetauthor()
2580 UpdateData();
2582 if (m_bSetAuthor)
2584 m_sAuthor.Format(_T("%s <%s>"), g_Git.GetUserName(), g_Git.GetUserEmail());
2585 if (m_bCommitAmend)
2587 GitRev headRevision;
2590 headRevision.GetCommit(_T("HEAD"));
2592 catch (const char *msg)
2594 CMessageBox::Show(m_hWnd, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
2596 m_sAuthor.Format(_T("%s <%s>"), headRevision.GetAuthorName(), headRevision.GetAuthorEmail());
2599 UpdateData(FALSE);
2601 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_SHOW);
2603 else
2604 GetDlgItem(IDC_COMMIT_AUTHORDATA)->ShowWindow(SW_HIDE);