1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "TortoiseProc.h"
21 #include "CommitDlg.h"
22 #include "DirFileEnum.h"
23 //#include "GitConfig.h"
24 #include "ProjectProperties.h"
25 #include "MessageBox.h"
27 #include "PathUtils.h"
30 #include "GitStatus.h"
31 #include "HistoryDlg.h"
33 #include "CommonResource.h"
34 #include "UnicodeUtils.h"
35 #include "ProgressDlg.h"
36 #include "ShellUpdater.h"
37 #include "Commands/PushCommand.h"
38 #include "PatchViewDlg.h"
45 static char THIS_FILE
[] = __FILE__
;
48 UINT
CCommitDlg::WM_AUTOLISTREADY
= RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
50 IMPLEMENT_DYNAMIC(CCommitDlg
, CResizableStandAloneDialog
)
51 CCommitDlg::CCommitDlg(CWnd
* pParent
/*=NULL*/)
52 : CResizableStandAloneDialog(CCommitDlg::IDD
, pParent
)
54 , m_bShowUnversioned(FALSE
)
56 , m_bThreadRunning(FALSE
)
59 , m_bWholeProject(FALSE
)
60 , m_bKeepChangeList(TRUE
)
62 , m_bSelectFilesForCommit(TRUE
)
64 this->m_bCommitAmend
=FALSE
;
65 m_bPushAfterCommit
= FALSE
;
68 CCommitDlg::~CCommitDlg()
76 void CCommitDlg::DoDataExchange(CDataExchange
* pDX
)
78 CResizableStandAloneDialog::DoDataExchange(pDX
);
79 DDX_Control(pDX
, IDC_FILELIST
, m_ListCtrl
);
80 DDX_Control(pDX
, IDC_LOGMESSAGE
, m_cLogMessage
);
81 DDX_Check(pDX
, IDC_SHOWUNVERSIONED
, m_bShowUnversioned
);
82 DDX_Control(pDX
, IDC_SELECTALL
, m_SelectAll
);
83 DDX_Text(pDX
, IDC_BUGID
, m_sBugID
);
84 DDX_Check(pDX
, IDC_WHOLE_PROJECT
, m_bWholeProject
);
85 DDX_Control(pDX
, IDC_SPLITTER
, m_wndSplitter
);
86 DDX_Check(pDX
, IDC_KEEPLISTS
, m_bKeepChangeList
);
87 DDX_Check(pDX
,IDC_COMMIT_AMEND
,m_bCommitAmend
);
88 DDX_Control(pDX
,IDC_VIEW_PATCH
,m_ctrlShowPatch
);
91 BEGIN_MESSAGE_MAP(CCommitDlg
, CResizableStandAloneDialog
)
92 ON_BN_CLICKED(IDC_SELECTALL
, OnBnClickedSelectall
)
93 ON_BN_CLICKED(IDHELP
, OnBnClickedHelp
)
94 ON_BN_CLICKED(IDC_SHOWUNVERSIONED
, OnBnClickedShowunversioned
)
95 ON_NOTIFY(SCN_UPDATEUI
, IDC_LOGMESSAGE
, OnScnUpdateUI
)
96 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
97 ON_BN_CLICKED(IDC_BUGTRAQBUTTON
, OnBnClickedBugtraqbutton
)
98 ON_EN_CHANGE(IDC_LOGMESSAGE
, OnEnChangeLogmessage
)
99 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED
, OnGitStatusListCtrlItemCountChanged
)
100 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
101 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE
, OnFileDropped
)
102 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_CHECKCHANGED
, &CCommitDlg::OnGitStatusListCtrlCheckChanged
)
103 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCHANGED
, &CCommitDlg::OnGitStatusListCtrlItemChanged
)
105 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY
, OnAutoListReady
)
108 ON_STN_CLICKED(IDC_EXTERNALWARNING
, &CCommitDlg::OnStnClickedExternalwarning
)
109 ON_BN_CLICKED(IDC_SIGNOFF
, &CCommitDlg::OnBnClickedSignOff
)
110 ON_BN_CLICKED(IDC_COMMIT_AMEND
, &CCommitDlg::OnBnClickedCommitAmend
)
111 ON_BN_CLICKED(IDC_WHOLE_PROJECT
, &CCommitDlg::OnBnClickedWholeProject
)
112 ON_COMMAND(ID_FOCUS_MESSAGE
,&CCommitDlg::OnFocusMessage
)
113 ON_STN_CLICKED(IDC_VIEW_PATCH
, &CCommitDlg::OnStnClickedViewPatch
)
117 ON_NOTIFY(HDN_ITEMCHANGED
, 0, &CCommitDlg::OnHdnItemchangedFilelist
)
120 BOOL
CCommitDlg::OnInitDialog()
122 CResizableStandAloneDialog::OnInitDialog();
124 CAppUtils::GetCommitTemplate(this->m_sLogMessage
);
126 if(PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_MSG")))
129 if(file
.Open(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_MSG"), CFile::modeRead
))
132 while(file
.ReadString(str
))
134 m_sLogMessage
+= str
;
136 m_sLogMessage
+= _T("\n");
140 m_regAddBeforeCommit
= CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE
);
141 m_bShowUnversioned
= m_regAddBeforeCommit
;
143 m_History
.SetMaxHistoryItems((LONG
)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
145 m_regKeepChangelists
= CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE
);
146 m_bKeepChangeList
= m_regKeepChangelists
;
148 m_hAccel
= LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG
));
151 // m_bWholeProject = config.KeepLocks();
153 if(this->m_pathList
.GetCount() == 0)
154 m_bWholeProject
=true;
156 if(this->m_pathList
.GetCount() == 1 && m_pathList
[0].IsEmpty())
157 m_bWholeProject
=true;
161 m_ListCtrl
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
| SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("CommitDlg"),(SVNSLC_POPALL
^ (SVNSLC_POPCOMMIT
| SVNSLC_POPSAVEAS
)));
162 m_ListCtrl
.SetSelectButton(&m_SelectAll
);
163 m_ListCtrl
.SetStatLabel(GetDlgItem(IDC_STATISTICS
));
164 m_ListCtrl
.SetCancelBool(&m_bCancelled
);
165 m_ListCtrl
.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT
);
166 m_ListCtrl
.EnableFileDrop();
167 m_ListCtrl
.SetBackgroundImage(IDI_COMMIT_BKG
);
169 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
170 m_ProjectProperties
.ReadPropsPathList(m_pathList
);
172 m_cLogMessage
.Init(m_ProjectProperties
);
173 m_cLogMessage
.SetFont((CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
174 m_cLogMessage
.RegisterContextMenuHandler(this);
176 OnEnChangeLogmessage();
178 m_tooltips
.Create(this);
179 m_tooltips
.AddTool(IDC_EXTERNALWARNING
, IDS_COMMITDLG_EXTERNALS
);
180 m_tooltips
.AddTool(IDC_COMMIT_AMEND
,IDS_COMMIT_AMEND_TT
);
181 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
183 m_SelectAll
.SetCheck(BST_INDETERMINATE
);
186 CBugTraqAssociations bugtraq_associations
;
187 bugtraq_associations
.Load();
189 if (bugtraq_associations
.FindProvider(g_Git
.m_CurrentDir
, &m_bugtraq_association
))
191 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
192 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
194 CComPtr
<IBugTraqProvider
> pProvider
;
195 HRESULT hr
= pProvider
.CoCreateInstance(m_bugtraq_association
.GetProviderClass());
198 m_BugTraqProvider
= pProvider
;
200 if (SUCCEEDED(hr
= pProvider
->GetLinkText(GetSafeHwnd(), m_bugtraq_association
.GetParameters().AllocSysString(), &temp
)))
202 SetDlgItemText(IDC_BUGTRAQBUTTON
, temp
);
203 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(TRUE
);
204 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_SHOW
);
210 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
212 else if (!m_ProjectProperties
.sMessage
.IsEmpty())
214 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_SHOW
);
215 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_SHOW
);
216 if (!m_ProjectProperties
.sLabel
.IsEmpty())
217 SetDlgItemText(IDC_BUGIDLABEL
, m_ProjectProperties
.sLabel
);
218 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
219 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
220 GetDlgItem(IDC_BUGID
)->SetFocus();
221 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(m_sLogMessage
);
222 if (!sBugID
.IsEmpty())
224 SetDlgItemText(IDC_BUGID
, sBugID
);
229 GetDlgItem(IDC_BUGID
)->ShowWindow(SW_HIDE
);
230 GetDlgItem(IDC_BUGIDLABEL
)->ShowWindow(SW_HIDE
);
231 GetDlgItem(IDC_BUGTRAQBUTTON
)->ShowWindow(SW_HIDE
);
232 GetDlgItem(IDC_BUGTRAQBUTTON
)->EnableWindow(FALSE
);
233 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
236 if (!m_sLogMessage
.IsEmpty())
237 m_cLogMessage
.SetText(m_sLogMessage
);
239 GetWindowText(m_sWindowTitle
);
241 AdjustControlSize(IDC_SHOWUNVERSIONED
);
242 AdjustControlSize(IDC_SELECTALL
);
243 AdjustControlSize(IDC_WHOLE_PROJECT
);
245 GetClientRect(m_DlgOrigRect
);
246 m_cLogMessage
.GetClientRect(m_LogMsgOrigRect
);
248 AddAnchor(IDC_COMMITLABEL
, TOP_LEFT
, TOP_RIGHT
);
249 AddAnchor(IDC_BUGIDLABEL
, TOP_RIGHT
);
250 AddAnchor(IDC_BUGID
, TOP_RIGHT
);
251 AddAnchor(IDC_BUGTRAQBUTTON
, TOP_RIGHT
);
252 AddAnchor(IDC_COMMIT_TO
, TOP_LEFT
, TOP_RIGHT
);
253 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
254 // AddAnchor(IDC_HISTORY, TOP_LEFT);
255 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
256 AddAnchor(IDC_SIGNOFF
, TOP_RIGHT
);
257 AddAnchor(IDC_VIEW_PATCH
,TOP_RIGHT
);
258 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
259 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
260 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
261 AddAnchor(IDC_SHOWUNVERSIONED
, BOTTOM_LEFT
);
262 AddAnchor(IDC_SELECTALL
, BOTTOM_LEFT
);
263 AddAnchor(IDC_EXTERNALWARNING
, BOTTOM_RIGHT
);
264 AddAnchor(IDC_STATISTICS
, BOTTOM_LEFT
, BOTTOM_RIGHT
);
265 AddAnchor(IDC_TEXT_INFO
, TOP_RIGHT
);
266 AddAnchor(IDC_WHOLE_PROJECT
, BOTTOM_LEFT
);
267 AddAnchor(IDC_KEEPLISTS
, BOTTOM_LEFT
);
268 AddAnchor(IDOK
, BOTTOM_RIGHT
);
269 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
270 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
271 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
274 CenterWindow(CWnd::FromHandle(hWndExplorer
));
275 EnableSaveRestore(_T("CommitDlg"));
276 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
277 RECT rcDlg
, rcLogMsg
, rcFileList
;
278 GetClientRect(&rcDlg
);
279 m_cLogMessage
.GetWindowRect(&rcLogMsg
);
280 ScreenToClient(&rcLogMsg
);
281 m_ListCtrl
.GetWindowRect(&rcFileList
);
282 ScreenToClient(&rcFileList
);
286 m_wndSplitter
.GetWindowRect(&rectSplitter
);
287 ScreenToClient(&rectSplitter
);
288 int delta
= yPos
- rectSplitter
.top
;
289 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
291 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
296 // add all directories to the watcher
298 for (int i=0; i<m_pathList.GetCount(); ++i)
300 if (m_pathList[i].IsDirectory())
301 m_pathwatcher.AddPath(m_pathList[i]);
304 m_updatedPathList
= m_pathList
;
306 //first start a thread to obtain the file list with the status without
307 //blocking the dialog
308 InterlockedExchange(&m_bBlock
, TRUE
);
309 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
312 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
313 InterlockedExchange(&m_bBlock
, FALSE
);
317 m_pThread
->m_bAutoDelete
= FALSE
;
318 m_pThread
->ResumeThread();
320 CRegDWORD err
= CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE
);
321 CRegDWORD historyhint
= CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE
);
322 if ((((DWORD
)err
)!=FALSE
)&&((((DWORD
)historyhint
)==FALSE
)))
325 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
329 //this->UpdateData(TRUE);
330 //this->m_bCommitAmend=FALSE;
331 //this->UpdateData(FALSE);
333 this->m_ctrlShowPatch
.SetURL(CString());
335 return FALSE
; // return TRUE unless you set the focus to a control
336 // EXCEPTION: OCX Property Pages should return FALSE
339 void CCommitDlg::OnOK()
343 if (m_bThreadRunning
)
346 InterlockedExchange(&m_bRunThread
, FALSE
);
347 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
348 if (m_bThreadRunning
)
350 // we gave the thread a chance to quit. Since the thread didn't
351 // listen to us we have to kill it.
352 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
353 InterlockedExchange(&m_bThreadRunning
, FALSE
);
359 GetDlgItemText(IDC_BUGID
, id
);
360 if (!m_ProjectProperties
.CheckBugID(id
))
362 ShowBalloon(IDC_BUGID
, IDS_COMMITDLG_ONLYNUMBERS
, IDI_EXCLAMATION
);
365 m_sLogMessage
= m_cLogMessage
.GetText();
366 if ( m_sLogMessage
.IsEmpty() )
368 // no message entered, go round again
369 CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
372 if ((m_ProjectProperties
.bWarnIfNoIssue
) && (id
.IsEmpty() && !m_ProjectProperties
.HasBugID(m_sLogMessage
)))
374 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_NOISSUEWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
378 m_ListCtrl
.WriteCheckedNamesToPathList(m_selectedPathList
);
380 CRegDWORD
regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE
);
381 if (!(DWORD
)regUnversionedRecurse
)
383 // Find unversioned directories which are marked for commit. The user might expect them
384 // to be added recursively since he cannot the the files. Let's ask the user if he knows
386 int nListItems
= m_ListCtrl
.GetItemCount();
387 for (int j
=0; j
<nListItems
; j
++)
389 const CGitStatusListCtrl::FileEntry
* entry
= m_ListCtrl
.GetListEntry(j
);
390 if (entry
->IsChecked() && (entry
->status
== Git_wc_status_unversioned
) && entry
->IsFolder() )
392 if (CMessageBox::Show(this->m_hWnd
, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING
, IDS_APPNAME
, MB_YESNO
| MB_ICONWARNING
)!=IDYES
)
398 m_pathwatcher
.Stop();
399 InterlockedExchange(&m_bBlock
, TRUE
);
400 CDWordArray arDeleted
;
401 //first add all the unversioned files the user selected
402 //and check if all versioned files are selected
405 int nListItems
= m_ListCtrl
.GetItemCount();
407 CTGitPathList itemsToAdd
;
408 CTGitPathList itemsToRemove
;
409 //std::set<CString> checkedLists;
410 //std::set<CString> uncheckedLists;
412 // now let the bugtraq plugin check the commit message
413 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
414 if (m_BugTraqProvider
)
416 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
420 CString common
= g_Git
.m_CurrentDir
;
421 BSTR repositoryRoot
= common
.AllocSysString();
422 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
423 BSTR commonRoot
= SysAllocString(m_pathList
.GetCommonRoot().GetDirectory().GetWinPath());
424 BSTR commitMessage
= m_sLogMessage
.AllocSysString();
425 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_selectedPathList
.GetCount());
427 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
428 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
430 if (FAILED(hr
= pProvider2
->CheckCommit(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, commitMessage
, &temp
)))
434 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), ce
.GetMessageAndDescription().c_str());
435 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseSVN"), MB_ICONERROR
);
439 CString sError
= temp
;
440 if (!sError
.IsEmpty())
442 CMessageBox::Show(m_hWnd
, sError
, _T("TortoiseSVN"), MB_ICONERROR
);
450 //CString checkedfiles;
451 //CString uncheckedfiles;
456 bool bAddSuccess
=true;
457 bool bCloseCommitDlg
=false;
459 for (int j
=0; j
<nListItems
; j
++)
461 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
462 CTGitPath
*entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(j
);
463 if (entry
->m_Checked
)
466 if (entry
->status
== Git_wc_status_unversioned
)
468 itemsToAdd
.AddPath(entry
->GetPath());
470 if (entry
->status
== Git_wc_status_conflicted
)
472 bHasConflicted
= true;
474 if (entry
->status
== Git_wc_status_missing
)
476 itemsToRemove
.AddPath(entry
->GetPath());
478 if (entry
->status
== Git_wc_status_deleted
)
482 if (entry
->IsInExternal())
484 bCheckedInExternal
= true;
487 if( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
488 cmd
.Format(_T("git.exe add -f -- \"%s\""),entry
->GetGitPathString());
489 else if ( entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
490 cmd
.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry
->GetGitPathString());
492 cmd
.Format(_T("git.exe update-index -- \"%s\""),entry
->GetGitPathString());
494 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
496 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
497 bAddSuccess
= false ;
501 if( entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
502 cmd
.Format(_T("git.exe rm -- \"%s\""), entry
->GetGitOldPathString());
504 g_Git
.Run(cmd
,&out
,CP_ACP
);
508 //checkedLists.insert(entry->GetGitPathString());
509 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
513 //uncheckedLists.insert(entry->GetGitPathString());
514 if(entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
)
515 { //To init git repository, there are not HEAD, so we can use git reset command
516 cmd
.Format(_T("git.exe rm --cache -- \"%s\""),entry
->GetGitPathString());
517 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
519 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
520 bAddSuccess
= false ;
521 bCloseCommitDlg
=false;
526 else if(!( entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
) )
528 cmd
.Format(_T("git.exe reset -- \"%s\""),entry
->GetGitPathString());
529 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
531 /* when reset a unstage file will report error.
532 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
533 bAddSuccess = false ;
534 bCloseCommitDlg=false;
540 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
542 if ((entry
->status
!= Git_wc_status_unversioned
) &&
543 (entry
->status
!= Git_wc_status_ignored
))
546 uncheckedLists
.insert(entry
->GetChangeList());
549 // This algorithm is for the sake of simplicity of the complexity O(N?
550 for (int k
=0; k
<nListItems
; k
++)
552 const CGitStatusListCtrl::FileEntry
* entryK
= m_ListCtrl
.GetListEntry(k
);
553 if (entryK
->IsChecked() && entryK
->GetPath().IsAncestorOf(entry
->GetPath()) )
555 // Fall back to a non-recursive commit to prevent items being
556 // committed which aren't checked although its parent is checked
557 // (property change, directory deletion, ... )
558 m_bRecursive
= false;
567 CShellUpdater::Instance().AddPathForUpdate(*entry
);
570 //if(uncheckedfiles.GetLength()>0)
572 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
573 // g_Git.Run(cmd,&out);
577 if (!m_sBugID
.IsEmpty())
579 m_sBugID
.Replace(_T(", "), _T(","));
580 m_sBugID
.Replace(_T(" ,"), _T(","));
581 CString sBugID
= m_ProjectProperties
.sMessage
;
582 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
583 if (m_ProjectProperties
.bAppend
)
584 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
586 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
590 if(PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_HEAD")))
594 //if(checkedfiles.GetLength()>0)
595 if( bAddSuccess
&& (nchecked
||m_bCommitAmend
||bIsMerge
) )
597 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
598 // g_Git.Run(cmd,&out);
600 bCloseCommitDlg
= true;
602 CString tempfile
=::GetTempFile();
604 CAppUtils::SaveCommitUnicodeFile(tempfile
,m_sLogMessage
);
605 //file.WriteString(m_sLogMessage);
607 CTGitPath path
=g_Git
.m_CurrentDir
;
609 BOOL IsGitSVN
= path
.GetAdminDirMask() & ITEMIS_GITSVN
;
613 if(this->m_bCommitAmend
)
617 cmd
.Format(_T("git.exe commit %s -F \"%s\""),amend
, tempfile
);
621 CCommitProgressDlg progress
;
622 progress
.m_bBufferAll
=true; // improve show speed when there are many file added.
623 progress
.m_GitCmd
=cmd
;
624 progress
.m_bShowCommand
= FALSE
; // don't show the commit command
625 progress
.m_PreText
= out
; // show any output already generated in log window
627 progress
.m_PostCmdList
.Add( IsGitSVN
? _T("&DCommit"): _T("&Push"));
628 progress
.m_PostCmdList
.Add(_T("&ReCommit"));
630 m_PostCmd
= IsGitSVN
? GIT_POST_CMD_DCOMMIT
:GIT_POST_CMD_PUSH
;
632 DWORD userResponse
= progress
.DoModal();
634 if(progress
.m_GitStatus
|| userResponse
== (IDC_PROGRESS_BUTTON1
+1))
636 bCloseCommitDlg
= false;
637 if( userResponse
== (IDC_PROGRESS_BUTTON1
+1 ))
639 this->m_sLogMessage
.Empty();
640 m_cLogMessage
.SetText(m_sLogMessage
);
645 else if(userResponse
== IDC_PROGRESS_BUTTON1
)
647 //User pressed 'Push' button after successful commit.
648 m_bPushAfterCommit
=true;
651 CFile::Remove(tempfile
);
653 if (m_BugTraqProvider
&& progress
.m_GitStatus
== 0)
655 CComPtr
<IBugTraqProvider2
> pProvider
= NULL
;
656 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
659 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
660 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0,this->m_selectedPathList
.GetCount());
662 for (LONG index
= 0; index
< m_selectedPathList
.GetCount(); ++index
)
663 SafeArrayPutElement(pathList
, &index
, m_selectedPathList
[index
].GetGitPathString().AllocSysString());
665 BSTR logMessage
= m_sLogMessage
.AllocSysString();
667 CString hash
=g_Git
.GetHash(CString(_T("HEAD")));
668 LONG version
= g_Git
.Hash2int(hash
);
671 if (FAILED(hr
= pProvider
->OnCommitFinished(GetSafeHwnd(),
680 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
684 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, ce
.GetSource().c_str(), ce
.GetMessageAndDescription().c_str());
685 CMessageBox::Show(NULL
,(sErr
),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
693 }else if(bAddSuccess
)
695 CMessageBox::Show(this->m_hWnd
, IDS_ERROR_NOTHING_COMMIT
, IDS_COMMIT_FINISH
, MB_OK
| MB_ICONINFORMATION
);
696 bCloseCommitDlg
=false;
699 if (m_pathwatcher
.GetNumberOfChangedPaths() && m_bRecursive
)
701 // There are paths which got changed (touched at least).
702 // We have to find out if this affects the selection in the commit dialog
703 // If it could affect the selection, revert back to a non-recursive commit
704 CTGitPathList changedList
= m_pathwatcher
.GetChangedPaths();
705 changedList
.RemoveDuplicates();
706 for (int i
=0; i
<changedList
.GetCount(); ++i
)
708 if (changedList
[i
].IsAdminDir())
710 // something inside an admin dir was changed.
711 // if it's the entries file, then we have to fully refresh because
712 // files may have been added/removed from version control
713 if ((changedList
[i
].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
714 (changedList
[i
].GetWinPathString().Find(_T("\\tmp\\"))<0))
716 m_bRecursive
= false;
720 else if (!m_ListCtrl
.IsPathShown(changedList
[i
]))
722 // a path which is not shown in the list has changed
723 CGitStatusListCtrl::FileEntry
* entry
= m_ListCtrl
.GetListEntry(changedList
[i
]);
726 // check if the changed path would get committed by a recursive commit
727 if ((!entry
->IsFromDifferentRepository()) &&
728 (!entry
->IsInExternal()) &&
729 (!entry
->IsNested()) &&
730 (!entry
->IsChecked()))
732 m_bRecursive
= false;
741 // Now, do all the adds - make sure that the list is sorted so that parents
742 // are added before their children
743 itemsToAdd
.SortByPathname();
745 if (!Git
.Add(itemsToAdd
, &m_ProjectProperties
, Git_depth_empty
, FALSE
, FALSE
, TRUE
))
747 CMessageBox::Show(m_hWnd
, Git
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
748 InterlockedExchange(&m_bBlock
, FALSE
);
753 // Remove any missing items
754 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
755 itemsToRemove
.SortByPathname();
756 Git
.Remove(itemsToRemove
, TRUE
);
758 //the next step: find all deleted files and check if they're
759 //inside a deleted folder. If that's the case, then remove those
760 //files from the list since they'll get deleted by the parent
761 //folder automatically.
762 m_ListCtrl
.Block(TRUE
, FALSE
);
763 INT_PTR nDeleted
= arDeleted
.GetCount();
764 for (INT_PTR i
=0; i
<arDeleted
.GetCount(); i
++)
766 if (m_ListCtrl
.GetCheck(arDeleted
.GetAt(i
)))
768 const CTGitPath
& path
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(i
))->GetPath();
769 if (path
.IsDirectory())
771 //now find all children of this directory
772 for (int j
=0; j
<arDeleted
.GetCount(); j
++)
776 CGitStatusListCtrl::FileEntry
* childEntry
= m_ListCtrl
.GetListEntry(arDeleted
.GetAt(j
));
777 if (childEntry
->IsChecked())
779 if (path
.IsAncestorOf(childEntry
->GetPath()))
781 m_ListCtrl
.SetEntryCheck(childEntry
, arDeleted
.GetAt(j
), false);
790 m_ListCtrl
.Block(FALSE
, FALSE
);
792 if ((nUnchecked
!= 0)||(bCheckedInExternal
)||(bHasConflicted
)||(!m_bRecursive
))
794 //save only the files the user has checked into the temporary file
795 m_ListCtrl
.WriteCheckedNamesToPathList(m_pathList
);
798 // the item count is used in the progress dialog to show the overall commit
800 // deleted items only send one notification event, all others send two
801 m_itemsCount
= ((m_selectedPathList
.GetCount() - nDeleted
- itemsToRemove
.GetCount()) * 2) + nDeleted
+ itemsToRemove
.GetCount();
803 if ((m_bRecursive
)&&(checkedLists
.size() == 1))
805 // all checked items belong to the same changelist
806 // find out if there are any unchecked items which belong to that changelist
807 if (uncheckedLists
.find(*checkedLists
.begin()) == uncheckedLists
.end())
808 m_sChangeList
= *checkedLists
.begin();
812 m_regAddBeforeCommit
= m_bShowUnversioned
;
813 if (!GetDlgItem(IDC_WHOLE_PROJECT
)->IsWindowEnabled())
814 m_bWholeProject
= FALSE
;
815 m_regKeepChangelists
= m_bKeepChangeList
;
816 if (!GetDlgItem(IDC_KEEPLISTS
)->IsWindowEnabled())
817 m_bKeepChangeList
= FALSE
;
818 InterlockedExchange(&m_bBlock
, FALSE
);
820 m_History
.AddEntry(m_sLogMessage
);
825 if( bCloseCommitDlg
)
826 CResizableStandAloneDialog::OnOK();
828 CShellUpdater::Instance().Flush();
831 void CCommitDlg::SaveSplitterPos()
835 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
837 m_wndSplitter
.GetWindowRect(&rectSplitter
);
838 ScreenToClient(&rectSplitter
);
839 regPos
= rectSplitter
.top
;
843 UINT
CCommitDlg::StatusThreadEntry(LPVOID pVoid
)
845 return ((CCommitDlg
*)pVoid
)->StatusThread();
848 UINT
CCommitDlg::StatusThread()
850 //get the status of all selected file/folders recursively
851 //and show the ones which have to be committed to the user
853 InterlockedExchange(&m_bBlock
, TRUE
);
854 InterlockedExchange(&m_bThreadRunning
, TRUE
);// so the main thread knows that this thread is still running
855 InterlockedExchange(&m_bRunThread
, TRUE
); // if this is set to FALSE, the thread should stop
857 m_pathwatcher
.Stop();
859 g_Git
.RefreshGitIndex();
861 m_bCancelled
= false;
863 DialogEnableWindow(IDOK
, false);
864 DialogEnableWindow(IDC_SHOWUNVERSIONED
, false);
865 DialogEnableWindow(IDC_WHOLE_PROJECT
, false);
866 DialogEnableWindow(IDC_SELECTALL
, false);
867 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_HIDE
);
868 DialogEnableWindow(IDC_EXTERNALWARNING
, false);
869 // read the list of recent log entries before querying the WC for status
870 // -> the user may select one and modify / update it while we are crawling the WC
872 if (m_History
.GetCount()==0)
875 reg
.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR
)m_ListCtrl
.m_sUUID
);
876 reg
.Replace(_T(':'),_T('_'));
877 m_History
.Load(reg
, _T("logmsgs"));
880 // Initialise the list control with the status of the files/folders below us
883 CTGitPathList
*pList
;
890 success
=m_ListCtrl
.GetStatus(pList
);
892 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
893 if(this->m_bShowUnversioned
)
894 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
,true,pList
);
896 m_ListCtrl
.CheckIfChangelistsArePresent(false);
898 DWORD dwShow
= SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| SVNSLC_SHOWLOCKS
| SVNSLC_SHOWINCHANGELIST
;
899 dwShow
|= DWORD(m_regAddBeforeCommit
) ? SVNSLC_SHOWUNVERSIONED
: 0;
902 if (m_checkedPathList
.GetCount())
903 m_ListCtrl
.Show(dwShow
, m_checkedPathList
);
906 DWORD dwCheck
= m_bSelectFilesForCommit
? dwShow
: 0;
907 dwCheck
&=~(CTGitPath::LOGACTIONS_UNVER
); //don't check unversion file default.
908 m_ListCtrl
.Show(dwShow
, dwCheck
);
909 m_bSelectFilesForCommit
= true;
912 if (m_ListCtrl
.HasExternalsFromDifferentRepos())
914 GetDlgItem(IDC_EXTERNALWARNING
)->ShowWindow(SW_SHOW
);
915 DialogEnableWindow(IDC_EXTERNALWARNING
, TRUE
);
918 SetDlgItemText(IDC_COMMIT_TO
, g_Git
.GetCurrentBranch());
919 m_tooltips
.AddTool(GetDlgItem(IDC_STATISTICS
), m_ListCtrl
.GetStatisticsString());
922 GetDlgItemText(IDC_LOGMESSAGE
, logmsg
);
923 DialogEnableWindow(IDOK
, logmsg
.GetLength() >= m_ProjectProperties
.nMinLogSize
);
926 if (!m_ListCtrl
.GetLastErrorMessage().IsEmpty())
927 m_ListCtrl
.SetEmptyString(m_ListCtrl
.GetLastErrorMessage());
928 m_ListCtrl
.Show(dwShow
);
930 if ((m_ListCtrl
.GetItemCount()==0)&&(m_ListCtrl
.HasUnversionedItems())
931 && !PathFileExists(g_Git
.m_CurrentDir
+_T("\\.git\\MERGE_HEAD")))
933 if (CMessageBox::Show(m_hWnd
, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
935 m_bShowUnversioned
= TRUE
;
936 GetDlgItem(IDC_SHOWUNVERSIONED
)->SendMessage(BM_SETCHECK
, BST_CHECKED
);
937 DWORD dwShow
= (DWORD
)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| SVNSLC_SHOWUNVERSIONED
| SVNSLC_SHOWLOCKS
);
938 m_ListCtrl
.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER
);
939 m_ListCtrl
.Show(dwShow
,dwShow
&(~CTGitPath::LOGACTIONS_UNVER
));
943 CTGitPath commonDir
= m_ListCtrl
.GetCommonDirectory(false);
945 if(this->m_bWholeProject
)
946 SetWindowText(m_sWindowTitle
+ _T(" - ") + commonDir
.GetWinPathString() + CString(_T(" (Whole Project)")));
948 SetWindowText(m_sWindowTitle
+ _T(" - ") + commonDir
.GetWinPathString());
951 // we don't have to block the commit dialog while we fetch the
952 // auto completion list.
953 m_pathwatcher
.ClearChangedPaths();
954 InterlockedExchange(&m_bBlock
, FALSE
);
955 if ((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE
)==TRUE
)
957 m_ListCtrl
.Block(TRUE
, TRUE
);
958 GetAutocompletionList();
959 m_ListCtrl
.Block(FALSE
, FALSE
);
963 DialogEnableWindow(IDC_SHOWUNVERSIONED
, true);
964 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
965 DialogEnableWindow(IDC_SELECTALL
, true);
966 if (m_ListCtrl
.HasChangeLists())
967 DialogEnableWindow(IDC_KEEPLISTS
, true);
968 if (m_ListCtrl
.HasLocks())
969 DialogEnableWindow(IDC_WHOLE_PROJECT
, true);
970 // we have the list, now signal the main thread about it
971 SendMessage(WM_AUTOLISTREADY
); // only send the message if the thread wasn't told to quit!
974 InterlockedExchange(&m_bRunThread
, FALSE
);
975 InterlockedExchange(&m_bThreadRunning
, FALSE
);
976 // force the cursor to normal
982 void CCommitDlg::OnCancel()
985 m_pathwatcher
.Stop();
990 if (m_bThreadRunning
)
992 InterlockedExchange(&m_bRunThread
, FALSE
);
993 WaitForSingleObject(m_pThread
->m_hThread
, 1000);
994 if (m_bThreadRunning
)
996 // we gave the thread a chance to quit. Since the thread didn't
997 // listen to us we have to kill it.
998 TerminateThread(m_pThread
->m_hThread
, (DWORD
)-1);
999 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1004 m_sLogMessage
= m_cLogMessage
.GetText();
1005 if (!m_sBugID
.IsEmpty())
1007 m_sBugID
.Replace(_T(", "), _T(","));
1008 m_sBugID
.Replace(_T(" ,"), _T(","));
1009 CString sBugID
= m_ProjectProperties
.sMessage
;
1010 sBugID
.Replace(_T("%BUGID%"), m_sBugID
);
1011 if (m_ProjectProperties
.bAppend
)
1012 m_sLogMessage
+= _T("\n") + sBugID
+ _T("\n");
1014 m_sLogMessage
= sBugID
+ _T("\n") + m_sLogMessage
;
1016 if (m_ProjectProperties
.sLogTemplate
.Compare(m_sLogMessage
) != 0)
1017 m_History
.AddEntry(m_sLogMessage
);
1020 CResizableStandAloneDialog::OnCancel();
1023 void CCommitDlg::OnBnClickedSelectall()
1025 m_tooltips
.Pop(); // hide the tooltips
1026 UINT state
= (m_SelectAll
.GetState() & 0x0003);
1027 if (state
== BST_INDETERMINATE
)
1029 // It is not at all useful to manually place the checkbox into the indeterminate state...
1030 // We will force this on to the unchecked state
1031 state
= BST_UNCHECKED
;
1032 m_SelectAll
.SetCheck(state
);
1034 m_ListCtrl
.SelectAll(state
== BST_CHECKED
);
1037 BOOL
CCommitDlg::PreTranslateMessage(MSG
* pMsg
)
1040 m_tooltips
.RelayEvent(pMsg
);
1044 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1049 if (pMsg
->message
== WM_KEYDOWN
)
1051 switch (pMsg
->wParam
)
1056 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1062 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
1064 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
1066 PostMessage(WM_COMMAND
, IDOK
);
1070 if ( GetFocus()==GetDlgItem(IDC_BUGID
) )
1072 // Pressing RETURN in the bug id control
1073 // moves the focus to the message
1074 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1082 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
1085 void CCommitDlg::Refresh()
1087 if (m_bThreadRunning
)
1090 InterlockedExchange(&m_bBlock
, TRUE
);
1091 m_pThread
= AfxBeginThread(StatusThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
1092 if (m_pThread
==NULL
)
1094 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1095 InterlockedExchange(&m_bBlock
, FALSE
);
1099 m_pThread
->m_bAutoDelete
= FALSE
;
1100 m_pThread
->ResumeThread();
1104 void CCommitDlg::OnBnClickedHelp()
1109 void CCommitDlg::OnBnClickedShowunversioned()
1111 m_tooltips
.Pop(); // hide the tooltips
1113 m_regAddBeforeCommit
= m_bShowUnversioned
;
1116 DWORD dwShow
= m_ListCtrl
.GetShowFlags();
1117 if (DWORD(m_regAddBeforeCommit
))
1118 dwShow
|= SVNSLC_SHOWUNVERSIONED
;
1120 dwShow
&= ~SVNSLC_SHOWUNVERSIONED
;
1121 if(dwShow
& SVNSLC_SHOWUNVERSIONED
)
1124 m_ListCtrl
.GetStatus(NULL
,false,false,true);
1126 m_ListCtrl
.GetStatus(&this->m_pathList
,false,false,true);
1128 m_ListCtrl
.Show(dwShow
,0,true,0,true);
1132 void CCommitDlg::OnStnClickedExternalwarning()
1137 void CCommitDlg::OnEnChangeLogmessage()
1142 LRESULT
CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
1145 if ((m_ListCtrl
.GetItemCount() == 0)&&(m_ListCtrl
.HasUnversionedItems())&&(!m_bShowUnversioned
))
1147 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED
, IDS_APPNAME
, MB_ICONINFORMATION
| MB_YESNO
)==IDYES
)
1149 m_bShowUnversioned
= TRUE
;
1150 DWORD dwShow
= GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS
| GitSLC_SHOWUNVERSIONED
| GitSLC_SHOWLOCKS
;
1151 m_ListCtrl
.Show(dwShow
);
1159 LRESULT
CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1165 LRESULT
CCommitDlg::OnFileDropped(WPARAM
, LPARAM
/*lParam*/)
1169 SetForegroundWindow();
1171 // if multiple files/folders are dropped
1172 // this handler is called for every single item
1174 // To avoid creating multiple refresh threads and
1175 // causing crashes, we only add the items to the
1176 // list control and start a timer.
1177 // When the timer expires, we start the refresh thread,
1178 // but only if it isn't already running - otherwise we
1179 // restart the timer.
1181 path
.SetFromWin((LPCTSTR
)lParam
);
1183 // just add all the items we get here.
1184 // if the item is versioned, the add will fail but nothing
1185 // more will happen.
1187 Git
.Add(CTGitPathList(path
), &m_ProjectProperties
, Git_depth_empty
, false, true, true);
1189 if (!m_ListCtrl
.HasPath(path
))
1191 if (m_pathList
.AreAllPathsFiles())
1193 m_pathList
.AddPath(path
);
1194 m_pathList
.RemoveDuplicates();
1195 m_updatedPathList
.AddPath(path
);
1196 m_updatedPathList
.RemoveDuplicates();
1200 // if the path list contains folders, we have to check whether
1201 // our just (maybe) added path is a child of one of those. If it is
1202 // a child of a folder already in the list, we must not add it. Otherwise
1203 // that path could show up twice in the list.
1204 bool bHasParentInList
= false;
1205 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
1207 if (m_pathList
[i
].IsAncestorOf(path
))
1209 bHasParentInList
= true;
1213 if (!bHasParentInList
)
1215 m_pathList
.AddPath(path
);
1216 m_pathList
.RemoveDuplicates();
1217 m_updatedPathList
.AddPath(path
);
1218 m_updatedPathList
.RemoveDuplicates();
1223 // Always start the timer, since the status of an existing item might have changed
1224 SetTimer(REFRESHTIMER
, 200, NULL
);
1225 ATLTRACE(_T("Item %s dropped, timer started\n"), path
.GetWinPath());
1230 LRESULT
CCommitDlg::OnAutoListReady(WPARAM
, LPARAM
)
1232 m_cLogMessage
.SetAutoCompletionList(m_autolist
, '*');
1236 //////////////////////////////////////////////////////////////////////////
1237 // functions which run in the status thread
1238 //////////////////////////////////////////////////////////////////////////
1240 void CCommitDlg::ParseRegexFile(const CString
& sFile
, std::map
<CString
, CString
>& mapRegex
)
1245 CStdioFile
file(sFile
, CFile::typeText
| CFile::modeRead
| CFile::shareDenyWrite
);
1246 while (m_bRunThread
&& file
.ReadString(strLine
))
1248 int eqpos
= strLine
.Find('=');
1250 rgx
= strLine
.Mid(eqpos
+1).Trim();
1253 while (((pos
= strLine
.Find(','))>=0)&&(pos
< eqpos
))
1255 mapRegex
[strLine
.Left(pos
)] = rgx
;
1256 strLine
= strLine
.Mid(pos
+1).Trim();
1258 mapRegex
[strLine
.Left(strLine
.Find('=')).Trim()] = rgx
;
1262 catch (CFileException
* pE
)
1264 TRACE("CFileException loading auto list regex file\n");
1269 void CCommitDlg::GetAutocompletionList()
1271 // the auto completion list is made of strings from each selected files.
1272 // the strings used are extracted from the files with regexes found
1273 // in the file "autolist.txt".
1274 // the format of that file is:
1275 // file extensions separated with commas '=' regular expression to use
1277 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1278 // .cpp = (?<=[^\s]::)\b\w+\b
1280 std::map
<CString
, CString
> mapRegex
;
1281 CString sRegexFile
= CPathUtils::GetAppDirectory();
1282 CRegDWORD regtimeout
= CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1283 DWORD timeoutvalue
= regtimeout
*1000;
1284 sRegexFile
+= _T("autolist.txt");
1287 ParseRegexFile(sRegexFile
, mapRegex
);
1288 SHGetFolderPath(NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, sRegexFile
.GetBuffer(MAX_PATH
+1));
1289 sRegexFile
.ReleaseBuffer();
1290 sRegexFile
+= _T("\\TortoiseGit\\autolist.txt");
1291 if (PathFileExists(sRegexFile
))
1293 ParseRegexFile(sRegexFile
, mapRegex
);
1295 DWORD starttime
= GetTickCount();
1297 // now we have two arrays of strings, where the first array contains all
1298 // file extensions we can use and the second the corresponding regex strings
1299 // to apply to those files.
1301 // the next step is to go over all files shown in the commit dialog
1302 // and scan them for strings we can use
1303 int nListItems
= m_ListCtrl
.GetItemCount();
1305 for (int i
=0; i
<nListItems
&& m_bRunThread
; ++i
)
1307 // stop parsing after timeout
1308 if ((!m_bRunThread
) || (GetTickCount() - starttime
> timeoutvalue
))
1311 CTGitPath
*path
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1316 CString sPartPath
=path
->GetGitPathString();
1317 m_autolist
.insert(sPartPath
);
1319 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1323 // add the path parts to the auto completion list too
1324 // CString sPartPath = entry->GetRelativeGitPath();
1325 // m_autolist.insert(sPartPath);
1330 while ((pos
= sPartPath
.Find('/', pos
)) >= 0)
1334 m_autolist
.insert(sPartPath
.Mid(pos
));
1337 // Last inserted entry is a file name.
1338 // Some users prefer to also list file name without extension.
1339 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE
))
1341 int dotPos
= sPartPath
.ReverseFind('.');
1342 if ((dotPos
>= 0) && (dotPos
> lastPos
))
1343 m_autolist
.insert(sPartPath
.Mid(lastPos
, dotPos
- lastPos
));
1346 if ((entry
->status
<= Git_wc_status_normal
)||(entry
->status
== Git_wc_status_ignored
))
1349 CString sExt
= entry
->GetPath().GetFileExtension();
1351 // find the regex string which corresponds to the file extension
1352 CString rdata
= mapRegex
[sExt
];
1353 if (rdata
.IsEmpty())
1356 ScanFile(entry
->GetPath().GetWinPathString(), rdata
);
1357 if ((entry
->textstatus
!= Git_wc_status_unversioned
) &&
1358 (entry
->textstatus
!= Git_wc_status_none
) &&
1359 (entry
->textstatus
!= Git_wc_status_ignored
) &&
1360 (entry
->textstatus
!= Git_wc_status_added
) &&
1361 (entry
->textstatus
!= Git_wc_status_normal
))
1363 CTGitPath basePath
= Git::GetPristinePath(entry
->GetPath());
1364 if (!basePath
.IsEmpty())
1365 ScanFile(basePath
.GetWinPathString(), rdata
);
1369 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime
);
1372 void CCommitDlg::ScanFile(const CString
& sFilePath
, const CString
& sRegex
)
1374 wstring sFileContent
;
1375 HANDLE hFile
= CreateFile(sFilePath
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
1376 if (hFile
!= INVALID_HANDLE_VALUE
)
1378 DWORD size
= GetFileSize(hFile
, NULL
);
1379 if (size
> 1000000L)
1381 // no files bigger than 1 Meg
1385 // allocate memory to hold file contents
1386 char * buffer
= new char[size
];
1388 ReadFile(hFile
, buffer
, size
, &readbytes
, NULL
);
1391 IsTextUnicode(buffer
, readbytes
, &opts
);
1392 if (opts
& IS_TEXT_UNICODE_NULL_BYTES
)
1397 if (opts
& IS_TEXT_UNICODE_UNICODE_MASK
)
1399 sFileContent
= wstring((wchar_t*)buffer
, readbytes
/sizeof(WCHAR
));
1401 if ((opts
& IS_TEXT_UNICODE_NOT_UNICODE_MASK
)||(opts
== 0))
1403 int ret
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, NULL
, 0);
1404 wchar_t * pWideBuf
= new wchar_t[ret
];
1405 int ret2
= MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, (LPCSTR
)buffer
, readbytes
, pWideBuf
, ret
);
1407 sFileContent
= wstring(pWideBuf
, ret
);
1412 if (sFileContent
.empty()|| !m_bRunThread
)
1419 const tr1::wregex
regCheck(sRegex
, tr1::regex_constants::icase
| tr1::regex_constants::ECMAScript
);
1420 const tr1::wsregex_iterator end
;
1421 wstring s
= sFileContent
;
1422 for (tr1::wsregex_iterator
it(s
.begin(), s
.end(), regCheck
); it
!= end
; ++it
)
1424 const tr1::wsmatch match
= *it
;
1425 for (size_t i
=1; i
<match
.size(); ++i
)
1427 if (match
[i
].second
-match
[i
].first
)
1429 ATLTRACE(_T("matched keyword : %s\n"), wstring(match
[i
]).c_str());
1430 m_autolist
.insert(wstring(match
[i
]).c_str());
1435 catch (exception
) {}
1438 // CSciEditContextMenuInterface
1439 void CCommitDlg::InsertMenuItems(CMenu
& mPopup
, int& nCmd
)
1441 CString
sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST
));
1442 m_nPopupPasteListCmd
= nCmd
++;
1443 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteListCmd
, sMenuItemText
);
1445 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1446 if(m_History
.GetCount() > 0)
1448 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE
);
1449 m_nPopupPasteLastMessage
= nCmd
++;
1450 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupPasteLastMessage
, sMenuItemText
);
1452 sMenuItemText
.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY
);
1453 m_nPopupRecentMessage
= nCmd
++;
1454 mPopup
.AppendMenu(MF_STRING
| MF_ENABLED
, m_nPopupRecentMessage
, sMenuItemText
);
1460 bool CCommitDlg::HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
)
1465 if (cmd
== m_nPopupPasteListCmd
)
1468 int nListItems
= m_ListCtrl
.GetItemCount();
1469 for (int i
=0; i
<nListItems
; ++i
)
1471 CTGitPath
* entry
= (CTGitPath
*)m_ListCtrl
.GetItemData(i
);
1472 if (entry
&&entry
->m_Checked
)
1475 CString status
= entry
->GetActionName();
1476 if(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1479 //git_wc_status_kind status = entry->status;
1480 WORD langID
= (WORD
)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1481 if (m_ProjectProperties
.bFileListInEnglish
)
1484 line
.Format(_T("%-10s %s\r\n"),status
, (LPCTSTR
)m_ListCtrl
.GetItemText(i
,0));
1488 pSciEdit
->InsertText(logmsg
);
1492 if(cmd
== m_nPopupPasteLastMessage
)
1494 if(m_History
.GetCount() ==0 )
1498 logmsg
+=m_History
.GetEntry(0);
1499 pSciEdit
->InsertText(logmsg
);
1503 if(cmd
== m_nPopupRecentMessage
)
1505 OnBnClickedHistory();
1511 void CCommitDlg::OnTimer(UINT_PTR nIDEvent
)
1515 case ENDDIALOGTIMER
:
1516 KillTimer(ENDDIALOGTIMER
);
1520 if (m_bThreadRunning
)
1522 SetTimer(REFRESHTIMER
, 200, NULL
);
1523 ATLTRACE("Wait some more before refreshing\n");
1527 KillTimer(REFRESHTIMER
);
1528 ATLTRACE("Refreshing after items dropped\n");
1533 __super::OnTimer(nIDEvent
);
1536 void CCommitDlg::OnBnClickedHistory()
1538 m_tooltips
.Pop(); // hide the tooltips
1539 if (m_pathList
.GetCount() == 0)
1542 CHistoryDlg historyDlg
;
1543 historyDlg
.SetHistory(m_History
);
1544 if (historyDlg
.DoModal() != IDOK
)
1547 CString sMsg
= historyDlg
.GetSelectedText();
1548 if (sMsg
!= m_cLogMessage
.GetText().Left(sMsg
.GetLength()))
1550 CString sBugID
= m_ProjectProperties
.GetBugIDFromLog(sMsg
);
1551 if (!sBugID
.IsEmpty())
1553 SetDlgItemText(IDC_BUGID
, sBugID
);
1555 if (m_ProjectProperties
.sLogTemplate
.Compare(m_cLogMessage
.GetText())!=0)
1556 m_cLogMessage
.InsertText(sMsg
, !m_cLogMessage
.GetText().IsEmpty());
1558 m_cLogMessage
.SetText(sMsg
);
1562 GetDlgItem(IDC_LOGMESSAGE
)->SetFocus();
1566 void CCommitDlg::OnBnClickedBugtraqbutton()
1568 m_tooltips
.Pop(); // hide the tooltips
1569 CString sMsg
= m_cLogMessage
.GetText();
1571 if (m_BugTraqProvider
== NULL
)
1574 BSTR parameters
= m_bugtraq_association
.GetParameters().AllocSysString();
1575 BSTR commonRoot
= SysAllocString(g_Git
.m_CurrentDir
);
1576 SAFEARRAY
*pathList
= SafeArrayCreateVector(VT_BSTR
, 0, m_pathList
.GetCount());
1578 for (LONG index
= 0; index
< m_pathList
.GetCount(); ++index
)
1579 SafeArrayPutElement(pathList
, &index
, m_pathList
[index
].GetGitPathString().AllocSysString());
1581 BSTR originalMessage
= sMsg
.AllocSysString();
1583 // m_revProps.clear();
1585 // first try the IBugTraqProvider2 interface
1586 CComPtr
<IBugTraqProvider2
> pProvider2
= NULL
;
1587 HRESULT hr
= m_BugTraqProvider
.QueryInterface(&pProvider2
);
1590 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1591 BSTR repositoryRoot
= g_Git
.m_CurrentDir
.AllocSysString();
1592 BSTR bugIDOut
= NULL
;
1593 GetDlgItemText(IDC_BUGID
, m_sBugID
);
1594 BSTR bugID
= m_sBugID
.AllocSysString();
1595 SAFEARRAY
* revPropNames
= NULL
;
1596 SAFEARRAY
* revPropValues
= NULL
;
1597 if (FAILED(hr
= pProvider2
->GetCommitMessage2(GetSafeHwnd(), parameters
, repositoryRoot
, commonRoot
, pathList
, originalMessage
, bugID
, &bugIDOut
, &revPropNames
, &revPropValues
, &temp
)))
1600 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1601 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1607 m_sBugID
= bugIDOut
;
1608 SysFreeString(bugIDOut
);
1609 SetDlgItemText(IDC_BUGID
, m_sBugID
);
1611 SysFreeString(bugID
);
1612 SysFreeString(repositoryRoot
);
1613 m_cLogMessage
.SetText(temp
);
1614 BSTR HUGEP
*pbRevNames
;
1615 BSTR HUGEP
*pbRevValues
;
1617 HRESULT hr1
= SafeArrayAccessData(revPropNames
, (void HUGEP
**)&pbRevNames
);
1620 HRESULT hr2
= SafeArrayAccessData(revPropValues
, (void HUGEP
**)&pbRevValues
);
1623 if (revPropNames
->rgsabound
->cElements
== revPropValues
->rgsabound
->cElements
)
1625 for (ULONG i
= 0; i
< revPropNames
->rgsabound
->cElements
; i
++)
1627 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1630 SafeArrayUnaccessData(revPropValues
);
1632 SafeArrayUnaccessData(revPropNames
);
1635 SafeArrayDestroy(revPropNames
);
1637 SafeArrayDestroy(revPropValues
);
1642 // if IBugTraqProvider2 failed, try IBugTraqProvider
1643 CComPtr
<IBugTraqProvider
> pProvider
= NULL
;
1644 hr
= m_BugTraqProvider
.QueryInterface(&pProvider
);
1648 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, (LPCTSTR
)m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1649 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1653 if (FAILED(hr
= pProvider
->GetCommitMessage(GetSafeHwnd(), parameters
, commonRoot
, pathList
, originalMessage
, &temp
)))
1656 sErr
.Format(IDS_ERR_FAILEDISSUETRACKERCOM
, m_bugtraq_association
.GetProviderName(), _com_error(hr
).ErrorMessage());
1657 CMessageBox::Show(m_hWnd
, sErr
, _T("TortoiseGit"), MB_ICONERROR
);
1660 m_cLogMessage
.SetText(temp
);
1662 m_sLogMessage
= m_cLogMessage
.GetText();
1663 if (!m_ProjectProperties
.sMessage
.IsEmpty())
1665 CString sBugID
= m_ProjectProperties
.FindBugID(m_sLogMessage
);
1666 if (!sBugID
.IsEmpty())
1668 SetDlgItemText(IDC_BUGID
, sBugID
);
1672 m_cLogMessage
.SetFocus();
1674 SysFreeString(parameters
);
1675 SysFreeString(commonRoot
);
1676 SafeArrayDestroy(pathList
);
1677 SysFreeString(originalMessage
);
1678 SysFreeString(temp
);
1682 void CCommitDlg::FillPatchView()
1684 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
1686 m_patchViewdlg
.m_ctrlPatchView
.SetText(CString());
1688 POSITION pos
=m_ListCtrl
.GetFirstSelectedItemPosition();
1689 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, FALSE
);
1694 int nSelect
= m_ListCtrl
.GetNextSelectedItem(pos
);
1695 CTGitPath
* p
=(CTGitPath
*)m_ListCtrl
.GetItemData(nSelect
);
1696 if(p
&& !(p
->m_Action
&CTGitPath::LOGACTIONS_UNVER
) )
1698 cmd
.Format(_T("git.exe diff -- \"%s\""),p
->GetGitPathString());
1699 g_Git
.Run(cmd
,&out
,CP_ACP
);
1705 m_patchViewdlg
.m_ctrlPatchView
.SetText(out
);
1706 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_SETREADONLY
, TRUE
);
1707 m_patchViewdlg
.m_ctrlPatchView
.Call(SCI_GOTOPOS
, 0);
1712 LRESULT
CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM wparam
, LPARAM lparam
)
1714 TRACE("OnGitStatusListCtrlItemChanged %d\r\n", wparam
);
1715 this->FillPatchView();
1720 LRESULT
CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM
, LPARAM
)
1726 void CCommitDlg::UpdateOKButton()
1729 BOOL bValidLogSize
= FALSE
;
1731 if (m_cLogMessage
.GetText().GetLength() >= m_ProjectProperties
.nMinLogSize
)
1732 bValidLogSize
= !m_bBlock
;
1734 LONG nSelectedItems
= m_ListCtrl
.GetSelected();
1735 DialogEnableWindow(IDOK
, bValidLogSize
&& nSelectedItems
>0);
1740 LRESULT
CCommitDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
1744 if (wParam
== IDC_SPLITTER
)
1746 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
1747 DoSize(pHdr
->delta
);
1752 return __super::DefWindowProc(message
, wParam
, lParam
);
1755 void CCommitDlg::SetSplitterRange()
1757 if ((m_ListCtrl
)&&(m_cLogMessage
))
1760 m_cLogMessage
.GetWindowRect(rcTop
);
1761 ScreenToClient(rcTop
);
1763 m_ListCtrl
.GetWindowRect(rcMiddle
);
1764 ScreenToClient(rcMiddle
);
1765 if (rcMiddle
.Height() && rcMiddle
.Width())
1766 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
1770 void CCommitDlg::DoSize(int delta
)
1772 RemoveAnchor(IDC_MESSAGEGROUP
);
1773 RemoveAnchor(IDC_LOGMESSAGE
);
1774 RemoveAnchor(IDC_SPLITTER
);
1775 RemoveAnchor(IDC_SIGNOFF
);
1776 RemoveAnchor(IDC_COMMIT_AMEND
);
1777 RemoveAnchor(IDC_LISTGROUP
);
1778 RemoveAnchor(IDC_FILELIST
);
1779 RemoveAnchor(IDC_TEXT_INFO
);
1780 RemoveAnchor(IDC_VIEW_PATCH
);
1782 CSplitterControl::ChangeHeight(&m_cLogMessage
, delta
, CW_TOPALIGN
);
1783 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP
), delta
, CW_TOPALIGN
);
1784 CSplitterControl::ChangeHeight(&m_ListCtrl
, -delta
, CW_BOTTOMALIGN
);
1785 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP
), -delta
, CW_BOTTOMALIGN
);
1786 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF
),0,delta
);
1787 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND
),0,delta
);
1788 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO
),0,delta
);
1789 CSplitterControl::ChangePos(GetDlgItem(IDC_VIEW_PATCH
),0,delta
);
1791 AddAnchor(IDC_VIEW_PATCH
,TOP_RIGHT
);
1792 AddAnchor(IDC_MESSAGEGROUP
, TOP_LEFT
, TOP_RIGHT
);
1793 AddAnchor(IDC_LOGMESSAGE
, TOP_LEFT
, TOP_RIGHT
);
1794 AddAnchor(IDC_SPLITTER
, TOP_LEFT
, TOP_RIGHT
);
1795 AddAnchor(IDC_LISTGROUP
, TOP_LEFT
, BOTTOM_RIGHT
);
1796 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
1797 AddAnchor(IDC_SIGNOFF
,TOP_RIGHT
);
1798 AddAnchor(IDC_COMMIT_AMEND
,TOP_LEFT
);
1799 AddAnchor(IDC_TEXT_INFO
,TOP_RIGHT
);
1801 // adjust the minimum size of the dialog to prevent the resizing from
1802 // moving the list control too far down.
1804 m_cLogMessage
.GetClientRect(rcLogMsg
);
1805 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_LogMsgOrigRect
.Height()+rcLogMsg
.Height()));
1808 m_cLogMessage
.Invalidate();
1809 GetDlgItem(IDC_LOGMESSAGE
)->Invalidate();
1812 void CCommitDlg::OnSize(UINT nType
, int cx
, int cy
)
1814 // first, let the resizing take place
1815 __super::OnSize(nType
, cx
, cy
);
1823 void CCommitDlg::OnBnClickedSignOff()
1828 username
=g_Git
.GetUserName();
1829 email
=g_Git
.GetUserEmail();
1830 username
.Remove(_T('\n'));
1831 email
.Remove(_T('\n'));
1832 str
.Format(_T("Signed-off-by: %s <%s>\n"),username
,email
);
1834 m_cLogMessage
.SetText(m_cLogMessage
.GetText()+_T("\r\n\r\n")+str
);
1837 void CCommitDlg::OnBnClickedCommitAmend()
1840 if(this->m_bCommitAmend
&& this->m_AmendStr
.IsEmpty())
1843 rev
.GetCommit(CString(_T("HEAD")));
1844 m_AmendStr
=rev
.GetSubject()+_T("\n")+rev
.GetBody();
1847 if(this->m_bCommitAmend
)
1849 this->m_NoAmendStr
=this->m_cLogMessage
.GetText();
1850 m_cLogMessage
.SetText(m_AmendStr
);
1854 this->m_AmendStr
=this->m_cLogMessage
.GetText();
1855 m_cLogMessage
.SetText(m_NoAmendStr
);
1859 void CCommitDlg::OnBnClickedWholeProject()
1861 m_tooltips
.Pop(); // hide the tooltips
1867 m_ListCtrl
.GetStatus(NULL
,true,false,true);
1869 m_ListCtrl
.GetStatus(&this->m_pathList
,true,false,true);
1871 m_ListCtrl
.Show(m_ListCtrl
.GetShowFlags());
1874 CTGitPath commonDir
= m_ListCtrl
.GetCommonDirectory(false);
1876 if(this->m_bWholeProject
)
1877 SetWindowText(m_sWindowTitle
+ _T(" - ") + CString(_T("Whole Project")));
1879 SetWindowText(m_sWindowTitle
+ _T(" - ") + commonDir
.GetWinPathString());
1883 void CCommitDlg::OnFocusMessage()
1885 m_cLogMessage
.SetFocus();
1888 void CCommitDlg::OnScnUpdateUI(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1890 int pos
=this->m_cLogMessage
.Call(SCI_GETCURRENTPOS
);
1891 int line
=this->m_cLogMessage
.Call(SCI_LINEFROMPOSITION
,pos
);
1892 int column
=this->m_cLogMessage
.Call(SCI_GETCOLUMN
,pos
);
1895 str
.Format(_T("%d/%d"),line
+1,column
+1);
1896 this->GetDlgItem(IDC_TEXT_INFO
)->SetWindowText(str
);
1901 void CCommitDlg::OnStnClickedViewPatch()
1903 m_patchViewdlg
.m_pProjectProperties
= &this->m_ProjectProperties
;
1904 m_patchViewdlg
.m_ParentCommitDlg
= this;
1905 if(!IsWindow(this->m_patchViewdlg
.m_hWnd
))
1907 m_patchViewdlg
.Create(IDD_PATCH_VIEW
,this);
1909 this->GetWindowRect(&rect
);
1911 m_patchViewdlg
.SetWindowPos(NULL
,rect
.right
,rect
.top
,rect
.Width(),rect
.Height(),
1912 SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
1914 m_patchViewdlg
.m_ctrlPatchView
.MoveWindow(0,0,rect
.Width(),rect
.Height());
1915 m_patchViewdlg
.ShowWindow(SW_SHOW
);
1917 ShowViewPatchText(false);
1922 m_patchViewdlg
.ShowWindow(SW_HIDE
);
1923 m_patchViewdlg
.DestroyWindow();
1924 ShowViewPatchText(true);
1926 this->m_ctrlShowPatch
.Invalidate();
1929 void CCommitDlg::OnMoving(UINT fwSide
, LPRECT pRect
)
1931 __super::OnMoving(fwSide
, pRect
);
1933 if (::IsWindow(m_patchViewdlg
.m_hWnd
))
1936 m_patchViewdlg
.GetWindowRect(&patchrect
);
1937 if (::IsWindow(m_hWnd
))
1940 GetWindowRect(&thisrect
);
1941 if (patchrect
.left
== thisrect
.right
)
1943 m_patchViewdlg
.SetWindowPos(NULL
, patchrect
.left
- (thisrect
.left
- pRect
->left
), patchrect
.top
- (thisrect
.top
- pRect
->top
),
1944 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
1951 void CCommitDlg::OnSizing(UINT fwSide
, LPRECT pRect
)
1953 __super::OnSizing(fwSide
, pRect
);
1955 if(::IsWindow(this->m_patchViewdlg
.m_hWnd
))
1957 CRect thisrect
, patchrect
;
1958 this->GetWindowRect(thisrect
);
1959 this->m_patchViewdlg
.GetWindowRect(patchrect
);
1960 if(thisrect
.right
==patchrect
.left
)
1962 patchrect
.left
-= (thisrect
.right
- pRect
->right
);
1963 patchrect
.right
-= (thisrect
.right
- pRect
->right
);
1965 if( patchrect
.bottom
== thisrect
.bottom
)
1967 patchrect
.bottom
-= (thisrect
.bottom
- pRect
->bottom
);
1969 if( patchrect
.top
== thisrect
.top
)
1971 patchrect
.top
-= thisrect
.top
-pRect
->top
;
1973 m_patchViewdlg
.MoveWindow(patchrect
);
1978 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1981 TRACE("Item Changed\r\n");
1984 int CCommitDlg::CheckHeadDetach()
1987 if(g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
,output
))
1989 if(CMessageBox::Show(NULL
,_T("<ct=0x0000FF>Current HEAD Detached</ct>, you are working on (no branch)\nDo you want create branch now?"),
1990 _T("TortoiseGit"),MB_YESNO
|MB_ICONWARNING
) == IDYES
)
1992 CAppUtils::CreateBranchTag(FALSE
,NULL
,true);