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
)
213 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
214 CString ext
= mergedfile
.GetFileExtension();
215 CString com
= regCom
;
216 bool bInternal
= false;
220 // is there an extension specific merge tool?
221 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
222 if (!CString(mergetool
).IsEmpty())
227 // is there a filename specific merge tool?
228 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\.") + mergedfile
.GetFilename().MakeLower());
229 if (!CString(mergetool
).IsEmpty())
234 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
236 // Maybe we should use TortoiseIDiff?
237 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
238 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
239 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
240 (ext
== _T(".tif")) || (ext
== _T(".tiff")) ||
241 (ext
== _T(".dib")) || (ext
== _T(".emf")))
243 com
= CPathUtils::GetAppDirectory() + _T("TortoiseGitIDiff.exe");
244 com
= _T("\"") + com
+ _T("\"");
245 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /result:%merged");
246 com
= com
+ _T(" /basetitle:%bname /theirstitle:%tname /minetitle:%yname");
250 // use TortoiseGitMerge
252 CRegString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE
);
253 com
= tortoiseMergePath
;
256 com
= CPathUtils::GetAppDirectory() + _T("TortoiseGitMerge.exe");
258 com
= _T("\"") + com
+ _T("\"");
259 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
260 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
261 com
+= _T(" /saverequired");
263 if (!g_sGroupingUUID
.IsEmpty())
265 com
+= L
" /groupuuid:\"";
266 com
+= g_sGroupingUUID
;
270 // check if the params are set. If not, just add the files to the command line
271 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
273 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
274 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
275 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
276 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
278 if (basefile
.IsEmpty())
280 com
.Replace(_T("/base:%base"), _T(""));
281 com
.Replace(_T("%base"), _T(""));
284 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
285 if (theirfile
.IsEmpty())
287 com
.Replace(_T("/theirs:%theirs"), _T(""));
288 com
.Replace(_T("%theirs"), _T(""));
291 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
292 if (yourfile
.IsEmpty())
294 com
.Replace(_T("/mine:%mine"), _T(""));
295 com
.Replace(_T("%mine"), _T(""));
298 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
299 if (mergedfile
.IsEmpty())
301 com
.Replace(_T("/merged:%merged"), _T(""));
302 com
.Replace(_T("%merged"), _T(""));
305 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
306 if (basename
.IsEmpty())
308 if (basefile
.IsEmpty())
310 com
.Replace(_T("/basename:%bname"), _T(""));
311 com
.Replace(_T("%bname"), _T(""));
315 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
319 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
320 if (theirname
.IsEmpty())
322 if (theirfile
.IsEmpty())
324 com
.Replace(_T("/theirsname:%tname"), _T(""));
325 com
.Replace(_T("%tname"), _T(""));
329 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
333 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
334 if (yourname
.IsEmpty())
336 if (yourfile
.IsEmpty())
338 com
.Replace(_T("/minename:%yname"), _T(""));
339 com
.Replace(_T("%yname"), _T(""));
343 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
347 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
348 if (mergedname
.IsEmpty())
350 if (mergedfile
.IsEmpty())
352 com
.Replace(_T("/mergedname:%mname"), _T(""));
353 com
.Replace(_T("%mname"), _T(""));
357 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
361 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
363 if ((bReadOnly
)&&(bInternal
))
364 com
+= _T(" /readonly");
366 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
374 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
377 // use TortoiseGitMerge
378 viewer
= CPathUtils::GetAppDirectory();
379 viewer
+= _T("TortoiseGitMerge.exe");
381 viewer
= _T("\"") + viewer
+ _T("\"");
382 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
383 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
385 viewer
+= _T(" /reversedpatch");
386 if (!sOriginalDescription
.IsEmpty())
387 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
388 if (!sPatchedDescription
.IsEmpty())
389 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
390 if (!g_sGroupingUUID
.IsEmpty())
392 viewer
+= L
" /groupuuid:\"";
393 viewer
+= g_sGroupingUUID
;
396 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
403 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
405 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file2
.GetFilename().MakeLower());
406 if (!difftool
.IsEmpty())
408 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file1
.GetFilename().MakeLower());
409 if (!difftool
.IsEmpty())
412 // Is there an extension specific diff tool?
413 CString ext
= file2
.GetFileExtension().MakeLower();
416 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
417 if (!difftool
.IsEmpty())
419 // Maybe we should use TortoiseIDiff?
420 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
421 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
422 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
423 (ext
== _T(".dib")) || (ext
== _T(".emf")))
426 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitIDiff.exe") + _T("\"") +
427 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname") +
428 L
" /groupuuid:\"" + g_sGroupingUUID
+ L
"\"";
432 // Finally, pick a generic external diff tool
433 difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
437 bool CAppUtils::StartExtDiff(
438 const CString
& file1
, const CString
& file2
,
439 const CString
& sName1
, const CString
& sName2
,
440 const CString
& originalFile1
, const CString
& originalFile2
,
441 const git_revnum_t
& hash1
, const git_revnum_t
& hash2
,
442 const DiffFlags
& flags
, int jumpToLine
)
446 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
447 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
449 viewer
= PickDiffTool(file1
, file2
);
450 // If registry entry for a diff program is commented out, use TortoiseGitMerge.
451 bool bCommentedOut
= viewer
.Left(1) == _T("#");
452 if (flags
.bAlternativeTool
)
454 // Invert external vs. internal diff tool selection.
456 viewer
.Delete(0); // uncomment
460 else if (bCommentedOut
)
464 bool bInternal
= viewer
.IsEmpty();
468 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitMerge.exe") + _T("\"") +
469 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
470 if (!g_sGroupingUUID
.IsEmpty())
472 viewer
+= L
" /groupuuid:\"";
473 viewer
+= g_sGroupingUUID
;
477 viewer
+= _T(" /blame");
479 // check if the params are set. If not, just add the files to the command line
480 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
482 viewer
+= _T(" \"")+file1
+_T("\"");
483 viewer
+= _T(" \"")+file2
+_T("\"");
485 if (viewer
.Find(_T("%base")) >= 0)
487 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
489 if (viewer
.Find(_T("%mine")) >= 0)
491 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
494 if (sName1
.IsEmpty())
495 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
497 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
499 if (sName2
.IsEmpty())
500 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
502 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
504 viewer
.Replace(_T("%bpath"), _T("\"") + originalFile1
+ _T("\""));
505 viewer
.Replace(_T("%ypath"), _T("\"") + originalFile2
+ _T("\""));
507 viewer
.Replace(_T("%brev"), _T("\"") + hash1
+ _T("\""));
508 viewer
.Replace(_T("%yrev"), _T("\"") + hash2
+ _T("\""));
510 if (flags
.bReadOnly
&& bInternal
)
511 viewer
+= _T(" /readonly");
516 temp
.Format(_T(" /line:%d"), jumpToLine
);
520 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
523 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
526 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
528 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
530 // use TortoiseGitUDiff
531 viewer
= CPathUtils::GetAppDirectory();
532 viewer
+= _T("TortoiseGitUDiff.exe");
533 // enquote the path to TortoiseGitUDiff
534 viewer
= _T("\"") + viewer
+ _T("\"");
536 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
537 if (!g_sGroupingUUID
.IsEmpty())
539 viewer
+= L
" /groupuuid:\"";
540 viewer
+= g_sGroupingUUID
;
544 if (viewer
.Find(_T("%1"))>=0)
546 if (viewer
.Find(_T("\"%1\"")) >= 0)
547 viewer
.Replace(_T("%1"), patchfile
);
549 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
552 viewer
+= _T(" \"") + patchfile
+ _T("\"");
553 if (viewer
.Find(_T("%title")) >= 0)
555 viewer
.Replace(_T("%title"), title
);
558 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
565 BOOL
CAppUtils::StartTextViewer(CString file
)
568 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
570 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
571 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
574 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
575 std::unique_ptr
<TCHAR
[]> buf(new TCHAR
[len
+ 1]);
576 ExpandEnvironmentStrings(viewer
, buf
.get(), len
);
578 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
579 std::unique_ptr
<TCHAR
[]> buf2(new TCHAR
[len
+ 1]);
580 ExpandEnvironmentStrings(file
, buf2
.get(), len
);
582 file
= _T("\"")+file
+_T("\"");
583 if (viewer
.IsEmpty())
585 viewer
= _T("RUNDLL32 Shell32,OpenAs_RunDLL");
587 if (viewer
.Find(_T("\"%1\"")) >= 0)
589 viewer
.Replace(_T("\"%1\""), file
);
591 else if (viewer
.Find(_T("%1")) >= 0)
593 viewer
.Replace(_T("%1"), file
);
601 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
608 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
611 CAutoFile hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
614 length
= ::GetFileSize(hFile
, NULL
);
621 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
624 HDC hScreenDC
= ::GetDC(NULL
);
625 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
626 ::ReleaseDC(NULL
, hScreenDC
);
628 logFont
.lfEscapement
= 0;
629 logFont
.lfOrientation
= 0;
630 logFont
.lfWeight
= FW_NORMAL
;
631 logFont
.lfItalic
= 0;
632 logFont
.lfUnderline
= 0;
633 logFont
.lfStrikeOut
= 0;
634 logFont
.lfCharSet
= DEFAULT_CHARSET
;
635 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
636 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
637 logFont
.lfQuality
= DRAFT_QUALITY
;
638 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
639 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
640 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
643 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
657 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
658 key
= g_Git
.GetConfigValue(cmd
);
666 CString proc
=CPathUtils::GetAppDirectory();
667 proc
+= _T("pageant.exe \"");
671 CString tempfile
= GetTempFile();
672 ::DeleteFile(tempfile
);
674 proc
+= _T(" -c \"");
675 proc
+= CPathUtils::GetAppDirectory();
676 proc
+= _T("tgittouch.exe\"");
681 CString appDir
= CPathUtils::GetAppDirectory();
682 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true, &appDir
);
687 while(!::PathFileExists(tempfile
))
692 break; //timeout 5 minutes
697 CMessageBox::Show(NULL
, IDS_ERR_PAEGENTTIMEOUT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
699 ::DeleteFile(tempfile
);
702 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
, bool uac
)
704 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
705 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
706 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
710 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
712 LaunchApplication(sCmd
, NULL
, false, NULL
, uac
);
715 bool CAppUtils::LaunchRemoteSetting()
717 CTGitPath
path(g_Git
.m_CurrentDir
);
718 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
719 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
720 dlg
.SetTreeWidth(220);
721 dlg
.m_DefaultPage
= _T("gitremote");
728 * Launch the external blame viewer
730 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
732 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
733 viewer
+= _T("TortoiseGitBlame.exe");
734 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
735 //viewer += _T(" \"") + sLogFile + _T("\"");
736 //viewer += _T(" \"") + sOriginalFile + _T("\"");
737 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
738 viewer
+= CString(_T(" /rev:"))+Rev
;
739 if (!g_sGroupingUUID
.IsEmpty())
741 viewer
+= L
" /groupuuid:\"";
742 viewer
+= g_sGroupingUUID
;
745 viewer
+= _T(" ")+sParams
;
747 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
750 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
755 bool bStyled
= false;
756 pWnd
->GetWindowText(sText
);
757 // the rich edit control doesn't count the CR char!
758 // to be exact: CRLF is treated as one char.
759 sText
.Remove(_T('\r'));
761 // style each line separately
766 nNewlinePos
= sText
.Find('\n', offset
);
767 CString sLine
= nNewlinePos
>= 0 ? sText
.Mid(offset
, nNewlinePos
- offset
) : sText
.Mid(offset
);
771 while (FindStyleChars(sLine
, '*', start
, end
))
773 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
774 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
775 SetCharFormat(pWnd
, CFM_BOLD
, CFE_BOLD
);
781 while (FindStyleChars(sLine
, '^', start
, end
))
783 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
784 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
785 SetCharFormat(pWnd
, CFM_ITALIC
, CFE_ITALIC
);
791 while (FindStyleChars(sLine
, '_', start
, end
))
793 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
794 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
795 SetCharFormat(pWnd
, CFM_UNDERLINE
, CFE_UNDERLINE
);
799 offset
= nNewlinePos
+1;
800 } while(nNewlinePos
>=0);
804 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
807 int last
= sText
.GetLength() - 1;
808 bool bFoundMarker
= false;
809 TCHAR c
= i
== 0 ? _T('\0') : sText
[i
- 1];
810 TCHAR nextChar
= i
>= last
? _T('\0') : sText
[i
+ 1];
812 // find a starting marker
817 nextChar
= sText
[i
+ 1];
819 // IsCharAlphaNumeric can be somewhat expensive.
820 // Long lines of "*****" or "----" will be pre-empted efficiently
821 // by the (c != nextChar) condition.
823 if ((c
== stylechar
) && (c
!= nextChar
))
825 if (IsCharAlphaNumeric(nextChar
) && !IsCharAlphaNumeric(prevChar
))
837 // find ending marker
840 bFoundMarker
= false;
847 if ((i
== last
) || (!IsCharAlphaNumeric(sText
[i
+ 1]) && IsCharAlphaNumeric(prevChar
)))
860 bool CAppUtils::StartShowUnifiedDiff(HWND hWnd
, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
861 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
862 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
863 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */,
864 bool /* blame = false */,
869 if (GetMsysgitVersion() > 0x01080100)
870 diffContext
= _ttoi(g_Git
.GetConfigValue(_T("diff.context")));
871 CString tempfile
=GetTempFile();
872 if (g_Git
.GetUnifiedDiff(url1
, rev1
, rev2
, tempfile
, bMerge
, bCombine
, diffContext
))
874 CMessageBox::Show(hWnd
, g_Git
.GetGitLastErr(_T("Could not get unified diff."), CGit::GIT_CMD_DIFF
), _T("TortoiseGit"), MB_OK
);
877 CAppUtils::StartUnifiedDiffViewer(tempfile
, rev1
+ _T(":") + rev2
);
881 sCmd
.Format(_T("%s /command:showcompare /unified"),
882 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseGitProc.exe")));
883 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
885 sCmd
+= _T(" /revision1:") + rev1
.ToString();
886 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
888 sCmd
+= _T(" /revision2:") + rev2
.ToString();
890 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
891 if (headpeg
.IsValid())
892 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
895 sCmd
+= _T(" /alternatediff");
898 sCmd
+= _T(" /ignoreancestry");
902 sCmd
+= _T(" /hwnd:");
904 _stprintf_s(buf
, 30, _T("%p"), (void*)hWnd
);
908 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
913 bool CAppUtils::SetupDiffScripts(bool force
, const CString
& type
)
915 CString scriptsdir
= CPathUtils::GetAppParentDirectory();
916 scriptsdir
+= _T("Diff-Scripts");
917 CSimpleFileFind
files(scriptsdir
);
918 while (files
.FindNextFileNoDirectories())
920 CString file
= files
.GetFilePath();
921 CString filename
= files
.GetFileName();
922 CString ext
= file
.Mid(file
.ReverseFind('-') + 1);
923 ext
= _T(".") + ext
.Left(ext
.ReverseFind('.'));
924 std::set
<CString
> extensions
;
925 extensions
.insert(ext
);
927 if (file
.Right(3).CompareNoCase(_T("vbs"))==0)
929 kind
= _T(" //E:vbscript");
931 if (file
.Right(2).CompareNoCase(_T("js"))==0)
933 kind
= _T(" //E:javascript");
935 // open the file, read the first line and find possible extensions
936 // this script can handle
939 CStdioFile
f(file
, CFile::modeRead
| CFile::shareDenyNone
);
941 if (f
.ReadString(extline
))
943 if ((extline
.GetLength() > 15 ) &&
944 ((extline
.Left(15).Compare(_T("// extensions: ")) == 0) ||
945 (extline
.Left(14).Compare(_T("' extensions: ")) == 0)))
947 if (extline
[0] == '/')
948 extline
= extline
.Mid(15);
950 extline
= extline
.Mid(14);
953 sToken
= extline
.Tokenize(_T(";"), curPos
);
954 while (!sToken
.IsEmpty())
956 if (!sToken
.IsEmpty())
958 if (sToken
[0] != '.')
959 sToken
= _T(".") + sToken
;
960 extensions
.insert(sToken
);
962 sToken
= extline
.Tokenize(_T(";"), curPos
);
968 catch (CFileException
* e
)
973 for (std::set
<CString
>::const_iterator it
= extensions
.begin(); it
!= extensions
.end(); ++it
)
975 if (type
.IsEmpty() || (type
.Compare(_T("Diff")) == 0))
977 if (filename
.Left(5).CompareNoCase(_T("diff-")) == 0)
979 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + *it
);
980 CString diffregstring
= diffreg
;
981 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
982 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %base %mine") + kind
;
985 if (type
.IsEmpty() || (type
.Compare(_T("Merge"))==0))
987 if (filename
.Left(6).CompareNoCase(_T("merge-"))==0)
989 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\MergeTools\\") + *it
);
990 CString diffregstring
= diffreg
;
991 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
992 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %merged %theirs %mine %base") + kind
;
1001 bool CAppUtils::Export(CString
*BashHash
, const CTGitPath
*orgPath
)
1003 // ask from where the export has to be done
1006 dlg
.m_Revision
=*BashHash
;
1009 if (PathIsRelative(orgPath
->GetWinPath()))
1010 dlg
.m_orgPath
= g_Git
.m_CurrentDir
+ _T("\\") + orgPath
->GetWinPathString();
1012 dlg
.m_orgPath
= *orgPath
;
1015 if (dlg
.DoModal() == IDOK
)
1018 cmd
.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s --"),
1019 dlg
.m_strFile
, g_Git
.FixBranchName(dlg
.m_VersionName
));
1024 if (!dlg
.m_bWholeProject
&& !dlg
.m_orgPath
.IsEmpty() && PathIsDirectory(dlg
.m_orgPath
.GetWinPathString()))
1026 git
.m_CurrentDir
= dlg
.m_orgPath
.GetWinPathString();
1029 return (pro
.DoModal() == IDOK
);
1034 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
, bool switch_new_brach
)
1036 CCreateBranchTagDlg dlg
;
1038 dlg
.m_bSwitch
=switch_new_brach
;
1041 dlg
.m_initialRefName
= *CommitHash
;
1043 if(dlg
.DoModal()==IDOK
)
1048 if(dlg
.m_bTrack
== TRUE
)
1049 track
=_T(" --track ");
1050 else if(dlg
.m_bTrack
== FALSE
)
1051 track
=_T(" --no-track");
1062 cmd
.Format(_T("git.exe tag %s %s %s %s"),
1065 dlg
.m_BranchTagName
,
1066 g_Git
.FixBranchName(dlg
.m_VersionName
)
1069 CString tempfile
=::GetTempFile();
1070 if(!dlg
.m_Message
.Trim().IsEmpty())
1072 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_Message
);
1073 cmd
+= _T(" -F ")+tempfile
;
1078 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1081 dlg
.m_BranchTagName
,
1082 g_Git
.FixBranchName(dlg
.m_VersionName
)
1086 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1088 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1091 if( !IsTag
&& dlg
.m_bSwitch
)
1093 // it is a new branch and the user has requested to switch to it
1094 PerformSwitch(dlg
.m_BranchTagName
);
1102 bool CAppUtils::Switch(CString initialRefName
)
1105 if(!initialRefName
.IsEmpty())
1106 dlg
.m_initialRefName
= initialRefName
;
1108 if (dlg
.DoModal() == IDOK
)
1112 branch
= dlg
.m_NewBranch
;
1114 // if refs/heads/ is not stripped, checkout will detach HEAD
1115 // checkout prefers branches on name clashes (with tags)
1116 if (dlg
.m_VersionName
.Left(11) ==_T("refs/heads/") && dlg
.m_bBranchOverride
!= TRUE
)
1117 dlg
.m_VersionName
= dlg
.m_VersionName
.Mid(11);
1119 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
, dlg
.m_bMerge
== TRUE
);
1124 bool CAppUtils::PerformSwitch(CString ref
, bool bForce
/* false */, CString sNewBranch
/* CString() */, bool bBranchOverride
/* false */, BOOL bTrack
/* 2 */, bool bMerge
/* false */)
1132 if(!sNewBranch
.IsEmpty()){
1133 if (bBranchOverride
)
1135 branch
.Format(_T("-B %s"), sNewBranch
);
1139 branch
.Format(_T("-b %s"), sNewBranch
);
1142 track
= _T("--track");
1143 else if (bTrack
== FALSE
)
1144 track
= _T("--no-track");
1149 merge
= _T("--merge");
1151 cmd
.Format(_T("git.exe checkout %s %s %s %s %s --"),
1156 g_Git
.FixBranchName(ref
));
1160 CProgressDlg progress
;
1161 progress
.m_GitCmd
= cmd
;
1163 INT_PTR idPull
= -1;
1164 INT_PTR idSubmoduleUpdate
= -1;
1165 INT_PTR idMerge
= -1;
1167 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1168 if (gitPath
.HasSubmodules())
1169 idSubmoduleUpdate
= progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1170 CString currentBranch
;
1171 bool hasBranch
= CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, currentBranch
) == 0;
1173 idMerge
= progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUMERGE
)));
1175 progress
.m_PostCmdCallback
= [&] ()
1177 if (!progress
.m_GitStatus
)
1180 if (!CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, newBranch
))
1181 idPull
= progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPULL
)));
1185 progress
.m_PostCmdList
.RemoveAll();
1186 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MSGBOX_RETRY
)));
1187 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_SWITCH_WITH_MERGE
)));
1191 INT_PTR ret
= progress
.DoModal();
1192 if (progress
.m_GitStatus
== 0)
1194 if (idSubmoduleUpdate
>= 0 && ret
== IDC_PROGRESS_BUTTON1
+ idSubmoduleUpdate
)
1197 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1199 RunTortoiseGitProc(sCmd
);
1202 else if (ret
== IDC_PROGRESS_BUTTON1
+ idPull
)
1207 else if (ret
== IDC_PROGRESS_BUTTON1
+ idMerge
)
1209 Merge(¤tBranch
);
1212 else if (ret
== IDOK
)
1215 else if (ret
== IDC_PROGRESS_BUTTON1
)
1217 else if (ret
== IDC_PROGRESS_BUTTON1
+ 1)
1219 merge
= _T("--merge");
1220 cmd
.Format(_T("git.exe checkout %s %s %s %s %s --"),
1221 force
, track
, merge
, branch
, g_Git
.FixBranchName(ref
));
1229 class CIgnoreFile
: public CStdioFile
1232 STRING_VECTOR m_Items
;
1235 virtual BOOL
ReadString(CString
& rString
)
1237 if (GetPosition() == 0)
1239 unsigned char utf8bom
[] = { 0xEF, 0xBB, 0xBF };
1240 char buf
[3] = { 0, 0, 0 };
1242 if (memcpy(buf
, utf8bom
, sizeof(utf8bom
)))
1249 char lastChar
= '\0';
1250 for (char c
= '\0'; Read(&c
, 1) == 1; lastChar
= c
)
1256 m_eol
= lastChar
== '\r' ? _T("\r\n") : _T("\n");
1264 rString
= CUnicodeUtils::GetUnicode(strA
);
1275 bool CAppUtils::OpenIgnoreFile(CIgnoreFile
&file
, const CString
& filename
)
1278 if (!file
.Open(filename
, CFile::modeCreate
| CFile::modeReadWrite
| CFile::modeNoTruncate
| CFile::typeBinary
))
1280 CMessageBox::Show(NULL
, filename
+ _T(" Open Failure"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1284 if (file
.GetLength() > 0)
1287 while (file
.ReadString(fileText
))
1288 file
.m_Items
.push_back(fileText
);
1289 file
.Seek(file
.GetLength() - 1, 0);
1290 char lastchar
[1] = { 0 };
1291 file
.Read(lastchar
, 1);
1293 if (lastchar
[0] != '\n')
1295 CStringA eol
= CStringA(file
.m_eol
.IsEmpty() ? _T("\n") : file
.m_eol
);
1296 file
.Write(eol
, eol
.GetLength());
1305 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1307 CIgnoreDlg ignoreDlg
;
1308 if (ignoreDlg
.DoModal() == IDOK
)
1311 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\");
1313 switch (ignoreDlg
.m_IgnoreFile
)
1316 ignorefile
+= _T(".gitignore");
1319 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, ignorefile
);
1320 ignorefile
+= _T("info/exclude");
1327 if (ignoreDlg
.m_IgnoreFile
!= 1 && !OpenIgnoreFile(file
, ignorefile
))
1330 for (int i
= 0; i
< path
.GetCount(); ++i
)
1332 if (ignoreDlg
.m_IgnoreFile
== 1)
1334 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\") + path
[i
].GetContainingDirectory().GetWinPathString() + _T("\\.gitignore");
1335 if (!OpenIgnoreFile(file
, ignorefile
))
1339 CString ignorePattern
;
1340 if (ignoreDlg
.m_IgnoreType
== 0)
1342 if (ignoreDlg
.m_IgnoreFile
!= 1 && !path
[i
].GetContainingDirectory().GetGitPathString().IsEmpty())
1343 ignorePattern
+= _T("/") + path
[i
].GetContainingDirectory().GetGitPathString();
1345 ignorePattern
+= _T("/");
1349 ignorePattern
+= _T("*") + path
[i
].GetFileExtension();
1353 ignorePattern
+= path
[i
].GetFileOrDirectoryName();
1356 // escape [ and ] so that files get ignored correctly
1357 ignorePattern
.Replace(_T("["), _T("\\["));
1358 ignorePattern
.Replace(_T("]"), _T("\\]"));
1361 for (size_t j
= 0; j
< file
.m_Items
.size(); ++j
)
1363 if (file
.m_Items
[j
] == ignorePattern
)
1371 file
.m_Items
.push_back(ignorePattern
);
1372 ignorePattern
+= file
.m_eol
.IsEmpty() ? _T("\n") : file
.m_eol
;
1373 CStringA ignorePatternA
= CUnicodeUtils::GetUTF8(ignorePattern
);
1374 file
.Write(ignorePatternA
, ignorePatternA
.GetLength());
1377 if (ignoreDlg
.m_IgnoreFile
== 1)
1381 if (ignoreDlg
.m_IgnoreFile
!= 1)
1396 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1399 dlg
.m_ResetType
=type
;
1400 dlg
.m_ResetToVersion
=*CommitHash
;
1401 dlg
.m_initialRefName
= *CommitHash
;
1402 if (dlg
.DoModal() == IDOK
)
1406 switch(dlg
.m_ResetType
)
1418 dlg
.m_ResetType
= 1;
1422 cmd
.Format(_T("git.exe reset %s %s --"),type
, dlg
.m_ResetToVersion
);
1426 CProgressDlg progress
;
1427 progress
.m_GitCmd
=cmd
;
1429 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1430 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2)
1431 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1433 progress
.m_PostFailCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MSGBOX_RETRY
)));
1436 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_RESET
))
1438 CGitProgressDlg gitdlg
;
1439 gitdlg
.SetCommand(CGitProgressList::GitProgress_Reset
);
1440 gitdlg
.SetRevision(dlg
.m_ResetToVersion
);
1441 gitdlg
.SetResetType(dlg
.m_ResetType
);
1442 ret
= gitdlg
.DoModal();
1445 ret
= progress
.DoModal();
1447 if (progress
.m_GitStatus
== 0 && gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2 && ret
== IDC_PROGRESS_BUTTON1
)
1450 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1452 RunTortoiseGitProc(sCmd
);
1455 else if (progress
.m_GitStatus
!= 0 && ret
== IDC_PROGRESS_BUTTON1
)
1457 else if (ret
== IDOK
)
1466 void CAppUtils::DescribeConflictFile(bool mode
, bool base
,CString
&descript
)
1470 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_DELETE
));
1475 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_MODIFIED
));
1478 descript
= CString(MAKEINTRESOURCE(IDS_PROC_CREATED
));
1482 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1484 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("LOCAL"), path
));
1485 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("REMOTE"), path
));
1486 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("BASE"), path
));
1488 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1491 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1496 bool ParseHashesFromLsFile(BYTE_VECTOR
&out
, CString
&hash1
, CString
&hash2
, CString
&hash3
)
1498 unsigned int pos
= 0;
1502 while (pos
>= 0 && pos
< out
.size())
1506 g_Git
.StringAppend(&one
, &out
[pos
], CP_UTF8
);
1508 one
.Tokenize(_T("\t"), tabstart
);
1511 part
= one
.Tokenize(_T(" "), tabstart
); //Tag
1512 part
= one
.Tokenize(_T(" "), tabstart
); //Mode
1513 part
= one
.Tokenize(_T(" "), tabstart
); //Hash
1514 CString hash
= part
;
1515 part
= one
.Tokenize(_T("\t"), tabstart
); //Stage
1516 int stage
= _ttol(part
);
1519 else if (stage
== 2)
1521 else if (stage
== 3)
1527 pos
= out
.findNextString(pos
);
1533 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool /*bAlternativeTool*/,bool revertTheirMy
)
1537 CTGitPath merge
=path
;
1538 CTGitPath directory
= merge
.GetDirectory();
1540 // we have the conflicted file (%merged)
1541 // now look for the other required files
1543 //stat.GetStatus(merge);
1544 //if (stat.status == NULL)
1550 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1552 if (g_Git
.Run(cmd
, &vector
))
1557 if (merge
.IsDirectory())
1559 CString baseHash
, localHash
, remoteHash
;
1560 if (!ParseHashesFromLsFile(vector
, baseHash
, localHash
, remoteHash
))
1564 msg
.Format(_T("BASE: %s\nLOCAL: %s\nREMOTE: %s"), baseHash
, localHash
, remoteHash
);
1565 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
);
1570 if (list
.ParserFromLsFile(vector
))
1572 CMessageBox::Show(NULL
, _T("Parse ls-files failed!"), _T("TortoiseGit"), MB_OK
);
1585 mine
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1586 theirs
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1590 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1591 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1593 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1597 //format=_T("git.exe cat-file blob \":%d:%s\"");
1598 format
= _T("git.exe checkout-index --temp --stage=%d -- \"%s\"");
1600 //create a empty file, incase stage is not three
1601 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1603 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1605 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1608 bool b_base
=false, b_local
=false, b_remote
=false;
1610 for (int i
= 0; i
< list
.GetCount(); ++i
)
1617 if( list
[i
].m_Stage
== 1)
1619 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1621 outfile
= base
.GetWinPathString();
1624 if( list
[i
].m_Stage
== 2 )
1626 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1628 outfile
= mine
.GetWinPathString();
1631 if( list
[i
].m_Stage
== 3 )
1633 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1635 outfile
= theirs
.GetWinPathString();
1637 CString output
, err
;
1638 if(!outfile
.IsEmpty())
1639 if (!g_Git
.Run(cmd
, &output
, &err
, CP_UTF8
))
1643 file
= output
.Tokenize(_T("\t"), start
);
1644 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1648 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1652 if(b_local
&& b_remote
)
1654 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1656 bRet
= !!CAppUtils::StartExtMerge(base
, mine
, theirs
, merge
, _T("BASE"), _T("REMOTE"), _T("LOCAL"));
1658 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"), _T("REMOTE"), _T("LOCAL"));
1663 ::DeleteFile(mine
.GetWinPathString());
1664 ::DeleteFile(theirs
.GetWinPathString());
1665 ::DeleteFile(base
.GetWinPathString());
1667 CDeleteConflictDlg dlg
;
1668 DescribeConflictFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1669 DescribeConflictFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1670 CGitHash localHash
, remoteHash
;
1671 if (!g_Git
.GetHash(localHash
, _T("HEAD")))
1672 dlg
.m_LocalHash
= localHash
.ToString();
1673 if (!g_Git
.GetHash(remoteHash
, _T("MERGE_HEAD")))
1674 dlg
.m_RemoteHash
= remoteHash
.ToString();
1675 else if (!g_Git
.GetHash(remoteHash
, _T("rebase-apply/original-commit")))
1676 dlg
.m_RemoteHash
= remoteHash
.ToString();
1677 else if (!g_Git
.GetHash(remoteHash
, _T("CHERRY_PICK_HEAD")))
1678 dlg
.m_RemoteHash
= remoteHash
.ToString();
1679 else if (!g_Git
.GetHash(remoteHash
, _T("REVERT_HEAD")))
1680 dlg
.m_RemoteHash
= remoteHash
.ToString();
1681 dlg
.m_bShowModifiedButton
=b_base
;
1682 dlg
.m_File
=merge
.GetGitPathString();
1683 if(dlg
.DoModal() == IDOK
)
1688 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1691 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1693 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1695 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1705 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1706 base
, theirs
, mine
, merge
);
1709 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1711 // we have a text conflict, use our merge tool to resolve the conflict
1713 CTSVNPath
theirs(directory
);
1714 CTSVNPath
mine(directory
);
1715 CTSVNPath
base(directory
);
1716 bool bConflictData
= false;
1718 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1720 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1721 bConflictData
= true;
1723 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1725 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1726 bConflictData
= true;
1728 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1730 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1731 bConflictData
= true;
1738 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1739 base
, theirs
, mine
, merge
);
1742 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1744 // we have a property conflict
1745 CTSVNPath
prej(directory
);
1746 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1748 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1749 // there's a problem: the prej file contains a _description_ of the conflict, and
1750 // that description string might be translated. That means we have no way of parsing
1751 // the file to find out the conflicting values.
1752 // The only thing we can do: show a dialog with the conflict description, then
1753 // let the user either accept the existing property or open the property edit dialog
1754 // to manually change the properties and values. And a button to mark the conflict as
1756 CEditPropConflictDlg dlg
;
1757 dlg
.SetPrejFile(prej
);
1758 dlg
.SetConflictedItem(merge
);
1759 bRet
= (dlg
.DoModal() != IDCANCEL
);
1763 if (stat
.status
->tree_conflict
)
1765 // we have a tree conflict
1767 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1770 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1772 CTSVNPath
theirs(directory
);
1773 CTSVNPath
mine(directory
);
1774 CTSVNPath
base(directory
);
1775 bool bConflictData
= false;
1777 if (pInfoData
->treeconflict_theirfile
)
1779 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1780 bConflictData
= true;
1782 if (pInfoData
->treeconflict_basefile
)
1784 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1785 bConflictData
= true;
1787 if (pInfoData
->treeconflict_myfile
)
1789 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1790 bConflictData
= true;
1797 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1798 base
, theirs
, mine
, merge
);
1800 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1802 CString sConflictAction
;
1803 CString sConflictReason
;
1804 CString sResolveTheirs
;
1805 CString sResolveMine
;
1806 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1807 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1809 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1811 switch (pInfoData
->treeconflict_operation
)
1813 case svn_wc_operation_update
:
1814 switch (pInfoData
->treeconflict_action
)
1816 case svn_wc_conflict_action_edit
:
1817 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1818 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1820 case svn_wc_conflict_action_add
:
1821 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1822 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1824 case svn_wc_conflict_action_delete
:
1825 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1826 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1830 case svn_wc_operation_switch
:
1831 switch (pInfoData
->treeconflict_action
)
1833 case svn_wc_conflict_action_edit
:
1834 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1835 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1837 case svn_wc_conflict_action_add
:
1838 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1839 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1841 case svn_wc_conflict_action_delete
:
1842 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1843 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1847 case svn_wc_operation_merge
:
1848 switch (pInfoData
->treeconflict_action
)
1850 case svn_wc_conflict_action_edit
:
1851 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1852 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1854 case svn_wc_conflict_action_add
:
1855 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1856 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1858 case svn_wc_conflict_action_delete
:
1859 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1860 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1866 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1868 switch (pInfoData
->treeconflict_operation
)
1870 case svn_wc_operation_update
:
1871 switch (pInfoData
->treeconflict_action
)
1873 case svn_wc_conflict_action_edit
:
1874 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1875 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1877 case svn_wc_conflict_action_add
:
1878 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1879 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1881 case svn_wc_conflict_action_delete
:
1882 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1883 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1887 case svn_wc_operation_switch
:
1888 switch (pInfoData
->treeconflict_action
)
1890 case svn_wc_conflict_action_edit
:
1891 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1892 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1894 case svn_wc_conflict_action_add
:
1895 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1896 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1898 case svn_wc_conflict_action_delete
:
1899 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1900 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1904 case svn_wc_operation_merge
:
1905 switch (pInfoData
->treeconflict_action
)
1907 case svn_wc_conflict_action_edit
:
1908 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1909 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1911 case svn_wc_conflict_action_add
:
1912 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1913 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1915 case svn_wc_conflict_action_delete
:
1916 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1917 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1925 switch (pInfoData
->treeconflict_reason
)
1927 case svn_wc_conflict_reason_edited
:
1928 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1929 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1931 case svn_wc_conflict_reason_obstructed
:
1932 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1933 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1935 case svn_wc_conflict_reason_deleted
:
1936 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1937 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1939 case svn_wc_conflict_reason_added
:
1940 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1941 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1943 case svn_wc_conflict_reason_missing
:
1944 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1945 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1947 case svn_wc_conflict_reason_unversioned
:
1948 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1949 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1952 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1954 CTreeConflictEditorDlg dlg
;
1955 dlg
.SetConflictInfoText(sConflictReason
);
1956 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1957 dlg
.SetPath(treeConflictPath
);
1958 INT_PTR dlgRet
= dlg
.DoModal();
1959 bRet
= (dlgRet
!= IDCANCEL
);
1967 bool CAppUtils::IsSSHPutty()
1969 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1970 sshclient
=sshclient
.MakeLower();
1971 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1978 CString
CAppUtils::GetClipboardLink(const CString
&skipGitPrefix
, int paramsCount
)
1980 if (!OpenClipboard(NULL
))
1983 CString sClipboardText
;
1984 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1987 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1988 sClipboardText
= CString(lpstr
);
1991 hglb
= GetClipboardData(CF_UNICODETEXT
);
1994 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1995 sClipboardText
= lpstr
;
2000 if(!sClipboardText
.IsEmpty())
2002 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
2003 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
2005 if(sClipboardText
.Find( _T("http://")) == 0)
2006 return sClipboardText
;
2008 if(sClipboardText
.Find( _T("https://")) == 0)
2009 return sClipboardText
;
2011 if(sClipboardText
.Find( _T("git://")) == 0)
2012 return sClipboardText
;
2014 if(sClipboardText
.Find( _T("ssh://")) == 0)
2015 return sClipboardText
;
2017 if(sClipboardText
.GetLength()>=2)
2018 if( sClipboardText
[1] == _T(':') )
2019 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
2020 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
2021 return sClipboardText
;
2023 // trim prefixes like "git clone "
2024 if (!skipGitPrefix
.IsEmpty() && sClipboardText
.Find(skipGitPrefix
) == 0)
2026 sClipboardText
= sClipboardText
.Mid(skipGitPrefix
.GetLength()).Trim();
2028 while (paramsCount
>= 0)
2031 spacePos
= sClipboardText
.Find(_T(' '), spacePos
+ 1);
2035 if (spacePos
> 0 && paramsCount
< 0)
2036 sClipboardText
= sClipboardText
.Left(spacePos
);
2037 return sClipboardText
;
2041 return CString(_T(""));
2044 CString
CAppUtils::ChooseRepository(CString
*path
)
2046 CBrowseFolder browseFolder
;
2047 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
2049 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
2050 CString strCloneDirectory
;
2052 strCloneDirectory
=*path
;
2055 strCloneDirectory
= regLastResopitory
;
2059 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
2061 browseFolder
.SetInfo(title
);
2063 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
2065 regLastResopitory
= strCloneDirectory
;
2066 return strCloneDirectory
;
2074 bool CAppUtils::SendPatchMail(CTGitPathList
& list
)
2078 dlg
.m_PathList
= list
;
2080 if(dlg
.DoModal()==IDOK
)
2082 if (dlg
.m_PathList
.IsEmpty())
2085 CGitProgressDlg progDlg
;
2087 theApp
.m_pMainWnd
= &progDlg
;
2088 progDlg
.SetCommand(CGitProgressList::GitProgress_SendMail
);
2090 progDlg
.SetPathList(dlg
.m_PathList
);
2091 //ProjectProperties props;
2092 //props.ReadPropsPathList(dlg.m_pathList);
2093 //progDlg.SetProjectProperties(props);
2094 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2096 CSendMailPatch
sendMailPatch(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
);
2097 progDlg
.SetSendMailOption(&sendMailPatch
);
2106 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
)
2109 CString log
=formatpatchoutput
;
2110 int start
=log
.Find(cmd
);
2112 CString one
=log
.Tokenize(_T("\n"),start
);
2118 CString one
=log
.Tokenize(_T("\n"),start
);
2120 if(one
.IsEmpty() || one
.Find(_T("Success")) == 0)
2122 one
.Replace(_T('/'),_T('\\'));
2124 path
.SetFromWin(one
);
2127 if (!list
.IsEmpty())
2129 return SendPatchMail(list
);
2133 CMessageBox::Show(NULL
, IDS_ERR_NOPATCHES
, IDS_APPNAME
, MB_ICONINFORMATION
);
2139 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
2142 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
2143 if(output
.IsEmpty())
2144 return CUnicodeUtils::GetCPCode(pGit
->GetConfigValue(_T("i18n.commitencoding")));
2147 return CUnicodeUtils::GetCPCode(output
);
2150 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
2152 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
2153 int cp
= CUnicodeUtils::GetCPCode(g_Git
.GetConfigValue(_T("i18n.commitencoding")));
2155 bool stripComments
= (CRegDWORD(_T("Software\\TortoiseGit\\StripCommentedLines"), FALSE
) == TRUE
);
2157 if (CRegDWORD(_T("Software\\TortoiseGit\\SanitizeCommitMsg"), TRUE
) == TRUE
)
2158 message
.TrimRight(L
" \r\n");
2160 int len
= message
.GetLength();
2162 while (start
>= 0 && start
< len
)
2164 int oldStart
= start
;
2165 start
= message
.Find(L
"\n", oldStart
);
2166 CString line
= message
.Mid(oldStart
);
2169 line
= line
.Left(start
- oldStart
);
2170 ++start
; // move forward so we don't find the same char again
2172 if (stripComments
&& (line
.GetLength() >= 1 && line
.GetAt(0) == '#') || (start
< 0 && line
.IsEmpty()))
2174 line
.TrimRight(L
" \r");
2175 CStringA lineA
= CUnicodeUtils::GetMulti(line
+ L
"\n", cp
);
2176 file
.Write(lineA
.GetBuffer(), lineA
.GetLength());
2182 bool CAppUtils::Pull(bool showPush
)
2185 dlg
.m_IsPull
= TRUE
;
2186 if (dlg
.DoModal() == IDOK
)
2188 CString url
= dlg
.m_RemoteURL
;
2190 if (dlg
.m_bAutoLoad
)
2192 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
2197 if (g_Git
.GetHash(hashOld
, _T("HEAD")))
2199 MessageBox(NULL
, g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
2211 cmdRebase
= "--rebase ";
2213 if (!dlg
.m_bFetchTags
)
2214 notags
= _T("--no-tags");
2220 ffonly
= _T("--ff-only");
2223 squash
= _T("--squash");
2225 if (dlg
.m_bNoCommit
)
2226 nocommit
= _T("--no-commit");
2228 int ver
= CAppUtils::GetMsysgitVersion();
2230 if(ver
>= 0x01070203) //above 1.7.0.2
2231 cmdRebase
+= _T("--progress ");
2233 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
);
2234 CProgressDlg progress
;
2235 progress
.m_GitCmd
= cmd
;
2236 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_DIFFS
)));
2237 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_LOG
)));
2238 INT_PTR pushButton
= showPush
? progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
))) + IDC_PROGRESS_BUTTON1
: -1;
2240 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
2241 INT_PTR smUpdateButton
= gitPath
.HasSubmodules() ? progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
))) + IDC_PROGRESS_BUTTON1
: -1;
2243 INT_PTR ret
= progress
.DoModal();
2245 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
)
2248 dlg
.m_pathList
.AddPath(CTGitPath());
2255 if (g_Git
.GetHash(hashNew
, _T("HEAD")))
2257 MessageBox(NULL
, g_Git
.GetGitLastErr(_T("Could not get HEAD hash after pulling.")), _T("TortoiseGit"), MB_ICONERROR
);
2261 if( ret
== IDC_PROGRESS_BUTTON1
)
2263 if(hashOld
== hashNew
)
2265 if(progress
.m_GitStatus
== 0)
2266 CMessageBox::Show(NULL
, IDS_UPTODATE
, IDS_APPNAME
, MB_OK
| MB_ICONINFORMATION
);
2271 dlg
.SetDiff(NULL
, hashNew
.ToString(), hashOld
.ToString());
2276 else if ( ret
== IDC_PROGRESS_BUTTON1
+1 )
2278 if(hashOld
== hashNew
)
2280 if(progress
.m_GitStatus
== 0)
2281 CMessageBox::Show(NULL
, IDS_UPTODATE
, IDS_APPNAME
, MB_OK
| MB_ICONINFORMATION
);
2286 dlg
.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), hashOld
.ToString() + _T("..") + hashNew
.ToString(), 0);
2289 else if (ret
== pushButton
)
2294 else if (ret
== smUpdateButton
)
2297 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
2299 CAppUtils::RunTortoiseGitProc(sCmd
);
2307 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
, bool allRemotes
)
2310 dlg
.m_PreSelectRemote
= remoteName
;
2311 dlg
.m_bAllowRebase
= allowRebase
;
2313 dlg
.m_bAllRemotes
= allRemotes
;
2315 if(dlg
.DoModal()==IDOK
)
2319 if (dlg
.m_bAllRemotes
)
2322 g_Git
.GetRemoteList(list
);
2324 STRING_VECTOR::const_iterator it
= list
.begin();
2325 while (it
!= list
.end())
2327 CString
remote(*it
);
2328 CAppUtils::LaunchPAgent(NULL
, &remote
);
2333 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
2337 url
=dlg
.m_RemoteURL
;
2341 int ver
= CAppUtils::GetMsysgitVersion();
2343 if(ver
>= 0x01070203) //above 1.7.0.2
2344 arg
= _T("--progress ");
2346 if (dlg
.m_bPrune
== TRUE
)
2347 arg
+= _T("--prune ");
2348 else if (dlg
.m_bPrune
== FALSE
&& ver
>= 0x01080500)
2349 arg
+= _T("--no-prune ");
2351 if (dlg
.m_bFetchTags
== 1)
2353 arg
+= _T("--tags ");
2355 else if (dlg
.m_bFetchTags
== 0)
2357 arg
+= _T("--no-tags ");
2360 if (dlg
.m_bAllRemotes
)
2361 cmd
.Format(_T("git.exe fetch --all -v %s"), arg
);
2363 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"), arg
, url
, dlg
.m_RemoteBranchName
);
2365 CProgressDlg progress
;
2367 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2368 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_RESET
)));
2370 if(!dlg
.m_bRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
2372 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2375 progress
.m_GitCmd
=cmd
;
2376 INT_PTR userResponse
;
2378 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
2380 CGitProgressDlg gitdlg
;
2381 if (!dlg
.m_bAllRemotes
)
2383 gitdlg
.SetCommand(CGitProgressList::GitProgress_Fetch
);
2384 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
);
2385 if (!dlg
.m_bAllRemotes
)
2386 gitdlg
.SetRefSpec(dlg
.m_RemoteBranchName
);
2387 userResponse
= gitdlg
.DoModal();
2391 userResponse
= progress
.DoModal();
2393 if (userResponse
== IDC_PROGRESS_BUTTON1
)
2395 CString cmd
= _T("/command:log");
2396 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2397 RunTortoiseGitProc(cmd
);
2400 else if (userResponse
== IDC_PROGRESS_BUTTON1
+ 1)
2402 CString currentBranch
= g_Git
.GetSymbolicRef();
2404 configName
.Format(_T("branch.%s.remote"), currentBranch
);
2405 CString pullRemote
= g_Git
.GetConfigValue(configName
);
2407 //Select pull-branch from current branch
2408 configName
.Format(_T("branch.%s.merge"), currentBranch
);
2409 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
2411 CString defaultUpstream
;
2412 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
2413 defaultUpstream
.Format(_T("remotes/%s/%s"), pullRemote
, pullBranch
);
2414 GitReset(&defaultUpstream
, 2);
2417 else if ((userResponse
== IDC_PROGRESS_BUTTON1
+ 2) || (progress
.m_GitStatus
== 0 && dlg
.m_bRebase
))
2422 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2423 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUDESSENDMAIL
)));
2424 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2425 INT_PTR response
= dlg
.DoModal();
2426 if(response
== IDOK
)
2430 else if (response
== IDC_REBASE_POST_BUTTON
)
2432 CString cmd
= _T("/command:log");
2433 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2434 RunTortoiseGitProc(cmd
);
2437 else if (response
== IDC_REBASE_POST_BUTTON
+ 1)
2439 CString cmd
, out
, err
;
2440 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2442 g_Git
.FixBranchName(dlg
.m_Upstream
),
2443 g_Git
.FixBranchName(dlg
.m_Branch
));
2444 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
2446 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2450 CAppUtils::SendPatchMail(cmd
,out
);
2453 else if (response
== IDC_REBASE_POST_BUTTON
+ 2)
2455 else if(response
== IDCANCEL
)
2460 else if (userResponse
!= IDCANCEL
)
2466 bool CAppUtils::Push(CString selectLocalBranch
)
2469 dlg
.m_BranchSourceName
= selectLocalBranch
;
2471 DWORD exitcode
= 0xFFFFFFFF;
2473 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
2474 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
2479 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2480 //ReportError(temp);
2481 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2486 if(dlg
.DoModal()==IDOK
)
2491 arg
+= _T("--thin ");
2492 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2493 arg
+= _T("--tags ");
2495 arg
+= _T("--force ");
2496 if (dlg
.m_bSetUpstream
)
2497 arg
+= _T("--set-upstream ");
2498 if (dlg
.m_RecurseSubmodules
== 1)
2499 arg
+= _T("--recurse-submodules=check ");
2500 if (dlg
.m_RecurseSubmodules
== 2)
2501 arg
+= _T("--recurse-submodules=on-demand ");
2503 int ver
= CAppUtils::GetMsysgitVersion();
2505 if(ver
>= 0x01070203) //above 1.7.0.2
2506 arg
+= _T("--progress ");
2508 CProgressDlg progress
;
2510 STRING_VECTOR remotesList
;
2511 if (dlg
.m_bPushAllRemotes
)
2512 g_Git
.GetRemoteList(remotesList
);
2514 remotesList
.push_back(dlg
.m_URL
);
2516 for (unsigned int i
= 0; i
< remotesList
.size(); ++i
)
2518 if (dlg
.m_bAutoLoad
)
2519 CAppUtils::LaunchPAgent(NULL
, &remotesList
[i
]);
2522 if (dlg
.m_bPushAllBranches
)
2524 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2530 progress
.m_GitCmdList
.push_back(cmd
);
2531 cmd
.Format(_T("git.exe push --tags %s \"%s\""), arg
, remotesList
[i
]);
2536 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2539 dlg
.m_BranchSourceName
);
2540 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2542 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2545 progress
.m_GitCmdList
.push_back(cmd
);
2548 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REQUESTPULL
)));
2549 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2550 bool rejected
= false;
2551 progress
.m_PostCmdCallback
= [&] ()
2553 if (progress
.m_GitStatus
)
2555 progress
.m_PostCmdList
.RemoveAll();
2556 rejected
= progress
.GetLogText().Find(_T("! [rejected]")) > 0;
2559 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPULL
)));
2560 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUFETCH
)));
2562 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2566 INT_PTR ret
= progress
.DoModal();
2568 if(!progress
.m_GitStatus
)
2570 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2575 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2576 //ReportError(temp);
2577 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2581 if(ret
== IDC_PROGRESS_BUTTON1
)
2583 RequestPull(dlg
.m_BranchRemoteName
);
2585 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2587 Push(selectLocalBranch
);
2595 // failed, pull first
2596 if (ret
== IDC_PROGRESS_BUTTON1
)
2600 else if (ret
== IDC_PROGRESS_BUTTON1
+ 1)
2602 Fetch(dlg
.m_bPushAllRemotes
? _T("") : dlg
.m_URL
, true, !!dlg
.m_bPushAllRemotes
);
2604 else if (ret
== IDC_PROGRESS_BUTTON1
+ 2)
2606 Push(selectLocalBranch
);
2611 if (ret
== IDC_PROGRESS_BUTTON1
)
2613 Push(selectLocalBranch
);
2621 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2623 CRequestPullDlg dlg
;
2624 dlg
.m_RepositoryURL
= repositoryUrl
;
2625 dlg
.m_EndRevision
= endrevision
;
2626 if (dlg
.DoModal()==IDOK
)
2629 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2631 CSysProgressDlg sysProgressDlg
;
2632 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2633 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CREATINGPULLREUQEST
)));
2634 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2635 sysProgressDlg
.SetShowProgressBar(false);
2636 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2638 CString tempFileName
= GetTempFile();
2640 DeleteFile(tempFileName
);
2641 CreateDirectory(tempFileName
, NULL
);
2642 tempFileName
+= _T("\\pullrequest.txt");
2643 if (g_Git
.RunLogFile(cmd
, tempFileName
, &err
))
2646 msg
.LoadString(IDS_ERR_PULLREUQESTFAILED
);
2647 CMessageBox::Show(NULL
, msg
+ _T("\n") + err
, _T("TortoiseGit"), MB_OK
);
2651 if (sysProgressDlg
.HasUserCancelled())
2653 CMessageBox::Show(NULL
, IDS_SVN_USERCANCELLED
, IDS_APPNAME
, MB_OK
);
2654 ::DeleteFile(tempFileName
);
2658 sysProgressDlg
.Stop();
2660 if (dlg
.m_bSendMail
)
2663 dlg
.m_PathList
= CTGitPathList(CTGitPath(tempFileName
));
2664 dlg
.m_bCustomSubject
= true;
2666 if (dlg
.DoModal() == IDOK
)
2668 if (dlg
.m_PathList
.IsEmpty())
2671 CGitProgressDlg progDlg
;
2673 theApp
.m_pMainWnd
= &progDlg
;
2674 progDlg
.SetCommand(CGitProgressList::GitProgress_SendMail
);
2676 progDlg
.SetPathList(dlg
.m_PathList
);
2677 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2679 CSendMailCombineable
sendMailCombineable(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
);
2680 progDlg
.SetSendMailOption(&sendMailCombineable
);
2689 CAppUtils::LaunchAlternativeEditor(tempFileName
);
2694 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2696 CString
strDir(szPath
);
2697 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2699 strDir
.AppendChar(_T('\\'));
2701 std::vector
<CString
> vPath
;
2703 bool bSuccess
= false;
2705 for (int i
=0;i
<strDir
.GetLength();++i
)
2707 if (strDir
.GetAt(i
) != _T('\\'))
2709 strTemp
.AppendChar(strDir
.GetAt(i
));
2713 vPath
.push_back(strTemp
);
2714 strTemp
.AppendChar(_T('\\'));
2718 for (auto vIter
= vPath
.begin(); vIter
!= vPath
.end(); ++vIter
)
2720 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2726 void CAppUtils::RemoveTrailSlash(CString
&path
)
2731 // For URL, do not trim the slash just after the host name component.
2732 int index
= path
.Find(_T("://"));
2736 index
= path
.Find(_T('/'), index
);
2737 if (index
== path
.GetLength() - 1)
2741 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2743 path
=path
.Left(path
.GetLength()-1);
2749 bool CAppUtils::CheckUserData()
2751 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
2753 if(CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
2755 CTGitPath
path(g_Git
.m_CurrentDir
);
2756 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2757 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2758 dlg
.SetTreeWidth(220);
2759 dlg
.m_DefaultPage
= _T("gitconfig");
2762 dlg
.HandleRestart();
2772 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2773 CTGitPathList
&pathList
,
2774 CTGitPathList
&selectedList
,
2775 bool bSelectFilesForCommit
)
2777 bool bFailed
= true;
2779 if (!CheckUserData())
2786 dlg
.m_sBugID
= bugid
;
2788 dlg
.m_bWholeProject
= bWholeProject
;
2790 dlg
.m_sLogMessage
= sLogMsg
;
2791 dlg
.m_pathList
= pathList
;
2792 dlg
.m_checkedPathList
= selectedList
;
2793 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2794 if (dlg
.DoModal() == IDOK
)
2796 if (dlg
.m_pathList
.IsEmpty())
2798 // if the user hasn't changed the list of selected items
2799 // we don't use that list. Because if we would use the list
2800 // of pre-checked items, the dialog would show different
2801 // checked items on the next startup: it would only try
2802 // to check the parent folder (which might not even show)
2803 // instead, we simply use an empty list and let the
2804 // default checking do its job.
2805 if (!dlg
.m_pathList
.IsEqual(pathList
))
2806 selectedList
= dlg
.m_pathList
;
2807 pathList
= dlg
.m_updatedPathList
;
2808 sLogMsg
= dlg
.m_sLogMessage
;
2809 bSelectFilesForCommit
= true;
2811 switch (dlg
.m_PostCmd
)
2813 case GIT_POSTCOMMIT_CMD_DCOMMIT
:
2814 CAppUtils::SVNDCommit();
2816 case GIT_POSTCOMMIT_CMD_PUSH
:
2819 case GIT_POSTCOMMIT_CMD_CREATETAG
:
2820 CAppUtils::CreateBranchTag(TRUE
);
2822 case GIT_POSTCOMMIT_CMD_PULL
:
2823 CAppUtils::Pull(true);
2829 // CGitProgressDlg progDlg;
2830 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2831 // if (parser.HasVal(_T("closeonend")))
2832 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2833 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2834 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2835 // progDlg.SetPathList(dlg.m_pathList);
2836 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2837 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2838 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2839 // progDlg.SetItemCount(dlg.m_itemsCount);
2840 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2841 // progDlg.DoModal();
2842 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2843 // err = (DWORD)progDlg.DidErrorsOccur();
2844 // bFailed = progDlg.DidErrorsOccur();
2845 // bRet = progDlg.DidErrorsOccur();
2846 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2847 // if (DWORD(bFailRepeat)==0)
2848 // bFailed = false; // do not repeat if the user chose not to in the settings.
2855 BOOL
CAppUtils::SVNDCommit()
2857 CSVNDCommitDlg dcommitdlg
;
2858 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2859 if (gitSetting
== _T("")) {
2860 if (dcommitdlg
.DoModal() != IDOK
)
2866 if (dcommitdlg
.m_remember
)
2868 if (dcommitdlg
.m_rmdir
)
2870 gitSetting
= _T("true");
2874 gitSetting
= _T("false");
2876 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2879 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, _T("svn.rmdir"), gitSetting
);
2880 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2886 BOOL IsStash
= false;
2887 if(!g_Git
.CheckCleanWorkTree())
2889 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
2891 CSysProgressDlg sysProgressDlg
;
2892 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2893 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2894 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2895 sysProgressDlg
.SetShowProgressBar(false);
2896 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2897 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2900 cmd
=_T("git.exe stash");
2901 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2903 sysProgressDlg
.Stop();
2904 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2907 sysProgressDlg
.Stop();
2917 CProgressDlg progress
;
2918 if (dcommitdlg
.m_rmdir
)
2920 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2924 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2926 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2928 ::DeleteFile(g_Git
.m_CurrentDir
+ _T("\\sys$command"));
2931 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2933 CSysProgressDlg sysProgressDlg
;
2934 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2935 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2936 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2937 sysProgressDlg
.SetShowProgressBar(false);
2938 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2939 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2942 cmd
=_T("git.exe stash pop");
2943 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2945 sysProgressDlg
.Stop();
2946 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2949 sysProgressDlg
.Stop();
2961 BOOL
CAppUtils::Merge(CString
*commit
)
2963 if (!CheckUserData())
2968 dlg
.m_initialRefName
= *commit
;
2970 if(dlg
.DoModal()==IDOK
)
2976 args
+= _T(" --no-ff");
2979 args
+= _T(" --squash");
2982 args
+= _T(" --no-commit");
2987 fmt
.Format(_T(" --log=%d"), dlg
.m_nLog
);
2991 if (!dlg
.m_MergeStrategy
.IsEmpty())
2993 args
+= _T(" --strategy=") + dlg
.m_MergeStrategy
;
2994 if (!dlg
.m_StrategyOption
.IsEmpty())
2996 args
+= _T(" --strategy-option=") + dlg
.m_StrategyOption
;
2997 if (!dlg
.m_StrategyParam
.IsEmpty())
2998 args
+= _T("=") + dlg
.m_StrategyParam
;
3002 if(!dlg
.m_strLogMesage
.IsEmpty())
3004 CString logmsg
= dlg
.m_strLogMesage
;
3005 logmsg
.Replace(_T("\""), _T("\\\""));
3006 args
+= _T(" -m \"") + logmsg
+ _T("\"");
3008 cmd
.Format(_T("git.exe merge %s %s"), args
, g_Git
.FixBranchName(dlg
.m_VersionName
));
3010 CProgressDlg Prodlg
;
3011 Prodlg
.m_GitCmd
= cmd
;
3013 BOOL hasGitSVN
= CTGitPath(g_Git
.m_CurrentDir
).GetAdminDirMask() & ITEMIS_GITSVN
;
3014 if (dlg
.m_bNoCommit
)
3015 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUCOMMIT
)));
3018 if (dlg
.m_bIsBranch
)
3019 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REMOVEBRANCH
)));
3022 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUSVNDCOMMIT
)));
3025 Prodlg
.m_PostCmdCallback
= [&] ()
3027 if (Prodlg
.m_GitStatus
)
3029 Prodlg
.m_PostCmdList
.RemoveAll();
3032 if (!g_Git
.ListConflictFile(list
) && !list
.IsEmpty())
3034 // there are conflict files
3035 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
3040 INT_PTR ret
= Prodlg
.DoModal();
3041 if (Prodlg
.m_GitStatus
!= 0 && ret
== IDC_PROGRESS_BUTTON1
)
3043 CTGitPathList pathlist
;
3044 CTGitPathList selectedlist
;
3045 pathlist
.AddPath(g_Git
.m_CurrentDir
);
3046 bool bSelectFilesForCommit
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
3048 CAppUtils::Commit(CString(), false, str
, pathlist
, selectedlist
, bSelectFilesForCommit
);
3050 else if (ret
== IDC_PROGRESS_BUTTON1
)
3052 if (dlg
.m_bNoCommit
)
3055 CTGitPathList pathList
;
3056 CTGitPathList selectedList
;
3057 return Commit(_T(""), TRUE
, sLogMsg
, pathList
, selectedList
, true);
3059 else if (dlg
.m_bIsBranch
)
3062 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, dlg
.m_VersionName
);
3063 if (CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
3066 cmd
.Format(_T("git.exe branch -D -- %s"), dlg
.m_VersionName
);
3067 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3068 MessageBox(NULL
, out
, _T("TortoiseGit"), MB_OK
);
3072 CAppUtils::SVNDCommit();
3074 else if (ret
== IDC_PROGRESS_BUTTON1
+ 1 && hasGitSVN
)
3075 CAppUtils::SVNDCommit();
3077 return !Prodlg
.m_GitStatus
;
3082 BOOL
CAppUtils::MergeAbort()
3085 if (dlg
.DoModal() == IDOK
)
3089 switch (dlg
.m_ResetType
)
3092 type
= _T("--mixed");
3095 type
= _T("--hard");
3098 dlg
.m_ResetType
= 0;
3099 type
= _T("--mixed");
3102 cmd
.Format(_T("git.exe reset %s HEAD --"), type
);
3106 CProgressDlg progress
;
3107 progress
.m_GitCmd
= cmd
;
3109 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
3110 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 1)
3111 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
3113 progress
.m_PostFailCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MSGBOX_RETRY
)));
3116 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_RESET
))
3118 CGitProgressDlg gitdlg
;
3119 gitdlg
.SetCommand(CGitProgressList::GitProgress_Reset
);
3120 gitdlg
.SetRevision(_T("HEAD"));
3121 gitdlg
.SetResetType(dlg
.m_ResetType
+ 1);
3122 ret
= gitdlg
.DoModal();
3125 ret
= progress
.DoModal();
3127 if (progress
.m_GitStatus
== 0 && gitPath
.HasSubmodules() && dlg
.m_ResetType
== 1 && ret
== IDC_PROGRESS_BUTTON1
)
3130 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
3132 CCommonAppUtils::RunTortoiseGitProc(sCmd
);
3135 else if (progress
.m_GitStatus
!= 0 && ret
== IDC_PROGRESS_BUTTON1
)
3137 else if (ret
== IDOK
)
3146 void CAppUtils::EditNote(GitRev
*rev
)
3148 if (!CheckUserData())
3152 dlg
.m_sHintText
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
3153 dlg
.m_sInputText
= rev
->m_Notes
;
3154 dlg
.m_sTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
3155 //dlg.m_pProjectProperties = &m_ProjectProperties;
3156 dlg
.m_bUseLogWidth
= true;
3157 if(dlg
.DoModal() == IDOK
)
3160 cmd
=_T("notes add -f -F \"");
3162 CString tempfile
=::GetTempFile();
3163 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
3166 cmd
+= rev
->m_CommitHash
.ToString();
3170 if (git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
3172 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3177 rev
->m_Notes
= dlg
.m_sInputText
;
3181 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3183 ::DeleteFile(tempfile
);
3188 int CAppUtils::GetMsysgitVersion()
3190 if (g_Git
.ms_LastMsysGitVersion
)
3191 return g_Git
.ms_LastMsysGitVersion
;
3194 CString versiondebug
;
3197 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
3198 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
3200 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
3203 if (!g_Git
.GetFileModifyTime(gitpath
, &time
))
3205 if((DWORD
)time
== regTime
)
3207 g_Git
.ms_LastMsysGitVersion
= regVersion
;
3213 cmd
= _T("git.exe --version");
3214 if (g_Git
.Run(cmd
, &version
, &err
, CP_UTF8
))
3216 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
);
3223 versiondebug
= version
;
3227 CString str
=version
.Tokenize(_T("."), start
);
3228 int space
= str
.ReverseFind(_T(' '));
3229 str
= str
.Mid(space
+1,start
);
3233 version
= version
.Mid(start
);
3236 str
= version
.Tokenize(_T("."), start
);
3238 ver
|= (_ttol(str
) & 0xFF) << 16;
3240 str
= version
.Tokenize(_T("."), start
);
3241 ver
|= (_ttol(str
) & 0xFF) << 8;
3243 str
= version
.Tokenize(_T("."), start
);
3244 ver
|= (_ttol(str
) & 0xFF);
3250 CMessageBox::Show(NULL
, _T("Could not parse git.exe version number: \"") + versiondebug
+ _T("\""), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
3255 regTime
= time
&0xFFFFFFFF;
3257 g_Git
.ms_LastMsysGitVersion
= ver
;
3262 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
3264 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
3266 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("Shell32.dll"));
3268 if (hShell
.IsValid()) {
3269 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
3271 IPropertyStore
*pps
;
3272 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
3273 if (SUCCEEDED(hr
)) {
3276 var
.boolVal
= VARIANT_TRUE
;
3277 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
3284 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
3286 ASSERT(dialogname
.GetLength() < 70);
3287 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
3288 WCHAR pathbuf
[MAX_PATH
] = {0};
3290 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
3292 wcscat_s(pathbuf
, L
" - ");
3293 wcscat_s(pathbuf
, dialogname
);
3294 wcscat_s(pathbuf
, L
" - ");
3295 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3296 SetWindowText(hWnd
, pathbuf
);
3299 bool CAppUtils::BisectStart(CString lastGood
, CString firstBad
)
3301 if (!g_Git
.CheckCleanWorkTree())
3303 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
3305 CSysProgressDlg sysProgressDlg
;
3306 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3307 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
3308 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
3309 sysProgressDlg
.SetShowProgressBar(false);
3310 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
3311 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
3314 cmd
= _T("git.exe stash");
3315 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3317 sysProgressDlg
.Stop();
3318 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
);
3321 sysProgressDlg
.Stop();
3327 CBisectStartDlg bisectStartDlg
;
3329 if (!lastGood
.IsEmpty())
3330 bisectStartDlg
.m_sLastGood
= lastGood
;
3331 if (!firstBad
.IsEmpty())
3332 bisectStartDlg
.m_sFirstBad
= firstBad
;
3334 if (bisectStartDlg
.DoModal() == IDOK
)
3336 CProgressDlg progress
;
3337 theApp
.m_pMainWnd
= &progress
;
3338 progress
.m_GitCmdList
.push_back(_T("git.exe bisect start"));
3339 progress
.m_GitCmdList
.push_back(_T("git.exe bisect good ") + bisectStartDlg
.m_LastGoodRevision
);
3340 progress
.m_GitCmdList
.push_back(_T("git.exe bisect bad ") + bisectStartDlg
.m_FirstBadRevision
);
3342 CTGitPath
path(g_Git
.m_CurrentDir
);
3344 if (path
.HasSubmodules())
3345 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
3347 INT_PTR ret
= progress
.DoModal();
3348 if (path
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
3351 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
3353 CAppUtils::RunTortoiseGitProc(sCmd
);
3356 else if (ret
== IDOK
)
3363 int CAppUtils::Git2GetUserPassword(git_cred
**out
, const char *url
, const char *username_from_url
, unsigned int /*allowed_types*/, void * /*payload*/)
3366 dlg
.m_URL
= CUnicodeUtils::GetUnicode(url
, CP_UTF8
);
3367 if (username_from_url
)
3368 dlg
.m_UserName
= CUnicodeUtils::GetUnicode(username_from_url
, CP_UTF8
);
3370 CStringA username
, password
;
3371 if (dlg
.DoModal() == IDOK
)
3373 username
= CUnicodeUtils::GetMulti(dlg
.m_UserName
, CP_UTF8
);
3374 password
= CUnicodeUtils::GetMulti(dlg
.m_Password
, CP_UTF8
);
3375 return git_cred_userpass_plaintext_new(out
, username
, password
);