1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2011 - 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.
22 #include "TortoiseProc.h"
23 #include "PathUtils.h"
25 //#include "GitProperties.h"
26 #include "StringUtils.h"
27 #include "MessageBox.h"
31 //#include "RepositoryBrowser.h"
32 //#include "BrowseFolder.h"
33 #include "UnicodeUtils.h"
34 #include "ExportDlg.h"
35 #include "ProgressDlg.h"
36 #include "GitAdminDir.h"
37 #include "ProgressDlg.h"
38 #include "BrowseFolder.h"
39 #include "DirFileEnum.h"
40 #include "MessageBox.h"
41 #include "GitStatus.h"
42 #include "CreateBranchTagDlg.h"
43 #include "GitSwitchDlg.h"
45 #include "DeleteConflictDlg.h"
46 #include "ChangedDlg.h"
47 #include "SendMailDlg.h"
48 #include "GITProgressDlg.h"
50 #include "CommitDlg.h"
53 #include "..\Settings\Settings.h"
55 #include "SVNDCommitDlg.h"
56 #include "requestpulldlg.h"
57 #include "PullFetchDlg.h"
58 #include "RebaseDlg.h"
60 #include "StashSave.h"
61 #include "IgnoreDlg.h"
62 #include "FormatMessageWrapper.h"
63 #include "SmartHandle.h"
64 #include "BisectStartDlg.h"
65 #include "SysProgressDlg.h"
67 CAppUtils::CAppUtils(void)
71 CAppUtils::~CAppUtils(void)
75 bool CAppUtils::StashSave()
79 if (dlg
.DoModal() == IDOK
)
82 cmd
= _T("git.exe stash save");
84 if (CAppUtils::GetMsysgitVersion() >= 0x01070700)
86 if (dlg
.m_bIncludeUntracked
)
87 cmd
+= _T(" --include-untracked");
92 if (!dlg
.m_sMessage
.IsEmpty())
94 CString message
= dlg
.m_sMessage
;
95 message
.Replace(_T("\""), _T("\"\""));
96 cmd
+= _T(" \"") + message
+ _T("\"");
99 CSysProgressDlg sysProgressDlg
;
100 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
101 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
102 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
103 sysProgressDlg
.SetShowProgressBar(false);
104 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
105 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
107 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
109 if (sysProgressDlg
.IsValid())
110 sysProgressDlg
.Stop();
111 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
115 if (sysProgressDlg
.IsValid())
116 sysProgressDlg
.Stop();
117 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHSUCCESS
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
124 bool CAppUtils::StashApply(CString ref
, bool showChanges
/* true */)
127 cmd
= _T("git.exe stash apply ");
128 if (ref
.Find(_T("refs/")) == 0)
130 if (ref
.Find(_T("stash{")) == 0)
131 ref
= _T("stash@") + ref
.Mid(5);
134 CSysProgressDlg sysProgressDlg
;
135 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
136 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
137 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
138 sysProgressDlg
.SetShowProgressBar(false);
139 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
140 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
142 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
144 if (sysProgressDlg
.IsValid())
145 sysProgressDlg
.Stop();
147 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
148 if (ret
&& !(ret
== 1 && hasConflicts
))
150 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHAPPLYFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
155 message
.LoadString(IDS_PROC_STASHAPPLYSUCCESS
);
157 message
.LoadString(IDS_PROC_STASHAPPLYFAILEDCONFLICTS
);
160 if(CMessageBox::Show(NULL
,message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
))
161 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
164 dlg
.m_pathList
.AddPath(CTGitPath());
171 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
178 bool CAppUtils::StashPop(bool showChanges
/* true */)
181 cmd
=_T("git.exe stash pop ");
183 CSysProgressDlg sysProgressDlg
;
184 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
185 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
186 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
187 sysProgressDlg
.SetShowProgressBar(false);
188 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
189 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
191 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
193 if (sysProgressDlg
.IsValid())
194 sysProgressDlg
.Stop();
196 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
197 if (ret
&& !(ret
== 1 && hasConflicts
))
199 CMessageBox::Show(NULL
,CString(MAKEINTRESOURCE(IDS_PROC_STASHPOPFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
204 message
.LoadString(IDS_PROC_STASHPOPSUCCESS
);
206 message
.LoadString(IDS_PROC_STASHPOPFAILEDCONFLICTS
);
209 if(CMessageBox::Show(NULL
,CString(message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
)))
210 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
213 dlg
.m_pathList
.AddPath(CTGitPath());
220 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
227 bool CAppUtils::GetMimeType(const CTGitPath
& /*file*/, CString
& /*mimetype*/)
230 GitProperties
props(file
, GitRev::REV_WC
, false);
231 for (int i
= 0; i
< props
.GetCount(); ++i
)
233 if (props
.GetItemName(i
).compare(_T("svn:mime-type"))==0)
235 mimetype
= props
.GetItemValue(i
).c_str();
243 BOOL
CAppUtils::StartExtMerge(
244 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
245 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
)
248 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
249 CString ext
= mergedfile
.GetFileExtension();
250 CString com
= regCom
;
251 bool bInternal
= false;
256 // is there an extension specific merge tool?
257 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
258 if (CString(mergetool
) != "")
263 if (GetMimeType(yourfile
, mimetype
) || GetMimeType(theirfile
, mimetype
) || GetMimeType(basefile
, mimetype
))
265 // is there a mime type specific merge tool?
266 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype
);
267 if (CString(mergetool
) != "")
273 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
277 CRegString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE
);
278 com
= tortoiseMergePath
;
281 com
= CPathUtils::GetAppDirectory();
282 com
+= _T("TortoiseMerge.exe");
284 com
= _T("\"") + com
+ _T("\"");
285 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
286 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
288 // check if the params are set. If not, just add the files to the command line
289 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
291 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
292 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
293 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
294 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
296 if (basefile
.IsEmpty())
298 com
.Replace(_T("/base:%base"), _T(""));
299 com
.Replace(_T("%base"), _T(""));
302 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
303 if (theirfile
.IsEmpty())
305 com
.Replace(_T("/theirs:%theirs"), _T(""));
306 com
.Replace(_T("%theirs"), _T(""));
309 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
310 if (yourfile
.IsEmpty())
312 com
.Replace(_T("/mine:%mine"), _T(""));
313 com
.Replace(_T("%mine"), _T(""));
316 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
317 if (mergedfile
.IsEmpty())
319 com
.Replace(_T("/merged:%merged"), _T(""));
320 com
.Replace(_T("%merged"), _T(""));
323 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
324 if (basename
.IsEmpty())
326 if (basefile
.IsEmpty())
328 com
.Replace(_T("/basename:%bname"), _T(""));
329 com
.Replace(_T("%bname"), _T(""));
333 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
337 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
338 if (theirname
.IsEmpty())
340 if (theirfile
.IsEmpty())
342 com
.Replace(_T("/theirsname:%tname"), _T(""));
343 com
.Replace(_T("%tname"), _T(""));
347 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
351 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
352 if (yourname
.IsEmpty())
354 if (yourfile
.IsEmpty())
356 com
.Replace(_T("/minename:%yname"), _T(""));
357 com
.Replace(_T("%yname"), _T(""));
361 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
365 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
366 if (mergedname
.IsEmpty())
368 if (mergedfile
.IsEmpty())
370 com
.Replace(_T("/mergedname:%mname"), _T(""));
371 com
.Replace(_T("%mname"), _T(""));
375 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
379 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
381 if ((bReadOnly
)&&(bInternal
))
382 com
+= _T(" /readonly");
384 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
392 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
396 viewer
= CPathUtils::GetAppDirectory();
397 viewer
+= _T("TortoiseMerge.exe");
399 viewer
= _T("\"") + viewer
+ _T("\"");
400 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
401 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
403 viewer
+= _T(" /reversedpatch");
404 if (!sOriginalDescription
.IsEmpty())
405 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
406 if (!sPatchedDescription
.IsEmpty())
407 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
408 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
415 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
417 // Is there a mime type specific diff tool?
419 if (GetMimeType(file1
, mimetype
) || GetMimeType(file2
, mimetype
))
421 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype
);
422 if (!difftool
.IsEmpty())
426 // Is there an extension specific diff tool?
427 CString ext
= file2
.GetFileExtension().MakeLower();
430 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
431 if (!difftool
.IsEmpty())
433 // Maybe we should use TortoiseIDiff?
434 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
435 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
436 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
437 (ext
== _T(".dib")) || (ext
== _T(".emf")))
440 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
441 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
445 // Finally, pick a generic external diff tool
446 CString difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
450 bool CAppUtils::StartExtDiff(
451 const CString
& file1
, const CString
& file2
,
452 const CString
& sName1
, const CString
& sName2
,
453 const CString
& originalFile1
, const CString
& originalFile2
,
454 const git_revnum_t
& hash1
, const git_revnum_t
& hash2
,
455 const DiffFlags
& flags
)
459 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
460 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
462 viewer
= PickDiffTool(file1
, file2
);
463 // If registry entry for a diff program is commented out, use TortoiseMerge.
464 bool bCommentedOut
= viewer
.Left(1) == _T("#");
465 if (flags
.bAlternativeTool
)
467 // Invert external vs. internal diff tool selection.
469 viewer
.Delete(0); // uncomment
473 else if (bCommentedOut
)
477 bool bInternal
= viewer
.IsEmpty();
481 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
482 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
484 viewer
+= _T(" /blame");
486 // check if the params are set. If not, just add the files to the command line
487 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
489 viewer
+= _T(" \"")+file1
+_T("\"");
490 viewer
+= _T(" \"")+file2
+_T("\"");
492 if (viewer
.Find(_T("%base")) >= 0)
494 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
496 if (viewer
.Find(_T("%mine")) >= 0)
498 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
501 if (sName1
.IsEmpty())
502 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
504 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
506 if (sName2
.IsEmpty())
507 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
509 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
511 viewer
.Replace(_T("%bpath"), _T("\"") + originalFile1
+ _T("\""));
512 viewer
.Replace(_T("%ypath"), _T("\"") + originalFile2
+ _T("\""));
514 viewer
.Replace(_T("%brev"), _T("\"") + hash1
+ _T("\""));
515 viewer
.Replace(_T("%yrev"), _T("\"") + hash2
+ _T("\""));
517 if (flags
.bReadOnly
&& bInternal
)
518 viewer
+= _T(" /readonly");
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))
531 viewer
= CPathUtils::GetAppDirectory();
532 viewer
+= _T("TortoiseUDiff.exe");
533 // enquote the path to TortoiseUDiff
534 viewer
= _T("\"") + viewer
+ _T("\"");
536 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
539 if (viewer
.Find(_T("%1"))>=0)
541 if (viewer
.Find(_T("\"%1\"")) >= 0)
542 viewer
.Replace(_T("%1"), patchfile
);
544 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
547 viewer
+= _T(" \"") + patchfile
+ _T("\"");
548 if (viewer
.Find(_T("%title")) >= 0)
550 viewer
.Replace(_T("%title"), title
);
553 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
560 BOOL
CAppUtils::StartTextViewer(CString file
)
563 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
565 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
566 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
569 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
570 TCHAR
* buf
= new TCHAR
[len
+1];
571 ExpandEnvironmentStrings(viewer
, buf
, len
);
574 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
575 buf
= new TCHAR
[len
+1];
576 ExpandEnvironmentStrings(file
, buf
, len
);
579 file
= _T("\"")+file
+_T("\"");
580 if (viewer
.IsEmpty())
582 viewer
= _T("RUNDLL32 Shell32,OpenAs_RunDLL");
584 if (viewer
.Find(_T("\"%1\"")) >= 0)
586 viewer
.Replace(_T("\"%1\""), file
);
588 else if (viewer
.Find(_T("%1")) >= 0)
590 viewer
.Replace(_T("%1"), file
);
598 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
605 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
608 CAutoFile hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
611 length
= ::GetFileSize(hFile
, NULL
);
618 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
621 HDC hScreenDC
= ::GetDC(NULL
);
622 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
623 ::ReleaseDC(NULL
, hScreenDC
);
625 logFont
.lfEscapement
= 0;
626 logFont
.lfOrientation
= 0;
627 logFont
.lfWeight
= FW_NORMAL
;
628 logFont
.lfItalic
= 0;
629 logFont
.lfUnderline
= 0;
630 logFont
.lfStrikeOut
= 0;
631 logFont
.lfCharSet
= DEFAULT_CHARSET
;
632 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
633 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
634 logFont
.lfQuality
= DRAFT_QUALITY
;
635 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
636 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
637 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
640 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
654 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
655 key
= g_Git
.GetConfigValue(cmd
);
657 key
= key
.Tokenize(_T("\n"),start
);
665 CString proc
=CPathUtils::GetAppDirectory();
666 proc
+= _T("pageant.exe \"");
670 CString tempfile
= GetTempFile();
671 ::DeleteFile(tempfile
);
673 proc
+= _T(" -c \"");
674 proc
+= CPathUtils::GetAppDirectory();
675 proc
+= _T("touch.exe\"");
680 CString appDir
= CPathUtils::GetAppDirectory();
681 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true, &appDir
);
686 while(!::PathFileExists(tempfile
))
691 break; //timeout 5 minutes
696 CMessageBox::Show(NULL
, IDS_ERR_PAEGENTTIMEOUT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
698 ::DeleteFile(tempfile
);
701 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
, bool uac
)
703 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
704 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
705 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
709 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
711 LaunchApplication(sCmd
, NULL
, false, NULL
, uac
);
714 bool CAppUtils::LaunchRemoteSetting()
716 CTGitPath
path(g_Git
.m_CurrentDir
);
717 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
718 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
719 //dlg.SetTreeWidth(220);
720 dlg
.m_DefaultPage
= _T("gitremote");
727 * Launch the external blame viewer
729 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
731 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
732 viewer
+= _T("TortoiseGitBlame.exe");
733 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
734 //viewer += _T(" \"") + sLogFile + _T("\"");
735 //viewer += _T(" \"") + sOriginalFile + _T("\"");
736 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
737 viewer
+= CString(_T(" /rev:"))+Rev
;
738 viewer
+= _T(" ")+sParams
;
740 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
743 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
748 bool bStyled
= false;
749 pWnd
->GetWindowText(sText
);
750 // the rich edit control doesn't count the CR char!
751 // to be exact: CRLF is treated as one char.
754 // style each line separately
759 nNewlinePos
= sText
.Find('\n', offset
);
760 CString sLine
= sText
.Mid(offset
);
762 sLine
= sLine
.Left(nNewlinePos
-offset
);
765 while (FindStyleChars(sLine
, '*', start
, end
))
767 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
768 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
770 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
771 format
.cbSize
= sizeof(CHARFORMAT2
);
772 format
.dwMask
= CFM_BOLD
;
773 format
.dwEffects
= CFE_BOLD
;
774 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
780 while (FindStyleChars(sLine
, '^', start
, end
))
782 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
783 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
785 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
786 format
.cbSize
= sizeof(CHARFORMAT2
);
787 format
.dwMask
= CFM_ITALIC
;
788 format
.dwEffects
= CFE_ITALIC
;
789 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
795 while (FindStyleChars(sLine
, '_', start
, end
))
797 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
798 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
800 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
801 format
.cbSize
= sizeof(CHARFORMAT2
);
802 format
.dwMask
= CFM_UNDERLINE
;
803 format
.dwEffects
= CFE_UNDERLINE
;
804 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
808 offset
= nNewlinePos
+1;
809 } while(nNewlinePos
>=0);
813 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
816 bool bFoundMarker
= false;
817 // find a starting marker
818 while (sText
[i
] != 0)
820 if (sText
[i
] == stylechar
)
822 if (((i
+1)<sText
.GetLength())&&(IsCharAlphaNumeric(sText
[i
+1])) &&
823 (((i
>0)&&(!IsCharAlphaNumeric(sText
[i
-1])))||(i
==0)))
835 // find ending marker
836 bFoundMarker
= false;
837 while (sText
[i
] != 0)
839 if (sText
[i
] == stylechar
)
841 if ((IsCharAlphaNumeric(sText
[i
-1])) &&
842 ((((i
+1)<sText
.GetLength())&&(!IsCharAlphaNumeric(sText
[i
+1])))||(i
+1)==sText
.GetLength()))
855 CString
CAppUtils::GetProjectNameFromURL(CString url
)
858 while (name
.IsEmpty() || (name
.CompareNoCase(_T("branches"))==0) ||
859 (name
.CompareNoCase(_T("tags"))==0) ||
860 (name
.CompareNoCase(_T("trunk"))==0))
862 name
= url
.Mid(url
.ReverseFind('/')+1);
863 url
= url
.Left(url
.ReverseFind('/'));
865 if ((name
.Compare(_T("svn")) == 0)||(name
.Compare(_T("svnroot")) == 0))
867 // a name of svn or svnroot indicates that it's not really the project name. In that
868 // case, we try the first part of the URL
869 // of course, this won't work in all cases (but it works for Google project hosting)
870 url
.Replace(_T("http://"), _T(""));
871 url
.Replace(_T("https://"), _T(""));
872 url
.Replace(_T("svn://"), _T(""));
873 url
.Replace(_T("svn+ssh://"), _T(""));
874 url
.TrimLeft(_T("/"));
875 name
= url
.Left(url
.Find('.'));
880 bool CAppUtils::StartShowUnifiedDiff(HWND
/*hWnd*/, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
881 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
882 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
883 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */, bool /* blame = false */, bool bMerge
)
886 CString tempfile
=GetTempFile();
888 if(rev2
== GitRev::GetWorkingCopy())
890 cmd
.Format(_T("git.exe diff --stat -p %s "), rev1
);
892 else if (rev1
== GitRev::GetWorkingCopy())
894 cmd
.Format(_T("git.exe diff -R --stat -p %s "), rev2
);
902 cmd
.Format(_T("git.exe diff-tree -r -p %s --stat %s %s"),merge
, rev1
,rev2
);
905 if( !url1
.IsEmpty() )
908 cmd
+= url1
.GetGitPathString();
911 g_Git
.RunLogFile(cmd
,tempfile
);
912 CAppUtils::StartUnifiedDiffViewer(tempfile
, rev1
+ _T(":") + rev2
);
917 sCmd
.Format(_T("%s /command:showcompare /unified"),
918 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
919 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
921 sCmd
+= _T(" /revision1:") + rev1
.ToString();
922 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
924 sCmd
+= _T(" /revision2:") + rev2
.ToString();
926 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
927 if (headpeg
.IsValid())
928 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
931 sCmd
+= _T(" /alternatediff");
934 sCmd
+= _T(" /ignoreancestry");
938 sCmd
+= _T(" /hwnd:");
940 _stprintf_s(buf
, 30, _T("%d"), hWnd
);
944 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
950 bool CAppUtils::Export(CString
*BashHash
)
952 // ask from where the export has to be done
955 dlg
.m_Revision
=*BashHash
;
957 if (dlg
.DoModal() == IDOK
)
960 cmd
.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s"),
961 dlg
.m_strExportDirectory
, g_Git
.FixBranchName(dlg
.m_VersionName
));
965 return (pro
.DoModal() == IDOK
);
970 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
, bool switch_new_brach
)
972 CCreateBranchTagDlg dlg
;
974 dlg
.m_bSwitch
=switch_new_brach
;
977 dlg
.m_initialRefName
= *CommitHash
;
979 if(dlg
.DoModal()==IDOK
)
984 if(dlg
.m_bTrack
== TRUE
)
985 track
=_T(" --track ");
986 else if(dlg
.m_bTrack
== FALSE
)
987 track
=_T(" --no-track");
998 cmd
.Format(_T("git.exe tag %s %s %s %s"),
1001 dlg
.m_BranchTagName
,
1002 g_Git
.FixBranchName(dlg
.m_VersionName
)
1005 CString tempfile
=::GetTempFile();
1006 if(!dlg
.m_Message
.Trim().IsEmpty())
1008 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_Message
);
1009 cmd
+= _T(" -F ")+tempfile
;
1014 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1017 dlg
.m_BranchTagName
,
1018 g_Git
.FixBranchName(dlg
.m_VersionName
)
1022 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1024 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1027 if( !IsTag
&& dlg
.m_bSwitch
)
1029 // it is a new branch and the user has requested to switch to it
1030 cmd
.Format(_T("git.exe checkout %s"), dlg
.m_BranchTagName
);
1031 g_Git
.Run(cmd
,&out
,CP_UTF8
);
1032 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1040 bool CAppUtils::Switch(CString initialRefName
, bool autoclose
)
1043 if(!initialRefName
.IsEmpty())
1044 dlg
.m_initialRefName
= initialRefName
;
1046 if (dlg
.DoModal() == IDOK
)
1050 branch
= dlg
.m_NewBranch
;
1052 // if refs/heads/ is not stripped, checkout will detach HEAD
1053 // checkout prefers branches on name clashes (with tags)
1054 if (dlg
.m_VersionName
.Left(11) ==_T("refs/heads/") && dlg
.m_bBranchOverride
!= TRUE
)
1055 dlg
.m_VersionName
= dlg
.m_VersionName
.Mid(11);
1057 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
, autoclose
);
1062 bool CAppUtils::PerformSwitch(CString ref
, bool bForce
/* false */, CString sNewBranch
/* CString() */, bool bBranchOverride
/* false */, BOOL bTrack
/* 2 */, bool autoClose
/* false */)
1069 if(!sNewBranch
.IsEmpty()){
1070 if (bBranchOverride
)
1072 branch
.Format(_T("-B %s"), sNewBranch
);
1076 branch
.Format(_T("-b %s"), sNewBranch
);
1079 track
= _T("--track");
1080 else if (bTrack
== FALSE
)
1081 track
= _T("--no-track");
1086 cmd
.Format(_T("git.exe checkout %s %s %s %s"),
1090 g_Git
.FixBranchName(ref
));
1092 CProgressDlg progress
;
1093 progress
.m_bAutoCloseOnSuccess
= autoClose
;
1094 progress
.m_GitCmd
= cmd
;
1096 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1097 if (gitPath
.HasSubmodules())
1098 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1100 INT_PTR ret
= progress
.DoModal();
1101 if (gitPath
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
1104 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1106 RunTortoiseProc(sCmd
);
1109 else if (ret
== IDOK
)
1115 bool CAppUtils::OpenIgnoreFile(CStdioFile
&file
, const CString
& filename
)
1117 if (!file
.Open(filename
, CFile::modeCreate
| CFile::modeReadWrite
| CFile::modeNoTruncate
))
1119 CMessageBox::Show(NULL
, filename
+ _T(" Open Failure"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1123 if (file
.GetLength() > 0)
1125 file
.Seek(file
.GetLength() - 1, 0);
1126 auto_buffer
<TCHAR
> buf(1);
1129 if (buf
[0] != _T('\n'))
1130 file
.WriteString(_T("\n"));
1138 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1140 CIgnoreDlg ignoreDlg
;
1141 if (ignoreDlg
.DoModal() == IDOK
)
1144 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\");
1146 switch (ignoreDlg
.m_IgnoreFile
)
1149 ignorefile
+= _T(".gitignore");
1152 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, ignorefile
);
1153 ignorefile
+= _T("info/exclude");
1160 if (ignoreDlg
.m_IgnoreFile
!= 1 && !OpenIgnoreFile(file
, ignorefile
))
1163 for (int i
= 0; i
< path
.GetCount(); i
++)
1165 if (ignoreDlg
.m_IgnoreFile
== 1)
1167 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\") + path
[i
].GetContainingDirectory().GetWinPathString() + _T("\\.gitignore");
1168 if (!OpenIgnoreFile(file
, ignorefile
))
1172 CString ignorePattern
;
1173 if (ignoreDlg
.m_IgnoreType
== 0)
1175 if (ignoreDlg
.m_IgnoreFile
!= 1 && !path
[i
].GetContainingDirectory().GetGitPathString().IsEmpty())
1176 ignorePattern
+= _T("/") + path
[i
].GetContainingDirectory().GetGitPathString();
1178 ignorePattern
+= _T("/");
1182 ignorePattern
+= _T("*") + path
[i
].GetFileExtension();
1186 ignorePattern
+= path
[i
].GetFileOrDirectoryName();
1189 // escape [ and ] so that files get ignored correctly
1190 ignorePattern
.Replace(_T("["), _T("\\["));
1191 ignorePattern
.Replace(_T("]"), _T("\\]"));
1193 ignorePattern
+= _T("\n");
1194 CStringA ignorePatternA
= CUnicodeUtils::GetUTF8(ignorePattern
);
1195 file
.Write(ignorePatternA
.GetBuffer(), ignorePatternA
.GetLength());
1196 ignorePatternA
.ReleaseBuffer();
1198 if (ignoreDlg
.m_IgnoreFile
== 1)
1202 if (ignoreDlg
.m_IgnoreFile
!= 1)
1217 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1220 dlg
.m_ResetType
=type
;
1221 dlg
.m_ResetToVersion
=*CommitHash
;
1222 if (dlg
.DoModal() == IDOK
)
1226 switch(dlg
.m_ResetType
)
1241 cmd
.Format(_T("git.exe reset %s %s"),type
, *CommitHash
);
1243 CProgressDlg progress
;
1244 progress
.m_GitCmd
=cmd
;
1246 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1247 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2)
1248 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1250 INT_PTR ret
= progress
.DoModal();
1251 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2 && ret
== IDC_PROGRESS_BUTTON1
)
1254 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1256 RunTortoiseProc(sCmd
);
1259 else if (ret
== IDOK
)
1266 void CAppUtils::DescribeFile(bool mode
, bool base
,CString
&descript
)
1270 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_DELETE
));
1275 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_MODIFIED
));
1278 descript
= CString(MAKEINTRESOURCE(IDS_PROC_CREATED
));
1282 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1284 CString tempmergefile
;
1287 tempmergefile
= CAppUtils::GetMergeTempFile(_T("LOCAL"),path
);
1288 CFile::Remove(tempmergefile
);
1295 tempmergefile
= CAppUtils::GetMergeTempFile(_T("REMOTE"),path
);
1296 CFile::Remove(tempmergefile
);
1303 tempmergefile
= CAppUtils::GetMergeTempFile(_T("BASE"),path
);
1304 CFile::Remove(tempmergefile
);
1309 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1312 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1317 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool /*bAlternativeTool*/,bool revertTheirMy
)
1321 CTGitPath merge
=path
;
1322 CTGitPath directory
= merge
.GetDirectory();
1324 // we have the conflicted file (%merged)
1325 // now look for the other required files
1327 //stat.GetStatus(merge);
1328 //if (stat.status == NULL)
1334 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1336 if (g_Git
.Run(cmd
, &vector
))
1342 list
.ParserFromLsFile(vector
);
1344 if(list
.GetCount() == 0)
1351 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge
));
1352 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge
));
1353 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1357 //format=_T("git.exe cat-file blob \":%d:%s\"");
1358 format
= _T("git checkout-index --temp --stage=%d -- \"%s\"");
1360 //create a empty file, incase stage is not three
1361 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1363 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1365 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1368 bool b_base
=false, b_local
=false, b_remote
=false;
1370 for(int i
=0;i
<list
.GetCount();i
++)
1377 if( list
[i
].m_Stage
== 1)
1379 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1381 outfile
= base
.GetWinPathString();
1384 if( list
[i
].m_Stage
== 2 )
1386 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1388 outfile
= mine
.GetWinPathString();
1391 if( list
[i
].m_Stage
== 3 )
1393 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1395 outfile
= theirs
.GetWinPathString();
1397 CString output
, err
;
1398 if(!outfile
.IsEmpty())
1399 if (!g_Git
.Run(cmd
, &output
, &err
, CP_UTF8
))
1403 file
= output
.Tokenize(_T("\t"), start
);
1404 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1408 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1412 if(b_local
&& b_remote
)
1414 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1416 bRet
= !!CAppUtils::StartExtMerge(base
,mine
, theirs
, merge
,_T("BASE"),_T("LOCAL"),_T("REMOTE"));
1418 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1423 CFile::Remove(mine
.GetWinPathString());
1424 CFile::Remove(theirs
.GetWinPathString());
1425 CFile::Remove(base
.GetWinPathString());
1427 CDeleteConflictDlg dlg
;
1428 DescribeFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1429 DescribeFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1430 dlg
.m_bShowModifiedButton
=b_base
;
1431 dlg
.m_File
=merge
.GetGitPathString();
1432 if(dlg
.DoModal() == IDOK
)
1437 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1440 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1442 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1444 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1454 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1455 base
, theirs
, mine
, merge
);
1458 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1460 // we have a text conflict, use our merge tool to resolve the conflict
1462 CTSVNPath
theirs(directory
);
1463 CTSVNPath
mine(directory
);
1464 CTSVNPath
base(directory
);
1465 bool bConflictData
= false;
1467 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1469 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1470 bConflictData
= true;
1472 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1474 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1475 bConflictData
= true;
1477 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1479 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1480 bConflictData
= true;
1487 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1488 base
, theirs
, mine
, merge
);
1491 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1493 // we have a property conflict
1494 CTSVNPath
prej(directory
);
1495 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1497 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1498 // there's a problem: the prej file contains a _description_ of the conflict, and
1499 // that description string might be translated. That means we have no way of parsing
1500 // the file to find out the conflicting values.
1501 // The only thing we can do: show a dialog with the conflict description, then
1502 // let the user either accept the existing property or open the property edit dialog
1503 // to manually change the properties and values. And a button to mark the conflict as
1505 CEditPropConflictDlg dlg
;
1506 dlg
.SetPrejFile(prej
);
1507 dlg
.SetConflictedItem(merge
);
1508 bRet
= (dlg
.DoModal() != IDCANCEL
);
1512 if (stat
.status
->tree_conflict
)
1514 // we have a tree conflict
1516 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1519 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1521 CTSVNPath
theirs(directory
);
1522 CTSVNPath
mine(directory
);
1523 CTSVNPath
base(directory
);
1524 bool bConflictData
= false;
1526 if (pInfoData
->treeconflict_theirfile
)
1528 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1529 bConflictData
= true;
1531 if (pInfoData
->treeconflict_basefile
)
1533 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1534 bConflictData
= true;
1536 if (pInfoData
->treeconflict_myfile
)
1538 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1539 bConflictData
= true;
1546 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1547 base
, theirs
, mine
, merge
);
1549 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1551 CString sConflictAction
;
1552 CString sConflictReason
;
1553 CString sResolveTheirs
;
1554 CString sResolveMine
;
1555 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1556 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1558 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1560 switch (pInfoData
->treeconflict_operation
)
1562 case svn_wc_operation_update
:
1563 switch (pInfoData
->treeconflict_action
)
1565 case svn_wc_conflict_action_edit
:
1566 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1567 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1569 case svn_wc_conflict_action_add
:
1570 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1571 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1573 case svn_wc_conflict_action_delete
:
1574 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1575 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1579 case svn_wc_operation_switch
:
1580 switch (pInfoData
->treeconflict_action
)
1582 case svn_wc_conflict_action_edit
:
1583 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1584 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1586 case svn_wc_conflict_action_add
:
1587 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1588 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1590 case svn_wc_conflict_action_delete
:
1591 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1592 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1596 case svn_wc_operation_merge
:
1597 switch (pInfoData
->treeconflict_action
)
1599 case svn_wc_conflict_action_edit
:
1600 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1601 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1603 case svn_wc_conflict_action_add
:
1604 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1605 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1607 case svn_wc_conflict_action_delete
:
1608 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1609 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1615 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1617 switch (pInfoData
->treeconflict_operation
)
1619 case svn_wc_operation_update
:
1620 switch (pInfoData
->treeconflict_action
)
1622 case svn_wc_conflict_action_edit
:
1623 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1624 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1626 case svn_wc_conflict_action_add
:
1627 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1628 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1630 case svn_wc_conflict_action_delete
:
1631 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1632 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1636 case svn_wc_operation_switch
:
1637 switch (pInfoData
->treeconflict_action
)
1639 case svn_wc_conflict_action_edit
:
1640 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1641 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1643 case svn_wc_conflict_action_add
:
1644 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1645 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1647 case svn_wc_conflict_action_delete
:
1648 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1649 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1653 case svn_wc_operation_merge
:
1654 switch (pInfoData
->treeconflict_action
)
1656 case svn_wc_conflict_action_edit
:
1657 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1658 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1660 case svn_wc_conflict_action_add
:
1661 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1662 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1664 case svn_wc_conflict_action_delete
:
1665 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1666 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1674 switch (pInfoData
->treeconflict_reason
)
1676 case svn_wc_conflict_reason_edited
:
1677 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1678 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1680 case svn_wc_conflict_reason_obstructed
:
1681 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1682 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1684 case svn_wc_conflict_reason_deleted
:
1685 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1686 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1688 case svn_wc_conflict_reason_added
:
1689 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1690 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1692 case svn_wc_conflict_reason_missing
:
1693 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1694 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1696 case svn_wc_conflict_reason_unversioned
:
1697 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1698 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1701 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1703 CTreeConflictEditorDlg dlg
;
1704 dlg
.SetConflictInfoText(sConflictReason
);
1705 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1706 dlg
.SetPath(treeConflictPath
);
1707 INT_PTR dlgRet
= dlg
.DoModal();
1708 bRet
= (dlgRet
!= IDCANCEL
);
1716 bool CAppUtils::IsSSHPutty()
1718 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1719 sshclient
=sshclient
.MakeLower();
1720 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1727 CString
CAppUtils::GetClipboardLink()
1729 if (!OpenClipboard(NULL
))
1732 CString sClipboardText
;
1733 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1736 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1737 sClipboardText
= CString(lpstr
);
1740 hglb
= GetClipboardData(CF_UNICODETEXT
);
1743 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1744 sClipboardText
= lpstr
;
1749 if(!sClipboardText
.IsEmpty())
1751 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1752 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1754 if(sClipboardText
.Find( _T("http://")) == 0)
1755 return sClipboardText
;
1757 if(sClipboardText
.Find( _T("https://")) == 0)
1758 return sClipboardText
;
1760 if(sClipboardText
.Find( _T("git://")) == 0)
1761 return sClipboardText
;
1763 if(sClipboardText
.Find( _T("ssh://")) == 0)
1764 return sClipboardText
;
1766 if(sClipboardText
.GetLength()>=2)
1767 if( sClipboardText
[1] == _T(':') )
1768 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1769 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1770 return sClipboardText
;
1773 return CString(_T(""));
1776 CString
CAppUtils::ChooseRepository(CString
*path
)
1778 CBrowseFolder browseFolder
;
1779 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
1781 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
1782 CString strCloneDirectory
;
1784 strCloneDirectory
=*path
;
1787 strCloneDirectory
= regLastResopitory
;
1791 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
1793 browseFolder
.SetInfo(title
);
1795 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
1797 regLastResopitory
= strCloneDirectory
;
1798 return strCloneDirectory
;
1806 bool CAppUtils::SendPatchMail(CTGitPathList
&list
,bool autoclose
)
1810 dlg
.m_PathList
= list
;
1812 if(dlg
.DoModal()==IDOK
)
1814 if(dlg
.m_PathList
.GetCount() == 0)
1817 CGitProgressDlg progDlg
;
1819 theApp
.m_pMainWnd
= &progDlg
;
1820 progDlg
.SetCommand(CGitProgressDlg::GitProgress_SendMail
);
1822 progDlg
.SetAutoClose(autoclose
);
1824 progDlg
.SetPathList(dlg
.m_PathList
);
1825 //ProjectProperties props;
1826 //props.ReadPropsPathList(dlg.m_pathList);
1827 //progDlg.SetProjectProperties(props);
1828 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
1831 if(dlg
.m_bAttachment
)
1832 flags
|= SENDMAIL_ATTACHMENT
;
1834 flags
|= SENDMAIL_COMBINED
;
1836 flags
|= SENDMAIL_MAPI
;
1838 progDlg
.SetSendMailOption(dlg
.m_To
,dlg
.m_CC
,dlg
.m_Subject
,flags
);
1847 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
)
1850 CString log
=formatpatchoutput
;
1851 int start
=log
.Find(cmd
);
1853 CString one
=log
.Tokenize(_T("\n"),start
);
1859 CString one
=log
.Tokenize(_T("\n"),start
);
1861 if(one
.IsEmpty() || one
== _T("Success"))
1863 one
.Replace(_T('/'),_T('\\'));
1865 path
.SetFromWin(one
);
1868 if (list
.GetCount() > 0)
1870 return SendPatchMail(list
, autoclose
);
1874 CMessageBox::Show(NULL
, IDS_ERR_NOPATCHES
, IDS_APPNAME
, MB_ICONINFORMATION
);
1880 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
1885 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
1886 if(output
.IsEmpty())
1888 output
= pGit
->GetConfigValue(_T("i18n.commitencoding"));
1889 if(output
.IsEmpty())
1893 output
=output
.Tokenize(_T("\n"),start
);
1894 return CUnicodeUtils::GetCPCode(output
);
1899 output
=output
.Tokenize(_T("\n"),start
);
1900 return CUnicodeUtils::GetCPCode(output
);
1903 int CAppUtils::GetCommitTemplate(CString
&temp
)
1907 output
= g_Git
.GetConfigValue(_T("commit.template"), CP_UTF8
);
1908 if( output
.IsEmpty() )
1911 if( output
.GetLength()<1)
1914 if( output
[0] == _T('/'))
1916 if(output
.GetLength()>=3)
1917 if(output
[2] == _T('/'))
1919 output
.GetBuffer()[0] = output
[1];
1920 output
.GetBuffer()[1] = _T(':');
1925 output
=output
.Tokenize(_T("\n"),start
);
1927 output
.Replace(_T('/'),_T('\\'));
1931 CStdioFile
file(output
,CFile::modeRead
|CFile::typeText
);
1933 while(file
.ReadString(str
))
1944 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
1946 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
1950 output
= g_Git
.GetConfigValue(_T("i18n.commitencoding"));
1951 if(output
.IsEmpty())
1955 output
=output
.Tokenize(_T("\n"),start
);
1956 cp
=CUnicodeUtils::GetCPCode(output
);
1958 int len
=message
.GetLength();
1961 buf
= new char[len
*4 + 4];
1962 SecureZeroMemory(buf
, (len
*4 + 4));
1964 int lengthIncTerminator
= WideCharToMultiByte(cp
, 0, message
, -1, buf
, len
*4, NULL
, NULL
);
1966 file
.Write(buf
,lengthIncTerminator
-1);
1972 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
, bool autoClose
)
1975 dlg
.m_PreSelectRemote
= remoteName
;
1976 dlg
.m_bAllowRebase
= allowRebase
;
1979 if(dlg
.DoModal()==IDOK
)
1983 if (dlg
.m_bAllRemotes
)
1986 g_Git
.GetRemoteList(list
);
1988 STRING_VECTOR::const_iterator it
= list
.begin();
1989 while (it
!= list
.end())
1991 CString
remote(*it
);
1992 CAppUtils::LaunchPAgent(NULL
, &remote
);
1997 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
2001 url
=dlg
.m_RemoteURL
;
2005 int ver
= CAppUtils::GetMsysgitVersion();
2007 if(ver
>= 0x01070203) //above 1.7.0.2
2008 arg
= _T("--progress ");
2011 arg
+= _T("--prune ");
2014 if (dlg
.m_bFetchTags
== 1)
2016 arg
+= _T("--tags ");
2018 else if (dlg
.m_bFetchTags
== 0)
2020 arg
+= _T("--no-tags ");
2023 if (dlg
.m_bAllRemotes
)
2024 cmd
.Format(_T("git.exe fetch --all -v %s"), arg
);
2026 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"), arg
, url
, dlg
.m_RemoteBranchName
);
2028 CProgressDlg progress
;
2030 progress
.m_bAutoCloseOnSuccess
= autoClose
;
2032 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2034 if(!dlg
.m_bRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
2036 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2039 progress
.m_GitCmd
=cmd
;
2040 INT_PTR userResponse
= progress
.DoModal();
2042 if (userResponse
== IDC_PROGRESS_BUTTON1
)
2044 CString cmd
= _T("/command:log");
2045 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2046 RunTortoiseProc(cmd
);
2049 else if ((userResponse
== IDC_PROGRESS_BUTTON1
+ 1) || (progress
.m_GitStatus
== 0 && dlg
.m_bRebase
))
2054 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUDESSENDMAIL
)));
2055 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2056 INT_PTR response
= dlg
.DoModal();
2057 if(response
== IDOK
)
2061 if(response
== IDC_REBASE_POST_BUTTON
)
2063 CString cmd
, out
, err
;
2064 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2066 g_Git
.FixBranchName(dlg
.m_Upstream
),
2067 g_Git
.FixBranchName(dlg
.m_Branch
));
2068 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
2070 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2074 CAppUtils::SendPatchMail(cmd
,out
);
2078 if(response
== IDC_REBASE_POST_BUTTON
+1 )
2081 if(response
== IDCANCEL
)
2086 else if (userResponse
!= IDCANCEL
)
2092 bool CAppUtils::Push(CString selectLocalBranch
, bool autoClose
)
2095 dlg
.m_BranchSourceName
= selectLocalBranch
;
2097 DWORD exitcode
= 0xFFFFFFFF;
2099 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
2100 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
2105 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2106 //ReportError(temp);
2107 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2112 if(dlg
.DoModal()==IDOK
)
2117 arg
+= _T("--thin ");
2118 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2119 arg
+= _T("--tags ");
2121 arg
+= _T("--force ");
2122 if (dlg
.m_bSetUpstream
)
2123 arg
+= _T("--set-upstream ");
2125 int ver
= CAppUtils::GetMsysgitVersion();
2127 if(ver
>= 0x01070203) //above 1.7.0.2
2128 arg
+= _T("--progress ");
2130 CProgressDlg progress
;
2131 progress
.m_bAutoCloseOnSuccess
=autoClose
;
2133 STRING_VECTOR remotesList
;
2134 if (dlg
.m_bPushAllRemotes
)
2135 g_Git
.GetRemoteList(remotesList
);
2137 remotesList
.push_back(dlg
.m_URL
);
2139 for (unsigned int i
= 0; i
< remotesList
.size(); i
++)
2141 if (dlg
.m_bAutoLoad
)
2142 CAppUtils::LaunchPAgent(NULL
, &remotesList
[i
]);
2145 if (dlg
.m_bPushAllBranches
)
2147 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2153 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2156 dlg
.m_BranchSourceName
);
2157 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2159 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2162 progress
.m_GitCmdList
.push_back(cmd
);
2165 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REQUESTPULL
)));
2166 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2167 INT_PTR ret
= progress
.DoModal();
2169 if(!progress
.m_GitStatus
)
2171 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2176 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2177 //ReportError(temp);
2178 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2182 if(ret
== IDC_PROGRESS_BUTTON1
)
2184 RequestPull(dlg
.m_BranchRemoteName
);
2186 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2197 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2199 CRequestPullDlg dlg
;
2200 dlg
.m_RepositoryURL
= repositoryUrl
;
2201 dlg
.m_EndRevision
= endrevision
;
2202 if (dlg
.DoModal()==IDOK
)
2205 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2207 CString tempFileName
= GetTempFile();
2208 if (g_Git
.RunLogFile(cmd
, tempFileName
))
2210 CMessageBox::Show(NULL
, IDS_ERR_PULLREUQESTFAILED
, IDS_APPNAME
, MB_OK
);
2213 CAppUtils::LaunchAlternativeEditor(tempFileName
);
2218 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2220 CString
strDir(szPath
);
2221 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2223 strDir
.AppendChar(_T('\\'));
2225 std::vector
<CString
> vPath
;
2227 bool bSuccess
= false;
2229 for (int i
=0;i
<strDir
.GetLength();++i
)
2231 if (strDir
.GetAt(i
) != _T('\\'))
2233 strTemp
.AppendChar(strDir
.GetAt(i
));
2237 vPath
.push_back(strTemp
);
2238 strTemp
.AppendChar(_T('\\'));
2242 std::vector
<CString
>::const_iterator vIter
;
2243 for (vIter
= vPath
.begin(); vIter
!= vPath
.end(); vIter
++)
2245 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2251 void CAppUtils::RemoveTrailSlash(CString
&path
)
2256 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2258 path
=path
.Left(path
.GetLength()-1);
2264 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2265 CTGitPathList
&pathList
,
2266 CTGitPathList
&selectedList
,
2267 bool bSelectFilesForCommit
,
2270 bool bFailed
= true;
2272 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
2274 if(CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
2276 CTGitPath
path(g_Git
.m_CurrentDir
);
2277 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2278 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2279 dlg
.SetTreeWidth(220);
2280 dlg
.m_DefaultPage
= _T("gitconfig");
2283 dlg
.HandleRestart();
2294 dlg
.m_sBugID
= bugid
;
2296 dlg
.m_bWholeProject
= bWholeProject
;
2298 dlg
.m_sLogMessage
= sLogMsg
;
2299 dlg
.m_pathList
= pathList
;
2300 dlg
.m_checkedPathList
= selectedList
;
2301 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2302 dlg
.m_bAutoClose
= autoClose
;
2303 if (dlg
.DoModal() == IDOK
)
2305 if (dlg
.m_pathList
.GetCount()==0)
2307 // if the user hasn't changed the list of selected items
2308 // we don't use that list. Because if we would use the list
2309 // of pre-checked items, the dialog would show different
2310 // checked items on the next startup: it would only try
2311 // to check the parent folder (which might not even show)
2312 // instead, we simply use an empty list and let the
2313 // default checking do its job.
2314 if (!dlg
.m_pathList
.IsEqual(pathList
))
2315 selectedList
= dlg
.m_pathList
;
2316 pathList
= dlg
.m_updatedPathList
;
2317 sLogMsg
= dlg
.m_sLogMessage
;
2318 bSelectFilesForCommit
= true;
2320 if( dlg
.m_bPushAfterCommit
)
2322 switch(dlg
.m_PostCmd
)
2324 case GIT_POST_CMD_DCOMMIT
:
2325 CAppUtils::SVNDCommit();
2331 else if (dlg
.m_bCreateTagAfterCommit
)
2333 CAppUtils::CreateBranchTag(TRUE
);
2336 // CGitProgressDlg progDlg;
2337 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2338 // if (parser.HasVal(_T("closeonend")))
2339 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2340 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2341 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2342 // progDlg.SetPathList(dlg.m_pathList);
2343 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2344 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2345 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2346 // progDlg.SetItemCount(dlg.m_itemsCount);
2347 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2348 // progDlg.DoModal();
2349 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2350 // err = (DWORD)progDlg.DidErrorsOccur();
2351 // bFailed = progDlg.DidErrorsOccur();
2352 // bRet = progDlg.DidErrorsOccur();
2353 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2354 // if (DWORD(bFailRepeat)==0)
2355 // bFailed = false; // do not repeat if the user chose not to in the settings.
2362 BOOL
CAppUtils::SVNDCommit()
2364 CSVNDCommitDlg dcommitdlg
;
2365 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2366 if (gitSetting
== _T("")) {
2367 if (dcommitdlg
.DoModal() != IDOK
)
2373 if (dcommitdlg
.m_remember
)
2375 if (dcommitdlg
.m_rmdir
)
2377 gitSetting
= _T("true");
2381 gitSetting
= _T("false");
2383 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2386 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, _T("svn.rmdir"), gitSetting
);
2387 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2393 BOOL IsStash
= false;
2394 if(!g_Git
.CheckCleanWorkTree())
2396 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
2398 CSysProgressDlg sysProgressDlg
;
2399 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2400 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2401 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2402 sysProgressDlg
.SetShowProgressBar(false);
2403 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2404 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2407 cmd
=_T("git.exe stash");
2408 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2410 if (sysProgressDlg
.IsValid())
2411 sysProgressDlg
.Stop();
2412 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2415 if (sysProgressDlg
.IsValid())
2416 sysProgressDlg
.Stop();
2426 CProgressDlg progress
;
2427 if (dcommitdlg
.m_rmdir
)
2429 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2433 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2435 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2439 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2441 CSysProgressDlg sysProgressDlg
;
2442 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2443 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2444 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2445 sysProgressDlg
.SetShowProgressBar(false);
2446 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2447 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2450 cmd
=_T("git.exe stash pop");
2451 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2453 if (sysProgressDlg
.IsValid())
2454 sysProgressDlg
.Stop();
2455 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2458 if (sysProgressDlg
.IsValid())
2459 sysProgressDlg
.Stop();
2471 BOOL
CAppUtils::Merge(CString
*commit
)
2475 dlg
.m_initialRefName
= *commit
;
2477 if(dlg
.DoModal()==IDOK
)
2489 squash
=_T("--squash");
2492 nocommit
=_T("--no-commit");
2494 if(!dlg
.m_strLogMesage
.IsEmpty())
2496 msg
+= _T("-m \"")+dlg
.m_strLogMesage
+_T("\"");
2498 cmd
.Format(_T("git.exe merge %s %s %s %s %s"),
2503 g_Git
.FixBranchName(dlg
.m_VersionName
));
2505 CProgressDlg Prodlg
;
2506 Prodlg
.m_GitCmd
= cmd
;
2508 if (dlg
.m_bNoCommit
)
2509 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUCOMMIT
)));
2510 else if (dlg
.m_bIsBranch
)
2511 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REMOVEBRANCH
)));
2513 INT_PTR ret
= Prodlg
.DoModal();
2515 if (ret
== IDC_PROGRESS_BUTTON1
)
2516 if (dlg
.m_bNoCommit
)
2519 CTGitPathList pathList
;
2520 CTGitPathList selectedList
;
2521 return Commit(_T(""), TRUE
, sLogMsg
, pathList
, selectedList
, true);
2523 else if (dlg
.m_bIsBranch
)
2526 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, dlg
.m_VersionName
);
2527 if (CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
2530 cmd
.Format(_T("git.exe branch -D -- %s"), dlg
.m_VersionName
);
2531 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2532 MessageBox(NULL
, out
, _T("TortoiseGit"), MB_OK
);
2536 return !Prodlg
.m_GitStatus
;
2541 void CAppUtils::EditNote(GitRev
*rev
)
2544 dlg
.m_sHintText
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2545 dlg
.m_sInputText
= rev
->m_Notes
;
2546 dlg
.m_sTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2547 //dlg.m_pProjectProperties = &m_ProjectProperties;
2548 dlg
.m_bUseLogWidth
= true;
2549 if(dlg
.DoModal() == IDOK
)
2552 cmd
=_T("notes add -f -F \"");
2554 CString tempfile
=::GetTempFile();
2555 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
2558 cmd
+= rev
->m_CommitHash
.ToString();
2562 if (git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2564 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2569 rev
->m_Notes
= dlg
.m_sInputText
;
2573 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2575 CFile::Remove(tempfile
);
2580 int CAppUtils::GetMsysgitVersion(CString
*versionstr
)
2583 CString progressarg
;
2586 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
2587 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
2589 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
2592 if(!g_Git
.GetFileModifyTime(gitpath
, &time
) && !versionstr
)
2594 if((DWORD
)time
== regTime
)
2601 version
= *versionstr
;
2605 cmd
= _T("git.exe --version");
2606 if (g_Git
.Run(cmd
, &version
, &err
, CP_UTF8
))
2608 CMessageBox::Show(NULL
, _T("git have not installed (") + err
+ _T(")"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2618 CString str
=version
.Tokenize(_T("."), start
);
2619 int space
= str
.ReverseFind(_T(' '));
2620 str
= str
.Mid(space
+1,start
);
2624 version
= version
.Mid(start
);
2627 str
= version
.Tokenize(_T("."), start
);
2629 ver
|= (_ttol(str
) & 0xFF) << 16;
2631 str
= version
.Tokenize(_T("."), start
);
2632 ver
|= (_ttol(str
) & 0xFF) << 8;
2634 str
= version
.Tokenize(_T("."), start
);
2635 ver
|= (_ttol(str
) & 0xFF);
2641 CMessageBox::Show(NULL
, _T("Could not parse git.exe version number."), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2646 regTime
= time
&0xFFFFFFFF;
2652 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
2654 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
2656 CAutoLibrary hShell
= LoadLibrary(_T("Shell32.dll"));
2658 if (hShell
.IsValid()) {
2659 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
2661 IPropertyStore
*pps
;
2662 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
2663 if (SUCCEEDED(hr
)) {
2666 var
.boolVal
= VARIANT_TRUE
;
2667 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
2674 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
2676 ASSERT(dialogname
.GetLength() < 70);
2677 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
2678 WCHAR pathbuf
[MAX_PATH
] = {0};
2680 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
2682 wcscat_s(pathbuf
, L
" - ");
2683 wcscat_s(pathbuf
, dialogname
);
2684 wcscat_s(pathbuf
, L
" - ");
2685 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2686 SetWindowText(hWnd
, pathbuf
);
2689 bool CAppUtils::BisectStart(CString lastGood
, CString firstBad
, bool autoClose
)
2691 if (!g_Git
.CheckCleanWorkTree())
2693 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
2695 CSysProgressDlg sysProgressDlg
;
2696 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2697 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2698 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2699 sysProgressDlg
.SetShowProgressBar(false);
2700 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2701 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2704 cmd
= _T("git.exe stash");
2705 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2707 if (sysProgressDlg
.IsValid())
2708 sysProgressDlg
.Stop();
2709 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
);
2712 if (sysProgressDlg
.IsValid())
2713 sysProgressDlg
.Stop();
2719 CBisectStartDlg bisectStartDlg
;
2721 if (!lastGood
.IsEmpty())
2722 bisectStartDlg
.m_sLastGood
= lastGood
;
2723 if (!firstBad
.IsEmpty())
2724 bisectStartDlg
.m_sFirstBad
= firstBad
;
2726 if (bisectStartDlg
.DoModal() == IDOK
)
2728 CProgressDlg progress
;
2729 theApp
.m_pMainWnd
= &progress
;
2730 progress
.m_bAutoCloseOnSuccess
= autoClose
;
2731 progress
.m_GitCmdList
.push_back(_T("git.exe bisect start"));
2732 progress
.m_GitCmdList
.push_back(_T("git.exe bisect good ") + bisectStartDlg
.m_LastGoodRevision
);
2733 progress
.m_GitCmdList
.push_back(_T("git.exe bisect bad ") + bisectStartDlg
.m_FirstBadRevision
);
2735 CTGitPath
path(g_Git
.m_CurrentDir
);
2737 if (path
.HasSubmodules())
2738 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
2740 INT_PTR ret
= progress
.DoModal();
2741 if (path
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
2744 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
2746 CAppUtils::RunTortoiseProc(sCmd
);
2749 else if (ret
== IDOK
)