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
) != "")
272 // is there a filename specific merge tool?
273 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\.") + mergedfile
.GetFilename().MakeLower());
274 if (CString(mergetool
) != "")
279 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
283 CRegString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE
);
284 com
= tortoiseMergePath
;
287 com
= CPathUtils::GetAppDirectory();
288 com
+= _T("TortoiseMerge.exe");
290 com
= _T("\"") + com
+ _T("\"");
291 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
292 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
294 // check if the params are set. If not, just add the files to the command line
295 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
297 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
298 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
299 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
300 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
302 if (basefile
.IsEmpty())
304 com
.Replace(_T("/base:%base"), _T(""));
305 com
.Replace(_T("%base"), _T(""));
308 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
309 if (theirfile
.IsEmpty())
311 com
.Replace(_T("/theirs:%theirs"), _T(""));
312 com
.Replace(_T("%theirs"), _T(""));
315 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
316 if (yourfile
.IsEmpty())
318 com
.Replace(_T("/mine:%mine"), _T(""));
319 com
.Replace(_T("%mine"), _T(""));
322 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
323 if (mergedfile
.IsEmpty())
325 com
.Replace(_T("/merged:%merged"), _T(""));
326 com
.Replace(_T("%merged"), _T(""));
329 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
330 if (basename
.IsEmpty())
332 if (basefile
.IsEmpty())
334 com
.Replace(_T("/basename:%bname"), _T(""));
335 com
.Replace(_T("%bname"), _T(""));
339 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
343 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
344 if (theirname
.IsEmpty())
346 if (theirfile
.IsEmpty())
348 com
.Replace(_T("/theirsname:%tname"), _T(""));
349 com
.Replace(_T("%tname"), _T(""));
353 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
357 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
358 if (yourname
.IsEmpty())
360 if (yourfile
.IsEmpty())
362 com
.Replace(_T("/minename:%yname"), _T(""));
363 com
.Replace(_T("%yname"), _T(""));
367 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
371 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
372 if (mergedname
.IsEmpty())
374 if (mergedfile
.IsEmpty())
376 com
.Replace(_T("/mergedname:%mname"), _T(""));
377 com
.Replace(_T("%mname"), _T(""));
381 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
385 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
387 if ((bReadOnly
)&&(bInternal
))
388 com
+= _T(" /readonly");
390 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
398 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
402 viewer
= CPathUtils::GetAppDirectory();
403 viewer
+= _T("TortoiseMerge.exe");
405 viewer
= _T("\"") + viewer
+ _T("\"");
406 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
407 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
409 viewer
+= _T(" /reversedpatch");
410 if (!sOriginalDescription
.IsEmpty())
411 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
412 if (!sPatchedDescription
.IsEmpty())
413 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
414 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
421 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
423 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file2
.GetFilename().MakeLower());
424 if (!difftool
.IsEmpty())
426 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file1
.GetFilename().MakeLower());
427 if (!difftool
.IsEmpty())
430 // Is there a mime type specific diff tool?
432 if (GetMimeType(file1
, mimetype
) || GetMimeType(file2
, mimetype
))
434 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype
);
435 if (!difftool
.IsEmpty())
439 // Is there an extension specific diff tool?
440 CString ext
= file2
.GetFileExtension().MakeLower();
443 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
444 if (!difftool
.IsEmpty())
446 // Maybe we should use TortoiseIDiff?
447 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
448 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
449 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
450 (ext
== _T(".dib")) || (ext
== _T(".emf")))
453 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
454 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
458 // Finally, pick a generic external diff tool
459 difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
463 bool CAppUtils::StartExtDiff(
464 const CString
& file1
, const CString
& file2
,
465 const CString
& sName1
, const CString
& sName2
,
466 const CString
& originalFile1
, const CString
& originalFile2
,
467 const git_revnum_t
& hash1
, const git_revnum_t
& hash2
,
468 const DiffFlags
& flags
)
472 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
473 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
475 viewer
= PickDiffTool(file1
, file2
);
476 // If registry entry for a diff program is commented out, use TortoiseMerge.
477 bool bCommentedOut
= viewer
.Left(1) == _T("#");
478 if (flags
.bAlternativeTool
)
480 // Invert external vs. internal diff tool selection.
482 viewer
.Delete(0); // uncomment
486 else if (bCommentedOut
)
490 bool bInternal
= viewer
.IsEmpty();
494 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
495 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
497 viewer
+= _T(" /blame");
499 // check if the params are set. If not, just add the files to the command line
500 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
502 viewer
+= _T(" \"")+file1
+_T("\"");
503 viewer
+= _T(" \"")+file2
+_T("\"");
505 if (viewer
.Find(_T("%base")) >= 0)
507 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
509 if (viewer
.Find(_T("%mine")) >= 0)
511 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
514 if (sName1
.IsEmpty())
515 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
517 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
519 if (sName2
.IsEmpty())
520 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
522 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
524 viewer
.Replace(_T("%bpath"), _T("\"") + originalFile1
+ _T("\""));
525 viewer
.Replace(_T("%ypath"), _T("\"") + originalFile2
+ _T("\""));
527 viewer
.Replace(_T("%brev"), _T("\"") + hash1
+ _T("\""));
528 viewer
.Replace(_T("%yrev"), _T("\"") + hash2
+ _T("\""));
530 if (flags
.bReadOnly
&& bInternal
)
531 viewer
+= _T(" /readonly");
533 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
536 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
539 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
541 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
544 viewer
= CPathUtils::GetAppDirectory();
545 viewer
+= _T("TortoiseUDiff.exe");
546 // enquote the path to TortoiseUDiff
547 viewer
= _T("\"") + viewer
+ _T("\"");
549 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
552 if (viewer
.Find(_T("%1"))>=0)
554 if (viewer
.Find(_T("\"%1\"")) >= 0)
555 viewer
.Replace(_T("%1"), patchfile
);
557 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
560 viewer
+= _T(" \"") + patchfile
+ _T("\"");
561 if (viewer
.Find(_T("%title")) >= 0)
563 viewer
.Replace(_T("%title"), title
);
566 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
573 BOOL
CAppUtils::StartTextViewer(CString file
)
576 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
578 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
579 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
582 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
583 TCHAR
* buf
= new TCHAR
[len
+1];
584 ExpandEnvironmentStrings(viewer
, buf
, len
);
587 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
588 buf
= new TCHAR
[len
+1];
589 ExpandEnvironmentStrings(file
, buf
, len
);
592 file
= _T("\"")+file
+_T("\"");
593 if (viewer
.IsEmpty())
595 viewer
= _T("RUNDLL32 Shell32,OpenAs_RunDLL");
597 if (viewer
.Find(_T("\"%1\"")) >= 0)
599 viewer
.Replace(_T("\"%1\""), file
);
601 else if (viewer
.Find(_T("%1")) >= 0)
603 viewer
.Replace(_T("%1"), file
);
611 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
618 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
621 CAutoFile hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
624 length
= ::GetFileSize(hFile
, NULL
);
631 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
634 HDC hScreenDC
= ::GetDC(NULL
);
635 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
636 ::ReleaseDC(NULL
, hScreenDC
);
638 logFont
.lfEscapement
= 0;
639 logFont
.lfOrientation
= 0;
640 logFont
.lfWeight
= FW_NORMAL
;
641 logFont
.lfItalic
= 0;
642 logFont
.lfUnderline
= 0;
643 logFont
.lfStrikeOut
= 0;
644 logFont
.lfCharSet
= DEFAULT_CHARSET
;
645 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
646 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
647 logFont
.lfQuality
= DRAFT_QUALITY
;
648 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
649 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
650 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
653 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
667 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
668 key
= g_Git
.GetConfigValue(cmd
);
670 key
= key
.Tokenize(_T("\n"),start
);
678 CString proc
=CPathUtils::GetAppDirectory();
679 proc
+= _T("pageant.exe \"");
683 CString tempfile
= GetTempFile();
684 ::DeleteFile(tempfile
);
686 proc
+= _T(" -c \"");
687 proc
+= CPathUtils::GetAppDirectory();
688 proc
+= _T("touch.exe\"");
693 CString appDir
= CPathUtils::GetAppDirectory();
694 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true, &appDir
);
699 while(!::PathFileExists(tempfile
))
704 break; //timeout 5 minutes
709 CMessageBox::Show(NULL
, IDS_ERR_PAEGENTTIMEOUT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
711 ::DeleteFile(tempfile
);
714 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
, bool uac
)
716 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
717 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
718 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
722 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
724 LaunchApplication(sCmd
, NULL
, false, NULL
, uac
);
727 bool CAppUtils::LaunchRemoteSetting()
729 CTGitPath
path(g_Git
.m_CurrentDir
);
730 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
731 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
732 //dlg.SetTreeWidth(220);
733 dlg
.m_DefaultPage
= _T("gitremote");
740 * Launch the external blame viewer
742 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
744 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
745 viewer
+= _T("TortoiseGitBlame.exe");
746 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
747 //viewer += _T(" \"") + sLogFile + _T("\"");
748 //viewer += _T(" \"") + sOriginalFile + _T("\"");
749 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
750 viewer
+= CString(_T(" /rev:"))+Rev
;
751 viewer
+= _T(" ")+sParams
;
753 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
756 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
761 bool bStyled
= false;
762 pWnd
->GetWindowText(sText
);
763 // the rich edit control doesn't count the CR char!
764 // to be exact: CRLF is treated as one char.
767 // style each line separately
772 nNewlinePos
= sText
.Find('\n', offset
);
773 CString sLine
= sText
.Mid(offset
);
775 sLine
= sLine
.Left(nNewlinePos
-offset
);
778 while (FindStyleChars(sLine
, '*', start
, end
))
780 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
781 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
783 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
784 format
.cbSize
= sizeof(CHARFORMAT2
);
785 format
.dwMask
= CFM_BOLD
;
786 format
.dwEffects
= CFE_BOLD
;
787 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
793 while (FindStyleChars(sLine
, '^', start
, end
))
795 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
796 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
798 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
799 format
.cbSize
= sizeof(CHARFORMAT2
);
800 format
.dwMask
= CFM_ITALIC
;
801 format
.dwEffects
= CFE_ITALIC
;
802 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
808 while (FindStyleChars(sLine
, '_', start
, end
))
810 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
811 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
813 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
814 format
.cbSize
= sizeof(CHARFORMAT2
);
815 format
.dwMask
= CFM_UNDERLINE
;
816 format
.dwEffects
= CFE_UNDERLINE
;
817 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
821 offset
= nNewlinePos
+1;
822 } while(nNewlinePos
>=0);
826 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
829 bool bFoundMarker
= false;
830 // find a starting marker
831 while (sText
[i
] != 0)
833 if (sText
[i
] == stylechar
)
835 if (((i
+1)<sText
.GetLength())&&(IsCharAlphaNumeric(sText
[i
+1])) &&
836 (((i
>0)&&(!IsCharAlphaNumeric(sText
[i
-1])))||(i
==0)))
848 // find ending marker
849 bFoundMarker
= false;
850 while (sText
[i
] != 0)
852 if (sText
[i
] == stylechar
)
854 if ((IsCharAlphaNumeric(sText
[i
-1])) &&
855 ((((i
+1)<sText
.GetLength())&&(!IsCharAlphaNumeric(sText
[i
+1])))||(i
+1)==sText
.GetLength()))
868 CString
CAppUtils::GetProjectNameFromURL(CString url
)
871 while (name
.IsEmpty() || (name
.CompareNoCase(_T("branches"))==0) ||
872 (name
.CompareNoCase(_T("tags"))==0) ||
873 (name
.CompareNoCase(_T("trunk"))==0))
875 name
= url
.Mid(url
.ReverseFind('/')+1);
876 url
= url
.Left(url
.ReverseFind('/'));
878 if ((name
.Compare(_T("svn")) == 0)||(name
.Compare(_T("svnroot")) == 0))
880 // a name of svn or svnroot indicates that it's not really the project name. In that
881 // case, we try the first part of the URL
882 // of course, this won't work in all cases (but it works for Google project hosting)
883 url
.Replace(_T("http://"), _T(""));
884 url
.Replace(_T("https://"), _T(""));
885 url
.Replace(_T("svn://"), _T(""));
886 url
.Replace(_T("svn+ssh://"), _T(""));
887 url
.TrimLeft(_T("/"));
888 name
= url
.Left(url
.Find('.'));
893 bool CAppUtils::StartShowUnifiedDiff(HWND
/*hWnd*/, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
894 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
895 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
896 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */, bool /* blame = false */, bool bMerge
)
899 CString tempfile
=GetTempFile();
901 if(rev2
== GitRev::GetWorkingCopy())
903 cmd
.Format(_T("git.exe diff --stat -p %s "), rev1
);
905 else if (rev1
== GitRev::GetWorkingCopy())
907 cmd
.Format(_T("git.exe diff -R --stat -p %s "), rev2
);
915 cmd
.Format(_T("git.exe diff-tree -r -p %s --stat %s %s"),merge
, rev1
,rev2
);
918 if( !url1
.IsEmpty() )
921 cmd
+= url1
.GetGitPathString();
924 g_Git
.RunLogFile(cmd
,tempfile
);
925 CAppUtils::StartUnifiedDiffViewer(tempfile
, rev1
+ _T(":") + rev2
);
930 sCmd
.Format(_T("%s /command:showcompare /unified"),
931 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
932 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
934 sCmd
+= _T(" /revision1:") + rev1
.ToString();
935 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
937 sCmd
+= _T(" /revision2:") + rev2
.ToString();
939 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
940 if (headpeg
.IsValid())
941 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
944 sCmd
+= _T(" /alternatediff");
947 sCmd
+= _T(" /ignoreancestry");
951 sCmd
+= _T(" /hwnd:");
953 _stprintf_s(buf
, 30, _T("%d"), hWnd
);
957 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
962 bool CAppUtils::SetupDiffScripts(bool force
, const CString
& type
)
964 CString scriptsdir
= CPathUtils::GetAppParentDirectory();
965 scriptsdir
+= _T("Diff-Scripts");
966 CSimpleFileFind
files(scriptsdir
);
967 while (files
.FindNextFileNoDirectories())
969 CString file
= files
.GetFilePath();
970 CString filename
= files
.GetFileName();
971 CString ext
= file
.Mid(file
.ReverseFind('-') + 1);
972 ext
= _T(".") + ext
.Left(ext
.ReverseFind('.'));
973 std::set
<CString
> extensions
;
974 extensions
.insert(ext
);
976 if (file
.Right(3).CompareNoCase(_T("vbs"))==0)
978 kind
= _T(" //E:vbscript");
980 if (file
.Right(2).CompareNoCase(_T("js"))==0)
982 kind
= _T(" //E:javascript");
984 // open the file, read the first line and find possible extensions
985 // this script can handle
988 CStdioFile
f(file
, CFile::modeRead
| CFile::shareDenyNone
);
990 if (f
.ReadString(extline
))
992 if ((extline
.GetLength() > 15 ) &&
993 ((extline
.Left(15).Compare(_T("// extensions: ")) == 0) ||
994 (extline
.Left(14).Compare(_T("' extensions: ")) == 0)))
996 if (extline
[0] == '/')
997 extline
= extline
.Mid(15);
999 extline
= extline
.Mid(14);
1002 sToken
= extline
.Tokenize(_T(";"), curPos
);
1003 while (!sToken
.IsEmpty())
1005 if (!sToken
.IsEmpty())
1007 if (sToken
[0] != '.')
1008 sToken
= _T(".") + sToken
;
1009 extensions
.insert(sToken
);
1011 sToken
= extline
.Tokenize(_T(";"), curPos
);
1017 catch (CFileException
* e
)
1022 for (std::set
<CString
>::const_iterator it
= extensions
.begin(); it
!= extensions
.end(); ++it
)
1024 if (type
.IsEmpty() || (type
.Compare(_T("Diff")) == 0))
1026 if (filename
.Left(5).CompareNoCase(_T("diff-")) == 0)
1028 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + *it
);
1029 CString diffregstring
= diffreg
;
1030 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
1031 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %base %mine") + kind
;
1034 if (type
.IsEmpty() || (type
.Compare(_T("Merge"))==0))
1036 if (filename
.Left(6).CompareNoCase(_T("merge-"))==0)
1038 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\MergeTools\\") + *it
);
1039 CString diffregstring
= diffreg
;
1040 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
1041 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %merged %theirs %mine %base") + kind
;
1050 bool CAppUtils::Export(CString
*BashHash
)
1052 // ask from where the export has to be done
1055 dlg
.m_Revision
=*BashHash
;
1057 if (dlg
.DoModal() == IDOK
)
1060 cmd
.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s"),
1061 dlg
.m_strExportDirectory
, g_Git
.FixBranchName(dlg
.m_VersionName
));
1065 return (pro
.DoModal() == IDOK
);
1070 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
, bool switch_new_brach
)
1072 CCreateBranchTagDlg dlg
;
1074 dlg
.m_bSwitch
=switch_new_brach
;
1077 dlg
.m_initialRefName
= *CommitHash
;
1079 if(dlg
.DoModal()==IDOK
)
1084 if(dlg
.m_bTrack
== TRUE
)
1085 track
=_T(" --track ");
1086 else if(dlg
.m_bTrack
== FALSE
)
1087 track
=_T(" --no-track");
1098 cmd
.Format(_T("git.exe tag %s %s %s %s"),
1101 dlg
.m_BranchTagName
,
1102 g_Git
.FixBranchName(dlg
.m_VersionName
)
1105 CString tempfile
=::GetTempFile();
1106 if(!dlg
.m_Message
.Trim().IsEmpty())
1108 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_Message
);
1109 cmd
+= _T(" -F ")+tempfile
;
1114 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1117 dlg
.m_BranchTagName
,
1118 g_Git
.FixBranchName(dlg
.m_VersionName
)
1122 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1124 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1127 if( !IsTag
&& dlg
.m_bSwitch
)
1129 // it is a new branch and the user has requested to switch to it
1130 cmd
.Format(_T("git.exe checkout %s"), dlg
.m_BranchTagName
);
1131 g_Git
.Run(cmd
,&out
,CP_UTF8
);
1132 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1140 bool CAppUtils::Switch(CString initialRefName
, bool autoclose
)
1143 if(!initialRefName
.IsEmpty())
1144 dlg
.m_initialRefName
= initialRefName
;
1146 if (dlg
.DoModal() == IDOK
)
1150 branch
= dlg
.m_NewBranch
;
1152 // if refs/heads/ is not stripped, checkout will detach HEAD
1153 // checkout prefers branches on name clashes (with tags)
1154 if (dlg
.m_VersionName
.Left(11) ==_T("refs/heads/") && dlg
.m_bBranchOverride
!= TRUE
)
1155 dlg
.m_VersionName
= dlg
.m_VersionName
.Mid(11);
1157 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
, autoclose
);
1162 bool CAppUtils::PerformSwitch(CString ref
, bool bForce
/* false */, CString sNewBranch
/* CString() */, bool bBranchOverride
/* false */, BOOL bTrack
/* 2 */, bool autoClose
/* false */)
1169 if(!sNewBranch
.IsEmpty()){
1170 if (bBranchOverride
)
1172 branch
.Format(_T("-B %s"), sNewBranch
);
1176 branch
.Format(_T("-b %s"), sNewBranch
);
1179 track
= _T("--track");
1180 else if (bTrack
== FALSE
)
1181 track
= _T("--no-track");
1186 cmd
.Format(_T("git.exe checkout %s %s %s %s"),
1190 g_Git
.FixBranchName(ref
));
1192 CProgressDlg progress
;
1193 progress
.m_bAutoCloseOnSuccess
= autoClose
;
1194 progress
.m_GitCmd
= cmd
;
1196 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1197 if (gitPath
.HasSubmodules())
1198 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1200 INT_PTR ret
= progress
.DoModal();
1201 if (gitPath
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
1204 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1206 RunTortoiseProc(sCmd
);
1209 else if (ret
== IDOK
)
1215 bool CAppUtils::OpenIgnoreFile(CStdioFile
&file
, const CString
& filename
)
1217 if (!file
.Open(filename
, CFile::modeCreate
| CFile::modeReadWrite
| CFile::modeNoTruncate
))
1219 CMessageBox::Show(NULL
, filename
+ _T(" Open Failure"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1223 if (file
.GetLength() > 0)
1225 file
.Seek(file
.GetLength() - 1, 0);
1226 auto_buffer
<TCHAR
> buf(1);
1229 if (buf
[0] != _T('\n'))
1230 file
.WriteString(_T("\n"));
1238 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1240 CIgnoreDlg ignoreDlg
;
1241 if (ignoreDlg
.DoModal() == IDOK
)
1244 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\");
1246 switch (ignoreDlg
.m_IgnoreFile
)
1249 ignorefile
+= _T(".gitignore");
1252 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, ignorefile
);
1253 ignorefile
+= _T("info/exclude");
1260 if (ignoreDlg
.m_IgnoreFile
!= 1 && !OpenIgnoreFile(file
, ignorefile
))
1263 for (int i
= 0; i
< path
.GetCount(); i
++)
1265 if (ignoreDlg
.m_IgnoreFile
== 1)
1267 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\") + path
[i
].GetContainingDirectory().GetWinPathString() + _T("\\.gitignore");
1268 if (!OpenIgnoreFile(file
, ignorefile
))
1272 CString ignorePattern
;
1273 if (ignoreDlg
.m_IgnoreType
== 0)
1275 if (ignoreDlg
.m_IgnoreFile
!= 1 && !path
[i
].GetContainingDirectory().GetGitPathString().IsEmpty())
1276 ignorePattern
+= _T("/") + path
[i
].GetContainingDirectory().GetGitPathString();
1278 ignorePattern
+= _T("/");
1282 ignorePattern
+= _T("*") + path
[i
].GetFileExtension();
1286 ignorePattern
+= path
[i
].GetFileOrDirectoryName();
1289 // escape [ and ] so that files get ignored correctly
1290 ignorePattern
.Replace(_T("["), _T("\\["));
1291 ignorePattern
.Replace(_T("]"), _T("\\]"));
1293 ignorePattern
+= _T("\n");
1294 CStringA ignorePatternA
= CUnicodeUtils::GetUTF8(ignorePattern
);
1295 file
.Write(ignorePatternA
.GetBuffer(), ignorePatternA
.GetLength());
1296 ignorePatternA
.ReleaseBuffer();
1298 if (ignoreDlg
.m_IgnoreFile
== 1)
1302 if (ignoreDlg
.m_IgnoreFile
!= 1)
1317 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1320 dlg
.m_ResetType
=type
;
1321 dlg
.m_ResetToVersion
=*CommitHash
;
1322 if (dlg
.DoModal() == IDOK
)
1326 switch(dlg
.m_ResetType
)
1341 cmd
.Format(_T("git.exe reset %s %s"),type
, *CommitHash
);
1343 CProgressDlg progress
;
1344 progress
.m_GitCmd
=cmd
;
1346 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1347 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2)
1348 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1350 INT_PTR ret
= progress
.DoModal();
1351 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2 && ret
== IDC_PROGRESS_BUTTON1
)
1354 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1356 RunTortoiseProc(sCmd
);
1359 else if (ret
== IDOK
)
1366 void CAppUtils::DescribeFile(bool mode
, bool base
,CString
&descript
)
1370 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_DELETE
));
1375 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_MODIFIED
));
1378 descript
= CString(MAKEINTRESOURCE(IDS_PROC_CREATED
));
1382 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1384 CString tempmergefile
;
1387 tempmergefile
= CAppUtils::GetMergeTempFile(_T("LOCAL"),path
);
1388 CFile::Remove(tempmergefile
);
1395 tempmergefile
= CAppUtils::GetMergeTempFile(_T("REMOTE"),path
);
1396 CFile::Remove(tempmergefile
);
1403 tempmergefile
= CAppUtils::GetMergeTempFile(_T("BASE"),path
);
1404 CFile::Remove(tempmergefile
);
1409 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1412 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1417 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool /*bAlternativeTool*/,bool revertTheirMy
)
1421 CTGitPath merge
=path
;
1422 CTGitPath directory
= merge
.GetDirectory();
1424 // we have the conflicted file (%merged)
1425 // now look for the other required files
1427 //stat.GetStatus(merge);
1428 //if (stat.status == NULL)
1434 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1436 if (g_Git
.Run(cmd
, &vector
))
1442 list
.ParserFromLsFile(vector
);
1444 if(list
.GetCount() == 0)
1451 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge
));
1452 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge
));
1453 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1457 //format=_T("git.exe cat-file blob \":%d:%s\"");
1458 format
= _T("git checkout-index --temp --stage=%d -- \"%s\"");
1460 //create a empty file, incase stage is not three
1461 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1463 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1465 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1468 bool b_base
=false, b_local
=false, b_remote
=false;
1470 for(int i
=0;i
<list
.GetCount();i
++)
1477 if( list
[i
].m_Stage
== 1)
1479 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1481 outfile
= base
.GetWinPathString();
1484 if( list
[i
].m_Stage
== 2 )
1486 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1488 outfile
= mine
.GetWinPathString();
1491 if( list
[i
].m_Stage
== 3 )
1493 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1495 outfile
= theirs
.GetWinPathString();
1497 CString output
, err
;
1498 if(!outfile
.IsEmpty())
1499 if (!g_Git
.Run(cmd
, &output
, &err
, CP_UTF8
))
1503 file
= output
.Tokenize(_T("\t"), start
);
1504 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1508 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1512 if(b_local
&& b_remote
)
1514 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1516 bRet
= !!CAppUtils::StartExtMerge(base
,mine
, theirs
, merge
,_T("BASE"),_T("LOCAL"),_T("REMOTE"));
1518 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1523 CFile::Remove(mine
.GetWinPathString());
1524 CFile::Remove(theirs
.GetWinPathString());
1525 CFile::Remove(base
.GetWinPathString());
1527 CDeleteConflictDlg dlg
;
1528 DescribeFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1529 DescribeFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1530 dlg
.m_bShowModifiedButton
=b_base
;
1531 dlg
.m_File
=merge
.GetGitPathString();
1532 if(dlg
.DoModal() == IDOK
)
1537 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1540 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1542 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1544 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1554 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1555 base
, theirs
, mine
, merge
);
1558 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1560 // we have a text conflict, use our merge tool to resolve the conflict
1562 CTSVNPath
theirs(directory
);
1563 CTSVNPath
mine(directory
);
1564 CTSVNPath
base(directory
);
1565 bool bConflictData
= false;
1567 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1569 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1570 bConflictData
= true;
1572 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1574 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1575 bConflictData
= true;
1577 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1579 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1580 bConflictData
= true;
1587 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1588 base
, theirs
, mine
, merge
);
1591 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1593 // we have a property conflict
1594 CTSVNPath
prej(directory
);
1595 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1597 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1598 // there's a problem: the prej file contains a _description_ of the conflict, and
1599 // that description string might be translated. That means we have no way of parsing
1600 // the file to find out the conflicting values.
1601 // The only thing we can do: show a dialog with the conflict description, then
1602 // let the user either accept the existing property or open the property edit dialog
1603 // to manually change the properties and values. And a button to mark the conflict as
1605 CEditPropConflictDlg dlg
;
1606 dlg
.SetPrejFile(prej
);
1607 dlg
.SetConflictedItem(merge
);
1608 bRet
= (dlg
.DoModal() != IDCANCEL
);
1612 if (stat
.status
->tree_conflict
)
1614 // we have a tree conflict
1616 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1619 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1621 CTSVNPath
theirs(directory
);
1622 CTSVNPath
mine(directory
);
1623 CTSVNPath
base(directory
);
1624 bool bConflictData
= false;
1626 if (pInfoData
->treeconflict_theirfile
)
1628 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1629 bConflictData
= true;
1631 if (pInfoData
->treeconflict_basefile
)
1633 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1634 bConflictData
= true;
1636 if (pInfoData
->treeconflict_myfile
)
1638 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1639 bConflictData
= true;
1646 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1647 base
, theirs
, mine
, merge
);
1649 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1651 CString sConflictAction
;
1652 CString sConflictReason
;
1653 CString sResolveTheirs
;
1654 CString sResolveMine
;
1655 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1656 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1658 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1660 switch (pInfoData
->treeconflict_operation
)
1662 case svn_wc_operation_update
:
1663 switch (pInfoData
->treeconflict_action
)
1665 case svn_wc_conflict_action_edit
:
1666 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1667 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1669 case svn_wc_conflict_action_add
:
1670 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1671 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1673 case svn_wc_conflict_action_delete
:
1674 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1675 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1679 case svn_wc_operation_switch
:
1680 switch (pInfoData
->treeconflict_action
)
1682 case svn_wc_conflict_action_edit
:
1683 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1684 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1686 case svn_wc_conflict_action_add
:
1687 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1688 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1690 case svn_wc_conflict_action_delete
:
1691 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1692 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1696 case svn_wc_operation_merge
:
1697 switch (pInfoData
->treeconflict_action
)
1699 case svn_wc_conflict_action_edit
:
1700 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1701 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1703 case svn_wc_conflict_action_add
:
1704 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1705 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1707 case svn_wc_conflict_action_delete
:
1708 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1709 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1715 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1717 switch (pInfoData
->treeconflict_operation
)
1719 case svn_wc_operation_update
:
1720 switch (pInfoData
->treeconflict_action
)
1722 case svn_wc_conflict_action_edit
:
1723 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1724 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1726 case svn_wc_conflict_action_add
:
1727 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1728 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1730 case svn_wc_conflict_action_delete
:
1731 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1732 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1736 case svn_wc_operation_switch
:
1737 switch (pInfoData
->treeconflict_action
)
1739 case svn_wc_conflict_action_edit
:
1740 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1741 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1743 case svn_wc_conflict_action_add
:
1744 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1745 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1747 case svn_wc_conflict_action_delete
:
1748 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1749 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1753 case svn_wc_operation_merge
:
1754 switch (pInfoData
->treeconflict_action
)
1756 case svn_wc_conflict_action_edit
:
1757 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1758 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1760 case svn_wc_conflict_action_add
:
1761 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1762 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1764 case svn_wc_conflict_action_delete
:
1765 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1766 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1774 switch (pInfoData
->treeconflict_reason
)
1776 case svn_wc_conflict_reason_edited
:
1777 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1778 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1780 case svn_wc_conflict_reason_obstructed
:
1781 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1782 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1784 case svn_wc_conflict_reason_deleted
:
1785 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1786 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1788 case svn_wc_conflict_reason_added
:
1789 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1790 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1792 case svn_wc_conflict_reason_missing
:
1793 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1794 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1796 case svn_wc_conflict_reason_unversioned
:
1797 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1798 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1801 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1803 CTreeConflictEditorDlg dlg
;
1804 dlg
.SetConflictInfoText(sConflictReason
);
1805 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1806 dlg
.SetPath(treeConflictPath
);
1807 INT_PTR dlgRet
= dlg
.DoModal();
1808 bRet
= (dlgRet
!= IDCANCEL
);
1816 bool CAppUtils::IsSSHPutty()
1818 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1819 sshclient
=sshclient
.MakeLower();
1820 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1827 CString
CAppUtils::GetClipboardLink()
1829 if (!OpenClipboard(NULL
))
1832 CString sClipboardText
;
1833 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1836 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1837 sClipboardText
= CString(lpstr
);
1840 hglb
= GetClipboardData(CF_UNICODETEXT
);
1843 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1844 sClipboardText
= lpstr
;
1849 if(!sClipboardText
.IsEmpty())
1851 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1852 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1854 if(sClipboardText
.Find( _T("http://")) == 0)
1855 return sClipboardText
;
1857 if(sClipboardText
.Find( _T("https://")) == 0)
1858 return sClipboardText
;
1860 if(sClipboardText
.Find( _T("git://")) == 0)
1861 return sClipboardText
;
1863 if(sClipboardText
.Find( _T("ssh://")) == 0)
1864 return sClipboardText
;
1866 if(sClipboardText
.GetLength()>=2)
1867 if( sClipboardText
[1] == _T(':') )
1868 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1869 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1870 return sClipboardText
;
1873 return CString(_T(""));
1876 CString
CAppUtils::ChooseRepository(CString
*path
)
1878 CBrowseFolder browseFolder
;
1879 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
1881 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
1882 CString strCloneDirectory
;
1884 strCloneDirectory
=*path
;
1887 strCloneDirectory
= regLastResopitory
;
1891 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
1893 browseFolder
.SetInfo(title
);
1895 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
1897 regLastResopitory
= strCloneDirectory
;
1898 return strCloneDirectory
;
1906 bool CAppUtils::SendPatchMail(CTGitPathList
&list
,bool autoclose
)
1910 dlg
.m_PathList
= list
;
1912 if(dlg
.DoModal()==IDOK
)
1914 if(dlg
.m_PathList
.GetCount() == 0)
1917 CGitProgressDlg progDlg
;
1919 theApp
.m_pMainWnd
= &progDlg
;
1920 progDlg
.SetCommand(CGitProgressDlg::GitProgress_SendMail
);
1922 progDlg
.SetAutoClose(autoclose
);
1924 progDlg
.SetPathList(dlg
.m_PathList
);
1925 //ProjectProperties props;
1926 //props.ReadPropsPathList(dlg.m_pathList);
1927 //progDlg.SetProjectProperties(props);
1928 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
1931 if(dlg
.m_bAttachment
)
1932 flags
|= SENDMAIL_ATTACHMENT
;
1934 flags
|= SENDMAIL_COMBINED
;
1936 flags
|= SENDMAIL_MAPI
;
1938 progDlg
.SetSendMailOption(dlg
.m_To
,dlg
.m_CC
,dlg
.m_Subject
,flags
);
1947 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
)
1950 CString log
=formatpatchoutput
;
1951 int start
=log
.Find(cmd
);
1953 CString one
=log
.Tokenize(_T("\n"),start
);
1959 CString one
=log
.Tokenize(_T("\n"),start
);
1961 if(one
.IsEmpty() || one
.Find(_T("Success")) == 0)
1963 one
.Replace(_T('/'),_T('\\'));
1965 path
.SetFromWin(one
);
1968 if (list
.GetCount() > 0)
1970 return SendPatchMail(list
, autoclose
);
1974 CMessageBox::Show(NULL
, IDS_ERR_NOPATCHES
, IDS_APPNAME
, MB_ICONINFORMATION
);
1980 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
1985 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
1986 if(output
.IsEmpty())
1988 output
= pGit
->GetConfigValue(_T("i18n.commitencoding"));
1989 if(output
.IsEmpty())
1993 output
=output
.Tokenize(_T("\n"),start
);
1994 return CUnicodeUtils::GetCPCode(output
);
1999 output
=output
.Tokenize(_T("\n"),start
);
2000 return CUnicodeUtils::GetCPCode(output
);
2003 int CAppUtils::GetCommitTemplate(CString
&temp
)
2007 output
= g_Git
.GetConfigValue(_T("commit.template"), CP_UTF8
);
2008 if( output
.IsEmpty() )
2011 if( output
.GetLength()<1)
2014 if( output
[0] == _T('/'))
2016 if(output
.GetLength()>=3)
2017 if(output
[2] == _T('/'))
2019 output
.GetBuffer()[0] = output
[1];
2020 output
.GetBuffer()[1] = _T(':');
2025 output
=output
.Tokenize(_T("\n"),start
);
2027 output
.Replace(_T('/'),_T('\\'));
2031 CStdioFile
file(output
,CFile::modeRead
|CFile::typeText
);
2033 while(file
.ReadString(str
))
2044 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
2046 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
2050 output
= g_Git
.GetConfigValue(_T("i18n.commitencoding"));
2051 if(output
.IsEmpty())
2055 output
=output
.Tokenize(_T("\n"),start
);
2056 cp
=CUnicodeUtils::GetCPCode(output
);
2058 int len
=message
.GetLength();
2061 buf
= new char[len
*4 + 4];
2062 SecureZeroMemory(buf
, (len
*4 + 4));
2064 int lengthIncTerminator
= WideCharToMultiByte(cp
, 0, message
, -1, buf
, len
*4, NULL
, NULL
);
2066 file
.Write(buf
,lengthIncTerminator
-1);
2072 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
, bool autoClose
)
2075 dlg
.m_PreSelectRemote
= remoteName
;
2076 dlg
.m_bAllowRebase
= allowRebase
;
2079 if(dlg
.DoModal()==IDOK
)
2083 if (dlg
.m_bAllRemotes
)
2086 g_Git
.GetRemoteList(list
);
2088 STRING_VECTOR::const_iterator it
= list
.begin();
2089 while (it
!= list
.end())
2091 CString
remote(*it
);
2092 CAppUtils::LaunchPAgent(NULL
, &remote
);
2097 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
2101 url
=dlg
.m_RemoteURL
;
2105 int ver
= CAppUtils::GetMsysgitVersion();
2107 if(ver
>= 0x01070203) //above 1.7.0.2
2108 arg
= _T("--progress ");
2111 arg
+= _T("--prune ");
2114 if (dlg
.m_bFetchTags
== 1)
2116 arg
+= _T("--tags ");
2118 else if (dlg
.m_bFetchTags
== 0)
2120 arg
+= _T("--no-tags ");
2123 if (dlg
.m_bAllRemotes
)
2124 cmd
.Format(_T("git.exe fetch --all -v %s"), arg
);
2126 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"), arg
, url
, dlg
.m_RemoteBranchName
);
2128 CProgressDlg progress
;
2130 progress
.m_bAutoCloseOnSuccess
= autoClose
;
2132 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2134 if(!dlg
.m_bRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
2136 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2139 progress
.m_GitCmd
=cmd
;
2140 INT_PTR userResponse
= progress
.DoModal();
2142 if (userResponse
== IDC_PROGRESS_BUTTON1
)
2144 CString cmd
= _T("/command:log");
2145 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2146 RunTortoiseProc(cmd
);
2149 else if ((userResponse
== IDC_PROGRESS_BUTTON1
+ 1) || (progress
.m_GitStatus
== 0 && dlg
.m_bRebase
))
2154 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUDESSENDMAIL
)));
2155 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2156 INT_PTR response
= dlg
.DoModal();
2157 if(response
== IDOK
)
2161 if(response
== IDC_REBASE_POST_BUTTON
)
2163 CString cmd
, out
, err
;
2164 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2166 g_Git
.FixBranchName(dlg
.m_Upstream
),
2167 g_Git
.FixBranchName(dlg
.m_Branch
));
2168 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
2170 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2174 CAppUtils::SendPatchMail(cmd
,out
);
2178 if(response
== IDC_REBASE_POST_BUTTON
+1 )
2181 if(response
== IDCANCEL
)
2186 else if (userResponse
!= IDCANCEL
)
2192 bool CAppUtils::Push(CString selectLocalBranch
, bool autoClose
)
2195 dlg
.m_BranchSourceName
= selectLocalBranch
;
2197 DWORD exitcode
= 0xFFFFFFFF;
2199 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
2200 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
2205 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2206 //ReportError(temp);
2207 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2212 if(dlg
.DoModal()==IDOK
)
2217 arg
+= _T("--thin ");
2218 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2219 arg
+= _T("--tags ");
2221 arg
+= _T("--force ");
2222 if (dlg
.m_bSetUpstream
)
2223 arg
+= _T("--set-upstream ");
2225 int ver
= CAppUtils::GetMsysgitVersion();
2227 if(ver
>= 0x01070203) //above 1.7.0.2
2228 arg
+= _T("--progress ");
2230 CProgressDlg progress
;
2231 progress
.m_bAutoCloseOnSuccess
=autoClose
;
2233 STRING_VECTOR remotesList
;
2234 if (dlg
.m_bPushAllRemotes
)
2235 g_Git
.GetRemoteList(remotesList
);
2237 remotesList
.push_back(dlg
.m_URL
);
2239 for (unsigned int i
= 0; i
< remotesList
.size(); i
++)
2241 if (dlg
.m_bAutoLoad
)
2242 CAppUtils::LaunchPAgent(NULL
, &remotesList
[i
]);
2245 if (dlg
.m_bPushAllBranches
)
2247 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2253 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2256 dlg
.m_BranchSourceName
);
2257 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2259 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2262 progress
.m_GitCmdList
.push_back(cmd
);
2265 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REQUESTPULL
)));
2266 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2267 INT_PTR ret
= progress
.DoModal();
2269 if(!progress
.m_GitStatus
)
2271 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2276 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2277 //ReportError(temp);
2278 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2282 if(ret
== IDC_PROGRESS_BUTTON1
)
2284 RequestPull(dlg
.m_BranchRemoteName
);
2286 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2297 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2299 CRequestPullDlg dlg
;
2300 dlg
.m_RepositoryURL
= repositoryUrl
;
2301 dlg
.m_EndRevision
= endrevision
;
2302 if (dlg
.DoModal()==IDOK
)
2305 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2307 CString tempFileName
= GetTempFile();
2308 if (g_Git
.RunLogFile(cmd
, tempFileName
))
2310 CMessageBox::Show(NULL
, IDS_ERR_PULLREUQESTFAILED
, IDS_APPNAME
, MB_OK
);
2313 CAppUtils::LaunchAlternativeEditor(tempFileName
);
2318 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2320 CString
strDir(szPath
);
2321 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2323 strDir
.AppendChar(_T('\\'));
2325 std::vector
<CString
> vPath
;
2327 bool bSuccess
= false;
2329 for (int i
=0;i
<strDir
.GetLength();++i
)
2331 if (strDir
.GetAt(i
) != _T('\\'))
2333 strTemp
.AppendChar(strDir
.GetAt(i
));
2337 vPath
.push_back(strTemp
);
2338 strTemp
.AppendChar(_T('\\'));
2342 std::vector
<CString
>::const_iterator vIter
;
2343 for (vIter
= vPath
.begin(); vIter
!= vPath
.end(); vIter
++)
2345 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2351 void CAppUtils::RemoveTrailSlash(CString
&path
)
2356 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2358 path
=path
.Left(path
.GetLength()-1);
2364 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2365 CTGitPathList
&pathList
,
2366 CTGitPathList
&selectedList
,
2367 bool bSelectFilesForCommit
,
2370 bool bFailed
= true;
2372 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
2374 if(CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
2376 CTGitPath
path(g_Git
.m_CurrentDir
);
2377 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2378 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2379 dlg
.SetTreeWidth(220);
2380 dlg
.m_DefaultPage
= _T("gitconfig");
2383 dlg
.HandleRestart();
2394 dlg
.m_sBugID
= bugid
;
2396 dlg
.m_bWholeProject
= bWholeProject
;
2398 dlg
.m_sLogMessage
= sLogMsg
;
2399 dlg
.m_pathList
= pathList
;
2400 dlg
.m_checkedPathList
= selectedList
;
2401 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2402 dlg
.m_bAutoClose
= autoClose
;
2403 if (dlg
.DoModal() == IDOK
)
2405 if (dlg
.m_pathList
.GetCount()==0)
2407 // if the user hasn't changed the list of selected items
2408 // we don't use that list. Because if we would use the list
2409 // of pre-checked items, the dialog would show different
2410 // checked items on the next startup: it would only try
2411 // to check the parent folder (which might not even show)
2412 // instead, we simply use an empty list and let the
2413 // default checking do its job.
2414 if (!dlg
.m_pathList
.IsEqual(pathList
))
2415 selectedList
= dlg
.m_pathList
;
2416 pathList
= dlg
.m_updatedPathList
;
2417 sLogMsg
= dlg
.m_sLogMessage
;
2418 bSelectFilesForCommit
= true;
2420 if( dlg
.m_bPushAfterCommit
)
2422 switch(dlg
.m_PostCmd
)
2424 case GIT_POST_CMD_DCOMMIT
:
2425 CAppUtils::SVNDCommit();
2431 else if (dlg
.m_bCreateTagAfterCommit
)
2433 CAppUtils::CreateBranchTag(TRUE
);
2436 // CGitProgressDlg progDlg;
2437 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2438 // if (parser.HasVal(_T("closeonend")))
2439 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2440 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2441 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2442 // progDlg.SetPathList(dlg.m_pathList);
2443 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2444 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2445 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2446 // progDlg.SetItemCount(dlg.m_itemsCount);
2447 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2448 // progDlg.DoModal();
2449 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2450 // err = (DWORD)progDlg.DidErrorsOccur();
2451 // bFailed = progDlg.DidErrorsOccur();
2452 // bRet = progDlg.DidErrorsOccur();
2453 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2454 // if (DWORD(bFailRepeat)==0)
2455 // bFailed = false; // do not repeat if the user chose not to in the settings.
2462 BOOL
CAppUtils::SVNDCommit()
2464 CSVNDCommitDlg dcommitdlg
;
2465 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2466 if (gitSetting
== _T("")) {
2467 if (dcommitdlg
.DoModal() != IDOK
)
2473 if (dcommitdlg
.m_remember
)
2475 if (dcommitdlg
.m_rmdir
)
2477 gitSetting
= _T("true");
2481 gitSetting
= _T("false");
2483 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2486 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, _T("svn.rmdir"), gitSetting
);
2487 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2493 BOOL IsStash
= false;
2494 if(!g_Git
.CheckCleanWorkTree())
2496 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
2498 CSysProgressDlg sysProgressDlg
;
2499 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2500 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2501 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2502 sysProgressDlg
.SetShowProgressBar(false);
2503 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2504 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2507 cmd
=_T("git.exe stash");
2508 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2510 if (sysProgressDlg
.IsValid())
2511 sysProgressDlg
.Stop();
2512 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2515 if (sysProgressDlg
.IsValid())
2516 sysProgressDlg
.Stop();
2526 CProgressDlg progress
;
2527 if (dcommitdlg
.m_rmdir
)
2529 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2533 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2535 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2539 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2541 CSysProgressDlg sysProgressDlg
;
2542 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2543 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2544 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2545 sysProgressDlg
.SetShowProgressBar(false);
2546 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2547 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2550 cmd
=_T("git.exe stash pop");
2551 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2553 if (sysProgressDlg
.IsValid())
2554 sysProgressDlg
.Stop();
2555 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2558 if (sysProgressDlg
.IsValid())
2559 sysProgressDlg
.Stop();
2571 BOOL
CAppUtils::Merge(CString
*commit
)
2575 dlg
.m_initialRefName
= *commit
;
2577 if(dlg
.DoModal()==IDOK
)
2589 squash
=_T("--squash");
2592 nocommit
=_T("--no-commit");
2594 if(!dlg
.m_strLogMesage
.IsEmpty())
2596 msg
+= _T("-m \"")+dlg
.m_strLogMesage
+_T("\"");
2598 cmd
.Format(_T("git.exe merge %s %s %s %s %s"),
2603 g_Git
.FixBranchName(dlg
.m_VersionName
));
2605 CProgressDlg Prodlg
;
2606 Prodlg
.m_GitCmd
= cmd
;
2608 if (dlg
.m_bNoCommit
)
2609 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUCOMMIT
)));
2610 else if (dlg
.m_bIsBranch
)
2611 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REMOVEBRANCH
)));
2613 INT_PTR ret
= Prodlg
.DoModal();
2615 if (ret
== IDC_PROGRESS_BUTTON1
)
2616 if (dlg
.m_bNoCommit
)
2619 CTGitPathList pathList
;
2620 CTGitPathList selectedList
;
2621 return Commit(_T(""), TRUE
, sLogMsg
, pathList
, selectedList
, true);
2623 else if (dlg
.m_bIsBranch
)
2626 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, dlg
.m_VersionName
);
2627 if (CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
2630 cmd
.Format(_T("git.exe branch -D -- %s"), dlg
.m_VersionName
);
2631 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2632 MessageBox(NULL
, out
, _T("TortoiseGit"), MB_OK
);
2636 return !Prodlg
.m_GitStatus
;
2641 void CAppUtils::EditNote(GitRev
*rev
)
2644 dlg
.m_sHintText
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2645 dlg
.m_sInputText
= rev
->m_Notes
;
2646 dlg
.m_sTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2647 //dlg.m_pProjectProperties = &m_ProjectProperties;
2648 dlg
.m_bUseLogWidth
= true;
2649 if(dlg
.DoModal() == IDOK
)
2652 cmd
=_T("notes add -f -F \"");
2654 CString tempfile
=::GetTempFile();
2655 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
2658 cmd
+= rev
->m_CommitHash
.ToString();
2662 if (git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2664 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2669 rev
->m_Notes
= dlg
.m_sInputText
;
2673 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2675 CFile::Remove(tempfile
);
2680 int CAppUtils::GetMsysgitVersion(CString
*versionstr
)
2683 CString progressarg
;
2686 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
2687 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
2689 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
2692 if(!g_Git
.GetFileModifyTime(gitpath
, &time
) && !versionstr
)
2694 if((DWORD
)time
== regTime
)
2701 version
= *versionstr
;
2705 cmd
= _T("git.exe --version");
2706 if (g_Git
.Run(cmd
, &version
, &err
, CP_UTF8
))
2708 CMessageBox::Show(NULL
, _T("git have not installed (") + err
+ _T(")"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2718 CString str
=version
.Tokenize(_T("."), start
);
2719 int space
= str
.ReverseFind(_T(' '));
2720 str
= str
.Mid(space
+1,start
);
2724 version
= version
.Mid(start
);
2727 str
= version
.Tokenize(_T("."), start
);
2729 ver
|= (_ttol(str
) & 0xFF) << 16;
2731 str
= version
.Tokenize(_T("."), start
);
2732 ver
|= (_ttol(str
) & 0xFF) << 8;
2734 str
= version
.Tokenize(_T("."), start
);
2735 ver
|= (_ttol(str
) & 0xFF);
2741 CMessageBox::Show(NULL
, _T("Could not parse git.exe version number."), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2746 regTime
= time
&0xFFFFFFFF;
2752 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
2754 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
2756 CAutoLibrary hShell
= LoadLibrary(_T("Shell32.dll"));
2758 if (hShell
.IsValid()) {
2759 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
2761 IPropertyStore
*pps
;
2762 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
2763 if (SUCCEEDED(hr
)) {
2766 var
.boolVal
= VARIANT_TRUE
;
2767 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
2774 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
2776 ASSERT(dialogname
.GetLength() < 70);
2777 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
2778 WCHAR pathbuf
[MAX_PATH
] = {0};
2780 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
2782 wcscat_s(pathbuf
, L
" - ");
2783 wcscat_s(pathbuf
, dialogname
);
2784 wcscat_s(pathbuf
, L
" - ");
2785 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2786 SetWindowText(hWnd
, pathbuf
);
2789 bool CAppUtils::BisectStart(CString lastGood
, CString firstBad
, bool autoClose
)
2791 if (!g_Git
.CheckCleanWorkTree())
2793 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
2795 CSysProgressDlg sysProgressDlg
;
2796 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2797 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2798 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2799 sysProgressDlg
.SetShowProgressBar(false);
2800 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2801 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2804 cmd
= _T("git.exe stash");
2805 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2807 if (sysProgressDlg
.IsValid())
2808 sysProgressDlg
.Stop();
2809 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
);
2812 if (sysProgressDlg
.IsValid())
2813 sysProgressDlg
.Stop();
2819 CBisectStartDlg bisectStartDlg
;
2821 if (!lastGood
.IsEmpty())
2822 bisectStartDlg
.m_sLastGood
= lastGood
;
2823 if (!firstBad
.IsEmpty())
2824 bisectStartDlg
.m_sFirstBad
= firstBad
;
2826 if (bisectStartDlg
.DoModal() == IDOK
)
2828 CProgressDlg progress
;
2829 theApp
.m_pMainWnd
= &progress
;
2830 progress
.m_bAutoCloseOnSuccess
= autoClose
;
2831 progress
.m_GitCmdList
.push_back(_T("git.exe bisect start"));
2832 progress
.m_GitCmdList
.push_back(_T("git.exe bisect good ") + bisectStartDlg
.m_LastGoodRevision
);
2833 progress
.m_GitCmdList
.push_back(_T("git.exe bisect bad ") + bisectStartDlg
.m_FirstBadRevision
);
2835 CTGitPath
path(g_Git
.m_CurrentDir
);
2837 if (path
.HasSubmodules())
2838 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
2840 INT_PTR ret
= progress
.DoModal();
2841 if (path
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
2844 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
2846 CAppUtils::RunTortoiseProc(sCmd
);
2849 else if (ret
== IDOK
)