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
));
1158 CProgressDlg progress
;
1159 progress
.m_GitCmd
= cmd
;
1161 INT_PTR idPull
= -1;
1162 INT_PTR idSubmoduleUpdate
= -1;
1163 INT_PTR idMerge
= -1;
1165 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1166 if (gitPath
.HasSubmodules())
1167 idSubmoduleUpdate
= progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1168 idPull
= progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPULL
)));
1169 CString currentBranch
;
1170 bool hasBranch
= CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, currentBranch
) == 0;
1172 idMerge
= progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUMERGE
)));
1174 INT_PTR ret
= progress
.DoModal();
1175 if (idSubmoduleUpdate
>= 0 && ret
== IDC_PROGRESS_BUTTON1
+ idSubmoduleUpdate
)
1178 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1180 RunTortoiseGitProc(sCmd
);
1183 else if (ret
== IDC_PROGRESS_BUTTON1
+ idPull
)
1188 else if (ret
== IDC_PROGRESS_BUTTON1
+ idMerge
)
1190 Merge(¤tBranch
);
1193 else if (ret
== IDOK
)
1199 class CIgnoreFile
: public CStdioFile
1202 STRING_VECTOR m_Items
;
1205 virtual BOOL
ReadString(CString
& rString
)
1207 if (GetPosition() == 0)
1209 unsigned char utf8bom
[] = { 0xEF, 0xBB, 0xBF };
1210 char buf
[3] = { 0, 0, 0 };
1212 if (memcpy(buf
, utf8bom
, sizeof(utf8bom
)))
1219 char lastChar
= '\0';
1220 for (char c
= '\0'; Read(&c
, 1) == 1; lastChar
= c
)
1226 m_eol
= lastChar
== '\r' ? _T("\r\n") : _T("\n");
1234 rString
= CUnicodeUtils::GetUnicode(strA
);
1245 bool CAppUtils::OpenIgnoreFile(CIgnoreFile
&file
, const CString
& filename
)
1248 if (!file
.Open(filename
, CFile::modeCreate
| CFile::modeReadWrite
| CFile::modeNoTruncate
| CFile::typeBinary
))
1250 CMessageBox::Show(NULL
, filename
+ _T(" Open Failure"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1254 if (file
.GetLength() > 0)
1257 while (file
.ReadString(fileText
))
1258 file
.m_Items
.push_back(fileText
);
1259 file
.Seek(file
.GetLength() - 1, 0);
1260 char lastchar
[1] = { 0 };
1261 file
.Read(lastchar
, 1);
1263 if (lastchar
[0] != '\n')
1265 CStringA eol
= CStringA(file
.m_eol
.IsEmpty() ? _T("\n") : file
.m_eol
);
1266 file
.Write(eol
, eol
.GetLength());
1275 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1277 CIgnoreDlg ignoreDlg
;
1278 if (ignoreDlg
.DoModal() == IDOK
)
1281 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\");
1283 switch (ignoreDlg
.m_IgnoreFile
)
1286 ignorefile
+= _T(".gitignore");
1289 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, ignorefile
);
1290 ignorefile
+= _T("info/exclude");
1297 if (ignoreDlg
.m_IgnoreFile
!= 1 && !OpenIgnoreFile(file
, ignorefile
))
1300 for (int i
= 0; i
< path
.GetCount(); ++i
)
1302 if (ignoreDlg
.m_IgnoreFile
== 1)
1304 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\") + path
[i
].GetContainingDirectory().GetWinPathString() + _T("\\.gitignore");
1305 if (!OpenIgnoreFile(file
, ignorefile
))
1309 CString ignorePattern
;
1310 if (ignoreDlg
.m_IgnoreType
== 0)
1312 if (ignoreDlg
.m_IgnoreFile
!= 1 && !path
[i
].GetContainingDirectory().GetGitPathString().IsEmpty())
1313 ignorePattern
+= _T("/") + path
[i
].GetContainingDirectory().GetGitPathString();
1315 ignorePattern
+= _T("/");
1319 ignorePattern
+= _T("*") + path
[i
].GetFileExtension();
1323 ignorePattern
+= path
[i
].GetFileOrDirectoryName();
1326 // escape [ and ] so that files get ignored correctly
1327 ignorePattern
.Replace(_T("["), _T("\\["));
1328 ignorePattern
.Replace(_T("]"), _T("\\]"));
1331 for (size_t j
= 0; j
< file
.m_Items
.size(); ++j
)
1333 if (file
.m_Items
[j
] == ignorePattern
)
1341 file
.m_Items
.push_back(ignorePattern
);
1342 ignorePattern
+= file
.m_eol
.IsEmpty() ? _T("\n") : file
.m_eol
;
1343 CStringA ignorePatternA
= CUnicodeUtils::GetUTF8(ignorePattern
);
1344 file
.Write(ignorePatternA
, ignorePatternA
.GetLength());
1347 if (ignoreDlg
.m_IgnoreFile
== 1)
1351 if (ignoreDlg
.m_IgnoreFile
!= 1)
1366 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1369 dlg
.m_ResetType
=type
;
1370 dlg
.m_ResetToVersion
=*CommitHash
;
1371 dlg
.m_initialRefName
= *CommitHash
;
1372 if (dlg
.DoModal() == IDOK
)
1376 switch(dlg
.m_ResetType
)
1388 dlg
.m_ResetType
= 1;
1392 cmd
.Format(_T("git.exe reset %s %s --"),type
, dlg
.m_ResetToVersion
);
1396 CProgressDlg progress
;
1397 progress
.m_GitCmd
=cmd
;
1399 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1400 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2)
1401 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1403 progress
.m_PostFailCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MSGBOX_RETRY
)));
1406 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_RESET
))
1408 CGitProgressDlg gitdlg
;
1409 gitdlg
.SetCommand(CGitProgressList::GitProgress_Reset
);
1410 gitdlg
.SetRevision(dlg
.m_ResetToVersion
);
1411 gitdlg
.SetResetType(dlg
.m_ResetType
);
1412 ret
= gitdlg
.DoModal();
1415 ret
= progress
.DoModal();
1417 if (progress
.m_GitStatus
== 0 && gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2 && ret
== IDC_PROGRESS_BUTTON1
)
1420 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1422 RunTortoiseGitProc(sCmd
);
1425 else if (progress
.m_GitStatus
!= 0 && ret
== IDC_PROGRESS_BUTTON1
)
1427 else if (ret
== IDOK
)
1436 void CAppUtils::DescribeConflictFile(bool mode
, bool base
,CString
&descript
)
1440 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_DELETE
));
1445 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_MODIFIED
));
1448 descript
= CString(MAKEINTRESOURCE(IDS_PROC_CREATED
));
1452 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1454 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("LOCAL"), path
));
1455 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("REMOTE"), path
));
1456 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("BASE"), path
));
1458 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1461 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1466 bool ParseHashesFromLsFile(BYTE_VECTOR
&out
, CString
&hash1
, CString
&hash2
, CString
&hash3
)
1468 unsigned int pos
= 0;
1472 while (pos
>= 0 && pos
< out
.size())
1476 g_Git
.StringAppend(&one
, &out
[pos
], CP_UTF8
);
1478 one
.Tokenize(_T("\t"), tabstart
);
1481 part
= one
.Tokenize(_T(" "), tabstart
); //Tag
1482 part
= one
.Tokenize(_T(" "), tabstart
); //Mode
1483 part
= one
.Tokenize(_T(" "), tabstart
); //Hash
1484 CString hash
= part
;
1485 part
= one
.Tokenize(_T("\t"), tabstart
); //Stage
1486 int stage
= _ttol(part
);
1489 else if (stage
== 2)
1491 else if (stage
== 3)
1497 pos
= out
.findNextString(pos
);
1503 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool /*bAlternativeTool*/,bool revertTheirMy
)
1507 CTGitPath merge
=path
;
1508 CTGitPath directory
= merge
.GetDirectory();
1510 // we have the conflicted file (%merged)
1511 // now look for the other required files
1513 //stat.GetStatus(merge);
1514 //if (stat.status == NULL)
1520 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1522 if (g_Git
.Run(cmd
, &vector
))
1527 if (merge
.IsDirectory())
1529 CString baseHash
, localHash
, remoteHash
;
1530 if (!ParseHashesFromLsFile(vector
, baseHash
, localHash
, remoteHash
))
1534 msg
.Format(_T("BASE: %s\nLOCAL: %s\nREMOTE: %s"), baseHash
, localHash
, remoteHash
);
1535 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
);
1540 if (list
.ParserFromLsFile(vector
))
1542 CMessageBox::Show(NULL
, _T("Parse ls-files failed!"), _T("TortoiseGit"), MB_OK
);
1555 mine
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1556 theirs
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1560 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1561 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1563 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1567 //format=_T("git.exe cat-file blob \":%d:%s\"");
1568 format
= _T("git.exe checkout-index --temp --stage=%d -- \"%s\"");
1570 //create a empty file, incase stage is not three
1571 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1573 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1575 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1578 bool b_base
=false, b_local
=false, b_remote
=false;
1580 for (int i
= 0; i
< list
.GetCount(); ++i
)
1587 if( list
[i
].m_Stage
== 1)
1589 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1591 outfile
= base
.GetWinPathString();
1594 if( list
[i
].m_Stage
== 2 )
1596 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1598 outfile
= mine
.GetWinPathString();
1601 if( list
[i
].m_Stage
== 3 )
1603 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1605 outfile
= theirs
.GetWinPathString();
1607 CString output
, err
;
1608 if(!outfile
.IsEmpty())
1609 if (!g_Git
.Run(cmd
, &output
, &err
, CP_UTF8
))
1613 file
= output
.Tokenize(_T("\t"), start
);
1614 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1618 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1622 if(b_local
&& b_remote
)
1624 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1626 bRet
= !!CAppUtils::StartExtMerge(base
, mine
, theirs
, merge
, _T("BASE"), _T("REMOTE"), _T("LOCAL"));
1628 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"), _T("REMOTE"), _T("LOCAL"));
1633 ::DeleteFile(mine
.GetWinPathString());
1634 ::DeleteFile(theirs
.GetWinPathString());
1635 ::DeleteFile(base
.GetWinPathString());
1637 CDeleteConflictDlg dlg
;
1638 DescribeConflictFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1639 DescribeConflictFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1640 CGitHash localHash
, remoteHash
;
1641 if (!g_Git
.GetHash(localHash
, _T("HEAD")))
1642 dlg
.m_LocalHash
= localHash
.ToString();
1643 if (!g_Git
.GetHash(remoteHash
, _T("MERGE_HEAD")))
1644 dlg
.m_RemoteHash
= remoteHash
.ToString();
1645 else if (!g_Git
.GetHash(remoteHash
, _T("rebase-apply/original-commit")))
1646 dlg
.m_RemoteHash
= remoteHash
.ToString();
1647 else if (!g_Git
.GetHash(remoteHash
, _T("CHERRY_PICK_HEAD")))
1648 dlg
.m_RemoteHash
= remoteHash
.ToString();
1649 else if (!g_Git
.GetHash(remoteHash
, _T("REVERT_HEAD")))
1650 dlg
.m_RemoteHash
= remoteHash
.ToString();
1651 dlg
.m_bShowModifiedButton
=b_base
;
1652 dlg
.m_File
=merge
.GetGitPathString();
1653 if(dlg
.DoModal() == IDOK
)
1658 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1661 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1663 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1665 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1675 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1676 base
, theirs
, mine
, merge
);
1679 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1681 // we have a text conflict, use our merge tool to resolve the conflict
1683 CTSVNPath
theirs(directory
);
1684 CTSVNPath
mine(directory
);
1685 CTSVNPath
base(directory
);
1686 bool bConflictData
= false;
1688 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1690 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1691 bConflictData
= true;
1693 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1695 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1696 bConflictData
= true;
1698 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1700 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1701 bConflictData
= true;
1708 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1709 base
, theirs
, mine
, merge
);
1712 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1714 // we have a property conflict
1715 CTSVNPath
prej(directory
);
1716 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1718 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1719 // there's a problem: the prej file contains a _description_ of the conflict, and
1720 // that description string might be translated. That means we have no way of parsing
1721 // the file to find out the conflicting values.
1722 // The only thing we can do: show a dialog with the conflict description, then
1723 // let the user either accept the existing property or open the property edit dialog
1724 // to manually change the properties and values. And a button to mark the conflict as
1726 CEditPropConflictDlg dlg
;
1727 dlg
.SetPrejFile(prej
);
1728 dlg
.SetConflictedItem(merge
);
1729 bRet
= (dlg
.DoModal() != IDCANCEL
);
1733 if (stat
.status
->tree_conflict
)
1735 // we have a tree conflict
1737 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1740 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1742 CTSVNPath
theirs(directory
);
1743 CTSVNPath
mine(directory
);
1744 CTSVNPath
base(directory
);
1745 bool bConflictData
= false;
1747 if (pInfoData
->treeconflict_theirfile
)
1749 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1750 bConflictData
= true;
1752 if (pInfoData
->treeconflict_basefile
)
1754 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1755 bConflictData
= true;
1757 if (pInfoData
->treeconflict_myfile
)
1759 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1760 bConflictData
= true;
1767 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1768 base
, theirs
, mine
, merge
);
1770 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1772 CString sConflictAction
;
1773 CString sConflictReason
;
1774 CString sResolveTheirs
;
1775 CString sResolveMine
;
1776 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1777 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1779 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1781 switch (pInfoData
->treeconflict_operation
)
1783 case svn_wc_operation_update
:
1784 switch (pInfoData
->treeconflict_action
)
1786 case svn_wc_conflict_action_edit
:
1787 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1788 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1790 case svn_wc_conflict_action_add
:
1791 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1792 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1794 case svn_wc_conflict_action_delete
:
1795 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1796 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1800 case svn_wc_operation_switch
:
1801 switch (pInfoData
->treeconflict_action
)
1803 case svn_wc_conflict_action_edit
:
1804 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1805 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1807 case svn_wc_conflict_action_add
:
1808 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1809 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1811 case svn_wc_conflict_action_delete
:
1812 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1813 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1817 case svn_wc_operation_merge
:
1818 switch (pInfoData
->treeconflict_action
)
1820 case svn_wc_conflict_action_edit
:
1821 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1822 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1824 case svn_wc_conflict_action_add
:
1825 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1826 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1828 case svn_wc_conflict_action_delete
:
1829 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1830 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1836 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1838 switch (pInfoData
->treeconflict_operation
)
1840 case svn_wc_operation_update
:
1841 switch (pInfoData
->treeconflict_action
)
1843 case svn_wc_conflict_action_edit
:
1844 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1845 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1847 case svn_wc_conflict_action_add
:
1848 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1849 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1851 case svn_wc_conflict_action_delete
:
1852 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1853 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1857 case svn_wc_operation_switch
:
1858 switch (pInfoData
->treeconflict_action
)
1860 case svn_wc_conflict_action_edit
:
1861 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1862 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1864 case svn_wc_conflict_action_add
:
1865 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1866 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1868 case svn_wc_conflict_action_delete
:
1869 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1870 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1874 case svn_wc_operation_merge
:
1875 switch (pInfoData
->treeconflict_action
)
1877 case svn_wc_conflict_action_edit
:
1878 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1879 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1881 case svn_wc_conflict_action_add
:
1882 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1883 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1885 case svn_wc_conflict_action_delete
:
1886 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1887 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1895 switch (pInfoData
->treeconflict_reason
)
1897 case svn_wc_conflict_reason_edited
:
1898 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1899 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1901 case svn_wc_conflict_reason_obstructed
:
1902 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1903 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1905 case svn_wc_conflict_reason_deleted
:
1906 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1907 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1909 case svn_wc_conflict_reason_added
:
1910 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1911 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1913 case svn_wc_conflict_reason_missing
:
1914 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1915 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1917 case svn_wc_conflict_reason_unversioned
:
1918 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1919 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1922 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1924 CTreeConflictEditorDlg dlg
;
1925 dlg
.SetConflictInfoText(sConflictReason
);
1926 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1927 dlg
.SetPath(treeConflictPath
);
1928 INT_PTR dlgRet
= dlg
.DoModal();
1929 bRet
= (dlgRet
!= IDCANCEL
);
1937 bool CAppUtils::IsSSHPutty()
1939 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1940 sshclient
=sshclient
.MakeLower();
1941 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1948 CString
CAppUtils::GetClipboardLink(const CString
&skipGitPrefix
, int paramsCount
)
1950 if (!OpenClipboard(NULL
))
1953 CString sClipboardText
;
1954 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1957 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1958 sClipboardText
= CString(lpstr
);
1961 hglb
= GetClipboardData(CF_UNICODETEXT
);
1964 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1965 sClipboardText
= lpstr
;
1970 if(!sClipboardText
.IsEmpty())
1972 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1973 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1975 if(sClipboardText
.Find( _T("http://")) == 0)
1976 return sClipboardText
;
1978 if(sClipboardText
.Find( _T("https://")) == 0)
1979 return sClipboardText
;
1981 if(sClipboardText
.Find( _T("git://")) == 0)
1982 return sClipboardText
;
1984 if(sClipboardText
.Find( _T("ssh://")) == 0)
1985 return sClipboardText
;
1987 if(sClipboardText
.GetLength()>=2)
1988 if( sClipboardText
[1] == _T(':') )
1989 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1990 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1991 return sClipboardText
;
1993 // trim prefixes like "git clone "
1994 if (!skipGitPrefix
.IsEmpty() && sClipboardText
.Find(skipGitPrefix
) == 0)
1996 sClipboardText
= sClipboardText
.Mid(skipGitPrefix
.GetLength()).Trim();
1998 while (paramsCount
>= 0)
2001 spacePos
= sClipboardText
.Find(_T(' '), spacePos
+ 1);
2005 if (spacePos
> 0 && paramsCount
< 0)
2006 sClipboardText
= sClipboardText
.Left(spacePos
);
2007 return sClipboardText
;
2011 return CString(_T(""));
2014 CString
CAppUtils::ChooseRepository(CString
*path
)
2016 CBrowseFolder browseFolder
;
2017 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
2019 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
2020 CString strCloneDirectory
;
2022 strCloneDirectory
=*path
;
2025 strCloneDirectory
= regLastResopitory
;
2029 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
2031 browseFolder
.SetInfo(title
);
2033 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
2035 regLastResopitory
= strCloneDirectory
;
2036 return strCloneDirectory
;
2044 bool CAppUtils::SendPatchMail(CTGitPathList
& list
)
2048 dlg
.m_PathList
= list
;
2050 if(dlg
.DoModal()==IDOK
)
2052 if (dlg
.m_PathList
.IsEmpty())
2055 CGitProgressDlg progDlg
;
2057 theApp
.m_pMainWnd
= &progDlg
;
2058 progDlg
.SetCommand(CGitProgressList::GitProgress_SendMail
);
2060 progDlg
.SetPathList(dlg
.m_PathList
);
2061 //ProjectProperties props;
2062 //props.ReadPropsPathList(dlg.m_pathList);
2063 //progDlg.SetProjectProperties(props);
2064 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2066 CSendMailPatch
sendMailPatch(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
);
2067 progDlg
.SetSendMailOption(&sendMailPatch
);
2076 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
)
2079 CString log
=formatpatchoutput
;
2080 int start
=log
.Find(cmd
);
2082 CString one
=log
.Tokenize(_T("\n"),start
);
2088 CString one
=log
.Tokenize(_T("\n"),start
);
2090 if(one
.IsEmpty() || one
.Find(_T("Success")) == 0)
2092 one
.Replace(_T('/'),_T('\\'));
2094 path
.SetFromWin(one
);
2097 if (!list
.IsEmpty())
2099 return SendPatchMail(list
);
2103 CMessageBox::Show(NULL
, IDS_ERR_NOPATCHES
, IDS_APPNAME
, MB_ICONINFORMATION
);
2109 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
2112 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
2113 if(output
.IsEmpty())
2114 return CUnicodeUtils::GetCPCode(pGit
->GetConfigValue(_T("i18n.commitencoding")));
2117 return CUnicodeUtils::GetCPCode(output
);
2120 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
2122 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
2123 int cp
= CUnicodeUtils::GetCPCode(g_Git
.GetConfigValue(_T("i18n.commitencoding")));
2125 bool stripComments
= (CRegDWORD(_T("Software\\TortoiseGit\\StripCommentedLines"), FALSE
) == TRUE
);
2127 message
.TrimRight(L
" \r\n");
2129 int len
= message
.GetLength();
2131 while (start
>= 0 && start
< len
)
2133 int oldStart
= start
;
2134 start
= message
.Find(L
"\n", oldStart
);
2135 CString line
= message
.Mid(oldStart
);
2138 line
= line
.Left(start
- oldStart
);
2139 ++start
; // move forward so we don't find the same char again
2141 if (stripComments
&& (line
.GetLength() >= 1 && line
.GetAt(0) == '#') || (start
< 0 && line
.IsEmpty()))
2143 line
.TrimRight(L
" \r");
2144 CStringA lineA
= CUnicodeUtils::GetMulti(line
+ L
"\n", cp
);
2145 file
.Write(lineA
.GetBuffer(), lineA
.GetLength());
2151 bool CAppUtils::Pull(bool showPush
)
2154 dlg
.m_IsPull
= TRUE
;
2155 if (dlg
.DoModal() == IDOK
)
2157 CString url
= dlg
.m_RemoteURL
;
2159 if (dlg
.m_bAutoLoad
)
2161 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
2166 if (g_Git
.GetHash(hashOld
, _T("HEAD")))
2168 MessageBox(NULL
, g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
2180 cmdRebase
= "--rebase ";
2182 if (!dlg
.m_bFetchTags
)
2183 notags
= _T("--no-tags");
2189 ffonly
= _T("--ff-only");
2192 squash
= _T("--squash");
2194 if (dlg
.m_bNoCommit
)
2195 nocommit
= _T("--no-commit");
2197 int ver
= CAppUtils::GetMsysgitVersion();
2199 if(ver
>= 0x01070203) //above 1.7.0.2
2200 cmdRebase
+= _T("--progress ");
2202 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
);
2203 CProgressDlg progress
;
2204 progress
.m_GitCmd
= cmd
;
2205 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_DIFFS
)));
2206 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_LOG
)));
2207 INT_PTR pushButton
= showPush
? progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
))) + IDC_PROGRESS_BUTTON1
: -1;
2209 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
2210 INT_PTR smUpdateButton
= gitPath
.HasSubmodules() ? progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
))) + IDC_PROGRESS_BUTTON1
: -1;
2212 INT_PTR ret
= progress
.DoModal();
2214 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
)
2217 dlg
.m_pathList
.AddPath(CTGitPath());
2224 if (g_Git
.GetHash(hashNew
, _T("HEAD")))
2226 MessageBox(NULL
, g_Git
.GetGitLastErr(_T("Could not get HEAD hash after pulling.")), _T("TortoiseGit"), MB_ICONERROR
);
2230 if( ret
== IDC_PROGRESS_BUTTON1
)
2232 if(hashOld
== hashNew
)
2234 if(progress
.m_GitStatus
== 0)
2235 CMessageBox::Show(NULL
, IDS_UPTODATE
, IDS_APPNAME
, MB_OK
| MB_ICONINFORMATION
);
2240 dlg
.SetDiff(NULL
, hashNew
.ToString(), hashOld
.ToString());
2245 else if ( ret
== IDC_PROGRESS_BUTTON1
+1 )
2247 if(hashOld
== hashNew
)
2249 if(progress
.m_GitStatus
== 0)
2250 CMessageBox::Show(NULL
, IDS_UPTODATE
, IDS_APPNAME
, MB_OK
| MB_ICONINFORMATION
);
2255 dlg
.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), hashOld
.ToString() + _T("..") + hashNew
.ToString(), 0);
2258 else if (ret
== pushButton
)
2263 else if (ret
== smUpdateButton
)
2266 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
2268 CAppUtils::RunTortoiseGitProc(sCmd
);
2276 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
)
2279 dlg
.m_PreSelectRemote
= remoteName
;
2280 dlg
.m_bAllowRebase
= allowRebase
;
2283 if(dlg
.DoModal()==IDOK
)
2287 if (dlg
.m_bAllRemotes
)
2290 g_Git
.GetRemoteList(list
);
2292 STRING_VECTOR::const_iterator it
= list
.begin();
2293 while (it
!= list
.end())
2295 CString
remote(*it
);
2296 CAppUtils::LaunchPAgent(NULL
, &remote
);
2301 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
2305 url
=dlg
.m_RemoteURL
;
2309 int ver
= CAppUtils::GetMsysgitVersion();
2311 if(ver
>= 0x01070203) //above 1.7.0.2
2312 arg
= _T("--progress ");
2314 if (dlg
.m_bPrune
== TRUE
)
2315 arg
+= _T("--prune ");
2316 else if (dlg
.m_bPrune
== FALSE
&& ver
>= 0x01080500)
2317 arg
+= _T("--no-prune ");
2319 if (dlg
.m_bFetchTags
== 1)
2321 arg
+= _T("--tags ");
2323 else if (dlg
.m_bFetchTags
== 0)
2325 arg
+= _T("--no-tags ");
2328 if (dlg
.m_bAllRemotes
)
2329 cmd
.Format(_T("git.exe fetch --all -v %s"), arg
);
2331 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"), arg
, url
, dlg
.m_RemoteBranchName
);
2333 CProgressDlg progress
;
2335 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2336 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_RESET
)));
2338 if(!dlg
.m_bRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
2340 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2343 progress
.m_GitCmd
=cmd
;
2344 INT_PTR userResponse
;
2346 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
2348 CGitProgressDlg gitdlg
;
2349 if (!dlg
.m_bAllRemotes
)
2351 gitdlg
.SetCommand(CGitProgressList::GitProgress_Fetch
);
2352 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
);
2353 if (!dlg
.m_bAllRemotes
)
2354 gitdlg
.SetRefSpec(dlg
.m_RemoteBranchName
);
2355 userResponse
= gitdlg
.DoModal();
2359 userResponse
= progress
.DoModal();
2361 if (userResponse
== IDC_PROGRESS_BUTTON1
)
2363 CString cmd
= _T("/command:log");
2364 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2365 RunTortoiseGitProc(cmd
);
2368 else if (userResponse
== IDC_PROGRESS_BUTTON1
+ 1)
2370 CString currentBranch
= g_Git
.GetSymbolicRef();
2372 configName
.Format(_T("branch.%s.remote"), currentBranch
);
2373 CString pullRemote
= g_Git
.GetConfigValue(configName
);
2375 //Select pull-branch from current branch
2376 configName
.Format(_T("branch.%s.merge"), currentBranch
);
2377 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
2379 CString defaultUpstream
;
2380 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
2381 defaultUpstream
.Format(_T("remotes/%s/%s"), pullRemote
, pullBranch
);
2382 GitReset(&defaultUpstream
, 2);
2385 else if ((userResponse
== IDC_PROGRESS_BUTTON1
+ 2) || (progress
.m_GitStatus
== 0 && dlg
.m_bRebase
))
2390 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2391 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUDESSENDMAIL
)));
2392 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2393 INT_PTR response
= dlg
.DoModal();
2394 if(response
== IDOK
)
2398 else if (response
== IDC_REBASE_POST_BUTTON
)
2400 CString cmd
= _T("/command:log");
2401 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2402 RunTortoiseGitProc(cmd
);
2405 else if (response
== IDC_REBASE_POST_BUTTON
+ 1)
2407 CString cmd
, out
, err
;
2408 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2410 g_Git
.FixBranchName(dlg
.m_Upstream
),
2411 g_Git
.FixBranchName(dlg
.m_Branch
));
2412 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
2414 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2418 CAppUtils::SendPatchMail(cmd
,out
);
2421 else if (response
== IDC_REBASE_POST_BUTTON
+ 2)
2423 else if(response
== IDCANCEL
)
2428 else if (userResponse
!= IDCANCEL
)
2434 static void PushCallback(CProgressDlg
*dlg
, void *caller
, int result
)
2438 dlg
->m_PostCmdList
.RemoveAll();
2439 bool rejected
= dlg
->GetLogText().Find(_T("! [rejected]")) > 0;
2440 *(bool*)caller
= rejected
;
2442 dlg
->m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPULL
)));
2443 dlg
->m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2447 bool CAppUtils::Push(CString selectLocalBranch
)
2450 dlg
.m_BranchSourceName
= selectLocalBranch
;
2452 DWORD exitcode
= 0xFFFFFFFF;
2454 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
2455 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
2460 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2461 //ReportError(temp);
2462 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2467 if(dlg
.DoModal()==IDOK
)
2472 arg
+= _T("--thin ");
2473 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2474 arg
+= _T("--tags ");
2476 arg
+= _T("--force ");
2477 if (dlg
.m_bSetUpstream
)
2478 arg
+= _T("--set-upstream ");
2479 if (dlg
.m_RecurseSubmodules
== 1)
2480 arg
+= _T("--recurse-submodules=check ");
2481 if (dlg
.m_RecurseSubmodules
== 2)
2482 arg
+= _T("--recurse-submodules=on-demand ");
2484 int ver
= CAppUtils::GetMsysgitVersion();
2486 if(ver
>= 0x01070203) //above 1.7.0.2
2487 arg
+= _T("--progress ");
2489 CProgressDlg progress
;
2491 STRING_VECTOR remotesList
;
2492 if (dlg
.m_bPushAllRemotes
)
2493 g_Git
.GetRemoteList(remotesList
);
2495 remotesList
.push_back(dlg
.m_URL
);
2497 for (unsigned int i
= 0; i
< remotesList
.size(); ++i
)
2499 if (dlg
.m_bAutoLoad
)
2500 CAppUtils::LaunchPAgent(NULL
, &remotesList
[i
]);
2503 if (dlg
.m_bPushAllBranches
)
2505 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2511 progress
.m_GitCmdList
.push_back(cmd
);
2512 cmd
.Format(_T("git.exe push --tags %s \"%s\""), arg
, remotesList
[i
]);
2517 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2520 dlg
.m_BranchSourceName
);
2521 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2523 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2526 progress
.m_GitCmdList
.push_back(cmd
);
2529 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REQUESTPULL
)));
2530 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2531 bool rejected
= false;
2532 progress
.m_caller
= &rejected
;
2533 progress
.m_PostCmdCallback
= PushCallback
;
2534 INT_PTR ret
= progress
.DoModal();
2536 if(!progress
.m_GitStatus
)
2538 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2543 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2544 //ReportError(temp);
2545 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2549 if(ret
== IDC_PROGRESS_BUTTON1
)
2551 RequestPull(dlg
.m_BranchRemoteName
);
2553 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2555 Push(selectLocalBranch
);
2563 // failed, pull first
2564 if (ret
== IDC_PROGRESS_BUTTON1
)
2568 else if (ret
== IDC_PROGRESS_BUTTON1
+ 1)
2570 Push(selectLocalBranch
);
2575 if (ret
== IDC_PROGRESS_BUTTON1
)
2577 Push(selectLocalBranch
);
2585 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2587 CRequestPullDlg dlg
;
2588 dlg
.m_RepositoryURL
= repositoryUrl
;
2589 dlg
.m_EndRevision
= endrevision
;
2590 if (dlg
.DoModal()==IDOK
)
2593 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2595 CSysProgressDlg sysProgressDlg
;
2596 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2597 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CREATINGPULLREUQEST
)));
2598 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2599 sysProgressDlg
.SetShowProgressBar(false);
2600 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2602 CString tempFileName
= GetTempFile();
2604 DeleteFile(tempFileName
);
2605 CreateDirectory(tempFileName
, NULL
);
2606 tempFileName
+= _T("\\pullrequest.txt");
2607 if (g_Git
.RunLogFile(cmd
, tempFileName
, &err
))
2610 msg
.LoadString(IDS_ERR_PULLREUQESTFAILED
);
2611 CMessageBox::Show(NULL
, msg
+ _T("\n") + err
, _T("TortoiseGit"), MB_OK
);
2615 if (sysProgressDlg
.HasUserCancelled())
2617 CMessageBox::Show(NULL
, IDS_SVN_USERCANCELLED
, IDS_APPNAME
, MB_OK
);
2618 ::DeleteFile(tempFileName
);
2622 sysProgressDlg
.Stop();
2624 if (dlg
.m_bSendMail
)
2627 dlg
.m_PathList
= CTGitPathList(CTGitPath(tempFileName
));
2628 dlg
.m_bCustomSubject
= true;
2630 if (dlg
.DoModal() == IDOK
)
2632 if (dlg
.m_PathList
.IsEmpty())
2635 CGitProgressDlg progDlg
;
2637 theApp
.m_pMainWnd
= &progDlg
;
2638 progDlg
.SetCommand(CGitProgressList::GitProgress_SendMail
);
2640 progDlg
.SetPathList(dlg
.m_PathList
);
2641 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2643 CSendMailCombineable
sendMailCombineable(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
);
2644 progDlg
.SetSendMailOption(&sendMailCombineable
);
2653 CAppUtils::LaunchAlternativeEditor(tempFileName
);
2658 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2660 CString
strDir(szPath
);
2661 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2663 strDir
.AppendChar(_T('\\'));
2665 std::vector
<CString
> vPath
;
2667 bool bSuccess
= false;
2669 for (int i
=0;i
<strDir
.GetLength();++i
)
2671 if (strDir
.GetAt(i
) != _T('\\'))
2673 strTemp
.AppendChar(strDir
.GetAt(i
));
2677 vPath
.push_back(strTemp
);
2678 strTemp
.AppendChar(_T('\\'));
2682 for (auto vIter
= vPath
.begin(); vIter
!= vPath
.end(); ++vIter
)
2684 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2690 void CAppUtils::RemoveTrailSlash(CString
&path
)
2695 // For URL, do not trim the slash just after the host name component.
2696 int index
= path
.Find(_T("://"));
2700 index
= path
.Find(_T('/'), index
);
2701 if (index
== path
.GetLength() - 1)
2705 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2707 path
=path
.Left(path
.GetLength()-1);
2713 bool CAppUtils::CheckUserData()
2715 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
2717 if(CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
2719 CTGitPath
path(g_Git
.m_CurrentDir
);
2720 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2721 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2722 dlg
.SetTreeWidth(220);
2723 dlg
.m_DefaultPage
= _T("gitconfig");
2726 dlg
.HandleRestart();
2736 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2737 CTGitPathList
&pathList
,
2738 CTGitPathList
&selectedList
,
2739 bool bSelectFilesForCommit
)
2741 bool bFailed
= true;
2743 if (!CheckUserData())
2750 dlg
.m_sBugID
= bugid
;
2752 dlg
.m_bWholeProject
= bWholeProject
;
2754 dlg
.m_sLogMessage
= sLogMsg
;
2755 dlg
.m_pathList
= pathList
;
2756 dlg
.m_checkedPathList
= selectedList
;
2757 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2758 if (dlg
.DoModal() == IDOK
)
2760 if (dlg
.m_pathList
.IsEmpty())
2762 // if the user hasn't changed the list of selected items
2763 // we don't use that list. Because if we would use the list
2764 // of pre-checked items, the dialog would show different
2765 // checked items on the next startup: it would only try
2766 // to check the parent folder (which might not even show)
2767 // instead, we simply use an empty list and let the
2768 // default checking do its job.
2769 if (!dlg
.m_pathList
.IsEqual(pathList
))
2770 selectedList
= dlg
.m_pathList
;
2771 pathList
= dlg
.m_updatedPathList
;
2772 sLogMsg
= dlg
.m_sLogMessage
;
2773 bSelectFilesForCommit
= true;
2775 switch (dlg
.m_PostCmd
)
2777 case GIT_POSTCOMMIT_CMD_DCOMMIT
:
2778 CAppUtils::SVNDCommit();
2780 case GIT_POSTCOMMIT_CMD_PUSH
:
2783 case GIT_POSTCOMMIT_CMD_CREATETAG
:
2784 CAppUtils::CreateBranchTag(TRUE
);
2786 case GIT_POSTCOMMIT_CMD_PULL
:
2787 CAppUtils::Pull(true);
2793 // CGitProgressDlg progDlg;
2794 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2795 // if (parser.HasVal(_T("closeonend")))
2796 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2797 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2798 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2799 // progDlg.SetPathList(dlg.m_pathList);
2800 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2801 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2802 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2803 // progDlg.SetItemCount(dlg.m_itemsCount);
2804 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2805 // progDlg.DoModal();
2806 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2807 // err = (DWORD)progDlg.DidErrorsOccur();
2808 // bFailed = progDlg.DidErrorsOccur();
2809 // bRet = progDlg.DidErrorsOccur();
2810 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2811 // if (DWORD(bFailRepeat)==0)
2812 // bFailed = false; // do not repeat if the user chose not to in the settings.
2819 BOOL
CAppUtils::SVNDCommit()
2821 CSVNDCommitDlg dcommitdlg
;
2822 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2823 if (gitSetting
== _T("")) {
2824 if (dcommitdlg
.DoModal() != IDOK
)
2830 if (dcommitdlg
.m_remember
)
2832 if (dcommitdlg
.m_rmdir
)
2834 gitSetting
= _T("true");
2838 gitSetting
= _T("false");
2840 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2843 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, _T("svn.rmdir"), gitSetting
);
2844 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2850 BOOL IsStash
= false;
2851 if(!g_Git
.CheckCleanWorkTree())
2853 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
2855 CSysProgressDlg sysProgressDlg
;
2856 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2857 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2858 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2859 sysProgressDlg
.SetShowProgressBar(false);
2860 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2861 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2864 cmd
=_T("git.exe stash");
2865 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2867 sysProgressDlg
.Stop();
2868 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2871 sysProgressDlg
.Stop();
2881 CProgressDlg progress
;
2882 if (dcommitdlg
.m_rmdir
)
2884 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2888 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2890 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2892 ::DeleteFile(g_Git
.m_CurrentDir
+ _T("\\sys$command"));
2895 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2897 CSysProgressDlg sysProgressDlg
;
2898 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2899 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2900 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2901 sysProgressDlg
.SetShowProgressBar(false);
2902 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2903 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2906 cmd
=_T("git.exe stash pop");
2907 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2909 sysProgressDlg
.Stop();
2910 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2913 sysProgressDlg
.Stop();
2925 static void MergeCallback(CProgressDlg
*dlg
, void * /*caller*/, int result
)
2929 dlg
->m_PostCmdList
.RemoveAll();
2932 if (!g_Git
.ListConflictFile(list
) && !list
.IsEmpty())
2934 // there are conflict files
2935 dlg
->m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
2940 BOOL
CAppUtils::Merge(CString
*commit
)
2942 if (!CheckUserData())
2947 dlg
.m_initialRefName
= *commit
;
2949 if(dlg
.DoModal()==IDOK
)
2955 args
+= _T(" --no-ff");
2958 args
+= _T(" --squash");
2961 args
+= _T(" --no-commit");
2966 fmt
.Format(_T(" --log=%d"), dlg
.m_nLog
);
2970 if (!dlg
.m_MergeStrategy
.IsEmpty())
2972 args
+= _T(" --strategy=") + dlg
.m_MergeStrategy
;
2973 if (!dlg
.m_StrategyOption
.IsEmpty())
2975 args
+= _T(" --strategy-option=") + dlg
.m_StrategyOption
;
2976 if (!dlg
.m_StrategyParam
.IsEmpty())
2977 args
+= _T("=") + dlg
.m_StrategyParam
;
2981 if(!dlg
.m_strLogMesage
.IsEmpty())
2983 CString logmsg
= dlg
.m_strLogMesage
;
2984 logmsg
.Replace(_T("\""), _T("\\\""));
2985 args
+= _T(" -m \"") + logmsg
+ _T("\"");
2987 cmd
.Format(_T("git.exe merge %s %s"), args
, g_Git
.FixBranchName(dlg
.m_VersionName
));
2989 CProgressDlg Prodlg
;
2990 Prodlg
.m_GitCmd
= cmd
;
2992 BOOL hasGitSVN
= CTGitPath(g_Git
.m_CurrentDir
).GetAdminDirMask() & ITEMIS_GITSVN
;
2993 if (dlg
.m_bNoCommit
)
2994 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUCOMMIT
)));
2997 if (dlg
.m_bIsBranch
)
2998 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REMOVEBRANCH
)));
3001 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUSVNDCOMMIT
)));
3004 Prodlg
.m_PostCmdCallback
= MergeCallback
;
3006 INT_PTR ret
= Prodlg
.DoModal();
3007 if (Prodlg
.m_GitStatus
!= 0 && ret
== IDC_PROGRESS_BUTTON1
)
3009 CTGitPathList pathlist
;
3010 CTGitPathList selectedlist
;
3011 pathlist
.AddPath(g_Git
.m_CurrentDir
);
3012 bool bSelectFilesForCommit
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
3014 CAppUtils::Commit(CString(), false, str
, pathlist
, selectedlist
, bSelectFilesForCommit
);
3016 else if (ret
== IDC_PROGRESS_BUTTON1
)
3018 if (dlg
.m_bNoCommit
)
3021 CTGitPathList pathList
;
3022 CTGitPathList selectedList
;
3023 return Commit(_T(""), TRUE
, sLogMsg
, pathList
, selectedList
, true);
3025 else if (dlg
.m_bIsBranch
)
3028 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, dlg
.m_VersionName
);
3029 if (CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
3032 cmd
.Format(_T("git.exe branch -D -- %s"), dlg
.m_VersionName
);
3033 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3034 MessageBox(NULL
, out
, _T("TortoiseGit"), MB_OK
);
3038 CAppUtils::SVNDCommit();
3040 else if (ret
== IDC_PROGRESS_BUTTON1
+ 1 && hasGitSVN
)
3041 CAppUtils::SVNDCommit();
3043 return !Prodlg
.m_GitStatus
;
3048 BOOL
CAppUtils::MergeAbort()
3051 if (dlg
.DoModal() == IDOK
)
3055 switch (dlg
.m_ResetType
)
3058 type
= _T("--mixed");
3061 type
= _T("--hard");
3064 dlg
.m_ResetType
= 0;
3065 type
= _T("--mixed");
3068 cmd
.Format(_T("git.exe reset %s HEAD --"), type
);
3072 CProgressDlg progress
;
3073 progress
.m_GitCmd
= cmd
;
3075 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
3076 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 1)
3077 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
3079 progress
.m_PostFailCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MSGBOX_RETRY
)));
3082 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_RESET
))
3084 CGitProgressDlg gitdlg
;
3085 gitdlg
.SetCommand(CGitProgressList::GitProgress_Reset
);
3086 gitdlg
.SetRevision(_T("HEAD"));
3087 gitdlg
.SetResetType(dlg
.m_ResetType
+ 1);
3088 ret
= gitdlg
.DoModal();
3091 ret
= progress
.DoModal();
3093 if (progress
.m_GitStatus
== 0 && gitPath
.HasSubmodules() && dlg
.m_ResetType
== 1 && ret
== IDC_PROGRESS_BUTTON1
)
3096 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
3098 CCommonAppUtils::RunTortoiseGitProc(sCmd
);
3101 else if (progress
.m_GitStatus
!= 0 && ret
== IDC_PROGRESS_BUTTON1
)
3103 else if (ret
== IDOK
)
3112 void CAppUtils::EditNote(GitRev
*rev
)
3114 if (!CheckUserData())
3118 dlg
.m_sHintText
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
3119 dlg
.m_sInputText
= rev
->m_Notes
;
3120 dlg
.m_sTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
3121 //dlg.m_pProjectProperties = &m_ProjectProperties;
3122 dlg
.m_bUseLogWidth
= true;
3123 if(dlg
.DoModal() == IDOK
)
3126 cmd
=_T("notes add -f -F \"");
3128 CString tempfile
=::GetTempFile();
3129 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
3132 cmd
+= rev
->m_CommitHash
.ToString();
3136 if (git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
3138 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3143 rev
->m_Notes
= dlg
.m_sInputText
;
3147 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3149 ::DeleteFile(tempfile
);
3154 int CAppUtils::GetMsysgitVersion()
3156 if (g_Git
.ms_LastMsysGitVersion
)
3157 return g_Git
.ms_LastMsysGitVersion
;
3160 CString versiondebug
;
3163 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
3164 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
3166 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
3169 if (!g_Git
.GetFileModifyTime(gitpath
, &time
))
3171 if((DWORD
)time
== regTime
)
3173 g_Git
.ms_LastMsysGitVersion
= regVersion
;
3179 cmd
= _T("git.exe --version");
3180 if (g_Git
.Run(cmd
, &version
, &err
, CP_UTF8
))
3182 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
);
3189 versiondebug
= version
;
3193 CString str
=version
.Tokenize(_T("."), start
);
3194 int space
= str
.ReverseFind(_T(' '));
3195 str
= str
.Mid(space
+1,start
);
3199 version
= version
.Mid(start
);
3202 str
= version
.Tokenize(_T("."), start
);
3204 ver
|= (_ttol(str
) & 0xFF) << 16;
3206 str
= version
.Tokenize(_T("."), start
);
3207 ver
|= (_ttol(str
) & 0xFF) << 8;
3209 str
= version
.Tokenize(_T("."), start
);
3210 ver
|= (_ttol(str
) & 0xFF);
3216 CMessageBox::Show(NULL
, _T("Could not parse git.exe version number: \"") + versiondebug
+ _T("\""), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
3221 regTime
= time
&0xFFFFFFFF;
3223 g_Git
.ms_LastMsysGitVersion
= ver
;
3228 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
3230 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
3232 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("Shell32.dll"));
3234 if (hShell
.IsValid()) {
3235 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
3237 IPropertyStore
*pps
;
3238 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
3239 if (SUCCEEDED(hr
)) {
3242 var
.boolVal
= VARIANT_TRUE
;
3243 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
3250 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
3252 ASSERT(dialogname
.GetLength() < 70);
3253 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
3254 WCHAR pathbuf
[MAX_PATH
] = {0};
3256 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
3258 wcscat_s(pathbuf
, L
" - ");
3259 wcscat_s(pathbuf
, dialogname
);
3260 wcscat_s(pathbuf
, L
" - ");
3261 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3262 SetWindowText(hWnd
, pathbuf
);
3265 bool CAppUtils::BisectStart(CString lastGood
, CString firstBad
)
3267 if (!g_Git
.CheckCleanWorkTree())
3269 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
3271 CSysProgressDlg sysProgressDlg
;
3272 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3273 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
3274 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
3275 sysProgressDlg
.SetShowProgressBar(false);
3276 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
3277 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
3280 cmd
= _T("git.exe stash");
3281 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3283 sysProgressDlg
.Stop();
3284 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
);
3287 sysProgressDlg
.Stop();
3293 CBisectStartDlg bisectStartDlg
;
3295 if (!lastGood
.IsEmpty())
3296 bisectStartDlg
.m_sLastGood
= lastGood
;
3297 if (!firstBad
.IsEmpty())
3298 bisectStartDlg
.m_sFirstBad
= firstBad
;
3300 if (bisectStartDlg
.DoModal() == IDOK
)
3302 CProgressDlg progress
;
3303 theApp
.m_pMainWnd
= &progress
;
3304 progress
.m_GitCmdList
.push_back(_T("git.exe bisect start"));
3305 progress
.m_GitCmdList
.push_back(_T("git.exe bisect good ") + bisectStartDlg
.m_LastGoodRevision
);
3306 progress
.m_GitCmdList
.push_back(_T("git.exe bisect bad ") + bisectStartDlg
.m_FirstBadRevision
);
3308 CTGitPath
path(g_Git
.m_CurrentDir
);
3310 if (path
.HasSubmodules())
3311 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
3313 INT_PTR ret
= progress
.DoModal();
3314 if (path
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
3317 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
3319 CAppUtils::RunTortoiseGitProc(sCmd
);
3322 else if (ret
== IDOK
)
3329 int CAppUtils::Git2GetUserPassword(git_cred
**out
, const char *url
, const char *username_from_url
, unsigned int /*allowed_types*/, void * /*payload*/)
3332 dlg
.m_URL
= CUnicodeUtils::GetUnicode(url
, CP_UTF8
);
3333 if (username_from_url
)
3334 dlg
.m_UserName
= CUnicodeUtils::GetUnicode(username_from_url
, CP_UTF8
);
3336 CStringA username
, password
;
3337 if (dlg
.DoModal() == IDOK
)
3339 username
= CUnicodeUtils::GetMulti(dlg
.m_UserName
, CP_UTF8
);
3340 password
= CUnicodeUtils::GetMulti(dlg
.m_Password
, CP_UTF8
);
3341 return git_cred_userpass_plaintext_new(out
, username
, password
);