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 (dlg
.m_bIncludeUntracked
&& CAppUtils::GetMsysgitVersion() >= 0x01070700)
85 cmd
+= _T(" --include-untracked");
87 if (!dlg
.m_sMessage
.IsEmpty())
89 CString message
= dlg
.m_sMessage
;
90 message
.Replace(_T("\""), _T("\"\""));
91 cmd
+= _T(" \"") + message
+ _T("\"");
94 CSysProgressDlg sysProgressDlg
;
95 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
96 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
97 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
98 sysProgressDlg
.SetShowProgressBar(false);
99 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
100 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
102 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
104 if (sysProgressDlg
.IsValid())
105 sysProgressDlg
.Stop();
106 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
110 if (sysProgressDlg
.IsValid())
111 sysProgressDlg
.Stop();
112 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHSUCCESS
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
119 bool CAppUtils::StashApply(CString ref
, bool showChanges
/* true */)
122 cmd
= _T("git.exe stash apply ");
123 if (ref
.Find(_T("refs/")) == 0)
125 if (ref
.Find(_T("stash{")) == 0)
126 ref
= _T("stash@") + ref
.Mid(5);
129 CSysProgressDlg sysProgressDlg
;
130 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
131 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
132 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
133 sysProgressDlg
.SetShowProgressBar(false);
134 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
135 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
137 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
139 if (sysProgressDlg
.IsValid())
140 sysProgressDlg
.Stop();
142 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
143 if (ret
&& !(ret
== 1 && hasConflicts
))
145 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHAPPLYFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
150 message
.LoadString(IDS_PROC_STASHAPPLYSUCCESS
);
152 message
.LoadString(IDS_PROC_STASHAPPLYFAILEDCONFLICTS
);
155 if(CMessageBox::Show(NULL
,message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
))
156 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
159 dlg
.m_pathList
.AddPath(CTGitPath());
166 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
173 bool CAppUtils::StashPop(bool showChanges
/* true */)
176 cmd
=_T("git.exe stash pop ");
178 CSysProgressDlg sysProgressDlg
;
179 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
180 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
181 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
182 sysProgressDlg
.SetShowProgressBar(false);
183 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
184 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
186 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
188 if (sysProgressDlg
.IsValid())
189 sysProgressDlg
.Stop();
191 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
192 if (ret
&& !(ret
== 1 && hasConflicts
))
194 CMessageBox::Show(NULL
,CString(MAKEINTRESOURCE(IDS_PROC_STASHPOPFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
199 message
.LoadString(IDS_PROC_STASHPOPSUCCESS
);
201 message
.LoadString(IDS_PROC_STASHPOPFAILEDCONFLICTS
);
204 if(CMessageBox::Show(NULL
,CString(message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
)))
205 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
208 dlg
.m_pathList
.AddPath(CTGitPath());
215 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
222 bool CAppUtils::GetMimeType(const CTGitPath
& /*file*/, CString
& /*mimetype*/)
225 GitProperties
props(file
, GitRev::REV_WC
, false);
226 for (int i
= 0; i
< props
.GetCount(); ++i
)
228 if (props
.GetItemName(i
).compare(_T("svn:mime-type"))==0)
230 mimetype
= props
.GetItemValue(i
).c_str();
238 BOOL
CAppUtils::StartExtMerge(
239 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
240 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
)
243 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
244 CString ext
= mergedfile
.GetFileExtension();
245 CString com
= regCom
;
246 bool bInternal
= false;
251 // is there an extension specific merge tool?
252 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
253 if (CString(mergetool
) != "")
258 if (GetMimeType(yourfile
, mimetype
) || GetMimeType(theirfile
, mimetype
) || GetMimeType(basefile
, mimetype
))
260 // is there a mime type specific merge tool?
261 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype
);
262 if (CString(mergetool
) != "")
268 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
272 CRegString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE
);
273 com
= tortoiseMergePath
;
276 com
= CPathUtils::GetAppDirectory();
277 com
+= _T("TortoiseMerge.exe");
279 com
= _T("\"") + com
+ _T("\"");
280 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
281 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
283 // check if the params are set. If not, just add the files to the command line
284 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
286 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
287 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
288 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
289 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
291 if (basefile
.IsEmpty())
293 com
.Replace(_T("/base:%base"), _T(""));
294 com
.Replace(_T("%base"), _T(""));
297 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
298 if (theirfile
.IsEmpty())
300 com
.Replace(_T("/theirs:%theirs"), _T(""));
301 com
.Replace(_T("%theirs"), _T(""));
304 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
305 if (yourfile
.IsEmpty())
307 com
.Replace(_T("/mine:%mine"), _T(""));
308 com
.Replace(_T("%mine"), _T(""));
311 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
312 if (mergedfile
.IsEmpty())
314 com
.Replace(_T("/merged:%merged"), _T(""));
315 com
.Replace(_T("%merged"), _T(""));
318 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
319 if (basename
.IsEmpty())
321 if (basefile
.IsEmpty())
323 com
.Replace(_T("/basename:%bname"), _T(""));
324 com
.Replace(_T("%bname"), _T(""));
328 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
332 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
333 if (theirname
.IsEmpty())
335 if (theirfile
.IsEmpty())
337 com
.Replace(_T("/theirsname:%tname"), _T(""));
338 com
.Replace(_T("%tname"), _T(""));
342 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
346 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
347 if (yourname
.IsEmpty())
349 if (yourfile
.IsEmpty())
351 com
.Replace(_T("/minename:%yname"), _T(""));
352 com
.Replace(_T("%yname"), _T(""));
356 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
360 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
361 if (mergedname
.IsEmpty())
363 if (mergedfile
.IsEmpty())
365 com
.Replace(_T("/mergedname:%mname"), _T(""));
366 com
.Replace(_T("%mname"), _T(""));
370 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
374 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
376 if ((bReadOnly
)&&(bInternal
))
377 com
+= _T(" /readonly");
379 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
387 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
391 viewer
= CPathUtils::GetAppDirectory();
392 viewer
+= _T("TortoiseMerge.exe");
394 viewer
= _T("\"") + viewer
+ _T("\"");
395 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
396 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
398 viewer
+= _T(" /reversedpatch");
399 if (!sOriginalDescription
.IsEmpty())
400 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
401 if (!sPatchedDescription
.IsEmpty())
402 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
403 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
410 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
412 // Is there a mime type specific diff tool?
414 if (GetMimeType(file1
, mimetype
) || GetMimeType(file2
, mimetype
))
416 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype
);
417 if (!difftool
.IsEmpty())
421 // Is there an extension specific diff tool?
422 CString ext
= file2
.GetFileExtension().MakeLower();
425 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
426 if (!difftool
.IsEmpty())
428 // Maybe we should use TortoiseIDiff?
429 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
430 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
431 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
432 (ext
== _T(".dib")) || (ext
== _T(".emf")))
435 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
436 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
440 // Finally, pick a generic external diff tool
441 CString difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
445 bool CAppUtils::StartExtDiff(
446 const CString
& file1
, const CString
& file2
,
447 const CString
& sName1
, const CString
& sName2
,
448 const CString
& originalFile1
, const CString
& originalFile2
,
449 const git_revnum_t
& hash1
, const git_revnum_t
& hash2
,
450 const DiffFlags
& flags
)
454 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
455 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
457 viewer
= PickDiffTool(file1
, file2
);
458 // If registry entry for a diff program is commented out, use TortoiseMerge.
459 bool bCommentedOut
= viewer
.Left(1) == _T("#");
460 if (flags
.bAlternativeTool
)
462 // Invert external vs. internal diff tool selection.
464 viewer
.Delete(0); // uncomment
468 else if (bCommentedOut
)
472 bool bInternal
= viewer
.IsEmpty();
476 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
477 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
479 viewer
+= _T(" /blame");
481 // check if the params are set. If not, just add the files to the command line
482 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
484 viewer
+= _T(" \"")+file1
+_T("\"");
485 viewer
+= _T(" \"")+file2
+_T("\"");
487 if (viewer
.Find(_T("%base")) >= 0)
489 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
491 if (viewer
.Find(_T("%mine")) >= 0)
493 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
496 if (sName1
.IsEmpty())
497 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
499 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
501 if (sName2
.IsEmpty())
502 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
504 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
506 viewer
.Replace(_T("%bpath"), _T("\"") + originalFile1
+ _T("\""));
507 viewer
.Replace(_T("%ypath"), _T("\"") + originalFile2
+ _T("\""));
509 viewer
.Replace(_T("%brev"), _T("\"") + hash1
+ _T("\""));
510 viewer
.Replace(_T("%yrev"), _T("\"") + hash2
+ _T("\""));
512 if (flags
.bReadOnly
&& bInternal
)
513 viewer
+= _T(" /readonly");
515 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
518 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
521 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
523 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
526 viewer
= CPathUtils::GetAppDirectory();
527 viewer
+= _T("TortoiseUDiff.exe");
528 // enquote the path to TortoiseUDiff
529 viewer
= _T("\"") + viewer
+ _T("\"");
531 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
534 if (viewer
.Find(_T("%1"))>=0)
536 if (viewer
.Find(_T("\"%1\"")) >= 0)
537 viewer
.Replace(_T("%1"), patchfile
);
539 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
542 viewer
+= _T(" \"") + patchfile
+ _T("\"");
543 if (viewer
.Find(_T("%title")) >= 0)
545 viewer
.Replace(_T("%title"), title
);
548 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
555 BOOL
CAppUtils::StartTextViewer(CString file
)
558 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
560 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
561 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
564 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
565 TCHAR
* buf
= new TCHAR
[len
+1];
566 ExpandEnvironmentStrings(viewer
, buf
, len
);
569 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
570 buf
= new TCHAR
[len
+1];
571 ExpandEnvironmentStrings(file
, buf
, len
);
574 file
= _T("\"")+file
+_T("\"");
575 if (viewer
.IsEmpty())
577 viewer
= _T("RUNDLL32 Shell32,OpenAs_RunDLL");
579 if (viewer
.Find(_T("\"%1\"")) >= 0)
581 viewer
.Replace(_T("\"%1\""), file
);
583 else if (viewer
.Find(_T("%1")) >= 0)
585 viewer
.Replace(_T("%1"), file
);
593 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
600 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
603 CAutoFile hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
606 length
= ::GetFileSize(hFile
, NULL
);
613 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
616 HDC hScreenDC
= ::GetDC(NULL
);
617 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
618 ::ReleaseDC(NULL
, hScreenDC
);
620 logFont
.lfEscapement
= 0;
621 logFont
.lfOrientation
= 0;
622 logFont
.lfWeight
= FW_NORMAL
;
623 logFont
.lfItalic
= 0;
624 logFont
.lfUnderline
= 0;
625 logFont
.lfStrikeOut
= 0;
626 logFont
.lfCharSet
= DEFAULT_CHARSET
;
627 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
628 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
629 logFont
.lfQuality
= DRAFT_QUALITY
;
630 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
631 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
632 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
635 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
649 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
650 key
= g_Git
.GetConfigValue(cmd
);
652 key
= key
.Tokenize(_T("\n"),start
);
660 CString proc
=CPathUtils::GetAppDirectory();
661 proc
+= _T("pageant.exe \"");
665 CString tempfile
= GetTempFile();
666 ::DeleteFile(tempfile
);
668 proc
+= _T(" -c \"");
669 proc
+= CPathUtils::GetAppDirectory();
670 proc
+= _T("touch.exe\"");
675 CString appDir
= CPathUtils::GetAppDirectory();
676 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true, &appDir
);
681 while(!::PathFileExists(tempfile
))
686 break; //timeout 5 minutes
691 CMessageBox::Show(NULL
, IDS_ERR_PAEGENTTIMEOUT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
693 ::DeleteFile(tempfile
);
696 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
, bool uac
)
698 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
699 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
700 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
704 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
706 LaunchApplication(sCmd
, NULL
, false, NULL
, uac
);
709 bool CAppUtils::LaunchRemoteSetting()
711 CTGitPath
path(g_Git
.m_CurrentDir
);
712 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
713 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
714 //dlg.SetTreeWidth(220);
715 dlg
.m_DefaultPage
= _T("gitremote");
722 * Launch the external blame viewer
724 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
726 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
727 viewer
+= _T("TortoiseGitBlame.exe");
728 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
729 //viewer += _T(" \"") + sLogFile + _T("\"");
730 //viewer += _T(" \"") + sOriginalFile + _T("\"");
731 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
732 viewer
+= CString(_T(" /rev:"))+Rev
;
733 viewer
+= _T(" ")+sParams
;
735 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
738 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
743 bool bStyled
= false;
744 pWnd
->GetWindowText(sText
);
745 // the rich edit control doesn't count the CR char!
746 // to be exact: CRLF is treated as one char.
749 // style each line separately
754 nNewlinePos
= sText
.Find('\n', offset
);
755 CString sLine
= sText
.Mid(offset
);
757 sLine
= sLine
.Left(nNewlinePos
-offset
);
760 while (FindStyleChars(sLine
, '*', start
, end
))
762 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
763 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
765 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
766 format
.cbSize
= sizeof(CHARFORMAT2
);
767 format
.dwMask
= CFM_BOLD
;
768 format
.dwEffects
= CFE_BOLD
;
769 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
775 while (FindStyleChars(sLine
, '^', start
, end
))
777 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
778 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
780 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
781 format
.cbSize
= sizeof(CHARFORMAT2
);
782 format
.dwMask
= CFM_ITALIC
;
783 format
.dwEffects
= CFE_ITALIC
;
784 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
790 while (FindStyleChars(sLine
, '_', start
, end
))
792 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
793 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
795 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
796 format
.cbSize
= sizeof(CHARFORMAT2
);
797 format
.dwMask
= CFM_UNDERLINE
;
798 format
.dwEffects
= CFE_UNDERLINE
;
799 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
803 offset
= nNewlinePos
+1;
804 } while(nNewlinePos
>=0);
808 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
811 bool bFoundMarker
= false;
812 // find a starting marker
813 while (sText
[i
] != 0)
815 if (sText
[i
] == stylechar
)
817 if (((i
+1)<sText
.GetLength())&&(IsCharAlphaNumeric(sText
[i
+1])) &&
818 (((i
>0)&&(!IsCharAlphaNumeric(sText
[i
-1])))||(i
==0)))
830 // find ending marker
831 bFoundMarker
= false;
832 while (sText
[i
] != 0)
834 if (sText
[i
] == stylechar
)
836 if ((IsCharAlphaNumeric(sText
[i
-1])) &&
837 ((((i
+1)<sText
.GetLength())&&(!IsCharAlphaNumeric(sText
[i
+1])))||(i
+1)==sText
.GetLength()))
850 CString
CAppUtils::GetProjectNameFromURL(CString url
)
853 while (name
.IsEmpty() || (name
.CompareNoCase(_T("branches"))==0) ||
854 (name
.CompareNoCase(_T("tags"))==0) ||
855 (name
.CompareNoCase(_T("trunk"))==0))
857 name
= url
.Mid(url
.ReverseFind('/')+1);
858 url
= url
.Left(url
.ReverseFind('/'));
860 if ((name
.Compare(_T("svn")) == 0)||(name
.Compare(_T("svnroot")) == 0))
862 // a name of svn or svnroot indicates that it's not really the project name. In that
863 // case, we try the first part of the URL
864 // of course, this won't work in all cases (but it works for Google project hosting)
865 url
.Replace(_T("http://"), _T(""));
866 url
.Replace(_T("https://"), _T(""));
867 url
.Replace(_T("svn://"), _T(""));
868 url
.Replace(_T("svn+ssh://"), _T(""));
869 url
.TrimLeft(_T("/"));
870 name
= url
.Left(url
.Find('.'));
875 bool CAppUtils::StartShowUnifiedDiff(HWND
/*hWnd*/, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
876 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
877 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
878 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */, bool /* blame = false */, bool bMerge
)
881 CString tempfile
=GetTempFile();
883 if(rev2
== GitRev::GetWorkingCopy())
885 cmd
.Format(_T("git.exe diff --stat -p %s "), rev1
);
887 else if (rev1
== GitRev::GetWorkingCopy())
889 cmd
.Format(_T("git.exe diff -R --stat -p %s "), rev2
);
897 cmd
.Format(_T("git.exe diff-tree -r -p %s --stat %s %s"),merge
, rev1
,rev2
);
900 if( !url1
.IsEmpty() )
903 cmd
+= url1
.GetGitPathString();
906 g_Git
.RunLogFile(cmd
,tempfile
);
907 CAppUtils::StartUnifiedDiffViewer(tempfile
, rev1
+ _T(":") + rev2
);
912 sCmd
.Format(_T("%s /command:showcompare /unified"),
913 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
914 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
916 sCmd
+= _T(" /revision1:") + rev1
.ToString();
917 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
919 sCmd
+= _T(" /revision2:") + rev2
.ToString();
921 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
922 if (headpeg
.IsValid())
923 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
926 sCmd
+= _T(" /alternatediff");
929 sCmd
+= _T(" /ignoreancestry");
933 sCmd
+= _T(" /hwnd:");
935 _stprintf_s(buf
, 30, _T("%d"), hWnd
);
939 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
945 bool CAppUtils::Export(CString
*BashHash
)
947 // ask from where the export has to be done
950 dlg
.m_Revision
=*BashHash
;
952 if (dlg
.DoModal() == IDOK
)
955 cmd
.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s"),
956 dlg
.m_strExportDirectory
, g_Git
.FixBranchName(dlg
.m_VersionName
));
960 return (pro
.DoModal() == IDOK
);
965 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
, bool switch_new_brach
)
967 CCreateBranchTagDlg dlg
;
969 dlg
.m_bSwitch
=switch_new_brach
;
972 dlg
.m_initialRefName
= *CommitHash
;
974 if(dlg
.DoModal()==IDOK
)
979 if(dlg
.m_bTrack
== TRUE
)
980 track
=_T(" --track ");
981 else if(dlg
.m_bTrack
== FALSE
)
982 track
=_T(" --no-track");
993 cmd
.Format(_T("git.exe tag %s %s %s %s"),
997 g_Git
.FixBranchName(dlg
.m_VersionName
)
1000 CString tempfile
=::GetTempFile();
1001 if(!dlg
.m_Message
.Trim().IsEmpty())
1003 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_Message
);
1004 cmd
+= _T(" -F ")+tempfile
;
1009 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1012 dlg
.m_BranchTagName
,
1013 g_Git
.FixBranchName(dlg
.m_VersionName
)
1017 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1019 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1022 if( !IsTag
&& dlg
.m_bSwitch
)
1024 // it is a new branch and the user has requested to switch to it
1025 cmd
.Format(_T("git.exe checkout %s"), dlg
.m_BranchTagName
);
1026 g_Git
.Run(cmd
,&out
,CP_UTF8
);
1027 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1035 bool CAppUtils::Switch(CString initialRefName
, bool autoclose
)
1038 if(!initialRefName
.IsEmpty())
1039 dlg
.m_initialRefName
= initialRefName
;
1041 if (dlg
.DoModal() == IDOK
)
1045 branch
= dlg
.m_NewBranch
;
1047 // if refs/heads/ is not stripped, checkout will detach HEAD
1048 // checkout prefers branches on name clashes (with tags)
1049 if (dlg
.m_VersionName
.Left(11) ==_T("refs/heads/") && dlg
.m_bBranchOverride
!= TRUE
)
1050 dlg
.m_VersionName
= dlg
.m_VersionName
.Mid(11);
1052 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
, autoclose
);
1057 bool CAppUtils::PerformSwitch(CString ref
, bool bForce
/* false */, CString sNewBranch
/* CString() */, bool bBranchOverride
/* false */, BOOL bTrack
/* 2 */, bool autoClose
/* false */)
1064 if(!sNewBranch
.IsEmpty()){
1065 if (bBranchOverride
)
1067 branch
.Format(_T("-B %s"), sNewBranch
);
1071 branch
.Format(_T("-b %s"), sNewBranch
);
1074 track
= _T("--track");
1075 else if (bTrack
== FALSE
)
1076 track
= _T("--no-track");
1081 cmd
.Format(_T("git.exe checkout %s %s %s %s"),
1085 g_Git
.FixBranchName(ref
));
1087 CProgressDlg progress
;
1088 progress
.m_bAutoCloseOnSuccess
= autoClose
;
1089 progress
.m_GitCmd
= cmd
;
1091 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1092 if (gitPath
.HasSubmodules())
1093 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1095 INT_PTR ret
= progress
.DoModal();
1096 if (gitPath
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
1099 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1101 RunTortoiseProc(sCmd
);
1104 else if (ret
== IDOK
)
1110 bool CAppUtils::OpenIgnoreFile(CStdioFile
&file
, const CString
& filename
)
1112 if (!file
.Open(filename
, CFile::modeCreate
| CFile::modeReadWrite
| CFile::modeNoTruncate
))
1114 CMessageBox::Show(NULL
, filename
+ _T(" Open Failure"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1118 if (file
.GetLength() > 0)
1120 file
.Seek(file
.GetLength() - 1, 0);
1121 auto_buffer
<TCHAR
> buf(1);
1124 if (buf
[0] != _T('\n'))
1125 file
.WriteString(_T("\n"));
1133 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1135 CIgnoreDlg ignoreDlg
;
1136 if (ignoreDlg
.DoModal() == IDOK
)
1139 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\");
1141 switch (ignoreDlg
.m_IgnoreFile
)
1144 ignorefile
+= _T(".gitignore");
1147 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, ignorefile
);
1148 ignorefile
+= _T("info/exclude");
1155 if (ignoreDlg
.m_IgnoreFile
!= 1 && !OpenIgnoreFile(file
, ignorefile
))
1158 for (int i
= 0; i
< path
.GetCount(); i
++)
1160 if (ignoreDlg
.m_IgnoreFile
== 1)
1162 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\") + path
[i
].GetContainingDirectory().GetWinPathString() + _T("\\.gitignore");
1163 if (!OpenIgnoreFile(file
, ignorefile
))
1167 CString ignorePattern
;
1168 if (ignoreDlg
.m_IgnoreType
== 0)
1170 if (ignoreDlg
.m_IgnoreFile
!= 1 && !path
[i
].GetContainingDirectory().GetGitPathString().IsEmpty())
1171 ignorePattern
+= _T("/") + path
[i
].GetContainingDirectory().GetGitPathString();
1173 ignorePattern
+= _T("/");
1177 ignorePattern
+= _T("*") + path
[i
].GetFileExtension();
1181 ignorePattern
+= path
[i
].GetFileOrDirectoryName();
1184 // escape [ and ] so that files get ignored correctly
1185 ignorePattern
.Replace(_T("["), _T("\\["));
1186 ignorePattern
.Replace(_T("]"), _T("\\]"));
1188 ignorePattern
+= _T("\n");
1189 CStringA ignorePatternA
= CUnicodeUtils::GetUTF8(ignorePattern
);
1190 file
.Write(ignorePatternA
.GetBuffer(), ignorePatternA
.GetLength());
1191 ignorePatternA
.ReleaseBuffer();
1193 if (ignoreDlg
.m_IgnoreFile
== 1)
1197 if (ignoreDlg
.m_IgnoreFile
!= 1)
1212 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1215 dlg
.m_ResetType
=type
;
1216 dlg
.m_ResetToVersion
=*CommitHash
;
1217 if (dlg
.DoModal() == IDOK
)
1221 switch(dlg
.m_ResetType
)
1236 cmd
.Format(_T("git.exe reset %s %s"),type
, *CommitHash
);
1238 CProgressDlg progress
;
1239 progress
.m_GitCmd
=cmd
;
1241 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1242 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2)
1243 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1245 INT_PTR ret
= progress
.DoModal();
1246 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2 && ret
== IDC_PROGRESS_BUTTON1
)
1249 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1251 RunTortoiseProc(sCmd
);
1254 else if (ret
== IDOK
)
1261 void CAppUtils::DescribeFile(bool mode
, bool base
,CString
&descript
)
1265 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_DELETE
));
1270 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_MODIFIED
));
1273 descript
= CString(MAKEINTRESOURCE(IDS_PROC_CREATED
));
1277 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1279 CString tempmergefile
;
1282 tempmergefile
= CAppUtils::GetMergeTempFile(_T("LOCAL"),path
);
1283 CFile::Remove(tempmergefile
);
1290 tempmergefile
= CAppUtils::GetMergeTempFile(_T("REMOTE"),path
);
1291 CFile::Remove(tempmergefile
);
1298 tempmergefile
= CAppUtils::GetMergeTempFile(_T("BASE"),path
);
1299 CFile::Remove(tempmergefile
);
1304 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1307 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1312 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool /*bAlternativeTool*/,bool revertTheirMy
)
1316 CTGitPath merge
=path
;
1317 CTGitPath directory
= merge
.GetDirectory();
1319 // we have the conflicted file (%merged)
1320 // now look for the other required files
1322 //stat.GetStatus(merge);
1323 //if (stat.status == NULL)
1329 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1331 if (g_Git
.Run(cmd
, &vector
))
1337 list
.ParserFromLsFile(vector
);
1339 if(list
.GetCount() == 0)
1346 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge
));
1347 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge
));
1348 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1352 //format=_T("git.exe cat-file blob \":%d:%s\"");
1353 format
= _T("git checkout-index --temp --stage=%d -- \"%s\"");
1355 //create a empty file, incase stage is not three
1356 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1358 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1360 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1363 bool b_base
=false, b_local
=false, b_remote
=false;
1365 for(int i
=0;i
<list
.GetCount();i
++)
1372 if( list
[i
].m_Stage
== 1)
1374 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1376 outfile
= base
.GetWinPathString();
1379 if( list
[i
].m_Stage
== 2 )
1381 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1383 outfile
= mine
.GetWinPathString();
1386 if( list
[i
].m_Stage
== 3 )
1388 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1390 outfile
= theirs
.GetWinPathString();
1392 CString output
, err
;
1393 if(!outfile
.IsEmpty())
1394 if (!g_Git
.Run(cmd
, &output
, &err
, CP_UTF8
))
1398 file
= output
.Tokenize(_T("\t"), start
);
1399 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1403 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1407 if(b_local
&& b_remote
)
1409 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1411 bRet
= !!CAppUtils::StartExtMerge(base
,mine
, theirs
, merge
,_T("BASE"),_T("LOCAL"),_T("REMOTE"));
1413 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1418 CFile::Remove(mine
.GetWinPathString());
1419 CFile::Remove(theirs
.GetWinPathString());
1420 CFile::Remove(base
.GetWinPathString());
1422 CDeleteConflictDlg dlg
;
1423 DescribeFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1424 DescribeFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1425 dlg
.m_bShowModifiedButton
=b_base
;
1426 dlg
.m_File
=merge
.GetGitPathString();
1427 if(dlg
.DoModal() == IDOK
)
1432 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1435 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1437 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1439 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1449 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1450 base
, theirs
, mine
, merge
);
1453 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1455 // we have a text conflict, use our merge tool to resolve the conflict
1457 CTSVNPath
theirs(directory
);
1458 CTSVNPath
mine(directory
);
1459 CTSVNPath
base(directory
);
1460 bool bConflictData
= false;
1462 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1464 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1465 bConflictData
= true;
1467 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1469 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1470 bConflictData
= true;
1472 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1474 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1475 bConflictData
= true;
1482 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1483 base
, theirs
, mine
, merge
);
1486 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1488 // we have a property conflict
1489 CTSVNPath
prej(directory
);
1490 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1492 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1493 // there's a problem: the prej file contains a _description_ of the conflict, and
1494 // that description string might be translated. That means we have no way of parsing
1495 // the file to find out the conflicting values.
1496 // The only thing we can do: show a dialog with the conflict description, then
1497 // let the user either accept the existing property or open the property edit dialog
1498 // to manually change the properties and values. And a button to mark the conflict as
1500 CEditPropConflictDlg dlg
;
1501 dlg
.SetPrejFile(prej
);
1502 dlg
.SetConflictedItem(merge
);
1503 bRet
= (dlg
.DoModal() != IDCANCEL
);
1507 if (stat
.status
->tree_conflict
)
1509 // we have a tree conflict
1511 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1514 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1516 CTSVNPath
theirs(directory
);
1517 CTSVNPath
mine(directory
);
1518 CTSVNPath
base(directory
);
1519 bool bConflictData
= false;
1521 if (pInfoData
->treeconflict_theirfile
)
1523 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1524 bConflictData
= true;
1526 if (pInfoData
->treeconflict_basefile
)
1528 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1529 bConflictData
= true;
1531 if (pInfoData
->treeconflict_myfile
)
1533 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1534 bConflictData
= true;
1541 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1542 base
, theirs
, mine
, merge
);
1544 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1546 CString sConflictAction
;
1547 CString sConflictReason
;
1548 CString sResolveTheirs
;
1549 CString sResolveMine
;
1550 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1551 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1553 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1555 switch (pInfoData
->treeconflict_operation
)
1557 case svn_wc_operation_update
:
1558 switch (pInfoData
->treeconflict_action
)
1560 case svn_wc_conflict_action_edit
:
1561 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1562 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1564 case svn_wc_conflict_action_add
:
1565 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1566 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1568 case svn_wc_conflict_action_delete
:
1569 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1570 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1574 case svn_wc_operation_switch
:
1575 switch (pInfoData
->treeconflict_action
)
1577 case svn_wc_conflict_action_edit
:
1578 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1579 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1581 case svn_wc_conflict_action_add
:
1582 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1583 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1585 case svn_wc_conflict_action_delete
:
1586 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1587 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1591 case svn_wc_operation_merge
:
1592 switch (pInfoData
->treeconflict_action
)
1594 case svn_wc_conflict_action_edit
:
1595 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1596 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1598 case svn_wc_conflict_action_add
:
1599 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1600 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1602 case svn_wc_conflict_action_delete
:
1603 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1604 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1610 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1612 switch (pInfoData
->treeconflict_operation
)
1614 case svn_wc_operation_update
:
1615 switch (pInfoData
->treeconflict_action
)
1617 case svn_wc_conflict_action_edit
:
1618 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1619 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1621 case svn_wc_conflict_action_add
:
1622 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1623 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1625 case svn_wc_conflict_action_delete
:
1626 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1627 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1631 case svn_wc_operation_switch
:
1632 switch (pInfoData
->treeconflict_action
)
1634 case svn_wc_conflict_action_edit
:
1635 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1636 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1638 case svn_wc_conflict_action_add
:
1639 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1640 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1642 case svn_wc_conflict_action_delete
:
1643 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1644 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1648 case svn_wc_operation_merge
:
1649 switch (pInfoData
->treeconflict_action
)
1651 case svn_wc_conflict_action_edit
:
1652 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1653 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1655 case svn_wc_conflict_action_add
:
1656 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1657 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1659 case svn_wc_conflict_action_delete
:
1660 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1661 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1669 switch (pInfoData
->treeconflict_reason
)
1671 case svn_wc_conflict_reason_edited
:
1672 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1673 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1675 case svn_wc_conflict_reason_obstructed
:
1676 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1677 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1679 case svn_wc_conflict_reason_deleted
:
1680 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1681 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1683 case svn_wc_conflict_reason_added
:
1684 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1685 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1687 case svn_wc_conflict_reason_missing
:
1688 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1689 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1691 case svn_wc_conflict_reason_unversioned
:
1692 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1693 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1696 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1698 CTreeConflictEditorDlg dlg
;
1699 dlg
.SetConflictInfoText(sConflictReason
);
1700 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1701 dlg
.SetPath(treeConflictPath
);
1702 INT_PTR dlgRet
= dlg
.DoModal();
1703 bRet
= (dlgRet
!= IDCANCEL
);
1711 bool CAppUtils::IsSSHPutty()
1713 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1714 sshclient
=sshclient
.MakeLower();
1715 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1722 CString
CAppUtils::GetClipboardLink()
1724 if (!OpenClipboard(NULL
))
1727 CString sClipboardText
;
1728 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1731 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1732 sClipboardText
= CString(lpstr
);
1735 hglb
= GetClipboardData(CF_UNICODETEXT
);
1738 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1739 sClipboardText
= lpstr
;
1744 if(!sClipboardText
.IsEmpty())
1746 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1747 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1749 if(sClipboardText
.Find( _T("http://")) == 0)
1750 return sClipboardText
;
1752 if(sClipboardText
.Find( _T("https://")) == 0)
1753 return sClipboardText
;
1755 if(sClipboardText
.Find( _T("git://")) == 0)
1756 return sClipboardText
;
1758 if(sClipboardText
.Find( _T("ssh://")) == 0)
1759 return sClipboardText
;
1761 if(sClipboardText
.GetLength()>=2)
1762 if( sClipboardText
[1] == _T(':') )
1763 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1764 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1765 return sClipboardText
;
1768 return CString(_T(""));
1771 CString
CAppUtils::ChooseRepository(CString
*path
)
1773 CBrowseFolder browseFolder
;
1774 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
1776 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
1777 CString strCloneDirectory
;
1779 strCloneDirectory
=*path
;
1782 strCloneDirectory
= regLastResopitory
;
1786 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
1788 browseFolder
.SetInfo(title
);
1790 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
1792 regLastResopitory
= strCloneDirectory
;
1793 return strCloneDirectory
;
1801 bool CAppUtils::SendPatchMail(CTGitPathList
&list
,bool autoclose
)
1805 dlg
.m_PathList
= list
;
1807 if(dlg
.DoModal()==IDOK
)
1809 if(dlg
.m_PathList
.GetCount() == 0)
1812 CGitProgressDlg progDlg
;
1814 theApp
.m_pMainWnd
= &progDlg
;
1815 progDlg
.SetCommand(CGitProgressDlg::GitProgress_SendMail
);
1817 progDlg
.SetAutoClose(autoclose
);
1819 progDlg
.SetPathList(dlg
.m_PathList
);
1820 //ProjectProperties props;
1821 //props.ReadPropsPathList(dlg.m_pathList);
1822 //progDlg.SetProjectProperties(props);
1823 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
1826 if(dlg
.m_bAttachment
)
1827 flags
|= SENDMAIL_ATTACHMENT
;
1829 flags
|= SENDMAIL_COMBINED
;
1831 flags
|= SENDMAIL_MAPI
;
1833 progDlg
.SetSendMailOption(dlg
.m_To
,dlg
.m_CC
,dlg
.m_Subject
,flags
);
1842 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
)
1845 CString log
=formatpatchoutput
;
1846 int start
=log
.Find(cmd
);
1848 CString one
=log
.Tokenize(_T("\n"),start
);
1854 CString one
=log
.Tokenize(_T("\n"),start
);
1856 if(one
.IsEmpty() || one
== _T("Success"))
1858 one
.Replace(_T('/'),_T('\\'));
1860 path
.SetFromWin(one
);
1863 if (list
.GetCount() > 0)
1865 return SendPatchMail(list
, autoclose
);
1869 CMessageBox::Show(NULL
, IDS_ERR_NOPATCHES
, IDS_APPNAME
, MB_ICONINFORMATION
);
1875 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
1880 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
1881 if(output
.IsEmpty())
1883 output
= pGit
->GetConfigValue(_T("i18n.commitencoding"));
1884 if(output
.IsEmpty())
1888 output
=output
.Tokenize(_T("\n"),start
);
1889 return CUnicodeUtils::GetCPCode(output
);
1894 output
=output
.Tokenize(_T("\n"),start
);
1895 return CUnicodeUtils::GetCPCode(output
);
1898 int CAppUtils::GetCommitTemplate(CString
&temp
)
1902 output
= g_Git
.GetConfigValue(_T("commit.template"), CP_UTF8
);
1903 if( output
.IsEmpty() )
1906 if( output
.GetLength()<1)
1909 if( output
[0] == _T('/'))
1911 if(output
.GetLength()>=3)
1912 if(output
[2] == _T('/'))
1914 output
.GetBuffer()[0] = output
[1];
1915 output
.GetBuffer()[1] = _T(':');
1920 output
=output
.Tokenize(_T("\n"),start
);
1922 output
.Replace(_T('/'),_T('\\'));
1926 CStdioFile
file(output
,CFile::modeRead
|CFile::typeText
);
1928 while(file
.ReadString(str
))
1939 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
1941 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
1945 output
= g_Git
.GetConfigValue(_T("i18n.commitencoding"));
1946 if(output
.IsEmpty())
1950 output
=output
.Tokenize(_T("\n"),start
);
1951 cp
=CUnicodeUtils::GetCPCode(output
);
1953 int len
=message
.GetLength();
1956 buf
= new char[len
*4 + 4];
1957 SecureZeroMemory(buf
, (len
*4 + 4));
1959 int lengthIncTerminator
= WideCharToMultiByte(cp
, 0, message
, -1, buf
, len
*4, NULL
, NULL
);
1961 file
.Write(buf
,lengthIncTerminator
-1);
1967 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
, bool autoClose
)
1970 dlg
.m_PreSelectRemote
= remoteName
;
1971 dlg
.m_bAllowRebase
= allowRebase
;
1974 if(dlg
.DoModal()==IDOK
)
1978 if (dlg
.m_bAllRemotes
)
1981 g_Git
.GetRemoteList(list
);
1983 STRING_VECTOR::const_iterator it
= list
.begin();
1984 while (it
!= list
.end())
1986 CString
remote(*it
);
1987 CAppUtils::LaunchPAgent(NULL
, &remote
);
1992 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
1996 url
=dlg
.m_RemoteURL
;
2000 int ver
= CAppUtils::GetMsysgitVersion();
2002 if(ver
>= 0x01070203) //above 1.7.0.2
2003 arg
= _T("--progress ");
2006 arg
+= _T("--prune ");
2009 if (dlg
.m_bFetchTags
== 1)
2011 arg
+= _T("--tags ");
2013 else if (dlg
.m_bFetchTags
== 0)
2015 arg
+= _T("--no-tags ");
2018 if (dlg
.m_bAllRemotes
)
2019 cmd
.Format(_T("git.exe fetch --all -v %s"), arg
);
2021 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"), arg
, url
, dlg
.m_RemoteBranchName
);
2023 CProgressDlg progress
;
2025 progress
.m_bAutoCloseOnSuccess
= autoClose
;
2027 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2029 if(!dlg
.m_bRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
2031 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2034 progress
.m_GitCmd
=cmd
;
2035 INT_PTR userResponse
= progress
.DoModal();
2037 if (userResponse
== IDC_PROGRESS_BUTTON1
)
2039 CString cmd
= _T("/command:log");
2040 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2041 RunTortoiseProc(cmd
);
2044 else if ((userResponse
== IDC_PROGRESS_BUTTON1
+ 1) || (progress
.m_GitStatus
== 0 && dlg
.m_bRebase
))
2049 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUDESSENDMAIL
)));
2050 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2051 INT_PTR response
= dlg
.DoModal();
2052 if(response
== IDOK
)
2056 if(response
== IDC_REBASE_POST_BUTTON
)
2058 CString cmd
, out
, err
;
2059 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2061 g_Git
.FixBranchName(dlg
.m_Upstream
),
2062 g_Git
.FixBranchName(dlg
.m_Branch
));
2063 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
2065 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2069 CAppUtils::SendPatchMail(cmd
,out
);
2073 if(response
== IDC_REBASE_POST_BUTTON
+1 )
2076 if(response
== IDCANCEL
)
2081 else if (userResponse
!= IDCANCEL
)
2087 bool CAppUtils::Push(CString selectLocalBranch
, bool autoClose
)
2090 dlg
.m_BranchSourceName
= selectLocalBranch
;
2092 DWORD exitcode
= 0xFFFFFFFF;
2094 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
2095 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
2100 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2101 //ReportError(temp);
2102 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2107 if(dlg
.DoModal()==IDOK
)
2112 arg
+= _T("--thin ");
2113 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2114 arg
+= _T("--tags ");
2116 arg
+= _T("--force ");
2117 if (dlg
.m_bSetUpstream
)
2118 arg
+= _T("--set-upstream ");
2120 int ver
= CAppUtils::GetMsysgitVersion();
2122 if(ver
>= 0x01070203) //above 1.7.0.2
2123 arg
+= _T("--progress ");
2125 CProgressDlg progress
;
2126 progress
.m_bAutoCloseOnSuccess
=autoClose
;
2128 STRING_VECTOR remotesList
;
2129 if (dlg
.m_bPushAllRemotes
)
2130 g_Git
.GetRemoteList(remotesList
);
2132 remotesList
.push_back(dlg
.m_URL
);
2134 for (unsigned int i
= 0; i
< remotesList
.size(); i
++)
2136 if (dlg
.m_bAutoLoad
)
2137 CAppUtils::LaunchPAgent(NULL
, &remotesList
[i
]);
2140 if (dlg
.m_bPushAllBranches
)
2142 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2148 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2151 dlg
.m_BranchSourceName
);
2152 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2154 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2157 progress
.m_GitCmdList
.push_back(cmd
);
2160 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REQUESTPULL
)));
2161 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2162 INT_PTR ret
= progress
.DoModal();
2164 if(!progress
.m_GitStatus
)
2166 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2171 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2172 //ReportError(temp);
2173 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2177 if(ret
== IDC_PROGRESS_BUTTON1
)
2179 RequestPull(dlg
.m_BranchRemoteName
);
2181 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2192 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2194 CRequestPullDlg dlg
;
2195 dlg
.m_RepositoryURL
= repositoryUrl
;
2196 dlg
.m_EndRevision
= endrevision
;
2197 if (dlg
.DoModal()==IDOK
)
2200 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2202 CString tempFileName
= GetTempFile();
2203 if (g_Git
.RunLogFile(cmd
, tempFileName
))
2205 CMessageBox::Show(NULL
, IDS_ERR_PULLREUQESTFAILED
, IDS_APPNAME
, MB_OK
);
2208 CAppUtils::LaunchAlternativeEditor(tempFileName
);
2213 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2215 CString
strDir(szPath
);
2216 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2218 strDir
.AppendChar(_T('\\'));
2220 std::vector
<CString
> vPath
;
2222 bool bSuccess
= false;
2224 for (int i
=0;i
<strDir
.GetLength();++i
)
2226 if (strDir
.GetAt(i
) != _T('\\'))
2228 strTemp
.AppendChar(strDir
.GetAt(i
));
2232 vPath
.push_back(strTemp
);
2233 strTemp
.AppendChar(_T('\\'));
2237 std::vector
<CString
>::const_iterator vIter
;
2238 for (vIter
= vPath
.begin(); vIter
!= vPath
.end(); vIter
++)
2240 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2246 void CAppUtils::RemoveTrailSlash(CString
&path
)
2251 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2253 path
=path
.Left(path
.GetLength()-1);
2259 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2260 CTGitPathList
&pathList
,
2261 CTGitPathList
&selectedList
,
2262 bool bSelectFilesForCommit
,
2265 bool bFailed
= true;
2267 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
2269 if(CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
2271 CTGitPath
path(g_Git
.m_CurrentDir
);
2272 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2273 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2274 dlg
.SetTreeWidth(220);
2275 dlg
.m_DefaultPage
= _T("gitconfig");
2278 dlg
.HandleRestart();
2289 dlg
.m_sBugID
= bugid
;
2291 dlg
.m_bWholeProject
= bWholeProject
;
2293 dlg
.m_sLogMessage
= sLogMsg
;
2294 dlg
.m_pathList
= pathList
;
2295 dlg
.m_checkedPathList
= selectedList
;
2296 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2297 dlg
.m_bAutoClose
= autoClose
;
2298 if (dlg
.DoModal() == IDOK
)
2300 if (dlg
.m_pathList
.GetCount()==0)
2302 // if the user hasn't changed the list of selected items
2303 // we don't use that list. Because if we would use the list
2304 // of pre-checked items, the dialog would show different
2305 // checked items on the next startup: it would only try
2306 // to check the parent folder (which might not even show)
2307 // instead, we simply use an empty list and let the
2308 // default checking do its job.
2309 if (!dlg
.m_pathList
.IsEqual(pathList
))
2310 selectedList
= dlg
.m_pathList
;
2311 pathList
= dlg
.m_updatedPathList
;
2312 sLogMsg
= dlg
.m_sLogMessage
;
2313 bSelectFilesForCommit
= true;
2315 if( dlg
.m_bPushAfterCommit
)
2317 switch(dlg
.m_PostCmd
)
2319 case GIT_POST_CMD_DCOMMIT
:
2320 CAppUtils::SVNDCommit();
2326 else if (dlg
.m_bCreateTagAfterCommit
)
2328 CAppUtils::CreateBranchTag(TRUE
);
2331 // CGitProgressDlg progDlg;
2332 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2333 // if (parser.HasVal(_T("closeonend")))
2334 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2335 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2336 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2337 // progDlg.SetPathList(dlg.m_pathList);
2338 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2339 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2340 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2341 // progDlg.SetItemCount(dlg.m_itemsCount);
2342 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2343 // progDlg.DoModal();
2344 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2345 // err = (DWORD)progDlg.DidErrorsOccur();
2346 // bFailed = progDlg.DidErrorsOccur();
2347 // bRet = progDlg.DidErrorsOccur();
2348 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2349 // if (DWORD(bFailRepeat)==0)
2350 // bFailed = false; // do not repeat if the user chose not to in the settings.
2357 BOOL
CAppUtils::SVNDCommit()
2359 CSVNDCommitDlg dcommitdlg
;
2360 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2361 if (gitSetting
== _T("")) {
2362 if (dcommitdlg
.DoModal() != IDOK
)
2368 if (dcommitdlg
.m_remember
)
2370 if (dcommitdlg
.m_rmdir
)
2372 gitSetting
= _T("true");
2376 gitSetting
= _T("false");
2378 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2381 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, _T("svn.rmdir"), gitSetting
);
2382 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2388 BOOL IsStash
= false;
2389 if(!g_Git
.CheckCleanWorkTree())
2391 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
2393 CSysProgressDlg sysProgressDlg
;
2394 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2395 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2396 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2397 sysProgressDlg
.SetShowProgressBar(false);
2398 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2399 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2402 cmd
=_T("git.exe stash");
2403 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2405 if (sysProgressDlg
.IsValid())
2406 sysProgressDlg
.Stop();
2407 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2410 if (sysProgressDlg
.IsValid())
2411 sysProgressDlg
.Stop();
2421 CProgressDlg progress
;
2422 if (dcommitdlg
.m_rmdir
)
2424 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2428 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2430 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2434 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2436 CSysProgressDlg sysProgressDlg
;
2437 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2438 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2439 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2440 sysProgressDlg
.SetShowProgressBar(false);
2441 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2442 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2445 cmd
=_T("git.exe stash pop");
2446 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2448 if (sysProgressDlg
.IsValid())
2449 sysProgressDlg
.Stop();
2450 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2453 if (sysProgressDlg
.IsValid())
2454 sysProgressDlg
.Stop();
2466 BOOL
CAppUtils::Merge(CString
*commit
)
2470 dlg
.m_initialRefName
= *commit
;
2472 if(dlg
.DoModal()==IDOK
)
2484 squash
=_T("--squash");
2487 nocommit
=_T("--no-commit");
2489 if(!dlg
.m_strLogMesage
.IsEmpty())
2491 msg
+= _T("-m \"")+dlg
.m_strLogMesage
+_T("\"");
2493 cmd
.Format(_T("git.exe merge %s %s %s %s %s"),
2498 g_Git
.FixBranchName(dlg
.m_VersionName
));
2500 CProgressDlg Prodlg
;
2501 Prodlg
.m_GitCmd
= cmd
;
2503 if (dlg
.m_bNoCommit
)
2504 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUCOMMIT
)));
2505 else if (dlg
.m_bIsBranch
)
2506 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REMOVEBRANCH
)));
2508 INT_PTR ret
= Prodlg
.DoModal();
2510 if (ret
== IDC_PROGRESS_BUTTON1
)
2511 if (dlg
.m_bNoCommit
)
2514 CTGitPathList pathList
;
2515 CTGitPathList selectedList
;
2516 return Commit(_T(""), TRUE
, sLogMsg
, pathList
, selectedList
, true);
2518 else if (dlg
.m_bIsBranch
)
2521 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, dlg
.m_VersionName
);
2522 if (CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
2525 cmd
.Format(_T("git.exe branch -D -- %s"), dlg
.m_VersionName
);
2526 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2527 MessageBox(NULL
, out
, _T("TortoiseGit"), MB_OK
);
2531 return !Prodlg
.m_GitStatus
;
2536 void CAppUtils::EditNote(GitRev
*rev
)
2539 dlg
.m_sHintText
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2540 dlg
.m_sInputText
= rev
->m_Notes
;
2541 dlg
.m_sTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2542 //dlg.m_pProjectProperties = &m_ProjectProperties;
2543 dlg
.m_bUseLogWidth
= true;
2544 if(dlg
.DoModal() == IDOK
)
2547 cmd
=_T("notes add -f -F \"");
2549 CString tempfile
=::GetTempFile();
2550 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
2553 cmd
+= rev
->m_CommitHash
.ToString();
2557 if (git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2559 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2564 rev
->m_Notes
= dlg
.m_sInputText
;
2568 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2570 CFile::Remove(tempfile
);
2575 int CAppUtils::GetMsysgitVersion(CString
*versionstr
)
2578 CString progressarg
;
2581 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
2582 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
2584 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
2587 if(!g_Git
.GetFileModifyTime(gitpath
, &time
) && !versionstr
)
2589 if((DWORD
)time
== regTime
)
2596 version
= *versionstr
;
2600 cmd
= _T("git.exe --version");
2601 if (g_Git
.Run(cmd
, &version
, &err
, CP_UTF8
))
2603 CMessageBox::Show(NULL
, _T("git have not installed (") + err
+ _T(")"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2613 CString str
=version
.Tokenize(_T("."), start
);
2614 int space
= str
.ReverseFind(_T(' '));
2615 str
= str
.Mid(space
+1,start
);
2619 version
= version
.Mid(start
);
2622 str
= version
.Tokenize(_T("."), start
);
2624 ver
|= (_ttol(str
) & 0xFF) << 16;
2626 str
= version
.Tokenize(_T("."), start
);
2627 ver
|= (_ttol(str
) & 0xFF) << 8;
2629 str
= version
.Tokenize(_T("."), start
);
2630 ver
|= (_ttol(str
) & 0xFF);
2636 CMessageBox::Show(NULL
, _T("Could not parse git.exe version number."), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2641 regTime
= time
&0xFFFFFFFF;
2647 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
2649 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
2651 CAutoLibrary hShell
= LoadLibrary(_T("Shell32.dll"));
2653 if (hShell
.IsValid()) {
2654 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
2656 IPropertyStore
*pps
;
2657 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
2658 if (SUCCEEDED(hr
)) {
2661 var
.boolVal
= VARIANT_TRUE
;
2662 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
2669 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
2671 ASSERT(dialogname
.GetLength() < 70);
2672 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
2673 WCHAR pathbuf
[MAX_PATH
] = {0};
2675 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
2677 wcscat_s(pathbuf
, L
" - ");
2678 wcscat_s(pathbuf
, dialogname
);
2679 wcscat_s(pathbuf
, L
" - ");
2680 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2681 SetWindowText(hWnd
, pathbuf
);
2684 bool CAppUtils::BisectStart(CString lastGood
, CString firstBad
, bool autoClose
)
2686 if (!g_Git
.CheckCleanWorkTree())
2688 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
2690 CSysProgressDlg sysProgressDlg
;
2691 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2692 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2693 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2694 sysProgressDlg
.SetShowProgressBar(false);
2695 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2696 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2699 cmd
= _T("git.exe stash");
2700 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2702 if (sysProgressDlg
.IsValid())
2703 sysProgressDlg
.Stop();
2704 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
);
2707 if (sysProgressDlg
.IsValid())
2708 sysProgressDlg
.Stop();
2714 CBisectStartDlg bisectStartDlg
;
2716 if (!lastGood
.IsEmpty())
2717 bisectStartDlg
.m_sLastGood
= lastGood
;
2718 if (!firstBad
.IsEmpty())
2719 bisectStartDlg
.m_sFirstBad
= firstBad
;
2721 if (bisectStartDlg
.DoModal() == IDOK
)
2723 CProgressDlg progress
;
2724 theApp
.m_pMainWnd
= &progress
;
2725 progress
.m_bAutoCloseOnSuccess
= autoClose
;
2726 progress
.m_GitCmdList
.push_back(_T("git.exe bisect start"));
2727 progress
.m_GitCmdList
.push_back(_T("git.exe bisect good ") + bisectStartDlg
.m_LastGoodRevision
);
2728 progress
.m_GitCmdList
.push_back(_T("git.exe bisect bad ") + bisectStartDlg
.m_FirstBadRevision
);
2730 CTGitPath
path(g_Git
.m_CurrentDir
);
2732 if (path
.HasSubmodules())
2733 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
2735 INT_PTR ret
= progress
.DoModal();
2736 if (path
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
2739 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
2741 CAppUtils::RunTortoiseProc(sCmd
);
2744 else if (ret
== IDOK
)