1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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"
66 #include "UserPassword.h"
69 CAppUtils::CAppUtils(void)
73 CAppUtils::~CAppUtils(void)
77 bool CAppUtils::StashSave()
81 if (dlg
.DoModal() == IDOK
)
84 cmd
= _T("git.exe stash save");
86 if (CAppUtils::GetMsysgitVersion() >= 0x01070700)
88 if (dlg
.m_bIncludeUntracked
)
89 cmd
+= _T(" --include-untracked");
94 if (!dlg
.m_sMessage
.IsEmpty())
96 CString message
= dlg
.m_sMessage
;
97 message
.Replace(_T("\""), _T("\"\""));
98 cmd
+= _T(" \"") + message
+ _T("\"");
101 CSysProgressDlg sysProgressDlg
;
102 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
103 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
104 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
105 sysProgressDlg
.SetShowProgressBar(false);
106 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
107 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
109 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
111 sysProgressDlg
.Stop();
112 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
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 sysProgressDlg
.Stop();
146 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
147 if (ret
&& !(ret
== 1 && hasConflicts
))
149 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHAPPLYFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
154 message
.LoadString(IDS_PROC_STASHAPPLYSUCCESS
);
156 message
.LoadString(IDS_PROC_STASHAPPLYFAILEDCONFLICTS
);
159 if(CMessageBox::Show(NULL
,message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
))
160 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
163 dlg
.m_pathList
.AddPath(CTGitPath());
170 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
177 bool CAppUtils::StashPop(bool showChanges
/* true */)
180 cmd
=_T("git.exe stash pop ");
182 CSysProgressDlg sysProgressDlg
;
183 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
184 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
185 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
186 sysProgressDlg
.SetShowProgressBar(false);
187 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
188 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
190 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
192 sysProgressDlg
.Stop();
194 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
195 if (ret
&& !(ret
== 1 && hasConflicts
))
197 CMessageBox::Show(NULL
,CString(MAKEINTRESOURCE(IDS_PROC_STASHPOPFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
202 message
.LoadString(IDS_PROC_STASHPOPSUCCESS
);
204 message
.LoadString(IDS_PROC_STASHPOPFAILEDCONFLICTS
);
207 if(CMessageBox::Show(NULL
,CString(message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
)))
208 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
211 dlg
.m_pathList
.AddPath(CTGitPath());
218 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
225 bool CAppUtils::GetMimeType(const CTGitPath
& /*file*/, CString
& /*mimetype*/)
228 GitProperties
props(file
, GitRev::REV_WC
, false);
229 for (int i
= 0; i
< props
.GetCount(); ++i
)
231 if (props
.GetItemName(i
).compare(_T("svn:mime-type"))==0)
233 mimetype
= props
.GetItemValue(i
).c_str();
241 BOOL
CAppUtils::StartExtMerge(
242 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
243 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
)
246 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
247 CString ext
= mergedfile
.GetFileExtension();
248 CString com
= regCom
;
249 bool bInternal
= false;
254 // is there an extension specific merge tool?
255 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
256 if (CString(mergetool
) != "")
261 if (GetMimeType(yourfile
, mimetype
) || GetMimeType(theirfile
, mimetype
) || GetMimeType(basefile
, mimetype
))
263 // is there a mime type specific merge tool?
264 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype
);
265 if (CString(mergetool
) != "")
270 // is there a filename specific merge tool?
271 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\.") + mergedfile
.GetFilename().MakeLower());
272 if (CString(mergetool
) != "")
277 // Maybe we should use TortoiseIDiff?
278 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
279 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
280 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
281 (ext
== _T(".dib")) || (ext
== _T(".emf")))
283 com
= _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitIDiff.exe") + _T("\"") +
284 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname") + _T("\n") +
286 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitIDiff.exe") + _T("\"") +
287 _T(" /left:%base /right:%theirs /lefttitle:%bname /righttitle:%tname");
290 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
292 // use TortoiseGitMerge
294 CRegString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE
);
295 com
= tortoiseMergePath
;
298 com
= CPathUtils::GetAppDirectory();
299 com
+= _T("TortoiseGitMerge.exe");
301 com
= _T("\"") + com
+ _T("\"");
302 if (!g_sGroupingUUID
.IsEmpty())
304 com
+= L
" /groupuuid:\"";
305 com
+= g_sGroupingUUID
;
308 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
309 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
311 // check if the params are set. If not, just add the files to the command line
312 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
314 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
315 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
316 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
317 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
319 if (basefile
.IsEmpty())
321 com
.Replace(_T("/base:%base"), _T(""));
322 com
.Replace(_T("%base"), _T(""));
325 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
326 if (theirfile
.IsEmpty())
328 com
.Replace(_T("/theirs:%theirs"), _T(""));
329 com
.Replace(_T("%theirs"), _T(""));
332 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
333 if (yourfile
.IsEmpty())
335 com
.Replace(_T("/mine:%mine"), _T(""));
336 com
.Replace(_T("%mine"), _T(""));
339 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
340 if (mergedfile
.IsEmpty())
342 com
.Replace(_T("/merged:%merged"), _T(""));
343 com
.Replace(_T("%merged"), _T(""));
346 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
347 if (basename
.IsEmpty())
349 if (basefile
.IsEmpty())
351 com
.Replace(_T("/basename:%bname"), _T(""));
352 com
.Replace(_T("%bname"), _T(""));
356 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
360 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
361 if (theirname
.IsEmpty())
363 if (theirfile
.IsEmpty())
365 com
.Replace(_T("/theirsname:%tname"), _T(""));
366 com
.Replace(_T("%tname"), _T(""));
370 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
374 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
375 if (yourname
.IsEmpty())
377 if (yourfile
.IsEmpty())
379 com
.Replace(_T("/minename:%yname"), _T(""));
380 com
.Replace(_T("%yname"), _T(""));
384 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
388 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
389 if (mergedname
.IsEmpty())
391 if (mergedfile
.IsEmpty())
393 com
.Replace(_T("/mergedname:%mname"), _T(""));
394 com
.Replace(_T("%mname"), _T(""));
398 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
402 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
404 if ((bReadOnly
)&&(bInternal
))
405 com
+= _T(" /readonly");
408 int newLine
= com
.Find(_T('\n'));
411 com2
= com
.Mid(newLine
+ 1);
412 com
= com
.Left(newLine
);
414 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
418 if (!com2
.IsEmpty() && !LaunchApplication(com2
, IDS_ERR_EXTMERGESTART
, false))
426 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
429 // use TortoiseGitMerge
430 viewer
= CPathUtils::GetAppDirectory();
431 viewer
+= _T("TortoiseGitMerge.exe");
433 viewer
= _T("\"") + viewer
+ _T("\"");
434 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
435 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
437 viewer
+= _T(" /reversedpatch");
438 if (!sOriginalDescription
.IsEmpty())
439 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
440 if (!sPatchedDescription
.IsEmpty())
441 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
442 if (!g_sGroupingUUID
.IsEmpty())
444 viewer
+= L
" /groupuuid:\"";
445 viewer
+= g_sGroupingUUID
;
448 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
455 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
457 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file2
.GetFilename().MakeLower());
458 if (!difftool
.IsEmpty())
460 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file1
.GetFilename().MakeLower());
461 if (!difftool
.IsEmpty())
464 // Is there a mime type specific diff tool?
466 if (GetMimeType(file1
, mimetype
) || GetMimeType(file2
, mimetype
))
468 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype
);
469 if (!difftool
.IsEmpty())
473 // Is there an extension specific diff tool?
474 CString ext
= file2
.GetFileExtension().MakeLower();
477 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
478 if (!difftool
.IsEmpty())
480 // Maybe we should use TortoiseIDiff?
481 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
482 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
483 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
484 (ext
== _T(".dib")) || (ext
== _T(".emf")))
487 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitIDiff.exe") + _T("\"") +
488 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname") +
489 L
" /groupuuid:\"" + g_sGroupingUUID
+ L
"\"";
493 // Finally, pick a generic external diff tool
494 difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
498 bool CAppUtils::StartExtDiff(
499 const CString
& file1
, const CString
& file2
,
500 const CString
& sName1
, const CString
& sName2
,
501 const CString
& originalFile1
, const CString
& originalFile2
,
502 const git_revnum_t
& hash1
, const git_revnum_t
& hash2
,
503 const DiffFlags
& flags
)
507 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
508 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
510 viewer
= PickDiffTool(file1
, file2
);
511 // If registry entry for a diff program is commented out, use TortoiseGitMerge.
512 bool bCommentedOut
= viewer
.Left(1) == _T("#");
513 if (flags
.bAlternativeTool
)
515 // Invert external vs. internal diff tool selection.
517 viewer
.Delete(0); // uncomment
521 else if (bCommentedOut
)
525 bool bInternal
= viewer
.IsEmpty();
529 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitMerge.exe") + _T("\"") +
530 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
531 if (!g_sGroupingUUID
.IsEmpty())
533 viewer
+= L
" /groupuuid:\"";
534 viewer
+= g_sGroupingUUID
;
538 viewer
+= _T(" /blame");
540 // check if the params are set. If not, just add the files to the command line
541 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
543 viewer
+= _T(" \"")+file1
+_T("\"");
544 viewer
+= _T(" \"")+file2
+_T("\"");
546 if (viewer
.Find(_T("%base")) >= 0)
548 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
550 if (viewer
.Find(_T("%mine")) >= 0)
552 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
555 if (sName1
.IsEmpty())
556 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
558 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
560 if (sName2
.IsEmpty())
561 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
563 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
565 viewer
.Replace(_T("%bpath"), _T("\"") + originalFile1
+ _T("\""));
566 viewer
.Replace(_T("%ypath"), _T("\"") + originalFile2
+ _T("\""));
568 viewer
.Replace(_T("%brev"), _T("\"") + hash1
+ _T("\""));
569 viewer
.Replace(_T("%yrev"), _T("\"") + hash2
+ _T("\""));
571 if (flags
.bReadOnly
&& bInternal
)
572 viewer
+= _T(" /readonly");
574 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
577 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
580 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
582 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
584 // use TortoiseGitUDiff
585 viewer
= CPathUtils::GetAppDirectory();
586 viewer
+= _T("TortoiseGitUDiff.exe");
587 // enquote the path to TortoiseGitUDiff
588 viewer
= _T("\"") + viewer
+ _T("\"");
590 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
591 if (!g_sGroupingUUID
.IsEmpty())
593 viewer
+= L
" /groupuuid:\"";
594 viewer
+= g_sGroupingUUID
;
598 if (viewer
.Find(_T("%1"))>=0)
600 if (viewer
.Find(_T("\"%1\"")) >= 0)
601 viewer
.Replace(_T("%1"), patchfile
);
603 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
606 viewer
+= _T(" \"") + patchfile
+ _T("\"");
607 if (viewer
.Find(_T("%title")) >= 0)
609 viewer
.Replace(_T("%title"), title
);
612 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
619 BOOL
CAppUtils::StartTextViewer(CString file
)
622 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
624 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
625 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
628 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
629 std::unique_ptr
<TCHAR
[]> buf(new TCHAR
[len
+ 1]);
630 ExpandEnvironmentStrings(viewer
, buf
.get(), len
);
632 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
633 std::unique_ptr
<TCHAR
[]> buf2(new TCHAR
[len
+ 1]);
634 ExpandEnvironmentStrings(file
, buf2
.get(), len
);
636 file
= _T("\"")+file
+_T("\"");
637 if (viewer
.IsEmpty())
639 viewer
= _T("RUNDLL32 Shell32,OpenAs_RunDLL");
641 if (viewer
.Find(_T("\"%1\"")) >= 0)
643 viewer
.Replace(_T("\"%1\""), file
);
645 else if (viewer
.Find(_T("%1")) >= 0)
647 viewer
.Replace(_T("%1"), file
);
655 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
662 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
665 CAutoFile hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
668 length
= ::GetFileSize(hFile
, NULL
);
675 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
678 HDC hScreenDC
= ::GetDC(NULL
);
679 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
680 ::ReleaseDC(NULL
, hScreenDC
);
682 logFont
.lfEscapement
= 0;
683 logFont
.lfOrientation
= 0;
684 logFont
.lfWeight
= FW_NORMAL
;
685 logFont
.lfItalic
= 0;
686 logFont
.lfUnderline
= 0;
687 logFont
.lfStrikeOut
= 0;
688 logFont
.lfCharSet
= DEFAULT_CHARSET
;
689 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
690 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
691 logFont
.lfQuality
= DRAFT_QUALITY
;
692 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
693 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
694 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
697 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
711 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
712 key
= g_Git
.GetConfigValue(cmd
);
714 key
= key
.Tokenize(_T("\n"),start
);
722 CString proc
=CPathUtils::GetAppDirectory();
723 proc
+= _T("pageant.exe \"");
727 CString tempfile
= GetTempFile();
728 ::DeleteFile(tempfile
);
730 proc
+= _T(" -c \"");
731 proc
+= CPathUtils::GetAppDirectory();
732 proc
+= _T("touch.exe\"");
737 CString appDir
= CPathUtils::GetAppDirectory();
738 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true, &appDir
);
743 while(!::PathFileExists(tempfile
))
748 break; //timeout 5 minutes
753 CMessageBox::Show(NULL
, IDS_ERR_PAEGENTTIMEOUT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
755 ::DeleteFile(tempfile
);
758 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
, bool uac
)
760 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
761 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
762 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
766 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
768 LaunchApplication(sCmd
, NULL
, false, NULL
, uac
);
771 bool CAppUtils::LaunchRemoteSetting()
773 CTGitPath
path(g_Git
.m_CurrentDir
);
774 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
775 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
776 dlg
.SetTreeWidth(220);
777 dlg
.m_DefaultPage
= _T("gitremote");
784 * Launch the external blame viewer
786 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
788 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
789 viewer
+= _T("TortoiseGitBlame.exe");
790 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
791 //viewer += _T(" \"") + sLogFile + _T("\"");
792 //viewer += _T(" \"") + sOriginalFile + _T("\"");
793 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
794 viewer
+= CString(_T(" /rev:"))+Rev
;
795 if (!g_sGroupingUUID
.IsEmpty())
797 viewer
+= L
" /groupuuid:\"";
798 viewer
+= g_sGroupingUUID
;
801 viewer
+= _T(" ")+sParams
;
803 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
806 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
811 bool bStyled
= false;
812 pWnd
->GetWindowText(sText
);
813 // the rich edit control doesn't count the CR char!
814 // to be exact: CRLF is treated as one char.
817 // style each line separately
822 nNewlinePos
= sText
.Find('\n', offset
);
823 CString sLine
= sText
.Mid(offset
);
825 sLine
= sLine
.Left(nNewlinePos
-offset
);
828 while (FindStyleChars(sLine
, '*', start
, end
))
830 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
831 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
833 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
834 format
.cbSize
= sizeof(CHARFORMAT2
);
835 format
.dwMask
= CFM_BOLD
;
836 format
.dwEffects
= CFE_BOLD
;
837 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
843 while (FindStyleChars(sLine
, '^', start
, end
))
845 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
846 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
848 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
849 format
.cbSize
= sizeof(CHARFORMAT2
);
850 format
.dwMask
= CFM_ITALIC
;
851 format
.dwEffects
= CFE_ITALIC
;
852 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
858 while (FindStyleChars(sLine
, '_', start
, end
))
860 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
861 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
863 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
864 format
.cbSize
= sizeof(CHARFORMAT2
);
865 format
.dwMask
= CFM_UNDERLINE
;
866 format
.dwEffects
= CFE_UNDERLINE
;
867 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
871 offset
= nNewlinePos
+1;
872 } while(nNewlinePos
>=0);
876 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
879 bool bFoundMarker
= false;
880 // find a starting marker
881 while (sText
[i
] != 0)
883 if (sText
[i
] == stylechar
)
885 if (((i
+1)<sText
.GetLength())&&(IsCharAlphaNumeric(sText
[i
+1])) &&
886 (((i
>0)&&(!IsCharAlphaNumeric(sText
[i
-1])))||(i
==0)))
898 // find ending marker
899 bFoundMarker
= false;
900 while (sText
[i
] != 0)
902 if (sText
[i
] == stylechar
)
904 if ((IsCharAlphaNumeric(sText
[i
-1])) &&
905 ((((i
+1)<sText
.GetLength())&&(!IsCharAlphaNumeric(sText
[i
+1])))||(i
+1)==sText
.GetLength()))
918 CString
CAppUtils::GetProjectNameFromURL(CString url
)
921 while (name
.IsEmpty() || (name
.CompareNoCase(_T("branches"))==0) ||
922 (name
.CompareNoCase(_T("tags"))==0) ||
923 (name
.CompareNoCase(_T("trunk"))==0))
925 name
= url
.Mid(url
.ReverseFind('/')+1);
926 url
= url
.Left(url
.ReverseFind('/'));
928 if ((name
.Compare(_T("svn")) == 0)||(name
.Compare(_T("svnroot")) == 0))
930 // a name of svn or svnroot indicates that it's not really the project name. In that
931 // case, we try the first part of the URL
932 // of course, this won't work in all cases (but it works for Google project hosting)
933 url
.Replace(_T("http://"), _T(""));
934 url
.Replace(_T("https://"), _T(""));
935 url
.Replace(_T("svn://"), _T(""));
936 url
.Replace(_T("svn+ssh://"), _T(""));
937 url
.TrimLeft(_T("/"));
938 name
= url
.Left(url
.Find('.'));
943 bool CAppUtils::StartShowUnifiedDiff(HWND
/*hWnd*/, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
944 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
945 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
946 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */, bool /* blame = false */, bool bMerge
)
949 CString tempfile
=GetTempFile();
951 if(rev2
== GitRev::GetWorkingCopy())
953 cmd
.Format(_T("git.exe diff --stat -p %s "), rev1
);
955 else if (rev1
== GitRev::GetWorkingCopy())
957 cmd
.Format(_T("git.exe diff -R --stat -p %s "), rev2
);
965 cmd
.Format(_T("git.exe diff-tree -r -p %s --stat %s %s"),merge
, rev1
,rev2
);
968 if( !url1
.IsEmpty() )
971 cmd
+= url1
.GetGitPathString();
974 g_Git
.RunLogFile(cmd
,tempfile
);
975 CAppUtils::StartUnifiedDiffViewer(tempfile
, rev1
+ _T(":") + rev2
);
980 sCmd
.Format(_T("%s /command:showcompare /unified"),
981 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseGitProc.exe")));
982 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
984 sCmd
+= _T(" /revision1:") + rev1
.ToString();
985 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
987 sCmd
+= _T(" /revision2:") + rev2
.ToString();
989 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
990 if (headpeg
.IsValid())
991 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
994 sCmd
+= _T(" /alternatediff");
997 sCmd
+= _T(" /ignoreancestry");
1001 sCmd
+= _T(" /hwnd:");
1003 _stprintf_s(buf
, 30, _T("%d"), hWnd
);
1007 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
1012 bool CAppUtils::SetupDiffScripts(bool force
, const CString
& type
)
1014 CString scriptsdir
= CPathUtils::GetAppParentDirectory();
1015 scriptsdir
+= _T("Diff-Scripts");
1016 CSimpleFileFind
files(scriptsdir
);
1017 while (files
.FindNextFileNoDirectories())
1019 CString file
= files
.GetFilePath();
1020 CString filename
= files
.GetFileName();
1021 CString ext
= file
.Mid(file
.ReverseFind('-') + 1);
1022 ext
= _T(".") + ext
.Left(ext
.ReverseFind('.'));
1023 std::set
<CString
> extensions
;
1024 extensions
.insert(ext
);
1026 if (file
.Right(3).CompareNoCase(_T("vbs"))==0)
1028 kind
= _T(" //E:vbscript");
1030 if (file
.Right(2).CompareNoCase(_T("js"))==0)
1032 kind
= _T(" //E:javascript");
1034 // open the file, read the first line and find possible extensions
1035 // this script can handle
1038 CStdioFile
f(file
, CFile::modeRead
| CFile::shareDenyNone
);
1040 if (f
.ReadString(extline
))
1042 if ((extline
.GetLength() > 15 ) &&
1043 ((extline
.Left(15).Compare(_T("// extensions: ")) == 0) ||
1044 (extline
.Left(14).Compare(_T("' extensions: ")) == 0)))
1046 if (extline
[0] == '/')
1047 extline
= extline
.Mid(15);
1049 extline
= extline
.Mid(14);
1052 sToken
= extline
.Tokenize(_T(";"), curPos
);
1053 while (!sToken
.IsEmpty())
1055 if (!sToken
.IsEmpty())
1057 if (sToken
[0] != '.')
1058 sToken
= _T(".") + sToken
;
1059 extensions
.insert(sToken
);
1061 sToken
= extline
.Tokenize(_T(";"), curPos
);
1067 catch (CFileException
* e
)
1072 for (std::set
<CString
>::const_iterator it
= extensions
.begin(); it
!= extensions
.end(); ++it
)
1074 if (type
.IsEmpty() || (type
.Compare(_T("Diff")) == 0))
1076 if (filename
.Left(5).CompareNoCase(_T("diff-")) == 0)
1078 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + *it
);
1079 CString diffregstring
= diffreg
;
1080 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
1081 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %base %mine") + kind
;
1084 if (type
.IsEmpty() || (type
.Compare(_T("Merge"))==0))
1086 if (filename
.Left(6).CompareNoCase(_T("merge-"))==0)
1088 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\MergeTools\\") + *it
);
1089 CString diffregstring
= diffreg
;
1090 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
1091 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %merged %theirs %mine %base") + kind
;
1100 bool CAppUtils::Export(CString
*BashHash
)
1102 // ask from where the export has to be done
1105 dlg
.m_Revision
=*BashHash
;
1107 if (dlg
.DoModal() == IDOK
)
1110 cmd
.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s"),
1111 dlg
.m_strExportDirectory
, g_Git
.FixBranchName(dlg
.m_VersionName
));
1115 return (pro
.DoModal() == IDOK
);
1120 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
, bool switch_new_brach
)
1122 CCreateBranchTagDlg dlg
;
1124 dlg
.m_bSwitch
=switch_new_brach
;
1127 dlg
.m_initialRefName
= *CommitHash
;
1129 if(dlg
.DoModal()==IDOK
)
1134 if(dlg
.m_bTrack
== TRUE
)
1135 track
=_T(" --track ");
1136 else if(dlg
.m_bTrack
== FALSE
)
1137 track
=_T(" --no-track");
1148 cmd
.Format(_T("git.exe tag %s %s %s %s"),
1151 dlg
.m_BranchTagName
,
1152 g_Git
.FixBranchName(dlg
.m_VersionName
)
1155 CString tempfile
=::GetTempFile();
1156 if(!dlg
.m_Message
.Trim().IsEmpty())
1158 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_Message
);
1159 cmd
+= _T(" -F ")+tempfile
;
1164 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1167 dlg
.m_BranchTagName
,
1168 g_Git
.FixBranchName(dlg
.m_VersionName
)
1172 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1174 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1177 if( !IsTag
&& dlg
.m_bSwitch
)
1179 // it is a new branch and the user has requested to switch to it
1180 cmd
.Format(_T("git.exe checkout %s"), dlg
.m_BranchTagName
);
1181 g_Git
.Run(cmd
,&out
,CP_UTF8
);
1182 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1190 bool CAppUtils::Switch(CString initialRefName
, bool autoclose
)
1193 if(!initialRefName
.IsEmpty())
1194 dlg
.m_initialRefName
= initialRefName
;
1196 if (dlg
.DoModal() == IDOK
)
1200 branch
= dlg
.m_NewBranch
;
1202 // if refs/heads/ is not stripped, checkout will detach HEAD
1203 // checkout prefers branches on name clashes (with tags)
1204 if (dlg
.m_VersionName
.Left(11) ==_T("refs/heads/") && dlg
.m_bBranchOverride
!= TRUE
)
1205 dlg
.m_VersionName
= dlg
.m_VersionName
.Mid(11);
1207 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
, autoclose
);
1212 bool CAppUtils::PerformSwitch(CString ref
, bool bForce
/* false */, CString sNewBranch
/* CString() */, bool bBranchOverride
/* false */, BOOL bTrack
/* 2 */, bool autoClose
/* false */)
1219 if(!sNewBranch
.IsEmpty()){
1220 if (bBranchOverride
)
1222 branch
.Format(_T("-B %s"), sNewBranch
);
1226 branch
.Format(_T("-b %s"), sNewBranch
);
1229 track
= _T("--track");
1230 else if (bTrack
== FALSE
)
1231 track
= _T("--no-track");
1236 cmd
.Format(_T("git.exe checkout %s %s %s %s"),
1240 g_Git
.FixBranchName(ref
));
1242 CProgressDlg progress
;
1243 progress
.m_bAutoCloseOnSuccess
= autoClose
;
1244 progress
.m_GitCmd
= cmd
;
1246 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1247 if (gitPath
.HasSubmodules())
1248 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1250 INT_PTR ret
= progress
.DoModal();
1251 if (gitPath
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
1254 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1256 RunTortoiseGitProc(sCmd
);
1259 else if (ret
== IDOK
)
1265 bool CAppUtils::OpenIgnoreFile(CStdioFile
&file
, const CString
& filename
)
1267 if (!file
.Open(filename
, CFile::modeCreate
| CFile::modeReadWrite
| CFile::modeNoTruncate
))
1269 CMessageBox::Show(NULL
, filename
+ _T(" Open Failure"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1273 if (file
.GetLength() > 0)
1275 file
.Seek(file
.GetLength() - 1, 0);
1276 std::unique_ptr
<TCHAR
[]> buf(new TCHAR
[1]);
1277 file
.Read(buf
.get(), 1);
1279 if (buf
.get()[0] != _T('\n'))
1280 file
.WriteString(_T("\n"));
1288 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1290 CIgnoreDlg ignoreDlg
;
1291 if (ignoreDlg
.DoModal() == IDOK
)
1294 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\");
1296 switch (ignoreDlg
.m_IgnoreFile
)
1299 ignorefile
+= _T(".gitignore");
1302 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, ignorefile
);
1303 ignorefile
+= _T("info/exclude");
1310 if (ignoreDlg
.m_IgnoreFile
!= 1 && !OpenIgnoreFile(file
, ignorefile
))
1313 for (int i
= 0; i
< path
.GetCount(); ++i
)
1315 if (ignoreDlg
.m_IgnoreFile
== 1)
1317 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\") + path
[i
].GetContainingDirectory().GetWinPathString() + _T("\\.gitignore");
1318 if (!OpenIgnoreFile(file
, ignorefile
))
1322 CString ignorePattern
;
1323 if (ignoreDlg
.m_IgnoreType
== 0)
1325 if (ignoreDlg
.m_IgnoreFile
!= 1 && !path
[i
].GetContainingDirectory().GetGitPathString().IsEmpty())
1326 ignorePattern
+= _T("/") + path
[i
].GetContainingDirectory().GetGitPathString();
1328 ignorePattern
+= _T("/");
1332 ignorePattern
+= _T("*") + path
[i
].GetFileExtension();
1336 ignorePattern
+= path
[i
].GetFileOrDirectoryName();
1339 // escape [ and ] so that files get ignored correctly
1340 ignorePattern
.Replace(_T("["), _T("\\["));
1341 ignorePattern
.Replace(_T("]"), _T("\\]"));
1343 ignorePattern
+= _T("\n");
1344 CStringA ignorePatternA
= CUnicodeUtils::GetUTF8(ignorePattern
);
1345 file
.Write(ignorePatternA
.GetBuffer(), ignorePatternA
.GetLength());
1346 ignorePatternA
.ReleaseBuffer();
1348 if (ignoreDlg
.m_IgnoreFile
== 1)
1352 if (ignoreDlg
.m_IgnoreFile
!= 1)
1367 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1370 dlg
.m_ResetType
=type
;
1371 dlg
.m_ResetToVersion
=*CommitHash
;
1372 dlg
.m_initialRefName
= *CommitHash
;
1373 if (dlg
.DoModal() == IDOK
)
1377 switch(dlg
.m_ResetType
)
1392 cmd
.Format(_T("git.exe reset %s %s"),type
, dlg
.m_ResetToVersion
);
1396 CProgressDlg progress
;
1397 progress
.m_GitCmd
=cmd
;
1399 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1400 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2)
1401 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1403 progress
.m_PostFailCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MSGBOX_RETRY
)));
1405 INT_PTR ret
= progress
.DoModal();
1406 if (progress
.m_GitStatus
== 0 && gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2 && ret
== IDC_PROGRESS_BUTTON1
)
1409 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1411 RunTortoiseGitProc(sCmd
);
1414 else if (progress
.m_GitStatus
!= 0 && ret
== IDC_PROGRESS_BUTTON1
)
1416 else if (ret
== IDOK
)
1425 void CAppUtils::DescribeFile(bool mode
, bool base
,CString
&descript
)
1429 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_DELETE
));
1434 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_MODIFIED
));
1437 descript
= CString(MAKEINTRESOURCE(IDS_PROC_CREATED
));
1441 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1443 CString tempmergefile
;
1446 tempmergefile
= CAppUtils::GetMergeTempFile(_T("LOCAL"),path
);
1447 CFile::Remove(tempmergefile
);
1454 tempmergefile
= CAppUtils::GetMergeTempFile(_T("REMOTE"),path
);
1455 CFile::Remove(tempmergefile
);
1462 tempmergefile
= CAppUtils::GetMergeTempFile(_T("BASE"),path
);
1463 CFile::Remove(tempmergefile
);
1468 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1471 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1476 bool ParseHashesFromLsFile(BYTE_VECTOR
&out
, CString
&hash1
, CString
&hash2
, CString
&hash3
)
1478 unsigned int pos
= 0;
1482 while (pos
>= 0 && pos
< out
.size())
1486 g_Git
.StringAppend(&one
, &out
[pos
], CP_UTF8
);
1488 one
.Tokenize(_T("\t"), tabstart
);
1491 part
= one
.Tokenize(_T(" "), tabstart
); //Tag
1492 part
= one
.Tokenize(_T(" "), tabstart
); //Mode
1493 part
= one
.Tokenize(_T(" "), tabstart
); //Hash
1494 CString hash
= part
;
1495 part
= one
.Tokenize(_T("\t"), tabstart
); //Stage
1496 int stage
= _ttol(part
);
1499 else if (stage
== 2)
1501 else if (stage
== 3)
1507 pos
= out
.findNextString(pos
);
1513 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool /*bAlternativeTool*/,bool revertTheirMy
)
1517 CTGitPath merge
=path
;
1518 CTGitPath directory
= merge
.GetDirectory();
1520 // we have the conflicted file (%merged)
1521 // now look for the other required files
1523 //stat.GetStatus(merge);
1524 //if (stat.status == NULL)
1530 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1532 if (g_Git
.Run(cmd
, &vector
))
1537 if (merge
.IsDirectory())
1539 CString baseHash
, localHash
, remoteHash
;
1540 if (!ParseHashesFromLsFile(vector
, baseHash
, localHash
, remoteHash
))
1544 msg
.Format(_T("BASE: %s\nLOCAL: %s\nREMOTE: %s"), baseHash
, localHash
, remoteHash
);
1545 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
);
1550 if (list
.ParserFromLsFile(vector
))
1552 CMessageBox::Show(NULL
, _T("Parse ls-files failed!"), _T("TortoiseGit"), MB_OK
);
1556 if(list
.GetCount() == 0)
1565 mine
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1566 theirs
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1570 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1571 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1573 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1577 //format=_T("git.exe cat-file blob \":%d:%s\"");
1578 format
= _T("git checkout-index --temp --stage=%d -- \"%s\"");
1580 //create a empty file, incase stage is not three
1581 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1583 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1585 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1588 bool b_base
=false, b_local
=false, b_remote
=false;
1590 for (int i
= 0; i
< list
.GetCount(); ++i
)
1597 if( list
[i
].m_Stage
== 1)
1599 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1601 outfile
= base
.GetWinPathString();
1604 if( list
[i
].m_Stage
== 2 )
1606 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1608 outfile
= mine
.GetWinPathString();
1611 if( list
[i
].m_Stage
== 3 )
1613 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1615 outfile
= theirs
.GetWinPathString();
1617 CString output
, err
;
1618 if(!outfile
.IsEmpty())
1619 if (!g_Git
.Run(cmd
, &output
, &err
, CP_UTF8
))
1623 file
= output
.Tokenize(_T("\t"), start
);
1624 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1628 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1632 if(b_local
&& b_remote
)
1634 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1636 bRet
= !!CAppUtils::StartExtMerge(base
, mine
, theirs
, merge
, _T("BASE"), _T("REMOTE"), _T("LOCAL"));
1638 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"), _T("REMOTE"), _T("LOCAL"));
1643 CFile::Remove(mine
.GetWinPathString());
1644 CFile::Remove(theirs
.GetWinPathString());
1645 CFile::Remove(base
.GetWinPathString());
1647 CDeleteConflictDlg dlg
;
1648 DescribeFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1649 DescribeFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1650 dlg
.m_bShowModifiedButton
=b_base
;
1651 dlg
.m_File
=merge
.GetGitPathString();
1652 if(dlg
.DoModal() == IDOK
)
1657 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1660 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1662 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1664 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1674 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1675 base
, theirs
, mine
, merge
);
1678 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1680 // we have a text conflict, use our merge tool to resolve the conflict
1682 CTSVNPath
theirs(directory
);
1683 CTSVNPath
mine(directory
);
1684 CTSVNPath
base(directory
);
1685 bool bConflictData
= false;
1687 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1689 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1690 bConflictData
= true;
1692 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1694 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1695 bConflictData
= true;
1697 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1699 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1700 bConflictData
= true;
1707 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1708 base
, theirs
, mine
, merge
);
1711 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1713 // we have a property conflict
1714 CTSVNPath
prej(directory
);
1715 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1717 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1718 // there's a problem: the prej file contains a _description_ of the conflict, and
1719 // that description string might be translated. That means we have no way of parsing
1720 // the file to find out the conflicting values.
1721 // The only thing we can do: show a dialog with the conflict description, then
1722 // let the user either accept the existing property or open the property edit dialog
1723 // to manually change the properties and values. And a button to mark the conflict as
1725 CEditPropConflictDlg dlg
;
1726 dlg
.SetPrejFile(prej
);
1727 dlg
.SetConflictedItem(merge
);
1728 bRet
= (dlg
.DoModal() != IDCANCEL
);
1732 if (stat
.status
->tree_conflict
)
1734 // we have a tree conflict
1736 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1739 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1741 CTSVNPath
theirs(directory
);
1742 CTSVNPath
mine(directory
);
1743 CTSVNPath
base(directory
);
1744 bool bConflictData
= false;
1746 if (pInfoData
->treeconflict_theirfile
)
1748 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1749 bConflictData
= true;
1751 if (pInfoData
->treeconflict_basefile
)
1753 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1754 bConflictData
= true;
1756 if (pInfoData
->treeconflict_myfile
)
1758 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1759 bConflictData
= true;
1766 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1767 base
, theirs
, mine
, merge
);
1769 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1771 CString sConflictAction
;
1772 CString sConflictReason
;
1773 CString sResolveTheirs
;
1774 CString sResolveMine
;
1775 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1776 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1778 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1780 switch (pInfoData
->treeconflict_operation
)
1782 case svn_wc_operation_update
:
1783 switch (pInfoData
->treeconflict_action
)
1785 case svn_wc_conflict_action_edit
:
1786 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1787 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1789 case svn_wc_conflict_action_add
:
1790 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1791 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1793 case svn_wc_conflict_action_delete
:
1794 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1795 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1799 case svn_wc_operation_switch
:
1800 switch (pInfoData
->treeconflict_action
)
1802 case svn_wc_conflict_action_edit
:
1803 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1804 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1806 case svn_wc_conflict_action_add
:
1807 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1808 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1810 case svn_wc_conflict_action_delete
:
1811 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1812 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1816 case svn_wc_operation_merge
:
1817 switch (pInfoData
->treeconflict_action
)
1819 case svn_wc_conflict_action_edit
:
1820 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1821 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1823 case svn_wc_conflict_action_add
:
1824 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1825 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1827 case svn_wc_conflict_action_delete
:
1828 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1829 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1835 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1837 switch (pInfoData
->treeconflict_operation
)
1839 case svn_wc_operation_update
:
1840 switch (pInfoData
->treeconflict_action
)
1842 case svn_wc_conflict_action_edit
:
1843 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1844 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1846 case svn_wc_conflict_action_add
:
1847 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1848 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1850 case svn_wc_conflict_action_delete
:
1851 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1852 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1856 case svn_wc_operation_switch
:
1857 switch (pInfoData
->treeconflict_action
)
1859 case svn_wc_conflict_action_edit
:
1860 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1861 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1863 case svn_wc_conflict_action_add
:
1864 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1865 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1867 case svn_wc_conflict_action_delete
:
1868 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1869 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1873 case svn_wc_operation_merge
:
1874 switch (pInfoData
->treeconflict_action
)
1876 case svn_wc_conflict_action_edit
:
1877 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1878 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1880 case svn_wc_conflict_action_add
:
1881 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1882 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1884 case svn_wc_conflict_action_delete
:
1885 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1886 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1894 switch (pInfoData
->treeconflict_reason
)
1896 case svn_wc_conflict_reason_edited
:
1897 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1898 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1900 case svn_wc_conflict_reason_obstructed
:
1901 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1902 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1904 case svn_wc_conflict_reason_deleted
:
1905 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1906 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1908 case svn_wc_conflict_reason_added
:
1909 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1910 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1912 case svn_wc_conflict_reason_missing
:
1913 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1914 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1916 case svn_wc_conflict_reason_unversioned
:
1917 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1918 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1921 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1923 CTreeConflictEditorDlg dlg
;
1924 dlg
.SetConflictInfoText(sConflictReason
);
1925 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1926 dlg
.SetPath(treeConflictPath
);
1927 INT_PTR dlgRet
= dlg
.DoModal();
1928 bRet
= (dlgRet
!= IDCANCEL
);
1936 bool CAppUtils::IsSSHPutty()
1938 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1939 sshclient
=sshclient
.MakeLower();
1940 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1947 CString
CAppUtils::GetClipboardLink()
1949 if (!OpenClipboard(NULL
))
1952 CString sClipboardText
;
1953 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1956 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1957 sClipboardText
= CString(lpstr
);
1960 hglb
= GetClipboardData(CF_UNICODETEXT
);
1963 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1964 sClipboardText
= lpstr
;
1969 if(!sClipboardText
.IsEmpty())
1971 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1972 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1974 if(sClipboardText
.Find( _T("http://")) == 0)
1975 return sClipboardText
;
1977 if(sClipboardText
.Find( _T("https://")) == 0)
1978 return sClipboardText
;
1980 if(sClipboardText
.Find( _T("git://")) == 0)
1981 return sClipboardText
;
1983 if(sClipboardText
.Find( _T("ssh://")) == 0)
1984 return sClipboardText
;
1986 if(sClipboardText
.GetLength()>=2)
1987 if( sClipboardText
[1] == _T(':') )
1988 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1989 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1990 return sClipboardText
;
1993 return CString(_T(""));
1996 CString
CAppUtils::ChooseRepository(CString
*path
)
1998 CBrowseFolder browseFolder
;
1999 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
2001 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
2002 CString strCloneDirectory
;
2004 strCloneDirectory
=*path
;
2007 strCloneDirectory
= regLastResopitory
;
2011 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
2013 browseFolder
.SetInfo(title
);
2015 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
2017 regLastResopitory
= strCloneDirectory
;
2018 return strCloneDirectory
;
2026 bool CAppUtils::SendPatchMail(CTGitPathList
&list
,bool autoclose
)
2030 dlg
.m_PathList
= list
;
2032 if(dlg
.DoModal()==IDOK
)
2034 if(dlg
.m_PathList
.GetCount() == 0)
2037 CGitProgressDlg progDlg
;
2039 theApp
.m_pMainWnd
= &progDlg
;
2040 progDlg
.SetCommand(CGitProgressList::GitProgress_SendMail
);
2042 progDlg
.SetAutoClose(autoclose
);
2044 progDlg
.SetPathList(dlg
.m_PathList
);
2045 //ProjectProperties props;
2046 //props.ReadPropsPathList(dlg.m_pathList);
2047 //progDlg.SetProjectProperties(props);
2048 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2050 CSendMailPatch
sendMailPatch(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
, !!dlg
.m_bUseMAPI
);
2051 progDlg
.SetSendMailOption(&sendMailPatch
);
2060 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
)
2063 CString log
=formatpatchoutput
;
2064 int start
=log
.Find(cmd
);
2066 CString one
=log
.Tokenize(_T("\n"),start
);
2072 CString one
=log
.Tokenize(_T("\n"),start
);
2074 if(one
.IsEmpty() || one
.Find(_T("Success")) == 0)
2076 one
.Replace(_T('/'),_T('\\'));
2078 path
.SetFromWin(one
);
2081 if (list
.GetCount() > 0)
2083 return SendPatchMail(list
, autoclose
);
2087 CMessageBox::Show(NULL
, IDS_ERR_NOPATCHES
, IDS_APPNAME
, MB_ICONINFORMATION
);
2093 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
2098 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
2099 if(output
.IsEmpty())
2101 output
= pGit
->GetConfigValue(_T("i18n.commitencoding"));
2102 if(output
.IsEmpty())
2106 output
=output
.Tokenize(_T("\n"),start
);
2107 return CUnicodeUtils::GetCPCode(output
);
2112 output
=output
.Tokenize(_T("\n"),start
);
2113 return CUnicodeUtils::GetCPCode(output
);
2116 int CAppUtils::GetCommitTemplate(CString
&temp
)
2120 output
= g_Git
.GetConfigValue(_T("commit.template"), CP_UTF8
);
2121 if( output
.IsEmpty() )
2124 if( output
.GetLength()<1)
2127 if( output
[0] == _T('/'))
2129 if(output
.GetLength()>=3)
2130 if(output
[2] == _T('/'))
2132 output
.GetBuffer()[0] = output
[1];
2133 output
.GetBuffer()[1] = _T(':');
2138 output
=output
.Tokenize(_T("\n"),start
);
2140 output
.Replace(_T('/'),_T('\\'));
2144 CStdioFile
file(output
,CFile::modeRead
|CFile::typeText
);
2146 while(file
.ReadString(str
))
2157 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
2159 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
2163 output
= g_Git
.GetConfigValue(_T("i18n.commitencoding"));
2164 if(output
.IsEmpty())
2168 output
=output
.Tokenize(_T("\n"),start
);
2169 cp
=CUnicodeUtils::GetCPCode(output
);
2171 int len
=message
.GetLength();
2173 std::unique_ptr
<char[]> buf(new char[len
* 4 + 4]);
2174 SecureZeroMemory(buf
.get(), len
* 4 + 4);
2176 int lengthIncTerminator
= WideCharToMultiByte(cp
, 0, message
, -1, buf
.get(), len
* 4, NULL
, NULL
);
2178 file
.Write(buf
.get(), lengthIncTerminator
- 1);
2183 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
, bool autoClose
)
2186 dlg
.m_PreSelectRemote
= remoteName
;
2187 dlg
.m_bAllowRebase
= allowRebase
;
2190 if(dlg
.DoModal()==IDOK
)
2194 if (dlg
.m_bAllRemotes
)
2197 g_Git
.GetRemoteList(list
);
2199 STRING_VECTOR::const_iterator it
= list
.begin();
2200 while (it
!= list
.end())
2202 CString
remote(*it
);
2203 CAppUtils::LaunchPAgent(NULL
, &remote
);
2208 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
2212 url
=dlg
.m_RemoteURL
;
2216 int ver
= CAppUtils::GetMsysgitVersion();
2218 if(ver
>= 0x01070203) //above 1.7.0.2
2219 arg
= _T("--progress ");
2222 arg
+= _T("--prune ");
2225 if (dlg
.m_bFetchTags
== 1)
2227 arg
+= _T("--tags ");
2229 else if (dlg
.m_bFetchTags
== 0)
2231 arg
+= _T("--no-tags ");
2234 if (dlg
.m_bAllRemotes
)
2235 cmd
.Format(_T("git.exe fetch --all -v %s"), arg
);
2237 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"), arg
, url
, dlg
.m_RemoteBranchName
);
2239 CProgressDlg progress
;
2241 progress
.m_bAutoCloseOnSuccess
= autoClose
;
2243 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2244 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_RESET
)));
2246 if(!dlg
.m_bRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
2248 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2251 progress
.m_GitCmd
=cmd
;
2252 INT_PTR userResponse
;
2254 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
2256 CGitProgressDlg gitdlg
;
2257 if (!dlg
.m_bAllRemotes
)
2259 gitdlg
.SetCommand(CGitProgressList::GitProgress_Fetch
);
2260 gitdlg
.SetAutoTag(dlg
.m_bFetchTags
? GIT_REMOTE_DOWNLOAD_TAGS_ALL
: GIT_REMOTE_DOWNLOAD_TAGS_NONE
);
2261 if (!dlg
.m_bAllRemotes
)
2262 gitdlg
.SetRefSpec(dlg
.m_RemoteBranchName
);
2263 userResponse
= gitdlg
.DoModal();
2267 userResponse
= progress
.DoModal();
2269 if (userResponse
== IDC_PROGRESS_BUTTON1
)
2271 CString cmd
= _T("/command:log");
2272 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2273 RunTortoiseGitProc(cmd
);
2276 else if (userResponse
== IDC_PROGRESS_BUTTON1
+ 1)
2278 CString currentBranch
= g_Git
.GetSymbolicRef();
2280 configName
.Format(_T("branch.%s.remote"), currentBranch
);
2281 CString pullRemote
= g_Git
.GetConfigValue(configName
);
2283 //Select pull-branch from current branch
2284 configName
.Format(_T("branch.%s.merge"), currentBranch
);
2285 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
2287 CString defaultUpstream
;
2288 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
2289 defaultUpstream
.Format(_T("remotes/%s/%s"), pullRemote
, pullBranch
);
2290 GitReset(&defaultUpstream
, 2);
2293 else if ((userResponse
== IDC_PROGRESS_BUTTON1
+ 2) || (progress
.m_GitStatus
== 0 && dlg
.m_bRebase
))
2298 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2299 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUDESSENDMAIL
)));
2300 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2301 INT_PTR response
= dlg
.DoModal();
2302 if(response
== IDOK
)
2306 else if (response
== IDC_REBASE_POST_BUTTON
)
2308 CString cmd
= _T("/command:log");
2309 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2310 RunTortoiseGitProc(cmd
);
2313 else if (response
== IDC_REBASE_POST_BUTTON
+ 1)
2315 CString cmd
, out
, err
;
2316 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2318 g_Git
.FixBranchName(dlg
.m_Upstream
),
2319 g_Git
.FixBranchName(dlg
.m_Branch
));
2320 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
2322 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2326 CAppUtils::SendPatchMail(cmd
,out
);
2329 else if (response
== IDC_REBASE_POST_BUTTON
+ 2)
2331 else if(response
== IDCANCEL
)
2336 else if (userResponse
!= IDCANCEL
)
2342 bool CAppUtils::Push(CString selectLocalBranch
, bool autoClose
)
2345 dlg
.m_BranchSourceName
= selectLocalBranch
;
2347 DWORD exitcode
= 0xFFFFFFFF;
2349 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
2350 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
2355 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2356 //ReportError(temp);
2357 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2362 if(dlg
.DoModal()==IDOK
)
2367 arg
+= _T("--thin ");
2368 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2369 arg
+= _T("--tags ");
2371 arg
+= _T("--force ");
2372 if (dlg
.m_bSetUpstream
)
2373 arg
+= _T("--set-upstream ");
2374 if (dlg
.m_RecurseSubmodules
== 1)
2375 arg
+= _T("--recurse-submodules=check ");
2376 if (dlg
.m_RecurseSubmodules
== 2)
2377 arg
+= _T("--recurse-submodules=on-demand ");
2379 int ver
= CAppUtils::GetMsysgitVersion();
2381 if(ver
>= 0x01070203) //above 1.7.0.2
2382 arg
+= _T("--progress ");
2384 CProgressDlg progress
;
2385 progress
.m_bAutoCloseOnSuccess
=autoClose
;
2387 STRING_VECTOR remotesList
;
2388 if (dlg
.m_bPushAllRemotes
)
2389 g_Git
.GetRemoteList(remotesList
);
2391 remotesList
.push_back(dlg
.m_URL
);
2393 for (unsigned int i
= 0; i
< remotesList
.size(); ++i
)
2395 if (dlg
.m_bAutoLoad
)
2396 CAppUtils::LaunchPAgent(NULL
, &remotesList
[i
]);
2399 if (dlg
.m_bPushAllBranches
)
2401 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2407 progress
.m_GitCmdList
.push_back(cmd
);
2408 cmd
.Format(_T("git.exe push --tags %s \"%s\""), arg
, remotesList
[i
]);
2413 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2416 dlg
.m_BranchSourceName
);
2417 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2419 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2422 progress
.m_GitCmdList
.push_back(cmd
);
2425 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REQUESTPULL
)));
2426 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2427 INT_PTR ret
= progress
.DoModal();
2429 if(!progress
.m_GitStatus
)
2431 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2436 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2437 //ReportError(temp);
2438 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2442 if(ret
== IDC_PROGRESS_BUTTON1
)
2444 RequestPull(dlg
.m_BranchRemoteName
);
2446 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2457 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2459 CRequestPullDlg dlg
;
2460 dlg
.m_RepositoryURL
= repositoryUrl
;
2461 dlg
.m_EndRevision
= endrevision
;
2462 if (dlg
.DoModal()==IDOK
)
2465 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2467 CSysProgressDlg sysProgressDlg
;
2468 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2469 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CREATINGPULLREUQEST
)));
2470 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2471 sysProgressDlg
.SetShowProgressBar(false);
2472 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2474 CString tempFileName
= GetTempFile();
2475 DeleteFile(tempFileName
);
2476 CreateDirectory(tempFileName
, NULL
);
2477 tempFileName
+= _T("\\pullrequest.txt");
2478 if (g_Git
.RunLogFile(cmd
, tempFileName
))
2480 CMessageBox::Show(NULL
, IDS_ERR_PULLREUQESTFAILED
, IDS_APPNAME
, MB_OK
);
2484 if (sysProgressDlg
.HasUserCancelled())
2486 CMessageBox::Show(NULL
, IDS_SVN_USERCANCELLED
, IDS_APPNAME
, MB_OK
);
2487 ::DeleteFile(tempFileName
);
2491 sysProgressDlg
.Stop();
2493 if (dlg
.m_bSendMail
)
2496 dlg
.m_PathList
= CTGitPathList(CTGitPath(tempFileName
));
2497 dlg
.m_bCustomSubject
= true;
2499 if (dlg
.DoModal() == IDOK
)
2501 if(dlg
.m_PathList
.GetCount() == 0)
2504 CGitProgressDlg progDlg
;
2506 theApp
.m_pMainWnd
= &progDlg
;
2507 progDlg
.SetCommand(CGitProgressList::GitProgress_SendMail
);
2509 progDlg
.SetPathList(dlg
.m_PathList
);
2510 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2512 CSendMailCombineable
sendMailCombineable(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
, !!dlg
.m_bUseMAPI
);
2513 progDlg
.SetSendMailOption(&sendMailCombineable
);
2522 CAppUtils::LaunchAlternativeEditor(tempFileName
);
2527 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2529 CString
strDir(szPath
);
2530 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2532 strDir
.AppendChar(_T('\\'));
2534 std::vector
<CString
> vPath
;
2536 bool bSuccess
= false;
2538 for (int i
=0;i
<strDir
.GetLength();++i
)
2540 if (strDir
.GetAt(i
) != _T('\\'))
2542 strTemp
.AppendChar(strDir
.GetAt(i
));
2546 vPath
.push_back(strTemp
);
2547 strTemp
.AppendChar(_T('\\'));
2551 for (auto vIter
= vPath
.begin(); vIter
!= vPath
.end(); ++vIter
)
2553 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2559 void CAppUtils::RemoveTrailSlash(CString
&path
)
2564 // For URL, do not trim the slash just after the host name component.
2565 int index
= path
.Find(_T("://"));
2569 index
= path
.Find(_T('/'), index
);
2570 if (index
== path
.GetLength() - 1)
2574 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2576 path
=path
.Left(path
.GetLength()-1);
2582 bool CAppUtils::CheckUserData()
2584 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
2586 if(CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
2588 CTGitPath
path(g_Git
.m_CurrentDir
);
2589 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2590 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2591 dlg
.SetTreeWidth(220);
2592 dlg
.m_DefaultPage
= _T("gitconfig");
2595 dlg
.HandleRestart();
2605 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2606 CTGitPathList
&pathList
,
2607 CTGitPathList
&selectedList
,
2608 bool bSelectFilesForCommit
,
2611 bool bFailed
= true;
2613 if (!CheckUserData())
2620 dlg
.m_sBugID
= bugid
;
2622 dlg
.m_bWholeProject
= bWholeProject
;
2624 dlg
.m_sLogMessage
= sLogMsg
;
2625 dlg
.m_pathList
= pathList
;
2626 dlg
.m_checkedPathList
= selectedList
;
2627 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2628 dlg
.m_bAutoClose
= autoClose
;
2629 if (dlg
.DoModal() == IDOK
)
2631 if (dlg
.m_pathList
.GetCount()==0)
2633 // if the user hasn't changed the list of selected items
2634 // we don't use that list. Because if we would use the list
2635 // of pre-checked items, the dialog would show different
2636 // checked items on the next startup: it would only try
2637 // to check the parent folder (which might not even show)
2638 // instead, we simply use an empty list and let the
2639 // default checking do its job.
2640 if (!dlg
.m_pathList
.IsEqual(pathList
))
2641 selectedList
= dlg
.m_pathList
;
2642 pathList
= dlg
.m_updatedPathList
;
2643 sLogMsg
= dlg
.m_sLogMessage
;
2644 bSelectFilesForCommit
= true;
2646 if( dlg
.m_bPushAfterCommit
)
2648 switch(dlg
.m_PostCmd
)
2650 case GIT_POST_CMD_DCOMMIT
:
2651 CAppUtils::SVNDCommit();
2657 else if (dlg
.m_bCreateTagAfterCommit
)
2659 CAppUtils::CreateBranchTag(TRUE
);
2662 // CGitProgressDlg progDlg;
2663 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2664 // if (parser.HasVal(_T("closeonend")))
2665 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2666 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2667 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2668 // progDlg.SetPathList(dlg.m_pathList);
2669 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2670 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2671 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2672 // progDlg.SetItemCount(dlg.m_itemsCount);
2673 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2674 // progDlg.DoModal();
2675 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2676 // err = (DWORD)progDlg.DidErrorsOccur();
2677 // bFailed = progDlg.DidErrorsOccur();
2678 // bRet = progDlg.DidErrorsOccur();
2679 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2680 // if (DWORD(bFailRepeat)==0)
2681 // bFailed = false; // do not repeat if the user chose not to in the settings.
2688 BOOL
CAppUtils::SVNDCommit()
2690 CSVNDCommitDlg dcommitdlg
;
2691 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2692 if (gitSetting
== _T("")) {
2693 if (dcommitdlg
.DoModal() != IDOK
)
2699 if (dcommitdlg
.m_remember
)
2701 if (dcommitdlg
.m_rmdir
)
2703 gitSetting
= _T("true");
2707 gitSetting
= _T("false");
2709 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2712 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, _T("svn.rmdir"), gitSetting
);
2713 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2719 BOOL IsStash
= false;
2720 if(!g_Git
.CheckCleanWorkTree())
2722 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
2724 CSysProgressDlg sysProgressDlg
;
2725 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2726 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2727 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2728 sysProgressDlg
.SetShowProgressBar(false);
2729 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2730 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2733 cmd
=_T("git.exe stash");
2734 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2736 sysProgressDlg
.Stop();
2737 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2740 sysProgressDlg
.Stop();
2750 CProgressDlg progress
;
2751 if (dcommitdlg
.m_rmdir
)
2753 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2757 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2759 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2763 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2765 CSysProgressDlg sysProgressDlg
;
2766 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2767 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2768 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2769 sysProgressDlg
.SetShowProgressBar(false);
2770 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2771 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2774 cmd
=_T("git.exe stash pop");
2775 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2777 sysProgressDlg
.Stop();
2778 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2781 sysProgressDlg
.Stop();
2793 static void MergeCallback(CProgressDlg
*dlg
, void * /*caller*/, int result
)
2797 dlg
->m_PostCmdList
.RemoveAll();
2800 if (!g_Git
.ListConflictFile(list
) && list
.GetCount() > 0)
2802 // there are conflict files
2803 dlg
->m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE
)));
2808 BOOL
CAppUtils::Merge(CString
*commit
)
2810 if (!CheckUserData())
2815 dlg
.m_initialRefName
= *commit
;
2817 if(dlg
.DoModal()==IDOK
)
2823 args
+= _T(" --no-ff");
2826 args
+= _T(" --squash");
2829 args
+= _T(" --no-commit");
2834 fmt
.Format(_T(" --log=%d"), dlg
.m_nLog
);
2838 if (!dlg
.m_MergeStrategy
.IsEmpty())
2840 args
+= _T(" --strategy=") + dlg
.m_MergeStrategy
;
2841 if (!dlg
.m_StrategyOption
.IsEmpty())
2843 args
+= _T(" --strategy-option=") + dlg
.m_StrategyOption
;
2844 if (!dlg
.m_StrategyParam
.IsEmpty())
2845 args
+= _T("=") + dlg
.m_StrategyParam
;
2849 if(!dlg
.m_strLogMesage
.IsEmpty())
2851 CString logmsg
= dlg
.m_strLogMesage
;
2852 logmsg
.Replace(_T("\""), _T("\\\""));
2853 args
+= _T(" -m \"") + logmsg
+ _T("\"");
2855 cmd
.Format(_T("git.exe merge %s %s"), args
, g_Git
.FixBranchName(dlg
.m_VersionName
));
2857 CProgressDlg Prodlg
;
2858 Prodlg
.m_GitCmd
= cmd
;
2860 if (dlg
.m_bNoCommit
)
2861 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUCOMMIT
)));
2862 else if (dlg
.m_bIsBranch
)
2863 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REMOVEBRANCH
)));
2865 Prodlg
.m_PostCmdCallback
= MergeCallback
;
2867 INT_PTR ret
= Prodlg
.DoModal();
2868 if (Prodlg
.m_GitStatus
!= 0 && ret
== IDC_PROGRESS_BUTTON1
)
2870 CTGitPathList pathlist
;
2871 CTGitPathList selectedlist
;
2872 pathlist
.AddPath(g_Git
.m_CurrentDir
);
2873 bool bSelectFilesForCommit
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
2875 CAppUtils::Commit(CString(), false, str
, pathlist
, selectedlist
, bSelectFilesForCommit
);
2877 else if (ret
== IDC_PROGRESS_BUTTON1
)
2879 if (dlg
.m_bNoCommit
)
2882 CTGitPathList pathList
;
2883 CTGitPathList selectedList
;
2884 return Commit(_T(""), TRUE
, sLogMsg
, pathList
, selectedList
, true);
2886 else if (dlg
.m_bIsBranch
)
2889 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, dlg
.m_VersionName
);
2890 if (CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
2893 cmd
.Format(_T("git.exe branch -D -- %s"), dlg
.m_VersionName
);
2894 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2895 MessageBox(NULL
, out
, _T("TortoiseGit"), MB_OK
);
2900 return !Prodlg
.m_GitStatus
;
2905 void CAppUtils::EditNote(GitRev
*rev
)
2907 if (!CheckUserData())
2911 dlg
.m_sHintText
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2912 dlg
.m_sInputText
= rev
->m_Notes
;
2913 dlg
.m_sTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2914 //dlg.m_pProjectProperties = &m_ProjectProperties;
2915 dlg
.m_bUseLogWidth
= true;
2916 if(dlg
.DoModal() == IDOK
)
2919 cmd
=_T("notes add -f -F \"");
2921 CString tempfile
=::GetTempFile();
2922 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
2925 cmd
+= rev
->m_CommitHash
.ToString();
2929 if (git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2931 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2936 rev
->m_Notes
= dlg
.m_sInputText
;
2940 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2942 CFile::Remove(tempfile
);
2947 int CAppUtils::GetMsysgitVersion(CString
*versionstr
)
2950 CString versiondebug
;
2953 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
2954 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
2956 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
2959 if(!g_Git
.GetFileModifyTime(gitpath
, &time
) && !versionstr
)
2961 if((DWORD
)time
== regTime
)
2968 version
= *versionstr
;
2972 cmd
= _T("git.exe --version");
2973 if (g_Git
.Run(cmd
, &version
, &err
, CP_UTF8
))
2975 CMessageBox::Show(NULL
, _T("git.exe not correctly set up (") + err
+ _T(")\nCheck TortoiseGit settings and consult help file for \"Git.exe Path\"."), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2983 versiondebug
= version
;
2987 CString str
=version
.Tokenize(_T("."), start
);
2988 int space
= str
.ReverseFind(_T(' '));
2989 str
= str
.Mid(space
+1,start
);
2993 version
= version
.Mid(start
);
2996 str
= version
.Tokenize(_T("."), start
);
2998 ver
|= (_ttol(str
) & 0xFF) << 16;
3000 str
= version
.Tokenize(_T("."), start
);
3001 ver
|= (_ttol(str
) & 0xFF) << 8;
3003 str
= version
.Tokenize(_T("."), start
);
3004 ver
|= (_ttol(str
) & 0xFF);
3010 CMessageBox::Show(NULL
, _T("Could not parse git.exe version number: \"") + versiondebug
+ _T("\""), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
3015 regTime
= time
&0xFFFFFFFF;
3021 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
3023 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
3025 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("Shell32.dll"));
3027 if (hShell
.IsValid()) {
3028 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
3030 IPropertyStore
*pps
;
3031 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
3032 if (SUCCEEDED(hr
)) {
3035 var
.boolVal
= VARIANT_TRUE
;
3036 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
3043 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
3045 ASSERT(dialogname
.GetLength() < 70);
3046 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
3047 WCHAR pathbuf
[MAX_PATH
] = {0};
3049 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
3051 wcscat_s(pathbuf
, L
" - ");
3052 wcscat_s(pathbuf
, dialogname
);
3053 wcscat_s(pathbuf
, L
" - ");
3054 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3055 SetWindowText(hWnd
, pathbuf
);
3058 bool CAppUtils::BisectStart(CString lastGood
, CString firstBad
, bool autoClose
)
3060 if (!g_Git
.CheckCleanWorkTree())
3062 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
3064 CSysProgressDlg sysProgressDlg
;
3065 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3066 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
3067 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
3068 sysProgressDlg
.SetShowProgressBar(false);
3069 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
3070 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
3073 cmd
= _T("git.exe stash");
3074 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3076 sysProgressDlg
.Stop();
3077 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
);
3080 sysProgressDlg
.Stop();
3086 CBisectStartDlg bisectStartDlg
;
3088 if (!lastGood
.IsEmpty())
3089 bisectStartDlg
.m_sLastGood
= lastGood
;
3090 if (!firstBad
.IsEmpty())
3091 bisectStartDlg
.m_sFirstBad
= firstBad
;
3093 if (bisectStartDlg
.DoModal() == IDOK
)
3095 CProgressDlg progress
;
3096 theApp
.m_pMainWnd
= &progress
;
3097 progress
.m_bAutoCloseOnSuccess
= autoClose
;
3098 progress
.m_GitCmdList
.push_back(_T("git.exe bisect start"));
3099 progress
.m_GitCmdList
.push_back(_T("git.exe bisect good ") + bisectStartDlg
.m_LastGoodRevision
);
3100 progress
.m_GitCmdList
.push_back(_T("git.exe bisect bad ") + bisectStartDlg
.m_FirstBadRevision
);
3102 CTGitPath
path(g_Git
.m_CurrentDir
);
3104 if (path
.HasSubmodules())
3105 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
3107 INT_PTR ret
= progress
.DoModal();
3108 if (path
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
3111 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
3113 CAppUtils::RunTortoiseGitProc(sCmd
);
3116 else if (ret
== IDOK
)
3123 int CAppUtils::Git2GetUserPassword(git_cred
**out
, const char *url
, const char *username_from_url
, unsigned int /*allowed_types*/, void * /*payload*/)
3126 dlg
.m_URL
= CUnicodeUtils::GetUnicode(url
, CP_UTF8
);
3127 if (username_from_url
)
3128 dlg
.m_UserName
= CUnicodeUtils::GetUnicode(username_from_url
, CP_UTF8
);
3130 CStringA username
, password
;
3131 if (dlg
.DoModal() == IDOK
)
3133 username
= CUnicodeUtils::GetMulti(dlg
.m_UserName
, CP_UTF8
);
3134 password
= CUnicodeUtils::GetMulti(dlg
.m_Password
, CP_UTF8
);
3135 return git_cred_userpass_plaintext_new(out
, username
, password
);