Clear %GIT_DIR% on process start to prevent from interfering gitdll and git command...
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob244aaf0bc7d54786bc6d8ba955f56d13f8dbba61
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"));
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)
76 this->m_bCommitAmend=FALSE;
77 m_bPushAfterCommit = FALSE;
80 CCommitDlg::~CCommitDlg()
82 if(m_pThread != NULL)
84 delete m_pThread;
88 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
90 CResizableStandAloneDialog::DoDataExchange(pDX);
91 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
92 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
93 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
94 DDX_Check(pDX, IDC_COMMIT_SETDATETIME, m_bSetCommitDateTime);
95 DDX_Check(pDX, IDC_CHECK_NEWBRANCH, m_bCreateNewBranch);
96 DDX_Text(pDX, IDC_NEWBRANCH, m_sCreateNewBranch);
97 DDX_Text(pDX, IDC_BUGID, m_sBugID);
98 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
99 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
100 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
101 DDX_Check(pDX, IDC_NOAUTOSELECTSUBMODULES, m_bDoNotAutoselectSubmodules);
102 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
103 DDX_Check(pDX, IDC_COMMIT_MESSAGEONLY, m_bCommitMessageOnly);
104 DDX_Check(pDX,IDC_COMMIT_AMENDDIFF,m_bAmendDiffToLastCommit);
105 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
106 DDX_Control(pDX, IDC_COMMIT_DATEPICKER, m_CommitDate);
107 DDX_Control(pDX, IDC_COMMIT_TIMEPICKER, m_CommitTime);
110 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
111 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
112 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
113 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
114 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
115 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
116 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
117 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
118 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
119 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE, OnFileDropped)
120 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
121 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
123 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED, &CCommitDlg::OnCheck)
124 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
125 ON_REGISTERED_MESSAGE(WM_UPDATEOKBUTTON, OnUpdateOKButton)
126 ON_WM_TIMER()
127 ON_WM_SIZE()
128 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
129 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
130 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
131 ON_BN_CLICKED(IDC_COMMIT_MESSAGEONLY, &CCommitDlg::OnBnClickedCommitMessageOnly)
132 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
133 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
134 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
135 ON_WM_MOVE()
136 ON_WM_MOVING()
137 ON_WM_SIZING()
138 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
139 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF, &CCommitDlg::OnBnClickedCommitAmenddiff)
140 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES, &CCommitDlg::OnBnClickedNoautoselectsubmodules)
141 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME, &CCommitDlg::OnBnClickedCommitSetDateTime)
142 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH, &CCommitDlg::OnBnClickedCheckNewBranch)
143 END_MESSAGE_MAP()
145 BOOL CCommitDlg::OnInitDialog()
147 CResizableStandAloneDialog::OnInitDialog();
148 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
150 CAppUtils::GetCommitTemplate(this->m_sLogMessage);
152 CString dotGitPath;
153 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
154 if(PathFileExists(dotGitPath + _T("MERGE_MSG")))
156 CStdioFile file;
157 if(file.Open(dotGitPath + _T("MERGE_MSG"), CFile::modeRead))
159 CString str;
160 while(file.ReadString(str))
162 m_sLogMessage += str;
163 str.Empty();
164 m_sLogMessage += _T("\n");
169 if (CTGitPath(g_Git.m_CurrentDir).IsMergeActive())
170 DialogEnableWindow(IDC_CHECK_NEWBRANCH, FALSE);
172 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
173 m_bShowUnversioned = m_regAddBeforeCommit;
175 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
177 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
178 m_bKeepChangeList = m_regKeepChangelists;
180 m_regDoNotAutoselectSubmodules = CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE);
181 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
183 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
185 // GitConfig config;
186 // m_bWholeProject = config.KeepLocks();
188 if(this->m_pathList.GetCount() == 0)
189 m_bWholeProject =true;
191 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
192 m_bWholeProject =true;
194 SetDlgTitle();
196 UpdateData(FALSE);
198 m_ListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD | GITSLC_COLDEL, _T("CommitDlg"),(GITSLC_POPALL ^ (GITSLC_POPCOMMIT | GITSLC_POPSAVEAS)), true, true);
199 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
200 m_ListCtrl.SetCancelBool(&m_bCancelled);
201 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
202 m_ListCtrl.EnableFileDrop();
203 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
205 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
206 m_ProjectProperties.ReadPropsPathList(m_pathList);
208 m_cLogMessage.Init(m_ProjectProperties);
209 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
210 m_cLogMessage.RegisterContextMenuHandler(this);
212 OnEnChangeLogmessage();
214 m_tooltips.Create(this);
215 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
216 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
217 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
219 CBugTraqAssociations bugtraq_associations;
220 bugtraq_associations.Load();
222 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
224 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
225 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
227 CComPtr<IBugTraqProvider> pProvider;
228 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
229 if (SUCCEEDED(hr))
231 m_BugTraqProvider = pProvider;
232 BSTR temp = NULL;
233 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
235 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
236 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
237 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
240 SysFreeString(temp);
243 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
245 else if (!m_ProjectProperties.sMessage.IsEmpty())
247 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
248 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
249 if (!m_ProjectProperties.sLabel.IsEmpty())
250 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
251 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
252 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
253 GetDlgItem(IDC_BUGID)->SetFocus();
254 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
255 if (!sBugID.IsEmpty())
257 SetDlgItemText(IDC_BUGID, sBugID);
260 else
262 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
263 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
264 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
265 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
266 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
269 if (!m_sLogMessage.IsEmpty())
270 m_cLogMessage.SetText(m_sLogMessage);
272 GetWindowText(m_sWindowTitle);
274 AdjustControlSize(IDC_SHOWUNVERSIONED);
275 AdjustControlSize(IDC_WHOLE_PROJECT);
276 AdjustControlSize(IDC_CHECK_NEWBRANCH);
277 AdjustControlSize(IDC_COMMIT_AMEND);
278 AdjustControlSize(IDC_COMMIT_MESSAGEONLY);
279 AdjustControlSize(IDC_COMMIT_AMENDDIFF);
280 AdjustControlSize(IDC_COMMIT_SETDATETIME);
281 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES);
282 AdjustControlSize(IDC_KEEPLISTS);
284 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKALL);
285 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKNONE);
286 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKUNVERSIONED);
287 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKVERSIONED);
288 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKADDED);
289 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKDELETED);
290 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKMODIFIED);
291 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKFILES);
292 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKSUBMODULES);
294 // line up all controls and adjust their sizes.
295 #define LINKSPACING 9
296 RECT rc = AdjustControlSize(IDC_SELECTLABEL);
297 rc.right -= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
298 rc = AdjustStaticSize(IDC_CHECKALL, rc, LINKSPACING);
299 rc = AdjustStaticSize(IDC_CHECKNONE, rc, LINKSPACING);
300 rc = AdjustStaticSize(IDC_CHECKUNVERSIONED, rc, LINKSPACING);
301 rc = AdjustStaticSize(IDC_CHECKVERSIONED, rc, LINKSPACING);
302 rc = AdjustStaticSize(IDC_CHECKADDED, rc, LINKSPACING);
303 rc = AdjustStaticSize(IDC_CHECKDELETED, rc, LINKSPACING);
304 rc = AdjustStaticSize(IDC_CHECKMODIFIED, rc, LINKSPACING);
305 rc = AdjustStaticSize(IDC_CHECKFILES, rc, LINKSPACING);
306 rc = AdjustStaticSize(IDC_CHECKSUBMODULES, rc, LINKSPACING);
308 GetClientRect(m_DlgOrigRect);
309 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
311 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
312 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
313 AddAnchor(IDC_BUGID, TOP_RIGHT);
314 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
315 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
316 AddAnchor(IDC_CHECK_NEWBRANCH, TOP_RIGHT);
317 AddAnchor(IDC_NEWBRANCH, TOP_LEFT, TOP_RIGHT);
318 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
319 // AddAnchor(IDC_HISTORY, TOP_LEFT);
320 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
321 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
322 AddAnchor(IDC_VIEW_PATCH, BOTTOM_RIGHT);
323 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
324 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
325 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
326 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
327 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
328 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
329 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
330 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
331 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
332 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
333 AddAnchor(IDOK, BOTTOM_RIGHT);
334 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
335 AddAnchor(IDHELP, BOTTOM_RIGHT);
336 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
337 AddAnchor(IDC_COMMIT_MESSAGEONLY, BOTTOM_LEFT);
338 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
339 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
340 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
341 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
343 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
344 AddAnchor(IDC_CHECKALL, TOP_LEFT);
345 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
346 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
347 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
348 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
349 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
350 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
351 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
352 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
354 if (hWndExplorer)
355 CenterWindow(CWnd::FromHandle(hWndExplorer));
356 EnableSaveRestore(_T("CommitDlg"));
357 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
358 RECT rcDlg, rcLogMsg, rcFileList;
359 GetClientRect(&rcDlg);
360 m_cLogMessage.GetWindowRect(&rcLogMsg);
361 ScreenToClient(&rcLogMsg);
362 m_ListCtrl.GetWindowRect(&rcFileList);
363 ScreenToClient(&rcFileList);
364 if (yPos)
366 RECT rectSplitter;
367 m_wndSplitter.GetWindowRect(&rectSplitter);
368 ScreenToClient(&rectSplitter);
369 int delta = yPos - rectSplitter.top;
370 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
372 m_wndSplitter.SetWindowPos(NULL, rectSplitter.left, yPos, 0, 0, SWP_NOSIZE);
373 DoSize(delta);
377 SetSplitterRange();
379 // add all directories to the watcher
381 for (int i=0; i<m_pathList.GetCount(); ++i)
383 if (m_pathList[i].IsDirectory())
384 m_pathwatcher.AddPath(m_pathList[i]);
387 m_updatedPathList = m_pathList;
389 //first start a thread to obtain the file list with the status without
390 //blocking the dialog
391 InterlockedExchange(&m_bBlock, TRUE);
392 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
393 if (m_pThread==NULL)
395 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
396 InterlockedExchange(&m_bBlock, FALSE);
398 else
400 m_pThread->m_bAutoDelete = FALSE;
401 m_pThread->ResumeThread();
403 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
404 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
405 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
407 historyhint = TRUE;
408 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
410 err = FALSE;
412 this->m_ctrlShowPatch.SetURL(CString());
414 BOOL viewPatchEnabled = FALSE;
415 m_ProjectProperties.GetBOOLProps(viewPatchEnabled, _T("tgit.commitshowpatch"));
416 if (viewPatchEnabled)
417 OnStnClickedViewPatch();
419 return FALSE; // return TRUE unless you set the focus to a control
420 // EXCEPTION: OCX Property Pages should return FALSE
423 void CCommitDlg::OnOK()
425 if (m_bBlock)
426 return;
427 if (m_bThreadRunning)
429 m_bCancelled = true;
430 InterlockedExchange(&m_bRunThread, FALSE);
431 WaitForSingleObject(m_pThread->m_hThread, 1000);
432 if (m_bThreadRunning)
434 // we gave the thread a chance to quit. Since the thread didn't
435 // listen to us we have to kill it.
436 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
437 InterlockedExchange(&m_bThreadRunning, FALSE);
440 this->UpdateData();
442 if (m_bCreateNewBranch)
444 if (!g_Git.IsBranchNameValid(m_sCreateNewBranch))
446 ShowEditBalloon(IDC_NEWBRANCH, IDS_B_T_NOTEMPTY, TTI_ERROR);
447 return;
449 if (g_Git.BranchTagExists(m_sCreateNewBranch))
451 // branch already exists
452 CString msg;
453 msg.LoadString(IDS_B_EXISTS);
454 msg += _T(" ") + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME));
455 ShowEditBalloon(IDC_NEWBRANCH, msg, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
456 return;
458 if (g_Git.BranchTagExists(m_sCreateNewBranch, false))
460 // tag with the same name exists -> shortref is ambiguous
461 if (CMessageBox::Show(m_hWnd, IDS_B_SAMETAGNAMEEXISTS, IDS_APPNAME, 2, IDI_EXCLAMATION, IDS_CONTINUEBUTTON, IDS_ABORTBUTTON) == 2)
462 return;
466 CString id;
467 GetDlgItemText(IDC_BUGID, id);
468 if (!m_ProjectProperties.CheckBugID(id))
470 ShowEditBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, TTI_ERROR);
471 return;
473 m_sLogMessage = m_cLogMessage.GetText();
474 if ( m_sLogMessage.IsEmpty() )
476 // no message entered, go round again
477 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
478 return;
480 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
482 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
483 return;
486 BOOL bWarnNoSignedOffBy = FALSE;
487 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy, _T("tgit.warnnosignedoffby"));
488 if (bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
490 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);
491 if (retval == 1)
493 OnBnClickedSignOff();
494 m_sLogMessage = m_cLogMessage.GetText();
496 else if (retval == 3)
497 return;
500 int nListItems = m_ListCtrl.GetItemCount();
501 for (int i = 0; i < nListItems && !m_bCommitMessageOnly; ++i)
503 CTGitPath *entry = (CTGitPath *)m_ListCtrl.GetItemData(i);
504 if (!entry->m_Checked || !entry->IsDirectory())
505 continue;
507 bool dirty = false;
508 if (entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
510 CGit subgit;
511 subgit.m_CurrentDir = g_Git.m_CurrentDir + _T("\\") + entry->GetWinPathString();
512 CString subcmdout;
513 subgit.Run(_T("git.exe status --porcelain"), &subcmdout, CP_UTF8);
514 dirty = !subcmdout.IsEmpty();
516 else
518 CString cmd, cmdout;
519 cmd.Format(_T("git.exe diff -- \"%s\""), entry->GetWinPathString());
520 g_Git.Run(cmd, &cmdout, CP_UTF8);
521 dirty = cmdout.Right(7) == _T("-dirty\n");
524 if (dirty)
526 CString message;
527 message.Format(CString(MAKEINTRESOURCE(IDS_COMMITDLG_SUBMODULEDIRTY)), entry->GetGitPathString());
528 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)));
529 if (result == 1)
531 CString cmdCommit;
532 cmdCommit.Format(_T("/command:commit /path:\"%s\\%s\""), g_Git.m_CurrentDir, entry->GetWinPathString());
533 CAppUtils::RunTortoiseGitProc(cmdCommit);
534 return;
536 else if (result == 2)
537 continue;
538 else
539 return;
543 if (!m_bCommitMessageOnly)
544 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
545 m_pathwatcher.Stop();
546 InterlockedExchange(&m_bBlock, TRUE);
547 CDWordArray arDeleted;
548 //first add all the unversioned files the user selected
549 //and check if all versioned files are selected
550 int nchecked = 0;
551 m_bRecursive = true;
553 CTGitPathList itemsToAdd;
554 CTGitPathList itemsToRemove;
555 CMassiveGitTask mgtReAddAfterCommit(_T("add --ignore-errors -f"));
557 CString cmd;
558 CString out;
560 bool bAddSuccess=true;
561 bool bCloseCommitDlg=false;
563 CSysProgressDlg sysProgressDlg;
564 if (nListItems >= 25)
566 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
567 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
568 sysProgressDlg.SetTime(true);
569 sysProgressDlg.SetShowProgressBar(true);
570 sysProgressDlg.ShowModal(this, true);
573 CBlockCacheForPath cacheBlock(g_Git.m_CurrentDir);
574 DWORD currentTicks = GetTickCount();
576 // ***************************************************
577 // ATTENTION: Similar code in RebaseDlg.cpp!!!
578 // ***************************************************
580 for (int j = 0; j < nListItems; ++j)
582 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
583 if (sysProgressDlg.IsVisible())
585 if (GetTickCount() - currentTicks > 1000 || j == nListItems - 1 || j == 0)
587 sysProgressDlg.SetLine(2, entry->GetGitPathString(), true);
588 sysProgressDlg.SetProgress(j, nListItems);
589 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too: this takes time!
590 currentTicks = GetTickCount();
593 if (entry->m_Checked && !m_bCommitMessageOnly)
595 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
596 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
597 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
598 cmd.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry->GetGitPathString());
599 else
600 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
602 if (g_Git.Run(cmd, &out, CP_UTF8))
604 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
605 bAddSuccess = false ;
606 break;
609 if( entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
610 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
612 g_Git.Run(cmd, &out, CP_UTF8);
614 ++nchecked;
616 else
618 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED || entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
619 { //To init git repository, there are not HEAD, so we can use git reset command
620 cmd.Format(_T("git.exe rm -f --cache -- \"%s\""),entry->GetGitPathString());
621 if (g_Git.Run(cmd, &out, CP_UTF8))
623 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
624 bAddSuccess = false ;
625 bCloseCommitDlg=false;
626 break;
628 mgtReAddAfterCommit.AddFile(*entry);
630 if (entry->m_Action & CTGitPath::LOGACTIONS_REPLACED && !entry->GetGitOldPathString().IsEmpty())
632 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
633 cmd.Format(_T("git.exe reset HEAD~1 -- \"%s\""), entry->GetGitOldPathString());
634 else
635 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitOldPathString());
636 g_Git.Run(cmd, &out, CP_UTF8);
639 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
641 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
643 cmd.Format(_T("git.exe reset HEAD~1 -- \"%s\""), entry->GetGitPathString());
645 else
647 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitPathString());
649 g_Git.Run(cmd, &out, CP_UTF8);
650 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
651 continue;
655 if (sysProgressDlg.HasUserCancelled())
657 bAddSuccess = false;
658 break;
661 CShellUpdater::Instance().AddPathForUpdate(*entry);
664 sysProgressDlg.Stop();
666 if (bAddSuccess && m_bCreateNewBranch)
668 if (g_Git.Run(_T("git branch ") + m_sCreateNewBranch, &out, CP_UTF8))
670 MessageBox(_T("Creating new branch failed:\n") + out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
671 bAddSuccess = false;
673 if (g_Git.Run(_T("git checkout ") + m_sCreateNewBranch, &out, CP_UTF8))
675 MessageBox(_T("Switching to new branch failed:\n") + out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
676 bAddSuccess = false;
680 if (bAddSuccess && CheckHeadDetach())
681 bAddSuccess = false;
683 m_sBugID.Trim();
684 CString sExistingBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
685 sExistingBugID.Trim();
686 if (!m_sBugID.IsEmpty() && m_sBugID.Compare(sExistingBugID))
688 m_sBugID.Replace(_T(", "), _T(","));
689 m_sBugID.Replace(_T(" ,"), _T(","));
690 CString sBugID = m_ProjectProperties.sMessage;
691 sBugID.Replace(_T("%BUGID%"), m_sBugID);
692 if (m_ProjectProperties.bAppend)
693 m_sLogMessage += _T("\n") + sBugID + _T("\n");
694 else
695 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
698 // now let the bugtraq plugin check the commit message
699 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
700 if (m_BugTraqProvider)
702 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
703 if (SUCCEEDED(hr))
705 BSTR temp = NULL;
706 CString common = g_Git.m_CurrentDir;
707 BSTR repositoryRoot = common.AllocSysString();
708 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
709 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
710 BSTR commitMessage = m_sLogMessage.AllocSysString();
711 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
713 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
714 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
716 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
718 COMError ce(hr);
719 CString sErr;
720 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
721 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
723 else
725 CString sError = temp;
726 if (!sError.IsEmpty())
728 CMessageBox::Show(m_hWnd, sError, _T("TortoiseGit"), MB_ICONERROR);
729 return;
731 SysFreeString(temp);
736 if (m_bCommitMessageOnly || bAddSuccess && (nchecked || m_bCommitAmend || CTGitPath(g_Git.m_CurrentDir).IsMergeActive()))
738 bCloseCommitDlg = true;
740 CString tempfile=::GetTempFile();
742 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
744 CTGitPath path=g_Git.m_CurrentDir;
746 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
748 out =_T("");
749 CString amend;
750 if(this->m_bCommitAmend)
752 amend=_T("--amend");
754 CString dateTime;
755 if (m_bSetCommitDateTime)
757 CTime date, time;
758 m_CommitDate.GetTime(date);
759 m_CommitTime.GetTime(time);
760 dateTime.Format(_T("--date=%sT%s"), date.Format(_T("%Y-%m-%d")), time.Format(_T("%H:%M:%S")));
762 CString allowEmpty = m_bCommitMessageOnly ? _T("--allow-empty") : _T("");
763 cmd.Format(_T("git.exe commit %s %s %s -F \"%s\""), dateTime, amend, allowEmpty, tempfile);
765 CCommitProgressDlg progress;
766 progress.m_bBufferAll=true; // improve show speed when there are many file added.
767 progress.m_GitCmd=cmd;
768 progress.m_bShowCommand = FALSE; // don't show the commit command
769 progress.m_PreText = out; // show any output already generated in log window
770 progress.m_bAutoCloseOnSuccess = m_bAutoClose;
772 int indexReCommit = -1;
773 int indexTag = -1;
775 if (!m_bNoPostActions && !m_bAutoClose)
777 if (IsGitSVN)
778 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUSVNDCOMMIT)));
779 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH)));
780 indexReCommit = (int)progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_RECOMMIT)));
781 indexTag = (int)progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUTAG)));
784 INT_PTR userResponse = progress.DoModal();
786 if(progress.m_GitStatus || userResponse == (IDC_PROGRESS_BUTTON1 + indexReCommit))
788 bCloseCommitDlg = false;
789 if (userResponse == IDC_PROGRESS_BUTTON1 + indexReCommit)
791 this->m_sLogMessage.Empty();
792 m_cLogMessage.SetText(m_sLogMessage);
795 m_bCommitAmend = FALSE;
796 UpdateData(FALSE);
797 this->Refresh();
799 else if (userResponse == IDC_PROGRESS_BUTTON1 + indexTag)
801 m_bCreateTagAfterCommit=true;
803 else if (userResponse >= IDC_PROGRESS_BUTTON1 && userResponse < IDC_PROGRESS_BUTTON1 + indexReCommit)
805 // User pressed 'DCommit' or 'Push' button after successful commit.
806 m_bPushAfterCommit=true;
807 if (userResponse == IDC_PROGRESS_BUTTON1 && IsGitSVN)
808 m_PostCmd = GIT_POST_CMD_DCOMMIT;
809 else
810 m_PostCmd = GIT_POST_CMD_PUSH;
813 CFile::Remove(tempfile);
815 if (m_BugTraqProvider && progress.m_GitStatus == 0)
817 CComPtr<IBugTraqProvider2> pProvider = NULL;
818 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
819 if (SUCCEEDED(hr))
821 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
822 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
824 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
825 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
827 BSTR logMessage = m_sLogMessage.AllocSysString();
829 CGitHash hash;
830 if (g_Git.GetHash(hash, _T("HEAD")))
831 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash after committing.")), _T("TortoiseGit"), MB_ICONERROR);
832 LONG version = g_Git.Hash2int(hash);
834 BSTR temp = NULL;
835 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
836 commonRoot,
837 pathList,
838 logMessage,
839 (LONG)version,
840 &temp)))
842 CString sErr = temp;
843 if (!sErr.IsEmpty())
844 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
845 else
847 COMError ce(hr);
848 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
849 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
853 SysFreeString(temp);
856 RestoreFiles(progress.m_GitStatus == 0);
857 if (((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit"), TRUE)) == TRUE)
859 BOOL cancel = FALSE;
860 mgtReAddAfterCommit.Execute(cancel);
863 else if(bAddSuccess)
865 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
866 bCloseCommitDlg=false;
869 UpdateData();
870 m_regAddBeforeCommit = m_bShowUnversioned;
871 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
872 m_bWholeProject = FALSE;
873 m_regKeepChangelists = m_bKeepChangeList;
874 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
875 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
876 m_bKeepChangeList = FALSE;
877 InterlockedExchange(&m_bBlock, FALSE);
879 if (!m_sLogMessage.IsEmpty())
881 m_History.AddEntry(m_sLogMessage);
882 m_History.Save();
885 SaveSplitterPos();
887 if( bCloseCommitDlg )
888 CResizableStandAloneDialog::OnOK();
890 CShellUpdater::Instance().Flush();
893 void CCommitDlg::SaveSplitterPos()
895 if (!IsIconic())
897 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
898 RECT rectSplitter;
899 m_wndSplitter.GetWindowRect(&rectSplitter);
900 ScreenToClient(&rectSplitter);
901 regPos = rectSplitter.top;
905 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
907 return ((CCommitDlg*)pVoid)->StatusThread();
910 UINT CCommitDlg::StatusThread()
912 //get the status of all selected file/folders recursively
913 //and show the ones which have to be committed to the user
914 //in a list control.
915 InterlockedExchange(&m_bBlock, TRUE);
916 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
917 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
919 m_pathwatcher.Stop();
921 m_ListCtrl.SetBusy(true);
922 g_Git.RefreshGitIndex();
924 m_bCancelled = false;
926 DialogEnableWindow(IDOK, false);
927 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
928 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
929 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
930 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
931 DialogEnableWindow(IDC_EXTERNALWARNING, false);
932 DialogEnableWindow(IDC_COMMIT_AMEND, FALSE);
933 DialogEnableWindow(IDC_COMMIT_AMENDDIFF, FALSE);
934 // read the list of recent log entries before querying the WC for status
935 // -> the user may select one and modify / update it while we are crawling the WC
937 DialogEnableWindow(IDC_CHECKALL, false);
938 DialogEnableWindow(IDC_CHECKNONE, false);
939 DialogEnableWindow(IDC_CHECKUNVERSIONED, false);
940 DialogEnableWindow(IDC_CHECKVERSIONED, false);
941 DialogEnableWindow(IDC_CHECKADDED, false);
942 DialogEnableWindow(IDC_CHECKDELETED, false);
943 DialogEnableWindow(IDC_CHECKMODIFIED, false);
944 DialogEnableWindow(IDC_CHECKFILES, false);
945 DialogEnableWindow(IDC_CHECKSUBMODULES, false);
947 if (m_History.GetCount()==0)
949 CString reg;
950 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
951 reg.Replace(_T(':'),_T('_'));
952 m_History.Load(reg, _T("logmsgs"));
955 // Initialise the list control with the status of the files/folders below us
956 m_ListCtrl.Clear();
957 BOOL success;
958 CTGitPathList *pList;
959 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE || m_bForceCommitAmend) && (m_bAmendDiffToLastCommit==FALSE);
960 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
962 if(m_bWholeProject)
963 pList=NULL;
964 else
965 pList = &m_pathList;
967 success=m_ListCtrl.GetStatus(pList);
969 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
970 if(this->m_bShowUnversioned)
971 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
973 m_ListCtrl.CheckIfChangelistsArePresent(false);
975 DWORD dwShow = GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWLOCKS | GITSLC_SHOWINCHANGELIST;
976 dwShow |= DWORD(m_regAddBeforeCommit) ? GITSLC_SHOWUNVERSIONED : 0;
977 if (success)
979 if (m_checkedPathList.GetCount())
980 m_ListCtrl.Show(dwShow, m_checkedPathList);
981 else
983 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
984 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
985 m_ListCtrl.Show(dwShow, dwCheck);
986 m_bSelectFilesForCommit = true;
989 if (m_ListCtrl.HasExternalsFromDifferentRepos())
991 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
992 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
995 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
996 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
998 if (!success)
1000 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
1001 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
1002 m_ListCtrl.Show(dwShow);
1005 CString dotGitPath;
1006 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
1007 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
1008 && !PathFileExists(dotGitPath + _T("MERGE_HEAD")))
1010 CString temp;
1011 temp.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED);
1012 if (CMessageBox::ShowCheck(m_hWnd, temp, _T("TortoiseGit"), MB_ICONINFORMATION | MB_YESNO, _T("NothingToCommitShowUnversioned"), NULL)==IDYES)
1014 m_bShowUnversioned = TRUE;
1015 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
1016 DWORD dwShow = (DWORD)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWUNVERSIONED | GITSLC_SHOWLOCKS);
1017 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
1018 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
1022 SetDlgTitle();
1024 m_autolist.clear();
1025 // we don't have to block the commit dialog while we fetch the
1026 // auto completion list.
1027 m_pathwatcher.ClearChangedPaths();
1028 InterlockedExchange(&m_bBlock, FALSE);
1029 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
1031 m_ListCtrl.Block(TRUE, TRUE);
1032 GetAutocompletionList();
1033 m_ListCtrl.Block(FALSE, FALSE);
1035 SendMessage(WM_UPDATEOKBUTTON);
1036 if (m_bRunThread)
1038 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1039 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1040 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1041 if (m_ListCtrl.HasChangeLists())
1042 DialogEnableWindow(IDC_KEEPLISTS, true);
1043 if (m_ListCtrl.HasLocks())
1044 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1046 // activate amend checkbox (if necessary)
1047 if (g_Git.IsInitRepos())
1049 m_bCommitAmend = FALSE;
1050 UpdateData(FALSE);
1052 else
1054 if (m_bForceCommitAmend)
1056 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
1057 m_bCommitAmend = TRUE;
1058 UpdateData(FALSE);
1060 else
1061 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(TRUE);
1063 CGitHash hash;
1064 if (g_Git.GetHash(hash, _T("HEAD")))
1066 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR);
1068 if (!hash.IsEmpty())
1070 GitRev headRevision;
1073 headRevision.GetParentFromHash(hash);
1075 catch (char* msg)
1077 CString err(msg);
1078 MessageBox(_T("Could not get parent from HEAD.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
1080 // do not allow to show diff to "last" revision if it has more that one parent
1081 if (headRevision.ParentsCount() != 1)
1083 m_bAmendDiffToLastCommit = true;
1084 UpdateData(FALSE);
1086 else
1087 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(TRUE);
1091 UpdateCheckLinks();
1093 // we have the list, now signal the main thread about it
1094 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1097 InterlockedExchange(&m_bRunThread, FALSE);
1098 InterlockedExchange(&m_bThreadRunning, FALSE);
1099 // force the cursor to normal
1100 RefreshCursor();
1102 return 0;
1105 void CCommitDlg::SetDlgTitle()
1107 if (m_sTitle.IsEmpty())
1108 GetWindowText(m_sTitle);
1110 if (m_bWholeProject)
1111 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
1112 else
1114 if (m_pathList.GetCount() == 1)
1115 CAppUtils::SetWindowTitle(m_hWnd, (g_Git.m_CurrentDir + _T("\\") + m_pathList[0].GetUIPathString()).TrimRight('\\'), m_sTitle);
1116 else
1117 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir + _T("\\") + m_ListCtrl.GetCommonDirectory(false), m_sTitle);
1121 void CCommitDlg::OnCancel()
1123 m_bCancelled = true;
1124 m_pathwatcher.Stop();
1126 if (m_bThreadRunning)
1128 InterlockedExchange(&m_bRunThread, FALSE);
1129 WaitForSingleObject(m_pThread->m_hThread, 1000);
1130 if (m_bThreadRunning)
1132 // we gave the thread a chance to quit. Since the thread didn't
1133 // listen to us we have to kill it.
1134 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1135 InterlockedExchange(&m_bThreadRunning, FALSE);
1138 UpdateData();
1139 m_sBugID.Trim();
1140 m_sLogMessage = m_cLogMessage.GetText();
1141 if (!m_sBugID.IsEmpty())
1143 m_sBugID.Replace(_T(", "), _T(","));
1144 m_sBugID.Replace(_T(" ,"), _T(","));
1145 CString sBugID = m_ProjectProperties.sMessage;
1146 sBugID.Replace(_T("%BUGID%"), m_sBugID);
1147 if (m_ProjectProperties.bAppend)
1148 m_sLogMessage += _T("\n") + sBugID + _T("\n");
1149 else
1150 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1152 if ((m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0) && !m_sLogMessage.IsEmpty())
1154 m_History.AddEntry(m_sLogMessage);
1155 m_History.Save();
1157 RestoreFiles();
1158 SaveSplitterPos();
1159 CResizableStandAloneDialog::OnCancel();
1162 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1164 if (!m_bBlock)
1165 m_tooltips.RelayEvent(pMsg);
1167 if (m_hAccel)
1169 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1170 if (ret)
1171 return TRUE;
1174 if (pMsg->message == WM_KEYDOWN)
1176 switch (pMsg->wParam)
1178 case VK_F5:
1180 if (m_bBlock)
1181 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1182 Refresh();
1184 break;
1185 case VK_RETURN:
1187 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1189 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1191 PostMessage(WM_COMMAND, IDOK);
1193 return TRUE;
1195 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1197 // Pressing RETURN in the bug id control
1198 // moves the focus to the message
1199 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1200 return TRUE;
1203 break;
1207 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1210 void CCommitDlg::Refresh()
1212 if (m_bThreadRunning)
1213 return;
1215 InterlockedExchange(&m_bBlock, TRUE);
1216 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1217 if (m_pThread==NULL)
1219 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1220 InterlockedExchange(&m_bBlock, FALSE);
1222 else
1224 m_pThread->m_bAutoDelete = FALSE;
1225 m_pThread->ResumeThread();
1229 void CCommitDlg::OnBnClickedHelp()
1231 OnHelp();
1234 void CCommitDlg::OnBnClickedShowunversioned()
1236 m_tooltips.Pop(); // hide the tooltips
1237 UpdateData();
1238 m_regAddBeforeCommit = m_bShowUnversioned;
1239 if (!m_bBlock)
1241 DWORD dwShow = m_ListCtrl.GetShowFlags();
1242 if (DWORD(m_regAddBeforeCommit))
1243 dwShow |= GITSLC_SHOWUNVERSIONED;
1244 else
1245 dwShow &= ~GITSLC_SHOWUNVERSIONED;
1246 if(dwShow & GITSLC_SHOWUNVERSIONED)
1248 if(m_bWholeProject)
1249 m_ListCtrl.GetStatus(NULL,false,false,true);
1250 else
1251 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1253 m_ListCtrl.Show(dwShow, 0, true, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
1254 UpdateCheckLinks();
1258 void CCommitDlg::OnStnClickedExternalwarning()
1260 m_tooltips.Popup();
1263 void CCommitDlg::OnEnChangeLogmessage()
1265 SendMessage(WM_UPDATEOKBUTTON);
1268 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1270 #if 0
1271 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1273 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1275 m_bShowUnversioned = TRUE;
1276 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1277 m_ListCtrl.Show(dwShow);
1278 UpdateData(FALSE);
1281 #endif
1282 return 0;
1285 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1287 Refresh();
1288 return 0;
1291 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1293 #if 0
1294 BringWindowToTop();
1295 SetForegroundWindow();
1296 SetActiveWindow();
1297 // if multiple files/folders are dropped
1298 // this handler is called for every single item
1299 // separately.
1300 // To avoid creating multiple refresh threads and
1301 // causing crashes, we only add the items to the
1302 // list control and start a timer.
1303 // When the timer expires, we start the refresh thread,
1304 // but only if it isn't already running - otherwise we
1305 // restart the timer.
1306 CTGitPath path;
1307 path.SetFromWin((LPCTSTR)lParam);
1309 // just add all the items we get here.
1310 // if the item is versioned, the add will fail but nothing
1311 // more will happen.
1312 Git Git;
1313 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1315 if (!m_ListCtrl.HasPath(path))
1317 if (m_pathList.AreAllPathsFiles())
1319 m_pathList.AddPath(path);
1320 m_pathList.RemoveDuplicates();
1321 m_updatedPathList.AddPath(path);
1322 m_updatedPathList.RemoveDuplicates();
1324 else
1326 // if the path list contains folders, we have to check whether
1327 // our just (maybe) added path is a child of one of those. If it is
1328 // a child of a folder already in the list, we must not add it. Otherwise
1329 // that path could show up twice in the list.
1330 bool bHasParentInList = false;
1331 for (int i=0; i<m_pathList.GetCount(); ++i)
1333 if (m_pathList[i].IsAncestorOf(path))
1335 bHasParentInList = true;
1336 break;
1339 if (!bHasParentInList)
1341 m_pathList.AddPath(path);
1342 m_pathList.RemoveDuplicates();
1343 m_updatedPathList.AddPath(path);
1344 m_updatedPathList.RemoveDuplicates();
1349 // Always start the timer, since the status of an existing item might have changed
1350 SetTimer(REFRESHTIMER, 200, NULL);
1351 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1352 #endif
1353 return 0;
1356 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1358 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1359 return 0;
1362 //////////////////////////////////////////////////////////////////////////
1363 // functions which run in the status thread
1364 //////////////////////////////////////////////////////////////////////////
1366 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1368 CString strLine;
1371 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1372 while (m_bRunThread && file.ReadString(strLine))
1374 int eqpos = strLine.Find('=');
1375 CString rgx;
1376 rgx = strLine.Mid(eqpos+1).Trim();
1378 int pos = -1;
1379 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1381 mapRegex[strLine.Left(pos)] = rgx;
1382 strLine = strLine.Mid(pos+1).Trim();
1384 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1386 file.Close();
1388 catch (CFileException* pE)
1390 TRACE("CFileException loading auto list regex file\n");
1391 pE->Delete();
1392 return;
1395 void CCommitDlg::GetAutocompletionList()
1397 // the auto completion list is made of strings from each selected files.
1398 // the strings used are extracted from the files with regexes found
1399 // in the file "autolist.txt".
1400 // the format of that file is:
1401 // file extensions separated with commas '=' regular expression to use
1402 // example:
1403 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1404 // .cpp = (?<=[^\s]::)\b\w+\b
1406 std::map<CString, CString> mapRegex;
1407 CString sRegexFile = CPathUtils::GetAppDirectory();
1408 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1409 DWORD timeoutvalue = regtimeout*1000;
1410 sRegexFile += _T("autolist.txt");
1411 if (!m_bRunThread)
1412 return;
1413 ParseRegexFile(sRegexFile, mapRegex);
1414 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1415 sRegexFile.ReleaseBuffer();
1416 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1417 if (PathFileExists(sRegexFile))
1419 ParseRegexFile(sRegexFile, mapRegex);
1421 DWORD starttime = GetTickCount();
1423 // now we have two arrays of strings, where the first array contains all
1424 // file extensions we can use and the second the corresponding regex strings
1425 // to apply to those files.
1427 // the next step is to go over all files shown in the commit dialog
1428 // and scan them for strings we can use
1429 int nListItems = m_ListCtrl.GetItemCount();
1431 for (int i=0; i<nListItems && m_bRunThread; ++i)
1433 // stop parsing after timeout
1434 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1435 return;
1437 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1439 if(path == NULL)
1440 continue;
1442 CString sPartPath =path->GetGitPathString();
1443 m_autolist.insert(sPartPath);
1445 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1446 // if (!entry)
1447 // continue;
1449 // add the path parts to the auto completion list too
1450 // CString sPartPath = entry->GetRelativeGitPath();
1451 // m_autolist.insert(sPartPath);
1454 int pos = 0;
1455 int lastPos = 0;
1456 while ((pos = sPartPath.Find('/', pos)) >= 0)
1458 ++pos;
1459 lastPos = pos;
1460 m_autolist.insert(sPartPath.Mid(pos));
1463 // Last inserted entry is a file name.
1464 // Some users prefer to also list file name without extension.
1465 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1467 int dotPos = sPartPath.ReverseFind('.');
1468 if ((dotPos >= 0) && (dotPos > lastPos))
1469 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1471 #if 0
1472 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1473 continue;
1475 CString sExt = entry->GetPath().GetFileExtension();
1476 sExt.MakeLower();
1477 // find the regex string which corresponds to the file extension
1478 CString rdata = mapRegex[sExt];
1479 if (rdata.IsEmpty())
1480 continue;
1482 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1483 if ((entry->textstatus != Git_wc_status_unversioned) &&
1484 (entry->textstatus != Git_wc_status_none) &&
1485 (entry->textstatus != Git_wc_status_ignored) &&
1486 (entry->textstatus != Git_wc_status_added) &&
1487 (entry->textstatus != Git_wc_status_normal))
1489 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1490 if (!basePath.IsEmpty())
1491 ScanFile(basePath.GetWinPathString(), rdata);
1493 #endif
1495 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1498 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1500 wstring sFileContent;
1501 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1502 if (hFile != INVALID_HANDLE_VALUE)
1504 DWORD size = GetFileSize(hFile, NULL);
1505 if (size > 1000000L)
1507 // no files bigger than 1 Meg
1508 CloseHandle(hFile);
1509 return;
1511 // allocate memory to hold file contents
1512 char * buffer = new char[size];
1513 DWORD readbytes;
1514 ReadFile(hFile, buffer, size, &readbytes, NULL);
1515 CloseHandle(hFile);
1516 int opts = 0;
1517 IsTextUnicode(buffer, readbytes, &opts);
1518 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1520 delete [] buffer;
1521 return;
1523 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1525 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1527 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1529 int ret = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1530 wchar_t * pWideBuf = new wchar_t[ret];
1531 int ret2 = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1532 if (ret2 == ret)
1533 sFileContent = wstring(pWideBuf, ret);
1534 delete [] pWideBuf;
1536 delete [] buffer;
1538 if (sFileContent.empty()|| !m_bRunThread)
1540 return;
1545 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1546 const tr1::wsregex_iterator end;
1547 wstring s = sFileContent;
1548 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1550 const tr1::wsmatch match = *it;
1551 for (size_t i=1; i<match.size(); ++i)
1553 if (match[i].second-match[i].first)
1555 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1556 m_autolist.insert(wstring(match[i]).c_str());
1561 catch (exception) {}
1564 // CSciEditContextMenuInterface
1565 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1567 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1568 m_nPopupPasteListCmd = nCmd++;
1569 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1571 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1572 if(m_History.GetCount() > 0)
1574 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1575 m_nPopupPasteLastMessage = nCmd++;
1576 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1578 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1579 m_nPopupRecentMessage = nCmd++;
1580 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1586 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1589 if (m_bBlock)
1590 return false;
1591 if (cmd == m_nPopupPasteListCmd)
1593 CString logmsg;
1594 int nListItems = m_ListCtrl.GetItemCount();
1595 for (int i=0; i<nListItems; ++i)
1597 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1598 if (entry&&entry->m_Checked)
1600 CString line;
1601 CString status = entry->GetActionName();
1602 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1603 status = _T("Add"); // I18N TODO
1605 //git_wc_status_kind status = entry->status;
1606 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1607 if (m_ProjectProperties.bFileListInEnglish)
1608 langID = 1033;
1610 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1611 logmsg += line;
1614 pSciEdit->InsertText(logmsg);
1615 return true;
1618 if(cmd == m_nPopupPasteLastMessage)
1620 if(m_History.GetCount() ==0 )
1621 return false;
1623 CString logmsg;
1624 logmsg +=m_History.GetEntry(0);
1625 pSciEdit->InsertText(logmsg);
1626 return true;
1629 if(cmd == m_nPopupRecentMessage )
1631 OnBnClickedHistory();
1632 return true;
1634 return false;
1637 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1639 switch (nIDEvent)
1641 case ENDDIALOGTIMER:
1642 KillTimer(ENDDIALOGTIMER);
1643 EndDialog(0);
1644 break;
1645 case REFRESHTIMER:
1646 if (m_bThreadRunning)
1648 SetTimer(REFRESHTIMER, 200, NULL);
1649 ATLTRACE("Wait some more before refreshing\n");
1651 else
1653 KillTimer(REFRESHTIMER);
1654 ATLTRACE("Refreshing after items dropped\n");
1655 Refresh();
1657 break;
1658 case FILLPATCHVTIMER:
1659 FillPatchView();
1660 break;
1662 __super::OnTimer(nIDEvent);
1665 void CCommitDlg::OnBnClickedHistory()
1667 m_tooltips.Pop(); // hide the tooltips
1668 if (m_pathList.GetCount() == 0)
1669 return;
1671 CHistoryDlg historyDlg;
1672 historyDlg.SetHistory(m_History);
1673 if (historyDlg.DoModal() != IDOK)
1674 return;
1676 CString sMsg = historyDlg.GetSelectedText();
1677 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1679 CString sBugID = m_ProjectProperties.FindBugID(sMsg);
1680 if ((!sBugID.IsEmpty()) && ((GetDlgItem(IDC_BUGID)->IsWindowVisible())))
1682 SetDlgItemText(IDC_BUGID, sBugID);
1684 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1685 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1686 else
1687 m_cLogMessage.SetText(sMsg);
1690 SendMessage(WM_UPDATEOKBUTTON);
1691 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1695 void CCommitDlg::OnBnClickedBugtraqbutton()
1697 m_tooltips.Pop(); // hide the tooltips
1698 CString sMsg = m_cLogMessage.GetText();
1700 if (m_BugTraqProvider == NULL)
1701 return;
1703 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1704 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1705 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1707 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1708 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1710 BSTR originalMessage = sMsg.AllocSysString();
1711 BSTR temp = NULL;
1712 // m_revProps.clear();
1714 // first try the IBugTraqProvider2 interface
1715 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1716 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1717 bool bugIdOutSet = false;
1718 if (SUCCEEDED(hr))
1720 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1721 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1722 BSTR bugIDOut = NULL;
1723 GetDlgItemText(IDC_BUGID, m_sBugID);
1724 BSTR bugID = m_sBugID.AllocSysString();
1725 SAFEARRAY * revPropNames = NULL;
1726 SAFEARRAY * revPropValues = NULL;
1727 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1729 CString sErr;
1730 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1731 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1733 else
1735 if (bugIDOut)
1737 bugIdOutSet = true;
1738 m_sBugID = bugIDOut;
1739 SysFreeString(bugIDOut);
1740 SetDlgItemText(IDC_BUGID, m_sBugID);
1742 SysFreeString(bugID);
1743 SysFreeString(repositoryRoot);
1744 m_cLogMessage.SetText(temp);
1745 BSTR HUGEP *pbRevNames;
1746 BSTR HUGEP *pbRevValues;
1748 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1749 if (SUCCEEDED(hr1))
1751 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1752 if (SUCCEEDED(hr2))
1754 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1756 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; ++i)
1758 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1761 SafeArrayUnaccessData(revPropValues);
1763 SafeArrayUnaccessData(revPropNames);
1765 if (revPropNames)
1766 SafeArrayDestroy(revPropNames);
1767 if (revPropValues)
1768 SafeArrayDestroy(revPropValues);
1771 else
1773 // if IBugTraqProvider2 failed, try IBugTraqProvider
1774 CComPtr<IBugTraqProvider> pProvider = NULL;
1775 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1776 if (FAILED(hr))
1778 CString sErr;
1779 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1780 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1781 return;
1784 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1786 CString sErr;
1787 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1788 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1790 else
1791 m_cLogMessage.SetText(temp);
1793 m_sLogMessage = m_cLogMessage.GetText();
1794 if (!m_ProjectProperties.sMessage.IsEmpty())
1796 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1797 if (!sBugID.IsEmpty() && !bugIdOutSet)
1799 SetDlgItemText(IDC_BUGID, sBugID);
1803 m_cLogMessage.SetFocus();
1805 SysFreeString(parameters);
1806 SysFreeString(commonRoot);
1807 SafeArrayDestroy(pathList);
1808 SysFreeString(originalMessage);
1809 SysFreeString(temp);
1812 void CCommitDlg::FillPatchView(bool onlySetTimer)
1814 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1816 KillTimer(FILLPATCHVTIMER);
1817 if (onlySetTimer)
1819 SetTimer(FILLPATCHVTIMER, 100, NULL);
1820 return;
1822 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
1824 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
1825 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
1826 CString cmd,out;
1828 while(pos)
1830 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
1831 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
1832 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
1834 CString head = _T("HEAD");
1835 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
1836 head = _T("HEAD~1");
1837 cmd.Format(_T("git.exe diff %s -- \"%s\""), head, p->GetGitPathString());
1838 g_Git.Run(cmd, &out, CP_UTF8);
1842 m_patchViewdlg.m_ctrlPatchView.SetText(out);
1843 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
1844 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
1845 CRect rect;
1846 m_patchViewdlg.m_ctrlPatchView.GetClientRect(rect);
1847 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTH, rect.Width() - 4);
1850 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1852 this->FillPatchView(true);
1853 return 0;
1857 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1859 SendMessage(WM_UPDATEOKBUTTON);
1860 return 0;
1863 LRESULT CCommitDlg::OnCheck(WPARAM wnd, LPARAM)
1865 HWND hwnd = (HWND)wnd;
1866 bool check = !(GetAsyncKeyState(VK_SHIFT) & 0x8000);
1867 if (hwnd == GetDlgItem(IDC_CHECKALL)->GetSafeHwnd())
1868 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, check);
1869 else if (hwnd == GetDlgItem(IDC_CHECKNONE)->GetSafeHwnd())
1870 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, !check);
1871 else if (hwnd == GetDlgItem(IDC_CHECKUNVERSIONED)->GetSafeHwnd())
1872 m_ListCtrl.Check(GITSLC_SHOWUNVERSIONED, check);
1873 else if (hwnd == GetDlgItem(IDC_CHECKVERSIONED)->GetSafeHwnd())
1874 m_ListCtrl.Check(GITSLC_SHOWVERSIONED, check);
1875 else if (hwnd == GetDlgItem(IDC_CHECKADDED)->GetSafeHwnd())
1876 m_ListCtrl.Check(GITSLC_SHOWADDED, check);
1877 else if (hwnd == GetDlgItem(IDC_CHECKDELETED)->GetSafeHwnd())
1878 m_ListCtrl.Check(GITSLC_SHOWREMOVED, check);
1879 else if (hwnd == GetDlgItem(IDC_CHECKMODIFIED)->GetSafeHwnd())
1880 m_ListCtrl.Check(GITSLC_SHOWMODIFIED, check);
1881 else if (hwnd == GetDlgItem(IDC_CHECKFILES)->GetSafeHwnd())
1882 m_ListCtrl.Check(GITSLC_SHOWFILES, check);
1883 else if (hwnd == GetDlgItem(IDC_CHECKSUBMODULES)->GetSafeHwnd())
1884 m_ListCtrl.Check(GITSLC_SHOWSUBMODULES, check);
1886 return 0;
1889 LRESULT CCommitDlg::OnUpdateOKButton(WPARAM, LPARAM)
1891 if (m_bBlock)
1892 return 0;
1894 bool bValidLogSize = m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize && m_cLogMessage.GetText().GetLength() > 0;
1895 bool bAmendOrSelectFilesOrMerge = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit) || CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1897 DialogEnableWindow(IDOK, bValidLogSize && (m_bCommitMessageOnly || bAmendOrSelectFilesOrMerge));
1899 return 0;
1902 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1904 switch (message) {
1905 case WM_NOTIFY:
1906 if (wParam == IDC_SPLITTER)
1908 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1909 DoSize(pHdr->delta);
1911 break;
1914 return __super::DefWindowProc(message, wParam, lParam);
1917 void CCommitDlg::SetSplitterRange()
1919 if ((m_ListCtrl)&&(m_cLogMessage))
1921 CRect rcTop;
1922 m_cLogMessage.GetWindowRect(rcTop);
1923 ScreenToClient(rcTop);
1924 CRect rcMiddle;
1925 m_ListCtrl.GetWindowRect(rcMiddle);
1926 ScreenToClient(rcMiddle);
1927 if (rcMiddle.Height() && rcMiddle.Width())
1928 m_wndSplitter.SetRange(rcTop.top + 100, rcMiddle.bottom - 80);
1932 void CCommitDlg::DoSize(int delta)
1934 RemoveAnchor(IDC_MESSAGEGROUP);
1935 RemoveAnchor(IDC_LOGMESSAGE);
1936 RemoveAnchor(IDC_SPLITTER);
1937 RemoveAnchor(IDC_SIGNOFF);
1938 RemoveAnchor(IDC_COMMIT_AMEND);
1939 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
1940 RemoveAnchor(IDC_COMMIT_SETDATETIME);
1941 RemoveAnchor(IDC_COMMIT_DATEPICKER);
1942 RemoveAnchor(IDC_COMMIT_TIMEPICKER);
1943 RemoveAnchor(IDC_LISTGROUP);
1944 RemoveAnchor(IDC_FILELIST);
1945 RemoveAnchor(IDC_TEXT_INFO);
1946 RemoveAnchor(IDC_SELECTLABEL);
1947 RemoveAnchor(IDC_CHECKALL);
1948 RemoveAnchor(IDC_CHECKNONE);
1949 RemoveAnchor(IDC_CHECKUNVERSIONED);
1950 RemoveAnchor(IDC_CHECKVERSIONED);
1951 RemoveAnchor(IDC_CHECKADDED);
1952 RemoveAnchor(IDC_CHECKDELETED);
1953 RemoveAnchor(IDC_CHECKMODIFIED);
1954 RemoveAnchor(IDC_CHECKFILES);
1955 RemoveAnchor(IDC_CHECKSUBMODULES);
1957 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
1958 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
1959 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
1960 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
1961 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
1962 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
1963 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
1964 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME),0,delta);
1965 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER),0,delta);
1966 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER),0,delta);
1967 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
1968 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL), 0, delta);
1969 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL), 0, delta);
1970 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE), 0, delta);
1971 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED), 0, delta);
1972 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED), 0, delta);
1973 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED), 0, delta);
1974 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED), 0, delta);
1975 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED), 0, delta);
1976 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES), 0, delta);
1977 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES), 0, delta);
1979 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
1980 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
1981 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
1982 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
1983 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
1984 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
1985 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
1986 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
1987 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
1988 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
1989 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
1990 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
1991 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
1992 AddAnchor(IDC_CHECKALL, TOP_LEFT);
1993 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
1994 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
1995 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
1996 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
1997 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
1998 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
1999 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
2000 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
2001 ArrangeLayout();
2002 // adjust the minimum size of the dialog to prevent the resizing from
2003 // moving the list control too far down.
2004 CRect rcLogMsg;
2005 m_cLogMessage.GetClientRect(rcLogMsg);
2006 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
2008 SetSplitterRange();
2009 m_cLogMessage.Invalidate();
2010 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
2013 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
2015 // first, let the resizing take place
2016 __super::OnSize(nType, cx, cy);
2018 //set range
2019 SetSplitterRange();
2022 CString CCommitDlg::GetSignedOffByLine()
2024 CString str;
2026 CString username = g_Git.GetUserName();
2027 CString email = g_Git.GetUserEmail();
2028 username.Remove(_T('\n'));
2029 email.Remove(_T('\n'));
2031 str.Format(_T("Signed-off-by: %s <%s>"), username, email);
2033 return str;
2036 void CCommitDlg::OnBnClickedSignOff()
2038 CString str = GetSignedOffByLine();
2040 if (m_cLogMessage.GetText().Find(str) == -1) {
2041 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
2042 int lastNewline = m_cLogMessage.GetText().ReverseFind(_T('\n'));
2043 int foundByLine = -1;
2044 if (lastNewline > 0)
2045 foundByLine = m_cLogMessage.GetText().Find(_T("-by: "), lastNewline);
2047 if (foundByLine == -1 || foundByLine < lastNewline)
2048 str = _T("\r\n") + str;
2050 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n")+str+_T("\r\n"));
2054 void CCommitDlg::OnBnClickedCommitAmend()
2056 this->UpdateData();
2057 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
2059 GitRev rev;
2060 rev.GetCommit(CString(_T("HEAD")));
2061 m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody();
2064 if(this->m_bCommitAmend)
2066 this->m_NoAmendStr=this->m_cLogMessage.GetText();
2067 m_cLogMessage.SetText(m_AmendStr);
2068 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
2070 else
2072 this->m_AmendStr=this->m_cLogMessage.GetText();
2073 m_cLogMessage.SetText(m_NoAmendStr);
2074 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
2077 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2079 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
2080 Refresh();
2083 void CCommitDlg::OnBnClickedCommitMessageOnly()
2085 this->UpdateData();
2086 this->m_ListCtrl.EnableWindow(m_bCommitMessageOnly ? FALSE : TRUE);
2087 SendMessage(WM_UPDATEOKBUTTON);
2090 void CCommitDlg::OnBnClickedWholeProject()
2092 m_tooltips.Pop(); // hide the tooltips
2093 UpdateData();
2094 m_ListCtrl.Clear();
2095 if (!m_bBlock)
2097 if(m_bWholeProject)
2098 m_ListCtrl.GetStatus(NULL,true,false,true);
2099 else
2100 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
2102 DWORD dwShow = m_ListCtrl.GetShowFlags();
2103 if (DWORD(m_regAddBeforeCommit))
2104 dwShow |= GITSLC_SHOWUNVERSIONED;
2105 else
2106 dwShow &= ~GITSLC_SHOWUNVERSIONED;
2108 m_ListCtrl.Show(dwShow, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
2109 UpdateCheckLinks();
2112 SetDlgTitle();
2115 void CCommitDlg::OnFocusMessage()
2117 m_cLogMessage.SetFocus();
2120 void CCommitDlg::OnScnUpdateUI(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2122 int pos = (int)this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
2123 int line = (int)this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
2124 int column = (int)this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
2126 CString str;
2127 str.Format(_T("%d/%d"),line+1,column+1);
2128 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
2130 if(*pResult)
2131 *pResult=0;
2133 void CCommitDlg::OnStnClickedViewPatch()
2135 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
2136 m_patchViewdlg.m_ParentCommitDlg = this;
2137 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
2139 BOOL viewPatchEnabled = FALSE;
2140 m_ProjectProperties.GetBOOLProps(viewPatchEnabled, _T("tgit.commitshowpatch"));
2141 if (viewPatchEnabled == FALSE)
2142 g_Git.SetConfigValue(_T("tgit.commitshowpatch"), _T("true"));
2143 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
2144 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2145 CRect rect;
2146 this->GetWindowRect(&rect);
2148 m_patchViewdlg.ShowWindow(SW_SHOW);
2150 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
2151 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
2153 ShowViewPatchText(false);
2154 FillPatchView();
2156 else
2158 g_Git.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2159 m_patchViewdlg.ShowWindow(SW_HIDE);
2160 m_patchViewdlg.DestroyWindow();
2161 ShowViewPatchText(true);
2163 this->m_ctrlShowPatch.Invalidate();
2166 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
2168 __super::OnMoving(fwSide, pRect);
2170 if (::IsWindow(m_patchViewdlg.m_hWnd))
2172 RECT patchrect;
2173 m_patchViewdlg.GetWindowRect(&patchrect);
2174 if (::IsWindow(m_hWnd))
2176 RECT thisrect;
2177 GetWindowRect(&thisrect);
2178 if (patchrect.left == thisrect.right)
2180 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2181 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2188 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2190 __super::OnSizing(fwSide, pRect);
2192 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2194 CRect thisrect, patchrect;
2195 this->GetWindowRect(thisrect);
2196 this->m_patchViewdlg.GetWindowRect(patchrect);
2197 if(thisrect.right==patchrect.left)
2199 patchrect.left -= (thisrect.right - pRect->right);
2200 patchrect.right-= (thisrect.right - pRect->right);
2202 if( patchrect.bottom == thisrect.bottom)
2204 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2206 if( patchrect.top == thisrect.top)
2208 patchrect.top -= thisrect.top-pRect->top;
2210 m_patchViewdlg.MoveWindow(patchrect);
2215 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2217 *pResult = 0;
2218 TRACE("Item Changed\r\n");
2221 int CCommitDlg::CheckHeadDetach()
2223 CString output;
2224 if(g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir,output))
2226 int retval = CMessageBox::Show(NULL, IDS_PROC_COMMIT_DETACHEDWARNING, IDS_APPNAME, MB_YESNOCANCEL | MB_ICONWARNING);
2227 if(retval == IDYES)
2229 if (CAppUtils::CreateBranchTag(FALSE, NULL, true) == FALSE)
2230 return 1;
2232 else if (retval == IDCANCEL)
2233 return 1;
2235 return 0;
2238 void CCommitDlg::OnBnClickedCommitAmenddiff()
2240 UpdateData();
2241 Refresh();
2244 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2246 UpdateData();
2247 Refresh();
2250 void CCommitDlg::OnBnClickedCommitSetDateTime()
2252 UpdateData();
2254 if (m_bSetCommitDateTime)
2256 CTime authordate = CTime::GetCurrentTime();
2257 if (m_bCommitAmend)
2259 GitRev headRevision;
2260 headRevision.GetCommit(_T("HEAD"));
2261 authordate = headRevision.GetAuthorDate();
2264 m_CommitDate.SetTime(&authordate);
2265 m_CommitTime.SetTime(&authordate);
2267 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
2268 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
2270 else
2272 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_HIDE);
2273 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_HIDE);
2277 void CCommitDlg::OnBnClickedCheckNewBranch()
2279 UpdateData();
2280 if (m_bCreateNewBranch)
2282 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_HIDE);
2283 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_SHOW);
2285 else
2287 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
2288 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);
2292 void CCommitDlg::RestoreFiles(bool doNotAsk)
2294 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))
2296 for (std::map<CString, CString>::iterator it = m_ListCtrl.m_restorepaths.begin(); it != m_ListCtrl.m_restorepaths.end(); ++it)
2297 CopyFile(it->second, g_Git.m_CurrentDir + _T("\\") + it->first, FALSE);
2298 m_ListCtrl.m_restorepaths.clear();
2302 void CCommitDlg::UpdateCheckLinks()
2304 DialogEnableWindow(IDC_CHECKALL, true);
2305 DialogEnableWindow(IDC_CHECKNONE, true);
2306 DialogEnableWindow(IDC_CHECKUNVERSIONED, m_ListCtrl.GetUnversionedCount() > 0);
2307 DialogEnableWindow(IDC_CHECKVERSIONED, m_ListCtrl.GetItemCount() > m_ListCtrl.GetUnversionedCount());
2308 DialogEnableWindow(IDC_CHECKADDED, m_ListCtrl.GetAddedCount() > 0);
2309 DialogEnableWindow(IDC_CHECKDELETED, m_ListCtrl.GetDeletedCount() > 0);
2310 DialogEnableWindow(IDC_CHECKMODIFIED, m_ListCtrl.GetModifiedCount() > 0);
2311 DialogEnableWindow(IDC_CHECKFILES, m_ListCtrl.GetFileCount() > 0);
2312 DialogEnableWindow(IDC_CHECKSUBMODULES, m_ListCtrl.GetSubmoduleCount() > 0);