1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
4 // Copyright (C) 2003-2011, 2013 - TortoiseSVN
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.
21 #include "TortoiseProc.h"
22 #include "PathUtils.h"
24 #include "StringUtils.h"
25 #include "MessageBox.h"
29 #include "UnicodeUtils.h"
30 #include "ExportDlg.h"
31 #include "ProgressDlg.h"
32 #include "GitAdminDir.h"
33 #include "ProgressDlg.h"
34 #include "BrowseFolder.h"
35 #include "DirFileEnum.h"
36 #include "MessageBox.h"
37 #include "GitStatus.h"
38 #include "CreateBranchTagDlg.h"
39 #include "GitSwitchDlg.h"
41 #include "DeleteConflictDlg.h"
42 #include "ChangedDlg.h"
43 #include "SendMailDlg.h"
44 #include "GitProgressDlg.h"
46 #include "CommitDlg.h"
48 #include "MergeAbortDlg.h"
50 #include "..\Settings\Settings.h"
52 #include "SVNDCommitDlg.h"
53 #include "requestpulldlg.h"
54 #include "PullFetchDlg.h"
55 #include "FileDiffDlg.h"
56 #include "RebaseDlg.h"
58 #include "StashSave.h"
59 #include "IgnoreDlg.h"
60 #include "FormatMessageWrapper.h"
61 #include "SmartHandle.h"
62 #include "BisectStartDlg.h"
63 #include "SysProgressDlg.h"
64 #include "UserPassword.h"
68 CAppUtils::CAppUtils(void)
72 CAppUtils::~CAppUtils(void)
76 bool CAppUtils::StashSave()
80 if (dlg
.DoModal() == IDOK
)
83 cmd
= _T("git.exe stash save");
85 if (CAppUtils::GetMsysgitVersion() >= 0x01070700)
87 if (dlg
.m_bIncludeUntracked
)
88 cmd
+= _T(" --include-untracked");
93 if (!dlg
.m_sMessage
.IsEmpty())
95 CString message
= dlg
.m_sMessage
;
96 message
.Replace(_T("\""), _T("\"\""));
97 cmd
+= _T(" -- \"") + message
+ _T("\"");
100 CProgressDlg progress
;
101 progress
.m_GitCmd
= cmd
;
102 return (progress
.DoModal() == IDOK
);
107 bool CAppUtils::StashApply(CString ref
, bool showChanges
/* true */)
110 cmd
= _T("git.exe stash apply ");
111 if (ref
.Find(_T("refs/")) == 0)
113 if (ref
.Find(_T("stash{")) == 0)
114 ref
= _T("stash@") + ref
.Mid(5);
117 CSysProgressDlg sysProgressDlg
;
118 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
119 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
120 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
121 sysProgressDlg
.SetShowProgressBar(false);
122 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
123 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
125 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
127 sysProgressDlg
.Stop();
129 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
130 if (ret
&& !(ret
== 1 && hasConflicts
))
132 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHAPPLYFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
137 message
.LoadString(IDS_PROC_STASHAPPLYSUCCESS
);
139 message
.LoadString(IDS_PROC_STASHAPPLYFAILEDCONFLICTS
);
142 if(CMessageBox::Show(NULL
,message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
))
143 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
146 dlg
.m_pathList
.AddPath(CTGitPath());
153 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
160 bool CAppUtils::StashPop(bool showChanges
/* true */)
163 cmd
=_T("git.exe stash pop ");
165 CSysProgressDlg sysProgressDlg
;
166 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
167 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
168 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
169 sysProgressDlg
.SetShowProgressBar(false);
170 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
171 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
173 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
175 sysProgressDlg
.Stop();
177 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
178 if (ret
&& !(ret
== 1 && hasConflicts
))
180 CMessageBox::Show(NULL
,CString(MAKEINTRESOURCE(IDS_PROC_STASHPOPFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
185 message
.LoadString(IDS_PROC_STASHPOPSUCCESS
);
187 message
.LoadString(IDS_PROC_STASHPOPFAILEDCONFLICTS
);
190 if(CMessageBox::Show(NULL
,CString(message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
)))
191 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
194 dlg
.m_pathList
.AddPath(CTGitPath());
201 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
208 BOOL
CAppUtils::StartExtMerge(
209 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
210 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
,
214 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
215 CString ext
= mergedfile
.GetFileExtension();
216 CString com
= regCom
;
217 bool bInternal
= false;
221 // is there an extension specific merge tool?
222 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
223 if (!CString(mergetool
).IsEmpty())
228 // is there a filename specific merge tool?
229 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\.") + mergedfile
.GetFilename().MakeLower());
230 if (!CString(mergetool
).IsEmpty())
235 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
237 // Maybe we should use TortoiseIDiff?
238 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
239 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
240 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
241 (ext
== _T(".tif")) || (ext
== _T(".tiff")) ||
242 (ext
== _T(".dib")) || (ext
== _T(".emf")))
244 com
= CPathUtils::GetAppDirectory() + _T("TortoiseGitIDiff.exe");
245 com
= _T("\"") + com
+ _T("\"");
246 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /result:%merged");
247 com
= com
+ _T(" /basetitle:%bname /theirstitle:%tname /minetitle:%yname");
251 // use TortoiseGitMerge
253 com
= CPathUtils::GetAppDirectory() + _T("TortoiseGitMerge.exe");
254 com
= _T("\"") + com
+ _T("\"");
255 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
256 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
257 com
+= _T(" /saverequired");
261 s
.Format(L
" /resolvemsghwnd:%I64d", (__int64
)resolveMsgHwnd
);
265 if (!g_sGroupingUUID
.IsEmpty())
267 com
+= L
" /groupuuid:\"";
268 com
+= g_sGroupingUUID
;
272 // check if the params are set. If not, just add the files to the command line
273 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
275 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
276 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
277 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
278 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
280 if (basefile
.IsEmpty())
282 com
.Replace(_T("/base:%base"), _T(""));
283 com
.Replace(_T("%base"), _T(""));
286 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
287 if (theirfile
.IsEmpty())
289 com
.Replace(_T("/theirs:%theirs"), _T(""));
290 com
.Replace(_T("%theirs"), _T(""));
293 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
294 if (yourfile
.IsEmpty())
296 com
.Replace(_T("/mine:%mine"), _T(""));
297 com
.Replace(_T("%mine"), _T(""));
300 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
301 if (mergedfile
.IsEmpty())
303 com
.Replace(_T("/merged:%merged"), _T(""));
304 com
.Replace(_T("%merged"), _T(""));
307 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
308 if (basename
.IsEmpty())
310 if (basefile
.IsEmpty())
312 com
.Replace(_T("/basename:%bname"), _T(""));
313 com
.Replace(_T("%bname"), _T(""));
317 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
321 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
322 if (theirname
.IsEmpty())
324 if (theirfile
.IsEmpty())
326 com
.Replace(_T("/theirsname:%tname"), _T(""));
327 com
.Replace(_T("%tname"), _T(""));
331 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
335 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
336 if (yourname
.IsEmpty())
338 if (yourfile
.IsEmpty())
340 com
.Replace(_T("/minename:%yname"), _T(""));
341 com
.Replace(_T("%yname"), _T(""));
345 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
349 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
350 if (mergedname
.IsEmpty())
352 if (mergedfile
.IsEmpty())
354 com
.Replace(_T("/mergedname:%mname"), _T(""));
355 com
.Replace(_T("%mname"), _T(""));
359 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
363 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
365 if ((bReadOnly
)&&(bInternal
))
366 com
+= _T(" /readonly");
368 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
376 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
379 // use TortoiseGitMerge
380 viewer
= CPathUtils::GetAppDirectory();
381 viewer
+= _T("TortoiseGitMerge.exe");
383 viewer
= _T("\"") + viewer
+ _T("\"");
384 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
385 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
387 viewer
+= _T(" /reversedpatch");
388 if (!sOriginalDescription
.IsEmpty())
389 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
390 if (!sPatchedDescription
.IsEmpty())
391 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
392 if (!g_sGroupingUUID
.IsEmpty())
394 viewer
+= L
" /groupuuid:\"";
395 viewer
+= g_sGroupingUUID
;
398 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
405 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
407 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file2
.GetFilename().MakeLower());
408 if (!difftool
.IsEmpty())
410 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file1
.GetFilename().MakeLower());
411 if (!difftool
.IsEmpty())
414 // Is there an extension specific diff tool?
415 CString ext
= file2
.GetFileExtension().MakeLower();
418 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
419 if (!difftool
.IsEmpty())
421 // Maybe we should use TortoiseIDiff?
422 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
423 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
424 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
425 (ext
== _T(".dib")) || (ext
== _T(".emf")))
428 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitIDiff.exe") + _T("\"") +
429 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname") +
430 L
" /groupuuid:\"" + g_sGroupingUUID
+ L
"\"";
434 // Finally, pick a generic external diff tool
435 difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
439 bool CAppUtils::StartExtDiff(
440 const CString
& file1
, const CString
& file2
,
441 const CString
& sName1
, const CString
& sName2
,
442 const CString
& originalFile1
, const CString
& originalFile2
,
443 const git_revnum_t
& hash1
, const git_revnum_t
& hash2
,
444 const DiffFlags
& flags
, int jumpToLine
)
448 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
449 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
451 viewer
= PickDiffTool(file1
, file2
);
452 // If registry entry for a diff program is commented out, use TortoiseGitMerge.
453 bool bCommentedOut
= viewer
.Left(1) == _T("#");
454 if (flags
.bAlternativeTool
)
456 // Invert external vs. internal diff tool selection.
458 viewer
.Delete(0); // uncomment
462 else if (bCommentedOut
)
466 bool bInternal
= viewer
.IsEmpty();
470 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitMerge.exe") + _T("\"") +
471 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
472 if (!g_sGroupingUUID
.IsEmpty())
474 viewer
+= L
" /groupuuid:\"";
475 viewer
+= g_sGroupingUUID
;
479 viewer
+= _T(" /blame");
481 // check if the params are set. If not, just add the files to the command line
482 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
484 viewer
+= _T(" \"")+file1
+_T("\"");
485 viewer
+= _T(" \"")+file2
+_T("\"");
487 if (viewer
.Find(_T("%base")) >= 0)
489 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
491 if (viewer
.Find(_T("%mine")) >= 0)
493 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
496 if (sName1
.IsEmpty())
497 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
499 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
501 if (sName2
.IsEmpty())
502 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
504 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
506 viewer
.Replace(_T("%bpath"), _T("\"") + originalFile1
+ _T("\""));
507 viewer
.Replace(_T("%ypath"), _T("\"") + originalFile2
+ _T("\""));
509 viewer
.Replace(_T("%brev"), _T("\"") + hash1
+ _T("\""));
510 viewer
.Replace(_T("%yrev"), _T("\"") + hash2
+ _T("\""));
512 if (flags
.bReadOnly
&& bInternal
)
513 viewer
+= _T(" /readonly");
518 temp
.Format(_T(" /line:%d"), jumpToLine
);
522 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
525 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
528 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
530 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
532 // use TortoiseGitUDiff
533 viewer
= CPathUtils::GetAppDirectory();
534 viewer
+= _T("TortoiseGitUDiff.exe");
535 // enquote the path to TortoiseGitUDiff
536 viewer
= _T("\"") + viewer
+ _T("\"");
538 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
539 if (!g_sGroupingUUID
.IsEmpty())
541 viewer
+= L
" /groupuuid:\"";
542 viewer
+= g_sGroupingUUID
;
546 if (viewer
.Find(_T("%1"))>=0)
548 if (viewer
.Find(_T("\"%1\"")) >= 0)
549 viewer
.Replace(_T("%1"), patchfile
);
551 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
554 viewer
+= _T(" \"") + patchfile
+ _T("\"");
555 if (viewer
.Find(_T("%title")) >= 0)
557 viewer
.Replace(_T("%title"), title
);
560 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
567 BOOL
CAppUtils::StartTextViewer(CString file
)
570 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
572 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
573 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
576 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
577 std::unique_ptr
<TCHAR
[]> buf(new TCHAR
[len
+ 1]);
578 ExpandEnvironmentStrings(viewer
, buf
.get(), len
);
580 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
581 std::unique_ptr
<TCHAR
[]> buf2(new TCHAR
[len
+ 1]);
582 ExpandEnvironmentStrings(file
, buf2
.get(), len
);
584 file
= _T("\"")+file
+_T("\"");
585 if (viewer
.IsEmpty())
587 viewer
= _T("RUNDLL32 Shell32,OpenAs_RunDLL");
589 if (viewer
.Find(_T("\"%1\"")) >= 0)
591 viewer
.Replace(_T("\"%1\""), file
);
593 else if (viewer
.Find(_T("%1")) >= 0)
595 viewer
.Replace(_T("%1"), file
);
603 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
610 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
613 CAutoFile hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
616 length
= ::GetFileSize(hFile
, NULL
);
623 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
626 HDC hScreenDC
= ::GetDC(NULL
);
627 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
628 ::ReleaseDC(NULL
, hScreenDC
);
630 logFont
.lfEscapement
= 0;
631 logFont
.lfOrientation
= 0;
632 logFont
.lfWeight
= FW_NORMAL
;
633 logFont
.lfItalic
= 0;
634 logFont
.lfUnderline
= 0;
635 logFont
.lfStrikeOut
= 0;
636 logFont
.lfCharSet
= DEFAULT_CHARSET
;
637 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
638 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
639 logFont
.lfQuality
= DRAFT_QUALITY
;
640 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
641 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
642 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
645 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
659 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
660 key
= g_Git
.GetConfigValue(cmd
);
668 CString proc
=CPathUtils::GetAppDirectory();
669 proc
+= _T("pageant.exe \"");
673 CString tempfile
= GetTempFile();
674 ::DeleteFile(tempfile
);
676 proc
+= _T(" -c \"");
677 proc
+= CPathUtils::GetAppDirectory();
678 proc
+= _T("tgittouch.exe\"");
683 CString appDir
= CPathUtils::GetAppDirectory();
684 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true, &appDir
);
689 while(!::PathFileExists(tempfile
))
694 break; //timeout 5 minutes
699 CMessageBox::Show(NULL
, IDS_ERR_PAEGENTTIMEOUT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
701 ::DeleteFile(tempfile
);
704 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
, bool uac
)
706 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
707 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
708 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
712 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
714 LaunchApplication(sCmd
, NULL
, false, NULL
, uac
);
717 bool CAppUtils::LaunchRemoteSetting()
719 CTGitPath
path(g_Git
.m_CurrentDir
);
720 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
721 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
722 dlg
.SetTreeWidth(220);
723 dlg
.m_DefaultPage
= _T("gitremote");
730 * Launch the external blame viewer
732 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
734 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
735 viewer
+= _T("TortoiseGitBlame.exe");
736 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
737 //viewer += _T(" \"") + sLogFile + _T("\"");
738 //viewer += _T(" \"") + sOriginalFile + _T("\"");
739 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
740 viewer
+= CString(_T(" /rev:"))+Rev
;
741 if (!g_sGroupingUUID
.IsEmpty())
743 viewer
+= L
" /groupuuid:\"";
744 viewer
+= g_sGroupingUUID
;
747 viewer
+= _T(" ")+sParams
;
749 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
752 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
757 bool bStyled
= false;
758 pWnd
->GetWindowText(sText
);
759 // the rich edit control doesn't count the CR char!
760 // to be exact: CRLF is treated as one char.
761 sText
.Remove(_T('\r'));
763 // style each line separately
768 nNewlinePos
= sText
.Find('\n', offset
);
769 CString sLine
= nNewlinePos
>= 0 ? sText
.Mid(offset
, nNewlinePos
- offset
) : sText
.Mid(offset
);
773 while (FindStyleChars(sLine
, '*', start
, end
))
775 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
776 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
777 SetCharFormat(pWnd
, CFM_BOLD
, CFE_BOLD
);
783 while (FindStyleChars(sLine
, '^', start
, end
))
785 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
786 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
787 SetCharFormat(pWnd
, CFM_ITALIC
, CFE_ITALIC
);
793 while (FindStyleChars(sLine
, '_', start
, end
))
795 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
796 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
797 SetCharFormat(pWnd
, CFM_UNDERLINE
, CFE_UNDERLINE
);
801 offset
= nNewlinePos
+1;
802 } while(nNewlinePos
>=0);
806 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
809 int last
= sText
.GetLength() - 1;
810 bool bFoundMarker
= false;
811 TCHAR c
= i
== 0 ? _T('\0') : sText
[i
- 1];
812 TCHAR nextChar
= i
>= last
? _T('\0') : sText
[i
+ 1];
814 // find a starting marker
819 nextChar
= sText
[i
+ 1];
821 // IsCharAlphaNumeric can be somewhat expensive.
822 // Long lines of "*****" or "----" will be pre-empted efficiently
823 // by the (c != nextChar) condition.
825 if ((c
== stylechar
) && (c
!= nextChar
))
827 if (IsCharAlphaNumeric(nextChar
) && !IsCharAlphaNumeric(prevChar
))
839 // find ending marker
842 bFoundMarker
= false;
849 if ((i
== last
) || (!IsCharAlphaNumeric(sText
[i
+ 1]) && IsCharAlphaNumeric(prevChar
)))
862 bool CAppUtils::StartShowUnifiedDiff(HWND hWnd
, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
863 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
864 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
865 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */,
866 bool /* blame = false */,
871 if (GetMsysgitVersion() > 0x01080100)
872 diffContext
= _ttoi(g_Git
.GetConfigValue(_T("diff.context")));
873 CString tempfile
=GetTempFile();
874 if (g_Git
.GetUnifiedDiff(url1
, rev1
, rev2
, tempfile
, bMerge
, bCombine
, diffContext
))
876 CMessageBox::Show(hWnd
, g_Git
.GetGitLastErr(_T("Could not get unified diff."), CGit::GIT_CMD_DIFF
), _T("TortoiseGit"), MB_OK
);
879 CAppUtils::StartUnifiedDiffViewer(tempfile
, rev1
+ _T(":") + rev2
);
883 sCmd
.Format(_T("%s /command:showcompare /unified"),
884 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseGitProc.exe")));
885 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
887 sCmd
+= _T(" /revision1:") + rev1
.ToString();
888 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
890 sCmd
+= _T(" /revision2:") + rev2
.ToString();
892 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
893 if (headpeg
.IsValid())
894 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
897 sCmd
+= _T(" /alternatediff");
900 sCmd
+= _T(" /ignoreancestry");
904 sCmd
+= _T(" /hwnd:");
906 _stprintf_s(buf
, 30, _T("%p"), (void*)hWnd
);
910 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
915 bool CAppUtils::SetupDiffScripts(bool force
, const CString
& type
)
917 CString scriptsdir
= CPathUtils::GetAppParentDirectory();
918 scriptsdir
+= _T("Diff-Scripts");
919 CSimpleFileFind
files(scriptsdir
);
920 while (files
.FindNextFileNoDirectories())
922 CString file
= files
.GetFilePath();
923 CString filename
= files
.GetFileName();
924 CString ext
= file
.Mid(file
.ReverseFind('-') + 1);
925 ext
= _T(".") + ext
.Left(ext
.ReverseFind('.'));
926 std::set
<CString
> extensions
;
927 extensions
.insert(ext
);
929 if (file
.Right(3).CompareNoCase(_T("vbs"))==0)
931 kind
= _T(" //E:vbscript");
933 if (file
.Right(2).CompareNoCase(_T("js"))==0)
935 kind
= _T(" //E:javascript");
937 // open the file, read the first line and find possible extensions
938 // this script can handle
941 CStdioFile
f(file
, CFile::modeRead
| CFile::shareDenyNone
);
943 if (f
.ReadString(extline
))
945 if ((extline
.GetLength() > 15 ) &&
946 ((extline
.Left(15).Compare(_T("// extensions: ")) == 0) ||
947 (extline
.Left(14).Compare(_T("' extensions: ")) == 0)))
949 if (extline
[0] == '/')
950 extline
= extline
.Mid(15);
952 extline
= extline
.Mid(14);
955 sToken
= extline
.Tokenize(_T(";"), curPos
);
956 while (!sToken
.IsEmpty())
958 if (!sToken
.IsEmpty())
960 if (sToken
[0] != '.')
961 sToken
= _T(".") + sToken
;
962 extensions
.insert(sToken
);
964 sToken
= extline
.Tokenize(_T(";"), curPos
);
970 catch (CFileException
* e
)
975 for (std::set
<CString
>::const_iterator it
= extensions
.begin(); it
!= extensions
.end(); ++it
)
977 if (type
.IsEmpty() || (type
.Compare(_T("Diff")) == 0))
979 if (filename
.Left(5).CompareNoCase(_T("diff-")) == 0)
981 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + *it
);
982 CString diffregstring
= diffreg
;
983 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
984 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %base %mine") + kind
;
987 if (type
.IsEmpty() || (type
.Compare(_T("Merge"))==0))
989 if (filename
.Left(6).CompareNoCase(_T("merge-"))==0)
991 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\MergeTools\\") + *it
);
992 CString diffregstring
= diffreg
;
993 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
994 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %merged %theirs %mine %base") + kind
;
1003 bool CAppUtils::Export(CString
*BashHash
, const CTGitPath
*orgPath
)
1005 // ask from where the export has to be done
1008 dlg
.m_Revision
=*BashHash
;
1011 if (PathIsRelative(orgPath
->GetWinPath()))
1012 dlg
.m_orgPath
= g_Git
.CombinePath(orgPath
);
1014 dlg
.m_orgPath
= *orgPath
;
1017 if (dlg
.DoModal() == IDOK
)
1020 cmd
.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s --"),
1021 dlg
.m_strFile
, g_Git
.FixBranchName(dlg
.m_VersionName
));
1026 if (!dlg
.m_bWholeProject
&& !dlg
.m_orgPath
.IsEmpty() && PathIsDirectory(dlg
.m_orgPath
.GetWinPathString()))
1028 git
.m_CurrentDir
= dlg
.m_orgPath
.GetWinPathString();
1031 return (pro
.DoModal() == IDOK
);
1036 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
, bool switch_new_brach
)
1038 CCreateBranchTagDlg dlg
;
1040 dlg
.m_bSwitch
=switch_new_brach
;
1043 dlg
.m_initialRefName
= *CommitHash
;
1045 if(dlg
.DoModal()==IDOK
)
1050 if(dlg
.m_bTrack
== TRUE
)
1051 track
=_T(" --track ");
1052 else if(dlg
.m_bTrack
== FALSE
)
1053 track
=_T(" --no-track");
1064 cmd
.Format(_T("git.exe tag %s %s %s %s"),
1067 dlg
.m_BranchTagName
,
1068 g_Git
.FixBranchName(dlg
.m_VersionName
)
1071 CString tempfile
=::GetTempFile();
1072 if(!dlg
.m_Message
.Trim().IsEmpty())
1074 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_Message
);
1075 cmd
+= _T(" -F ")+tempfile
;
1080 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1083 dlg
.m_BranchTagName
,
1084 g_Git
.FixBranchName(dlg
.m_VersionName
)
1088 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1090 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1093 if( !IsTag
&& dlg
.m_bSwitch
)
1095 // it is a new branch and the user has requested to switch to it
1096 PerformSwitch(dlg
.m_BranchTagName
);
1104 bool CAppUtils::Switch(CString initialRefName
)
1107 if(!initialRefName
.IsEmpty())
1108 dlg
.m_initialRefName
= initialRefName
;
1110 if (dlg
.DoModal() == IDOK
)
1114 branch
= dlg
.m_NewBranch
;
1116 // if refs/heads/ is not stripped, checkout will detach HEAD
1117 // checkout prefers branches on name clashes (with tags)
1118 if (dlg
.m_VersionName
.Left(11) ==_T("refs/heads/") && dlg
.m_bBranchOverride
!= TRUE
)
1119 dlg
.m_VersionName
= dlg
.m_VersionName
.Mid(11);
1121 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
, dlg
.m_bMerge
== TRUE
);
1126 bool CAppUtils::PerformSwitch(CString ref
, bool bForce
/* false */, CString sNewBranch
/* CString() */, bool bBranchOverride
/* false */, BOOL bTrack
/* 2 */, bool bMerge
/* false */)
1134 if(!sNewBranch
.IsEmpty()){
1135 if (bBranchOverride
)
1137 branch
.Format(_T("-B %s"), sNewBranch
);
1141 branch
.Format(_T("-b %s"), sNewBranch
);
1144 track
= _T("--track");
1145 else if (bTrack
== FALSE
)
1146 track
= _T("--no-track");
1151 merge
= _T("--merge");
1153 cmd
.Format(_T("git.exe checkout %s %s %s %s %s --"),
1158 g_Git
.FixBranchName(ref
));
1162 CProgressDlg progress
;
1163 progress
.m_GitCmd
= cmd
;
1165 INT_PTR idPull
= -1;
1166 INT_PTR idSubmoduleUpdate
= -1;
1167 INT_PTR idMerge
= -1;
1169 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1170 if (gitPath
.HasSubmodules())
1171 idSubmoduleUpdate
= progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1172 CString currentBranch
;
1173 bool hasBranch
= CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, currentBranch
) == 0;
1175 idMerge
= progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUMERGE
)));
1177 progress
.m_PostCmdCallback
= [&] ()
1179 if (!progress
.m_GitStatus
)
1182 if (!CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, newBranch
))
1183 idPull
= progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPULL
)));
1187 progress
.m_PostCmdList
.RemoveAll();
1188 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MSGBOX_RETRY
)));
1189 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_SWITCH_WITH_MERGE
)));
1193 INT_PTR ret
= progress
.DoModal();
1194 if (progress
.m_GitStatus
== 0)
1196 if (idSubmoduleUpdate
>= 0 && ret
== IDC_PROGRESS_BUTTON1
+ idSubmoduleUpdate
)
1199 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1201 RunTortoiseGitProc(sCmd
);
1204 else if (ret
== IDC_PROGRESS_BUTTON1
+ idPull
)
1209 else if (ret
== IDC_PROGRESS_BUTTON1
+ idMerge
)
1211 Merge(¤tBranch
);
1214 else if (ret
== IDOK
)
1217 else if (ret
== IDC_PROGRESS_BUTTON1
)
1219 else if (ret
== IDC_PROGRESS_BUTTON1
+ 1)
1221 merge
= _T("--merge");
1222 cmd
.Format(_T("git.exe checkout %s %s %s %s %s --"),
1223 force
, track
, merge
, branch
, g_Git
.FixBranchName(ref
));
1231 class CIgnoreFile
: public CStdioFile
1234 STRING_VECTOR m_Items
;
1237 virtual BOOL
ReadString(CString
& rString
)
1239 if (GetPosition() == 0)
1241 unsigned char utf8bom
[] = { 0xEF, 0xBB, 0xBF };
1242 char buf
[3] = { 0, 0, 0 };
1244 if (memcpy(buf
, utf8bom
, sizeof(utf8bom
)))
1251 char lastChar
= '\0';
1252 for (char c
= '\0'; Read(&c
, 1) == 1; lastChar
= c
)
1258 m_eol
= lastChar
== '\r' ? _T("\r\n") : _T("\n");
1266 rString
= CUnicodeUtils::GetUnicode(strA
);
1277 bool CAppUtils::OpenIgnoreFile(CIgnoreFile
&file
, const CString
& filename
)
1280 if (!file
.Open(filename
, CFile::modeCreate
| CFile::modeReadWrite
| CFile::modeNoTruncate
| CFile::typeBinary
))
1282 CMessageBox::Show(NULL
, filename
+ _T(" Open Failure"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1286 if (file
.GetLength() > 0)
1289 while (file
.ReadString(fileText
))
1290 file
.m_Items
.push_back(fileText
);
1291 file
.Seek(file
.GetLength() - 1, 0);
1292 char lastchar
[1] = { 0 };
1293 file
.Read(lastchar
, 1);
1295 if (lastchar
[0] != '\n')
1297 CStringA eol
= CStringA(file
.m_eol
.IsEmpty() ? _T("\n") : file
.m_eol
);
1298 file
.Write(eol
, eol
.GetLength());
1307 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1309 CIgnoreDlg ignoreDlg
;
1310 if (ignoreDlg
.DoModal() == IDOK
)
1313 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\");
1315 switch (ignoreDlg
.m_IgnoreFile
)
1318 ignorefile
+= _T(".gitignore");
1321 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, ignorefile
);
1322 ignorefile
+= _T("info/exclude");
1329 if (ignoreDlg
.m_IgnoreFile
!= 1 && !OpenIgnoreFile(file
, ignorefile
))
1332 for (int i
= 0; i
< path
.GetCount(); ++i
)
1334 if (ignoreDlg
.m_IgnoreFile
== 1)
1336 ignorefile
= g_Git
.CombinePath(path
[i
].GetContainingDirectory()) + _T("\\.gitignore");
1337 if (!OpenIgnoreFile(file
, ignorefile
))
1341 CString ignorePattern
;
1342 if (ignoreDlg
.m_IgnoreType
== 0)
1344 if (ignoreDlg
.m_IgnoreFile
!= 1 && !path
[i
].GetContainingDirectory().GetGitPathString().IsEmpty())
1345 ignorePattern
+= _T("/") + path
[i
].GetContainingDirectory().GetGitPathString();
1347 ignorePattern
+= _T("/");
1351 ignorePattern
+= _T("*") + path
[i
].GetFileExtension();
1355 ignorePattern
+= path
[i
].GetFileOrDirectoryName();
1358 // escape [ and ] so that files get ignored correctly
1359 ignorePattern
.Replace(_T("["), _T("\\["));
1360 ignorePattern
.Replace(_T("]"), _T("\\]"));
1363 for (size_t j
= 0; j
< file
.m_Items
.size(); ++j
)
1365 if (file
.m_Items
[j
] == ignorePattern
)
1373 file
.m_Items
.push_back(ignorePattern
);
1374 ignorePattern
+= file
.m_eol
.IsEmpty() ? _T("\n") : file
.m_eol
;
1375 CStringA ignorePatternA
= CUnicodeUtils::GetUTF8(ignorePattern
);
1376 file
.Write(ignorePatternA
, ignorePatternA
.GetLength());
1379 if (ignoreDlg
.m_IgnoreFile
== 1)
1383 if (ignoreDlg
.m_IgnoreFile
!= 1)
1398 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1401 dlg
.m_ResetType
=type
;
1402 dlg
.m_ResetToVersion
=*CommitHash
;
1403 dlg
.m_initialRefName
= *CommitHash
;
1404 if (dlg
.DoModal() == IDOK
)
1408 switch(dlg
.m_ResetType
)
1420 dlg
.m_ResetType
= 1;
1424 cmd
.Format(_T("git.exe reset %s %s --"),type
, dlg
.m_ResetToVersion
);
1428 CProgressDlg progress
;
1429 progress
.m_GitCmd
=cmd
;
1431 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1432 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2)
1433 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1435 progress
.m_PostFailCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MSGBOX_RETRY
)));
1438 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_RESET
))
1440 CGitProgressDlg gitdlg
;
1441 gitdlg
.SetCommand(CGitProgressList::GitProgress_Reset
);
1442 gitdlg
.SetRevision(dlg
.m_ResetToVersion
);
1443 gitdlg
.SetResetType(dlg
.m_ResetType
);
1444 ret
= gitdlg
.DoModal();
1447 ret
= progress
.DoModal();
1449 if (progress
.m_GitStatus
== 0 && gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2 && ret
== IDC_PROGRESS_BUTTON1
)
1452 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1454 RunTortoiseGitProc(sCmd
);
1457 else if (progress
.m_GitStatus
!= 0 && ret
== IDC_PROGRESS_BUTTON1
)
1459 else if (ret
== IDOK
)
1468 void CAppUtils::DescribeConflictFile(bool mode
, bool base
,CString
&descript
)
1472 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_DELETE
));
1477 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_MODIFIED
));
1480 descript
= CString(MAKEINTRESOURCE(IDS_PROC_CREATED
));
1484 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1486 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("LOCAL"), path
));
1487 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("REMOTE"), path
));
1488 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("BASE"), path
));
1490 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1493 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1498 bool ParseHashesFromLsFile(BYTE_VECTOR
&out
, CString
&hash1
, CString
&hash2
, CString
&hash3
)
1500 unsigned int pos
= 0;
1504 while (pos
>= 0 && pos
< out
.size())
1508 g_Git
.StringAppend(&one
, &out
[pos
], CP_UTF8
);
1510 one
.Tokenize(_T("\t"), tabstart
);
1513 part
= one
.Tokenize(_T(" "), tabstart
); //Tag
1514 part
= one
.Tokenize(_T(" "), tabstart
); //Mode
1515 part
= one
.Tokenize(_T(" "), tabstart
); //Hash
1516 CString hash
= part
;
1517 part
= one
.Tokenize(_T("\t"), tabstart
); //Stage
1518 int stage
= _ttol(part
);
1521 else if (stage
== 2)
1523 else if (stage
== 3)
1529 pos
= out
.findNextString(pos
);
1535 bool CAppUtils::ConflictEdit(CTGitPath
& path
, bool /*bAlternativeTool = false*/, bool revertTheirMy
/*= false*/, HWND resolveMsgHwnd
/*= nullptr*/)
1539 CTGitPath merge
=path
;
1540 CTGitPath directory
= merge
.GetDirectory();
1542 // we have the conflicted file (%merged)
1543 // now look for the other required files
1545 //stat.GetStatus(merge);
1546 //if (stat.status == NULL)
1552 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1554 if (g_Git
.Run(cmd
, &vector
))
1559 if (merge
.IsDirectory())
1561 CString baseHash
, localHash
, remoteHash
;
1562 if (!ParseHashesFromLsFile(vector
, baseHash
, localHash
, remoteHash
))
1566 msg
.Format(_T("BASE: %s\nLOCAL: %s\nREMOTE: %s"), baseHash
, localHash
, remoteHash
);
1567 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
);
1572 if (list
.ParserFromLsFile(vector
))
1574 CMessageBox::Show(NULL
, _T("Parse ls-files failed!"), _T("TortoiseGit"), MB_OK
);
1587 mine
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1588 theirs
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1592 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1593 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1595 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1599 //format=_T("git.exe cat-file blob \":%d:%s\"");
1600 format
= _T("git.exe checkout-index --temp --stage=%d -- \"%s\"");
1602 //create a empty file, incase stage is not three
1603 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1605 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1607 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1610 bool b_base
=false, b_local
=false, b_remote
=false;
1612 for (int i
= 0; i
< list
.GetCount(); ++i
)
1619 if( list
[i
].m_Stage
== 1)
1621 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1623 outfile
= base
.GetWinPathString();
1626 if( list
[i
].m_Stage
== 2 )
1628 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1630 outfile
= mine
.GetWinPathString();
1633 if( list
[i
].m_Stage
== 3 )
1635 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1637 outfile
= theirs
.GetWinPathString();
1639 CString output
, err
;
1640 if(!outfile
.IsEmpty())
1641 if (!g_Git
.Run(cmd
, &output
, &err
, CP_UTF8
))
1645 file
= output
.Tokenize(_T("\t"), start
);
1646 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1650 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1654 if(b_local
&& b_remote
)
1656 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1658 bRet
= !!CAppUtils::StartExtMerge(base
, mine
, theirs
, merge
, _T("BASE"), _T("REMOTE"), _T("LOCAL"), CString(), false, resolveMsgHwnd
);
1660 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
, _T("BASE"), _T("REMOTE"), _T("LOCAL"), CString(), false, resolveMsgHwnd
);
1665 ::DeleteFile(mine
.GetWinPathString());
1666 ::DeleteFile(theirs
.GetWinPathString());
1667 ::DeleteFile(base
.GetWinPathString());
1669 CDeleteConflictDlg dlg
;
1670 DescribeConflictFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1671 DescribeConflictFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1672 CGitHash localHash
, remoteHash
;
1673 if (!g_Git
.GetHash(localHash
, _T("HEAD")))
1674 dlg
.m_LocalHash
= localHash
.ToString();
1675 if (!g_Git
.GetHash(remoteHash
, _T("MERGE_HEAD")))
1676 dlg
.m_RemoteHash
= remoteHash
.ToString();
1677 else if (!g_Git
.GetHash(remoteHash
, _T("rebase-apply/original-commit")))
1678 dlg
.m_RemoteHash
= remoteHash
.ToString();
1679 else if (!g_Git
.GetHash(remoteHash
, _T("CHERRY_PICK_HEAD")))
1680 dlg
.m_RemoteHash
= remoteHash
.ToString();
1681 else if (!g_Git
.GetHash(remoteHash
, _T("REVERT_HEAD")))
1682 dlg
.m_RemoteHash
= remoteHash
.ToString();
1683 dlg
.m_bShowModifiedButton
=b_base
;
1684 dlg
.m_File
=merge
.GetGitPathString();
1685 if(dlg
.DoModal() == IDOK
)
1690 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1693 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1695 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1697 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1707 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1708 base
, theirs
, mine
, merge
);
1711 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1713 // we have a text conflict, use our merge tool to resolve the conflict
1715 CTSVNPath
theirs(directory
);
1716 CTSVNPath
mine(directory
);
1717 CTSVNPath
base(directory
);
1718 bool bConflictData
= false;
1720 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1722 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1723 bConflictData
= true;
1725 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1727 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1728 bConflictData
= true;
1730 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1732 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1733 bConflictData
= true;
1740 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1741 base
, theirs
, mine
, merge
);
1744 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1746 // we have a property conflict
1747 CTSVNPath
prej(directory
);
1748 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1750 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1751 // there's a problem: the prej file contains a _description_ of the conflict, and
1752 // that description string might be translated. That means we have no way of parsing
1753 // the file to find out the conflicting values.
1754 // The only thing we can do: show a dialog with the conflict description, then
1755 // let the user either accept the existing property or open the property edit dialog
1756 // to manually change the properties and values. And a button to mark the conflict as
1758 CEditPropConflictDlg dlg
;
1759 dlg
.SetPrejFile(prej
);
1760 dlg
.SetConflictedItem(merge
);
1761 bRet
= (dlg
.DoModal() != IDCANCEL
);
1765 if (stat
.status
->tree_conflict
)
1767 // we have a tree conflict
1769 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1772 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1774 CTSVNPath
theirs(directory
);
1775 CTSVNPath
mine(directory
);
1776 CTSVNPath
base(directory
);
1777 bool bConflictData
= false;
1779 if (pInfoData
->treeconflict_theirfile
)
1781 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1782 bConflictData
= true;
1784 if (pInfoData
->treeconflict_basefile
)
1786 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1787 bConflictData
= true;
1789 if (pInfoData
->treeconflict_myfile
)
1791 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1792 bConflictData
= true;
1799 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1800 base
, theirs
, mine
, merge
);
1802 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1804 CString sConflictAction
;
1805 CString sConflictReason
;
1806 CString sResolveTheirs
;
1807 CString sResolveMine
;
1808 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1809 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1811 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1813 switch (pInfoData
->treeconflict_operation
)
1815 case svn_wc_operation_update
:
1816 switch (pInfoData
->treeconflict_action
)
1818 case svn_wc_conflict_action_edit
:
1819 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1820 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1822 case svn_wc_conflict_action_add
:
1823 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1824 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1826 case svn_wc_conflict_action_delete
:
1827 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1828 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1832 case svn_wc_operation_switch
:
1833 switch (pInfoData
->treeconflict_action
)
1835 case svn_wc_conflict_action_edit
:
1836 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1837 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1839 case svn_wc_conflict_action_add
:
1840 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1841 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1843 case svn_wc_conflict_action_delete
:
1844 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1845 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1849 case svn_wc_operation_merge
:
1850 switch (pInfoData
->treeconflict_action
)
1852 case svn_wc_conflict_action_edit
:
1853 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1854 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1856 case svn_wc_conflict_action_add
:
1857 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1858 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1860 case svn_wc_conflict_action_delete
:
1861 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1862 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1868 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1870 switch (pInfoData
->treeconflict_operation
)
1872 case svn_wc_operation_update
:
1873 switch (pInfoData
->treeconflict_action
)
1875 case svn_wc_conflict_action_edit
:
1876 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1877 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1879 case svn_wc_conflict_action_add
:
1880 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1881 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1883 case svn_wc_conflict_action_delete
:
1884 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1885 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1889 case svn_wc_operation_switch
:
1890 switch (pInfoData
->treeconflict_action
)
1892 case svn_wc_conflict_action_edit
:
1893 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1894 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1896 case svn_wc_conflict_action_add
:
1897 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1898 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1900 case svn_wc_conflict_action_delete
:
1901 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1902 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1906 case svn_wc_operation_merge
:
1907 switch (pInfoData
->treeconflict_action
)
1909 case svn_wc_conflict_action_edit
:
1910 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1911 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1913 case svn_wc_conflict_action_add
:
1914 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1915 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1917 case svn_wc_conflict_action_delete
:
1918 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1919 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1927 switch (pInfoData
->treeconflict_reason
)
1929 case svn_wc_conflict_reason_edited
:
1930 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1931 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1933 case svn_wc_conflict_reason_obstructed
:
1934 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1935 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1937 case svn_wc_conflict_reason_deleted
:
1938 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1939 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1941 case svn_wc_conflict_reason_added
:
1942 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1943 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1945 case svn_wc_conflict_reason_missing
:
1946 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1947 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1949 case svn_wc_conflict_reason_unversioned
:
1950 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1951 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1954 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1956 CTreeConflictEditorDlg dlg
;
1957 dlg
.SetConflictInfoText(sConflictReason
);
1958 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1959 dlg
.SetPath(treeConflictPath
);
1960 INT_PTR dlgRet
= dlg
.DoModal();
1961 bRet
= (dlgRet
!= IDCANCEL
);
1969 bool CAppUtils::IsSSHPutty()
1971 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1972 sshclient
=sshclient
.MakeLower();
1973 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1980 CString
CAppUtils::GetClipboardLink(const CString
&skipGitPrefix
, int paramsCount
)
1982 if (!OpenClipboard(NULL
))
1985 CString sClipboardText
;
1986 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1989 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1990 sClipboardText
= CString(lpstr
);
1993 hglb
= GetClipboardData(CF_UNICODETEXT
);
1996 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1997 sClipboardText
= lpstr
;
2002 if(!sClipboardText
.IsEmpty())
2004 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
2005 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
2007 if(sClipboardText
.Find( _T("http://")) == 0)
2008 return sClipboardText
;
2010 if(sClipboardText
.Find( _T("https://")) == 0)
2011 return sClipboardText
;
2013 if(sClipboardText
.Find( _T("git://")) == 0)
2014 return sClipboardText
;
2016 if(sClipboardText
.Find( _T("ssh://")) == 0)
2017 return sClipboardText
;
2019 if(sClipboardText
.GetLength()>=2)
2020 if( sClipboardText
[1] == _T(':') )
2021 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
2022 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
2023 return sClipboardText
;
2025 // trim prefixes like "git clone "
2026 if (!skipGitPrefix
.IsEmpty() && sClipboardText
.Find(skipGitPrefix
) == 0)
2028 sClipboardText
= sClipboardText
.Mid(skipGitPrefix
.GetLength()).Trim();
2030 while (paramsCount
>= 0)
2033 spacePos
= sClipboardText
.Find(_T(' '), spacePos
+ 1);
2037 if (spacePos
> 0 && paramsCount
< 0)
2038 sClipboardText
= sClipboardText
.Left(spacePos
);
2039 return sClipboardText
;
2043 return CString(_T(""));
2046 CString
CAppUtils::ChooseRepository(CString
*path
)
2048 CBrowseFolder browseFolder
;
2049 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
2051 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
2052 CString strCloneDirectory
;
2054 strCloneDirectory
=*path
;
2057 strCloneDirectory
= regLastResopitory
;
2061 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
2063 browseFolder
.SetInfo(title
);
2065 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
2067 regLastResopitory
= strCloneDirectory
;
2068 return strCloneDirectory
;
2076 bool CAppUtils::SendPatchMail(CTGitPathList
& list
)
2080 dlg
.m_PathList
= list
;
2082 if(dlg
.DoModal()==IDOK
)
2084 if (dlg
.m_PathList
.IsEmpty())
2087 CGitProgressDlg progDlg
;
2089 theApp
.m_pMainWnd
= &progDlg
;
2090 progDlg
.SetCommand(CGitProgressList::GitProgress_SendMail
);
2092 progDlg
.SetPathList(dlg
.m_PathList
);
2093 //ProjectProperties props;
2094 //props.ReadPropsPathList(dlg.m_pathList);
2095 //progDlg.SetProjectProperties(props);
2096 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2098 CSendMailPatch
sendMailPatch(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
);
2099 progDlg
.SetSendMailOption(&sendMailPatch
);
2108 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
)
2111 CString log
=formatpatchoutput
;
2112 int start
=log
.Find(cmd
);
2114 CString one
=log
.Tokenize(_T("\n"),start
);
2120 CString one
=log
.Tokenize(_T("\n"),start
);
2122 if(one
.IsEmpty() || one
.Find(_T("Success")) == 0)
2124 one
.Replace(_T('/'),_T('\\'));
2126 path
.SetFromWin(one
);
2129 if (!list
.IsEmpty())
2131 return SendPatchMail(list
);
2135 CMessageBox::Show(NULL
, IDS_ERR_NOPATCHES
, IDS_APPNAME
, MB_ICONINFORMATION
);
2141 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
2144 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
2145 if(output
.IsEmpty())
2146 return CUnicodeUtils::GetCPCode(pGit
->GetConfigValue(_T("i18n.commitencoding")));
2149 return CUnicodeUtils::GetCPCode(output
);
2152 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
2154 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
2155 int cp
= CUnicodeUtils::GetCPCode(g_Git
.GetConfigValue(_T("i18n.commitencoding")));
2157 bool stripComments
= (CRegDWORD(_T("Software\\TortoiseGit\\StripCommentedLines"), FALSE
) == TRUE
);
2159 if (CRegDWORD(_T("Software\\TortoiseGit\\SanitizeCommitMsg"), TRUE
) == TRUE
)
2160 message
.TrimRight(L
" \r\n");
2162 int len
= message
.GetLength();
2164 while (start
>= 0 && start
< len
)
2166 int oldStart
= start
;
2167 start
= message
.Find(L
"\n", oldStart
);
2168 CString line
= message
.Mid(oldStart
);
2171 line
= line
.Left(start
- oldStart
);
2172 ++start
; // move forward so we don't find the same char again
2174 if (stripComments
&& (line
.GetLength() >= 1 && line
.GetAt(0) == '#') || (start
< 0 && line
.IsEmpty()))
2176 line
.TrimRight(L
" \r");
2177 CStringA lineA
= CUnicodeUtils::GetMulti(line
+ L
"\n", cp
);
2178 file
.Write(lineA
.GetBuffer(), lineA
.GetLength());
2184 bool CAppUtils::Pull(bool showPush
)
2187 dlg
.m_IsPull
= TRUE
;
2188 if (dlg
.DoModal() == IDOK
)
2190 CString url
= dlg
.m_RemoteURL
;
2192 if (dlg
.m_bAutoLoad
)
2194 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
2199 if (g_Git
.GetHash(hashOld
, _T("HEAD")))
2201 MessageBox(NULL
, g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
2213 cmdRebase
= "--rebase ";
2215 if (!dlg
.m_bFetchTags
)
2216 notags
= _T("--no-tags");
2222 ffonly
= _T("--ff-only");
2225 squash
= _T("--squash");
2227 if (dlg
.m_bNoCommit
)
2228 nocommit
= _T("--no-commit");
2230 int ver
= CAppUtils::GetMsysgitVersion();
2232 if(ver
>= 0x01070203) //above 1.7.0.2
2233 cmdRebase
+= _T("--progress ");
2235 cmd
.Format(_T("git.exe pull -v %s %s %s %s %s %s \"%s\" %s"), cmdRebase
, noff
, ffonly
, squash
, nocommit
, notags
, url
, dlg
.m_RemoteBranchName
);
2236 CProgressDlg progress
;
2237 progress
.m_GitCmd
= cmd
;
2238 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_DIFFS
)));
2239 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_LOG
)));
2240 INT_PTR pushButton
= showPush
? progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
))) + IDC_PROGRESS_BUTTON1
: -1;
2242 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
2243 INT_PTR smUpdateButton
= gitPath
.HasSubmodules() ? progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
))) + IDC_PROGRESS_BUTTON1
: -1;
2245 INT_PTR ret
= progress
.DoModal();
2247 if (ret
== IDOK
&& progress
.m_GitStatus
== 1 && progress
.m_LogText
.Find(_T("CONFLICT")) >= 0 && CMessageBox::Show(NULL
, IDS_SEECHANGES
, IDS_APPNAME
, MB_YESNO
| MB_ICONINFORMATION
) == IDYES
)
2250 dlg
.m_pathList
.AddPath(CTGitPath());
2257 if (g_Git
.GetHash(hashNew
, _T("HEAD")))
2259 MessageBox(NULL
, g_Git
.GetGitLastErr(_T("Could not get HEAD hash after pulling.")), _T("TortoiseGit"), MB_ICONERROR
);
2263 if( ret
== IDC_PROGRESS_BUTTON1
)
2265 if(hashOld
== hashNew
)
2267 if(progress
.m_GitStatus
== 0)
2268 CMessageBox::Show(NULL
, IDS_UPTODATE
, IDS_APPNAME
, MB_OK
| MB_ICONINFORMATION
);
2273 dlg
.SetDiff(NULL
, hashNew
.ToString(), hashOld
.ToString());
2278 else if ( ret
== IDC_PROGRESS_BUTTON1
+1 )
2280 if(hashOld
== hashNew
)
2282 if(progress
.m_GitStatus
== 0)
2283 CMessageBox::Show(NULL
, IDS_UPTODATE
, IDS_APPNAME
, MB_OK
| MB_ICONINFORMATION
);
2288 dlg
.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), hashOld
.ToString() + _T("..") + hashNew
.ToString(), 0);
2291 else if (ret
== pushButton
)
2296 else if (ret
== smUpdateButton
)
2299 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
2301 CAppUtils::RunTortoiseGitProc(sCmd
);
2309 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
, bool allRemotes
)
2312 dlg
.m_PreSelectRemote
= remoteName
;
2313 dlg
.m_bAllowRebase
= allowRebase
;
2315 dlg
.m_bAllRemotes
= allRemotes
;
2317 if(dlg
.DoModal()==IDOK
)
2321 if (dlg
.m_bAllRemotes
)
2324 g_Git
.GetRemoteList(list
);
2326 STRING_VECTOR::const_iterator it
= list
.begin();
2327 while (it
!= list
.end())
2329 CString
remote(*it
);
2330 CAppUtils::LaunchPAgent(NULL
, &remote
);
2335 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
2339 url
=dlg
.m_RemoteURL
;
2343 int ver
= CAppUtils::GetMsysgitVersion();
2345 if(ver
>= 0x01070203) //above 1.7.0.2
2346 arg
= _T("--progress ");
2348 if (dlg
.m_bPrune
== TRUE
)
2349 arg
+= _T("--prune ");
2350 else if (dlg
.m_bPrune
== FALSE
&& ver
>= 0x01080500)
2351 arg
+= _T("--no-prune ");
2353 if (dlg
.m_bFetchTags
== 1)
2355 arg
+= _T("--tags ");
2357 else if (dlg
.m_bFetchTags
== 0)
2359 arg
+= _T("--no-tags ");
2362 if (dlg
.m_bAllRemotes
)
2363 cmd
.Format(_T("git.exe fetch --all -v %s"), arg
);
2365 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"), arg
, url
, dlg
.m_RemoteBranchName
);
2367 CProgressDlg progress
;
2369 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2370 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_RESET
)));
2372 if(!dlg
.m_bRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
2374 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2377 progress
.m_GitCmd
=cmd
;
2378 INT_PTR userResponse
;
2380 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
2382 CGitProgressDlg gitdlg
;
2383 if (!dlg
.m_bAllRemotes
)
2385 gitdlg
.SetCommand(CGitProgressList::GitProgress_Fetch
);
2386 gitdlg
.SetAutoTag(dlg
.m_bFetchTags
== 1 ? GIT_REMOTE_DOWNLOAD_TAGS_ALL
: dlg
.m_bFetchTags
== 2 ? GIT_REMOTE_DOWNLOAD_TAGS_AUTO
: GIT_REMOTE_DOWNLOAD_TAGS_NONE
);
2387 if (!dlg
.m_bAllRemotes
)
2388 gitdlg
.SetRefSpec(dlg
.m_RemoteBranchName
);
2389 userResponse
= gitdlg
.DoModal();
2393 userResponse
= progress
.DoModal();
2395 if (userResponse
== IDC_PROGRESS_BUTTON1
)
2397 CString cmd
= _T("/command:log");
2398 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2399 RunTortoiseGitProc(cmd
);
2402 else if (userResponse
== IDC_PROGRESS_BUTTON1
+ 1)
2404 CString pullRemote
, pullBranch
;
2405 g_Git
.GetRemoteTrackedBranchForHEAD(pullRemote
, pullBranch
);
2407 CString defaultUpstream
;
2408 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
2409 defaultUpstream
.Format(_T("remotes/%s/%s"), pullRemote
, pullBranch
);
2410 GitReset(&defaultUpstream
, 2);
2413 else if ((userResponse
== IDC_PROGRESS_BUTTON1
+ 2) || (progress
.m_GitStatus
== 0 && dlg
.m_bRebase
))
2418 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2419 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUDESSENDMAIL
)));
2420 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2421 INT_PTR response
= dlg
.DoModal();
2422 if(response
== IDOK
)
2426 else if (response
== IDC_REBASE_POST_BUTTON
)
2428 CString cmd
= _T("/command:log");
2429 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2430 RunTortoiseGitProc(cmd
);
2433 else if (response
== IDC_REBASE_POST_BUTTON
+ 1)
2435 CString cmd
, out
, err
;
2436 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2438 g_Git
.FixBranchName(dlg
.m_Upstream
),
2439 g_Git
.FixBranchName(dlg
.m_Branch
));
2440 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
2442 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2446 CAppUtils::SendPatchMail(cmd
,out
);
2449 else if (response
== IDC_REBASE_POST_BUTTON
+ 2)
2451 else if(response
== IDCANCEL
)
2456 else if (userResponse
!= IDCANCEL
)
2462 bool CAppUtils::Push(CString selectLocalBranch
)
2465 dlg
.m_BranchSourceName
= selectLocalBranch
;
2467 DWORD exitcode
= 0xFFFFFFFF;
2469 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
2470 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
2475 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2476 //ReportError(temp);
2477 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2482 if(dlg
.DoModal()==IDOK
)
2487 arg
+= _T("--thin ");
2488 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2489 arg
+= _T("--tags ");
2491 arg
+= _T("--force ");
2492 if (dlg
.m_bSetUpstream
)
2493 arg
+= _T("--set-upstream ");
2494 if (dlg
.m_RecurseSubmodules
== 1)
2495 arg
+= _T("--recurse-submodules=check ");
2496 if (dlg
.m_RecurseSubmodules
== 2)
2497 arg
+= _T("--recurse-submodules=on-demand ");
2499 int ver
= CAppUtils::GetMsysgitVersion();
2501 if(ver
>= 0x01070203) //above 1.7.0.2
2502 arg
+= _T("--progress ");
2504 CProgressDlg progress
;
2506 STRING_VECTOR remotesList
;
2507 if (dlg
.m_bPushAllRemotes
)
2508 g_Git
.GetRemoteList(remotesList
);
2510 remotesList
.push_back(dlg
.m_URL
);
2512 for (unsigned int i
= 0; i
< remotesList
.size(); ++i
)
2514 if (dlg
.m_bAutoLoad
)
2515 CAppUtils::LaunchPAgent(NULL
, &remotesList
[i
]);
2518 if (dlg
.m_bPushAllBranches
)
2520 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2526 progress
.m_GitCmdList
.push_back(cmd
);
2527 cmd
.Format(_T("git.exe push --tags %s \"%s\""), arg
, remotesList
[i
]);
2532 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2535 dlg
.m_BranchSourceName
);
2536 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2538 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2541 progress
.m_GitCmdList
.push_back(cmd
);
2544 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REQUESTPULL
)));
2545 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2546 bool rejected
= false;
2547 progress
.m_PostCmdCallback
= [&] ()
2549 if (progress
.m_GitStatus
)
2551 progress
.m_PostCmdList
.RemoveAll();
2552 rejected
= progress
.GetLogText().Find(_T("! [rejected]")) > 0;
2555 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPULL
)));
2556 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUFETCH
)));
2558 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2562 INT_PTR ret
= progress
.DoModal();
2564 if(!progress
.m_GitStatus
)
2566 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2571 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2572 //ReportError(temp);
2573 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2577 if(ret
== IDC_PROGRESS_BUTTON1
)
2579 RequestPull(dlg
.m_BranchRemoteName
);
2581 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2583 Push(selectLocalBranch
);
2591 // failed, pull first
2592 if (ret
== IDC_PROGRESS_BUTTON1
)
2596 else if (ret
== IDC_PROGRESS_BUTTON1
+ 1)
2598 Fetch(dlg
.m_bPushAllRemotes
? _T("") : dlg
.m_URL
, true, !!dlg
.m_bPushAllRemotes
);
2600 else if (ret
== IDC_PROGRESS_BUTTON1
+ 2)
2602 Push(selectLocalBranch
);
2607 if (ret
== IDC_PROGRESS_BUTTON1
)
2609 Push(selectLocalBranch
);
2617 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2619 CRequestPullDlg dlg
;
2620 dlg
.m_RepositoryURL
= repositoryUrl
;
2621 dlg
.m_EndRevision
= endrevision
;
2622 if (dlg
.DoModal()==IDOK
)
2625 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2627 CSysProgressDlg sysProgressDlg
;
2628 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2629 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CREATINGPULLREUQEST
)));
2630 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2631 sysProgressDlg
.SetShowProgressBar(false);
2632 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2634 CString tempFileName
= GetTempFile();
2636 DeleteFile(tempFileName
);
2637 CreateDirectory(tempFileName
, NULL
);
2638 tempFileName
+= _T("\\pullrequest.txt");
2639 if (g_Git
.RunLogFile(cmd
, tempFileName
, &err
))
2642 msg
.LoadString(IDS_ERR_PULLREUQESTFAILED
);
2643 CMessageBox::Show(NULL
, msg
+ _T("\n") + err
, _T("TortoiseGit"), MB_OK
);
2647 if (sysProgressDlg
.HasUserCancelled())
2649 CMessageBox::Show(NULL
, IDS_SVN_USERCANCELLED
, IDS_APPNAME
, MB_OK
);
2650 ::DeleteFile(tempFileName
);
2654 sysProgressDlg
.Stop();
2656 if (dlg
.m_bSendMail
)
2659 dlg
.m_PathList
= CTGitPathList(CTGitPath(tempFileName
));
2660 dlg
.m_bCustomSubject
= true;
2662 if (dlg
.DoModal() == IDOK
)
2664 if (dlg
.m_PathList
.IsEmpty())
2667 CGitProgressDlg progDlg
;
2669 theApp
.m_pMainWnd
= &progDlg
;
2670 progDlg
.SetCommand(CGitProgressList::GitProgress_SendMail
);
2672 progDlg
.SetPathList(dlg
.m_PathList
);
2673 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2675 CSendMailCombineable
sendMailCombineable(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
);
2676 progDlg
.SetSendMailOption(&sendMailCombineable
);
2685 CAppUtils::LaunchAlternativeEditor(tempFileName
);
2690 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2692 CString
strDir(szPath
);
2693 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2695 strDir
.AppendChar(_T('\\'));
2697 std::vector
<CString
> vPath
;
2699 bool bSuccess
= false;
2701 for (int i
=0;i
<strDir
.GetLength();++i
)
2703 if (strDir
.GetAt(i
) != _T('\\'))
2705 strTemp
.AppendChar(strDir
.GetAt(i
));
2709 vPath
.push_back(strTemp
);
2710 strTemp
.AppendChar(_T('\\'));
2714 for (auto vIter
= vPath
.begin(); vIter
!= vPath
.end(); ++vIter
)
2716 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2722 void CAppUtils::RemoveTrailSlash(CString
&path
)
2727 // For URL, do not trim the slash just after the host name component.
2728 int index
= path
.Find(_T("://"));
2732 index
= path
.Find(_T('/'), index
);
2733 if (index
== path
.GetLength() - 1)
2737 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2739 path
=path
.Left(path
.GetLength()-1);
2745 bool CAppUtils::CheckUserData()
2747 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
2749 if(CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
2751 CTGitPath
path(g_Git
.m_CurrentDir
);
2752 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2753 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2754 dlg
.SetTreeWidth(220);
2755 dlg
.m_DefaultPage
= _T("gitconfig");
2758 dlg
.HandleRestart();
2768 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2769 CTGitPathList
&pathList
,
2770 CTGitPathList
&selectedList
,
2771 bool bSelectFilesForCommit
)
2773 bool bFailed
= true;
2775 if (!CheckUserData())
2782 dlg
.m_sBugID
= bugid
;
2784 dlg
.m_bWholeProject
= bWholeProject
;
2786 dlg
.m_sLogMessage
= sLogMsg
;
2787 dlg
.m_pathList
= pathList
;
2788 dlg
.m_checkedPathList
= selectedList
;
2789 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2790 if (dlg
.DoModal() == IDOK
)
2792 if (dlg
.m_pathList
.IsEmpty())
2794 // if the user hasn't changed the list of selected items
2795 // we don't use that list. Because if we would use the list
2796 // of pre-checked items, the dialog would show different
2797 // checked items on the next startup: it would only try
2798 // to check the parent folder (which might not even show)
2799 // instead, we simply use an empty list and let the
2800 // default checking do its job.
2801 if (!dlg
.m_pathList
.IsEqual(pathList
))
2802 selectedList
= dlg
.m_pathList
;
2803 pathList
= dlg
.m_updatedPathList
;
2804 sLogMsg
= dlg
.m_sLogMessage
;
2805 bSelectFilesForCommit
= true;
2807 switch (dlg
.m_PostCmd
)
2809 case GIT_POSTCOMMIT_CMD_DCOMMIT
:
2810 CAppUtils::SVNDCommit();
2812 case GIT_POSTCOMMIT_CMD_PUSH
:
2815 case GIT_POSTCOMMIT_CMD_CREATETAG
:
2816 CAppUtils::CreateBranchTag(TRUE
);
2818 case GIT_POSTCOMMIT_CMD_PULL
:
2819 CAppUtils::Pull(true);
2825 // CGitProgressDlg progDlg;
2826 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2827 // if (parser.HasVal(_T("closeonend")))
2828 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2829 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2830 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2831 // progDlg.SetPathList(dlg.m_pathList);
2832 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2833 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2834 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2835 // progDlg.SetItemCount(dlg.m_itemsCount);
2836 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2837 // progDlg.DoModal();
2838 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2839 // err = (DWORD)progDlg.DidErrorsOccur();
2840 // bFailed = progDlg.DidErrorsOccur();
2841 // bRet = progDlg.DidErrorsOccur();
2842 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2843 // if (DWORD(bFailRepeat)==0)
2844 // bFailed = false; // do not repeat if the user chose not to in the settings.
2851 BOOL
CAppUtils::SVNDCommit()
2853 CSVNDCommitDlg dcommitdlg
;
2854 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2855 if (gitSetting
== _T("")) {
2856 if (dcommitdlg
.DoModal() != IDOK
)
2862 if (dcommitdlg
.m_remember
)
2864 if (dcommitdlg
.m_rmdir
)
2866 gitSetting
= _T("true");
2870 gitSetting
= _T("false");
2872 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2875 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, _T("svn.rmdir"), gitSetting
);
2876 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2882 BOOL IsStash
= false;
2883 if(!g_Git
.CheckCleanWorkTree())
2885 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
2887 CSysProgressDlg sysProgressDlg
;
2888 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2889 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2890 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2891 sysProgressDlg
.SetShowProgressBar(false);
2892 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2893 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2896 cmd
=_T("git.exe stash");
2897 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2899 sysProgressDlg
.Stop();
2900 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2903 sysProgressDlg
.Stop();
2913 CProgressDlg progress
;
2914 if (dcommitdlg
.m_rmdir
)
2916 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2920 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2922 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2924 ::DeleteFile(g_Git
.m_CurrentDir
+ _T("\\sys$command"));
2927 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2929 CSysProgressDlg sysProgressDlg
;
2930 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2931 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2932 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2933 sysProgressDlg
.SetShowProgressBar(false);
2934 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2935 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2938 cmd
=_T("git.exe stash pop");
2939 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2941 sysProgressDlg
.Stop();
2942 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2945 sysProgressDlg
.Stop();
2957 BOOL
CAppUtils::Merge(CString
*commit
)
2959 if (!CheckUserData())
2964 dlg
.m_initialRefName
= *commit
;
2966 if(dlg
.DoModal()==IDOK
)
2972 args
+= _T(" --no-ff");
2975 args
+= _T(" --squash");
2978 args
+= _T(" --no-commit");
2983 fmt
.Format(_T(" --log=%d"), dlg
.m_nLog
);
2987 if (!dlg
.m_MergeStrategy
.IsEmpty())
2989 args
+= _T(" --strategy=") + dlg
.m_MergeStrategy
;
2990 if (!dlg
.m_StrategyOption
.IsEmpty())
2992 args
+= _T(" --strategy-option=") + dlg
.m_StrategyOption
;
2993 if (!dlg
.m_StrategyParam
.IsEmpty())
2994 args
+= _T("=") + dlg
.m_StrategyParam
;
2998 if(!dlg
.m_strLogMesage
.IsEmpty())
3000 CString logmsg
= dlg
.m_strLogMesage
;
3001 logmsg
.Replace(_T("\""), _T("\\\""));
3002 args
+= _T(" -m \"") + logmsg
+ _T("\"");
3004 cmd
.Format(_T("git.exe merge %s %s"), args
, g_Git
.FixBranchName(dlg
.m_VersionName
));
3006 CProgressDlg Prodlg
;
3007 Prodlg
.m_GitCmd
= cmd
;
3009 BOOL hasGitSVN
= CTGitPath(g_Git
.m_CurrentDir
).GetAdminDirMask() & ITEMIS_GITSVN
;
3010 if (dlg
.m_bNoCommit
)
3011 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUCOMMIT
)));
3014 if (dlg
.m_bIsBranch
)
3015 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REMOVEBRANCH
)));
3018 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUSVNDCOMMIT
)));
3021 Prodlg
.m_PostCmdCallback
= [&] ()
3023 if (Prodlg
.m_GitStatus
)
3025 Prodlg
.m_PostCmdList
.RemoveAll();
3028 if (!g_Git
.ListConflictFile(list
) && !list
.IsEmpty())
3030 // there are conflict files
3031 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
3036 INT_PTR ret
= Prodlg
.DoModal();
3037 if (Prodlg
.m_GitStatus
!= 0 && ret
== IDC_PROGRESS_BUTTON1
)
3039 CTGitPathList pathlist
;
3040 CTGitPathList selectedlist
;
3041 pathlist
.AddPath(g_Git
.m_CurrentDir
);
3042 bool bSelectFilesForCommit
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
3044 CAppUtils::Commit(CString(), false, str
, pathlist
, selectedlist
, bSelectFilesForCommit
);
3046 else if (ret
== IDC_PROGRESS_BUTTON1
)
3048 if (dlg
.m_bNoCommit
)
3051 CTGitPathList pathList
;
3052 CTGitPathList selectedList
;
3053 return Commit(_T(""), TRUE
, sLogMsg
, pathList
, selectedList
, true);
3055 else if (dlg
.m_bIsBranch
)
3058 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, dlg
.m_VersionName
);
3059 if (CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
3062 cmd
.Format(_T("git.exe branch -D -- %s"), dlg
.m_VersionName
);
3063 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3064 MessageBox(NULL
, out
, _T("TortoiseGit"), MB_OK
);
3068 CAppUtils::SVNDCommit();
3070 else if (ret
== IDC_PROGRESS_BUTTON1
+ 1 && hasGitSVN
)
3071 CAppUtils::SVNDCommit();
3073 return !Prodlg
.m_GitStatus
;
3078 BOOL
CAppUtils::MergeAbort()
3081 if (dlg
.DoModal() == IDOK
)
3085 switch (dlg
.m_ResetType
)
3088 type
= _T("--mixed");
3091 type
= _T("--hard");
3094 dlg
.m_ResetType
= 0;
3095 type
= _T("--mixed");
3098 cmd
.Format(_T("git.exe reset %s HEAD --"), type
);
3102 CProgressDlg progress
;
3103 progress
.m_GitCmd
= cmd
;
3105 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
3106 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 1)
3107 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
3109 progress
.m_PostFailCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MSGBOX_RETRY
)));
3112 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_RESET
))
3114 CGitProgressDlg gitdlg
;
3115 gitdlg
.SetCommand(CGitProgressList::GitProgress_Reset
);
3116 gitdlg
.SetRevision(_T("HEAD"));
3117 gitdlg
.SetResetType(dlg
.m_ResetType
+ 1);
3118 ret
= gitdlg
.DoModal();
3121 ret
= progress
.DoModal();
3123 if (progress
.m_GitStatus
== 0 && gitPath
.HasSubmodules() && dlg
.m_ResetType
== 1 && ret
== IDC_PROGRESS_BUTTON1
)
3126 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
3128 CCommonAppUtils::RunTortoiseGitProc(sCmd
);
3131 else if (progress
.m_GitStatus
!= 0 && ret
== IDC_PROGRESS_BUTTON1
)
3133 else if (ret
== IDOK
)
3142 void CAppUtils::EditNote(GitRev
*rev
)
3144 if (!CheckUserData())
3148 dlg
.m_sHintText
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
3149 dlg
.m_sInputText
= rev
->m_Notes
;
3150 dlg
.m_sTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
3151 //dlg.m_pProjectProperties = &m_ProjectProperties;
3152 dlg
.m_bUseLogWidth
= true;
3153 if(dlg
.DoModal() == IDOK
)
3156 cmd
=_T("notes add -f -F \"");
3158 CString tempfile
=::GetTempFile();
3159 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
3162 cmd
+= rev
->m_CommitHash
.ToString();
3166 if (git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
3168 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3173 rev
->m_Notes
= dlg
.m_sInputText
;
3177 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3179 ::DeleteFile(tempfile
);
3184 int CAppUtils::GetMsysgitVersion()
3186 if (g_Git
.ms_LastMsysGitVersion
)
3187 return g_Git
.ms_LastMsysGitVersion
;
3190 CString versiondebug
;
3193 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
3194 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
3196 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
3199 if (!g_Git
.GetFileModifyTime(gitpath
, &time
))
3201 if((DWORD
)time
== regTime
)
3203 g_Git
.ms_LastMsysGitVersion
= regVersion
;
3209 cmd
= _T("git.exe --version");
3210 if (g_Git
.Run(cmd
, &version
, &err
, CP_UTF8
))
3212 CMessageBox::Show(NULL
, _T("git.exe not correctly set up (") + err
+ _T(")\nCheck TortoiseGit settings and consult help file for \"Git.exe Path\"."), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
3219 versiondebug
= version
;
3223 CString str
=version
.Tokenize(_T("."), start
);
3224 int space
= str
.ReverseFind(_T(' '));
3225 str
= str
.Mid(space
+1,start
);
3229 version
= version
.Mid(start
);
3232 str
= version
.Tokenize(_T("."), start
);
3234 ver
|= (_ttol(str
) & 0xFF) << 16;
3236 str
= version
.Tokenize(_T("."), start
);
3237 ver
|= (_ttol(str
) & 0xFF) << 8;
3239 str
= version
.Tokenize(_T("."), start
);
3240 ver
|= (_ttol(str
) & 0xFF);
3246 CMessageBox::Show(NULL
, _T("Could not parse git.exe version number: \"") + versiondebug
+ _T("\""), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
3251 regTime
= time
&0xFFFFFFFF;
3253 g_Git
.ms_LastMsysGitVersion
= ver
;
3258 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
3260 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
3262 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("Shell32.dll"));
3264 if (hShell
.IsValid()) {
3265 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
3267 IPropertyStore
*pps
;
3268 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
3269 if (SUCCEEDED(hr
)) {
3272 var
.boolVal
= VARIANT_TRUE
;
3273 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
3280 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
3282 ASSERT(dialogname
.GetLength() < 70);
3283 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
3284 WCHAR pathbuf
[MAX_PATH
] = {0};
3286 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
3288 wcscat_s(pathbuf
, L
" - ");
3289 wcscat_s(pathbuf
, dialogname
);
3290 wcscat_s(pathbuf
, L
" - ");
3291 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3292 SetWindowText(hWnd
, pathbuf
);
3295 bool CAppUtils::BisectStart(CString lastGood
, CString firstBad
)
3297 if (!g_Git
.CheckCleanWorkTree())
3299 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
3301 CSysProgressDlg sysProgressDlg
;
3302 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3303 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
3304 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
3305 sysProgressDlg
.SetShowProgressBar(false);
3306 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
3307 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
3310 cmd
= _T("git.exe stash");
3311 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3313 sysProgressDlg
.Stop();
3314 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
);
3317 sysProgressDlg
.Stop();
3323 CBisectStartDlg bisectStartDlg
;
3325 if (!lastGood
.IsEmpty())
3326 bisectStartDlg
.m_sLastGood
= lastGood
;
3327 if (!firstBad
.IsEmpty())
3328 bisectStartDlg
.m_sFirstBad
= firstBad
;
3330 if (bisectStartDlg
.DoModal() == IDOK
)
3332 CProgressDlg progress
;
3333 theApp
.m_pMainWnd
= &progress
;
3334 progress
.m_GitCmdList
.push_back(_T("git.exe bisect start"));
3335 progress
.m_GitCmdList
.push_back(_T("git.exe bisect good ") + bisectStartDlg
.m_LastGoodRevision
);
3336 progress
.m_GitCmdList
.push_back(_T("git.exe bisect bad ") + bisectStartDlg
.m_FirstBadRevision
);
3338 CTGitPath
path(g_Git
.m_CurrentDir
);
3340 if (path
.HasSubmodules())
3341 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
3343 INT_PTR ret
= progress
.DoModal();
3344 if (path
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
3347 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
3349 CAppUtils::RunTortoiseGitProc(sCmd
);
3352 else if (ret
== IDOK
)
3359 int CAppUtils::Git2GetUserPassword(git_cred
**out
, const char *url
, const char *username_from_url
, unsigned int /*allowed_types*/, void * /*payload*/)
3362 dlg
.m_URL
= CUnicodeUtils::GetUnicode(url
, CP_UTF8
);
3363 if (username_from_url
)
3364 dlg
.m_UserName
= CUnicodeUtils::GetUnicode(username_from_url
, CP_UTF8
);
3366 CStringA username
, password
;
3367 if (dlg
.DoModal() == IDOK
)
3369 username
= CUnicodeUtils::GetMulti(dlg
.m_UserName
, CP_UTF8
);
3370 password
= CUnicodeUtils::GetMulti(dlg
.m_Password
, CP_UTF8
);
3371 return git_cred_userpass_plaintext_new(out
, username
, password
);