1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - TortoiseGit
4 // Copyright (C) 2003-2011, 2013-2014 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "TortoiseProc.h"
22 #include "PathUtils.h"
24 #include "StringUtils.h"
25 #include "MessageBox.h"
29 #include "UnicodeUtils.h"
30 #include "ExportDlg.h"
31 #include "ProgressDlg.h"
32 #include "GitAdminDir.h"
33 #include "ProgressDlg.h"
34 #include "BrowseFolder.h"
35 #include "DirFileEnum.h"
36 #include "MessageBox.h"
37 #include "GitStatus.h"
38 #include "CreateBranchTagDlg.h"
39 #include "GitSwitchDlg.h"
41 #include "DeleteConflictDlg.h"
42 #include "ChangedDlg.h"
43 #include "SendMailDlg.h"
44 #include "GitProgressDlg.h"
46 #include "CommitDlg.h"
48 #include "MergeAbortDlg.h"
50 #include "..\Settings\Settings.h"
52 #include "SVNDCommitDlg.h"
53 #include "requestpulldlg.h"
54 #include "PullFetchDlg.h"
55 #include "FileDiffDlg.h"
56 #include "RebaseDlg.h"
58 #include "StashSave.h"
59 #include "IgnoreDlg.h"
60 #include "FormatMessageWrapper.h"
61 #include "SmartHandle.h"
62 #include "BisectStartDlg.h"
63 #include "SysProgressDlg.h"
64 #include "UserPassword.h"
67 #include "ProgressCommands/ResetProgressCommand.h"
68 #include "ProgressCommands/FetchProgressCommand.h"
69 #include "ProgressCommands/SendMailProgressCommand.h"
70 #include "CertificateValidationHelper.h"
71 #include "CheckCertificateDlg.h"
72 #include "SubmoduleResolveConflictDlg.h"
74 #include "../TGitCache/CacheInterface.h"
76 static struct last_accepted_cert
{
89 boolean
cmp(git_cert_x509
* cert
)
91 return len
> 0 && len
== cert
->len
&& memcmp(data
, cert
->data
, len
) == 0;
93 void set(git_cert_x509
* cert
)
102 data
= new BYTE
[len
];
103 memcpy(data
, cert
->data
, len
);
105 } last_accepted_cert
;
107 static bool DoFetch(const CString
& url
, const bool fetchAllRemotes
, const bool loadPuttyAgent
, const int prune
, const bool bDepth
, const int nDepth
, const int fetchTags
, const CString
& remoteBranch
, boolean runRebase
);
109 CAppUtils::CAppUtils(void)
113 CAppUtils::~CAppUtils(void)
117 bool CAppUtils::StashSave(const CString
& msg
, bool showPull
, bool pullShowPush
, bool showMerge
, const CString
& mergeRev
)
120 dlg
.m_sMessage
= msg
;
121 if (dlg
.DoModal() == IDOK
)
124 cmd
= _T("git.exe stash save");
126 if (CAppUtils::GetMsysgitVersion() >= 0x01070700)
128 if (dlg
.m_bIncludeUntracked
)
129 cmd
+= _T(" --include-untracked");
134 if (!dlg
.m_sMessage
.IsEmpty())
136 CString message
= dlg
.m_sMessage
;
137 message
.Replace(_T("\""), _T("\"\""));
138 cmd
+= _T(" -- \"") + message
+ _T("\"");
141 CProgressDlg progress
;
142 progress
.m_GitCmd
= cmd
;
143 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
149 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUPULL
, [&]{ CAppUtils::Pull(pullShowPush
, true); }));
151 postCmdList
.push_back(PostCmd(IDI_MERGE
, IDS_MENUMERGE
, [&]{ CAppUtils::Merge(&mergeRev
, true); }));
153 return (progress
.DoModal() == IDOK
);
158 bool CAppUtils::StashApply(CString ref
, bool showChanges
/* true */)
161 cmd
= _T("git.exe stash apply ");
162 if (ref
.Find(_T("refs/")) == 0)
164 if (ref
.Find(_T("stash{")) == 0)
165 ref
= _T("stash@") + ref
.Mid(5);
168 CSysProgressDlg sysProgressDlg
;
169 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
170 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
171 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
172 sysProgressDlg
.SetShowProgressBar(false);
173 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
174 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
176 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
178 sysProgressDlg
.Stop();
180 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
181 if (ret
&& !(ret
== 1 && hasConflicts
))
183 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHAPPLYFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
188 message
.LoadString(IDS_PROC_STASHAPPLYSUCCESS
);
190 message
.LoadString(IDS_PROC_STASHAPPLYFAILEDCONFLICTS
);
193 if(CMessageBox::Show(NULL
,message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
))
194 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
197 dlg
.m_pathList
.AddPath(CTGitPath());
204 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
211 bool CAppUtils::StashPop(bool showChanges
/* true */)
214 cmd
=_T("git.exe stash pop ");
216 CSysProgressDlg sysProgressDlg
;
217 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
218 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
219 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
220 sysProgressDlg
.SetShowProgressBar(false);
221 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
222 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
224 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
226 sysProgressDlg
.Stop();
228 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
229 if (ret
&& !(ret
== 1 && hasConflicts
))
231 CMessageBox::Show(NULL
,CString(MAKEINTRESOURCE(IDS_PROC_STASHPOPFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
236 message
.LoadString(IDS_PROC_STASHPOPSUCCESS
);
238 message
.LoadString(IDS_PROC_STASHPOPFAILEDCONFLICTS
);
241 if(CMessageBox::Show(NULL
,CString(message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
)))
242 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
245 dlg
.m_pathList
.AddPath(CTGitPath());
252 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
259 BOOL
CAppUtils::StartExtMerge(
260 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
261 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
,
262 HWND resolveMsgHwnd
, bool bDeleteBaseTheirsMineOnClose
)
265 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
266 CString ext
= mergedfile
.GetFileExtension();
267 CString com
= regCom
;
268 bool bInternal
= false;
272 // is there an extension specific merge tool?
273 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
274 if (!CString(mergetool
).IsEmpty())
279 // is there a filename specific merge tool?
280 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\.") + mergedfile
.GetFilename().MakeLower());
281 if (!CString(mergetool
).IsEmpty())
286 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
288 // Maybe we should use TortoiseIDiff?
289 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
290 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
291 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
292 (ext
== _T(".tif")) || (ext
== _T(".tiff")) ||
293 (ext
== _T(".dib")) || (ext
== _T(".emf")) ||
296 com
= CPathUtils::GetAppDirectory() + _T("TortoiseGitIDiff.exe");
297 com
= _T("\"") + com
+ _T("\"");
298 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /result:%merged");
299 com
= com
+ _T(" /basetitle:%bname /theirstitle:%tname /minetitle:%yname");
303 // use TortoiseGitMerge
305 com
= CPathUtils::GetAppDirectory() + _T("TortoiseGitMerge.exe");
306 com
= _T("\"") + com
+ _T("\"");
307 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
308 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
309 com
+= _T(" /saverequired");
313 s
.Format(L
" /resolvemsghwnd:%I64d", (__int64
)resolveMsgHwnd
);
316 if (bDeleteBaseTheirsMineOnClose
)
317 com
+= _T(" /deletebasetheirsmineonclose");
319 if (!g_sGroupingUUID
.IsEmpty())
321 com
+= L
" /groupuuid:\"";
322 com
+= g_sGroupingUUID
;
326 // check if the params are set. If not, just add the files to the command line
327 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
329 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
330 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
331 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
332 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
334 if (basefile
.IsEmpty())
336 com
.Replace(_T("/base:%base"), _T(""));
337 com
.Replace(_T("%base"), _T(""));
340 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
341 if (theirfile
.IsEmpty())
343 com
.Replace(_T("/theirs:%theirs"), _T(""));
344 com
.Replace(_T("%theirs"), _T(""));
347 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
348 if (yourfile
.IsEmpty())
350 com
.Replace(_T("/mine:%mine"), _T(""));
351 com
.Replace(_T("%mine"), _T(""));
354 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
355 if (mergedfile
.IsEmpty())
357 com
.Replace(_T("/merged:%merged"), _T(""));
358 com
.Replace(_T("%merged"), _T(""));
361 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
362 if (basename
.IsEmpty())
364 if (basefile
.IsEmpty())
366 com
.Replace(_T("/basename:%bname"), _T(""));
367 com
.Replace(_T("%bname"), _T(""));
371 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
375 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
376 if (theirname
.IsEmpty())
378 if (theirfile
.IsEmpty())
380 com
.Replace(_T("/theirsname:%tname"), _T(""));
381 com
.Replace(_T("%tname"), _T(""));
385 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
389 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
390 if (yourname
.IsEmpty())
392 if (yourfile
.IsEmpty())
394 com
.Replace(_T("/minename:%yname"), _T(""));
395 com
.Replace(_T("%yname"), _T(""));
399 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
403 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
404 if (mergedname
.IsEmpty())
406 if (mergedfile
.IsEmpty())
408 com
.Replace(_T("/mergedname:%mname"), _T(""));
409 com
.Replace(_T("%mname"), _T(""));
413 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
417 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
419 if ((bReadOnly
)&&(bInternal
))
420 com
+= _T(" /readonly");
422 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
430 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
433 // use TortoiseGitMerge
434 viewer
= CPathUtils::GetAppDirectory();
435 viewer
+= _T("TortoiseGitMerge.exe");
437 viewer
= _T("\"") + viewer
+ _T("\"");
438 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
439 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
441 viewer
+= _T(" /reversedpatch");
442 if (!sOriginalDescription
.IsEmpty())
443 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
444 if (!sPatchedDescription
.IsEmpty())
445 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
446 if (!g_sGroupingUUID
.IsEmpty())
448 viewer
+= L
" /groupuuid:\"";
449 viewer
+= g_sGroupingUUID
;
452 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
459 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
461 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file2
.GetFilename().MakeLower());
462 if (!difftool
.IsEmpty())
464 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file1
.GetFilename().MakeLower());
465 if (!difftool
.IsEmpty())
468 // Is there an extension specific diff tool?
469 CString ext
= file2
.GetFileExtension().MakeLower();
472 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
473 if (!difftool
.IsEmpty())
475 // Maybe we should use TortoiseIDiff?
476 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
477 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
478 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
479 (ext
== _T(".tif")) || (ext
== _T(".tiff")) ||
480 (ext
== _T(".dib")) || (ext
== _T(".emf")) ||
484 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitIDiff.exe") + _T("\"") +
485 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname") +
486 L
" /groupuuid:\"" + g_sGroupingUUID
+ L
"\"";
490 // Finally, pick a generic external diff tool
491 difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
495 bool CAppUtils::StartExtDiff(
496 const CString
& file1
, const CString
& file2
,
497 const CString
& sName1
, const CString
& sName2
,
498 const CString
& originalFile1
, const CString
& originalFile2
,
499 const git_revnum_t
& hash1
, const git_revnum_t
& hash2
,
500 const DiffFlags
& flags
, int jumpToLine
)
504 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
505 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
507 viewer
= PickDiffTool(file1
, file2
);
508 // If registry entry for a diff program is commented out, use TortoiseGitMerge.
509 bool bCommentedOut
= viewer
.Left(1) == _T("#");
510 if (flags
.bAlternativeTool
)
512 // Invert external vs. internal diff tool selection.
514 viewer
.Delete(0); // uncomment
518 else if (bCommentedOut
)
522 bool bInternal
= viewer
.IsEmpty();
526 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitMerge.exe") + _T("\"") +
527 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname") +
528 _T(" /basereflectedname:%bpath /minereflectedname:%ypath");
529 if (!g_sGroupingUUID
.IsEmpty())
531 viewer
+= L
" /groupuuid:\"";
532 viewer
+= g_sGroupingUUID
;
536 viewer
+= _T(" /blame");
538 // check if the params are set. If not, just add the files to the command line
539 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
541 viewer
+= _T(" \"")+file1
+_T("\"");
542 viewer
+= _T(" \"")+file2
+_T("\"");
544 if (viewer
.Find(_T("%base")) >= 0)
546 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
548 if (viewer
.Find(_T("%mine")) >= 0)
550 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
553 if (sName1
.IsEmpty())
554 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
556 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
558 if (sName2
.IsEmpty())
559 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
561 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
563 viewer
.Replace(_T("%bpath"), _T("\"") + originalFile1
+ _T("\""));
564 viewer
.Replace(_T("%ypath"), _T("\"") + originalFile2
+ _T("\""));
566 viewer
.Replace(_T("%brev"), _T("\"") + hash1
+ _T("\""));
567 viewer
.Replace(_T("%yrev"), _T("\"") + hash2
+ _T("\""));
569 if (flags
.bReadOnly
&& bInternal
)
570 viewer
+= _T(" /readonly");
575 temp
.Format(_T(" /line:%d"), jumpToLine
);
579 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
582 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
585 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
587 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
589 // use TortoiseGitUDiff
590 viewer
= CPathUtils::GetAppDirectory();
591 viewer
+= _T("TortoiseGitUDiff.exe");
592 // enquote the path to TortoiseGitUDiff
593 viewer
= _T("\"") + viewer
+ _T("\"");
595 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
596 if (!g_sGroupingUUID
.IsEmpty())
598 viewer
+= L
" /groupuuid:\"";
599 viewer
+= g_sGroupingUUID
;
603 if (viewer
.Find(_T("%1"))>=0)
605 if (viewer
.Find(_T("\"%1\"")) >= 0)
606 viewer
.Replace(_T("%1"), patchfile
);
608 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
611 viewer
+= _T(" \"") + patchfile
+ _T("\"");
612 if (viewer
.Find(_T("%title")) >= 0)
614 viewer
.Replace(_T("%title"), title
);
617 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
624 BOOL
CAppUtils::StartTextViewer(CString file
)
627 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
629 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
630 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
633 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
634 std::unique_ptr
<TCHAR
[]> buf(new TCHAR
[len
+ 1]);
635 ExpandEnvironmentStrings(viewer
, buf
.get(), len
);
637 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
638 std::unique_ptr
<TCHAR
[]> buf2(new TCHAR
[len
+ 1]);
639 ExpandEnvironmentStrings(file
, buf2
.get(), len
);
641 file
= _T("\"")+file
+_T("\"");
642 if (viewer
.IsEmpty())
644 return CAppUtils::ShowOpenWithDialog(file
) ? TRUE
: FALSE
;
646 if (viewer
.Find(_T("\"%1\"")) >= 0)
648 viewer
.Replace(_T("\"%1\""), file
);
650 else if (viewer
.Find(_T("%1")) >= 0)
652 viewer
.Replace(_T("%1"), file
);
660 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
667 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
670 CAutoFile hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
673 length
= ::GetFileSize(hFile
, NULL
);
680 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
683 HDC hScreenDC
= ::GetDC(NULL
);
684 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
685 ::ReleaseDC(NULL
, hScreenDC
);
687 logFont
.lfEscapement
= 0;
688 logFont
.lfOrientation
= 0;
689 logFont
.lfWeight
= FW_NORMAL
;
690 logFont
.lfItalic
= 0;
691 logFont
.lfUnderline
= 0;
692 logFont
.lfStrikeOut
= 0;
693 logFont
.lfCharSet
= DEFAULT_CHARSET
;
694 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
695 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
696 logFont
.lfQuality
= DRAFT_QUALITY
;
697 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
698 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
699 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
702 bool CAppUtils::LaunchPAgent(const CString
* keyfile
, const CString
* pRemote
)
716 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
717 key
= g_Git
.GetConfigValue(cmd
);
725 CString proc
=CPathUtils::GetAppDirectory();
726 proc
+= _T("pageant.exe \"");
730 CString tempfile
= GetTempFile();
731 ::DeleteFile(tempfile
);
733 proc
+= _T(" -c \"");
734 proc
+= CPathUtils::GetAppDirectory();
735 proc
+= _T("tgittouch.exe\"");
740 CString appDir
= CPathUtils::GetAppDirectory();
741 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true, &appDir
);
746 while(!::PathFileExists(tempfile
))
751 break; //timeout 5 minutes
756 CMessageBox::Show(NULL
, IDS_ERR_PAEGENTTIMEOUT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
758 ::DeleteFile(tempfile
);
761 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
, bool uac
)
763 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
764 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
765 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
769 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
771 LaunchApplication(sCmd
, NULL
, false, NULL
, uac
);
774 bool CAppUtils::LaunchRemoteSetting()
776 CTGitPath
path(g_Git
.m_CurrentDir
);
777 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
778 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
779 dlg
.SetTreeWidth(220);
780 dlg
.m_DefaultPage
= _T("gitremote");
787 * Launch the external blame viewer
789 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
, const CString
& Rev
, const CString
& sParams
)
791 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
792 viewer
+= _T("TortoiseGitBlame.exe");
793 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
794 //viewer += _T(" \"") + sLogFile + _T("\"");
795 //viewer += _T(" \"") + sOriginalFile + _T("\"");
796 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
797 viewer
+= CString(_T(" /rev:"))+Rev
;
798 if (!g_sGroupingUUID
.IsEmpty())
800 viewer
+= L
" /groupuuid:\"";
801 viewer
+= g_sGroupingUUID
;
804 viewer
+= _T(" ")+sParams
;
806 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
809 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
814 bool bStyled
= false;
815 pWnd
->GetWindowText(sText
);
816 // the rich edit control doesn't count the CR char!
817 // to be exact: CRLF is treated as one char.
818 sText
.Remove(_T('\r'));
820 // style each line separately
825 nNewlinePos
= sText
.Find('\n', offset
);
826 CString sLine
= nNewlinePos
>= 0 ? sText
.Mid(offset
, nNewlinePos
- offset
) : sText
.Mid(offset
);
830 while (FindStyleChars(sLine
, '*', start
, end
))
832 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
833 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
834 SetCharFormat(pWnd
, CFM_BOLD
, CFE_BOLD
);
840 while (FindStyleChars(sLine
, '^', start
, end
))
842 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
843 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
844 SetCharFormat(pWnd
, CFM_ITALIC
, CFE_ITALIC
);
850 while (FindStyleChars(sLine
, '_', start
, end
))
852 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
853 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
854 SetCharFormat(pWnd
, CFM_UNDERLINE
, CFE_UNDERLINE
);
858 offset
= nNewlinePos
+1;
859 } while(nNewlinePos
>=0);
863 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
866 int last
= sText
.GetLength() - 1;
867 bool bFoundMarker
= false;
868 TCHAR c
= i
== 0 ? _T('\0') : sText
[i
- 1];
869 TCHAR nextChar
= i
>= last
? _T('\0') : sText
[i
+ 1];
871 // find a starting marker
876 nextChar
= sText
[i
+ 1];
878 // IsCharAlphaNumeric can be somewhat expensive.
879 // Long lines of "*****" or "----" will be pre-empted efficiently
880 // by the (c != nextChar) condition.
882 if ((c
== stylechar
) && (c
!= nextChar
))
884 if (IsCharAlphaNumeric(nextChar
) && !IsCharAlphaNumeric(prevChar
))
896 // find ending marker
899 bFoundMarker
= false;
906 if ((i
== last
) || (!IsCharAlphaNumeric(sText
[i
+ 1]) && IsCharAlphaNumeric(prevChar
)))
921 bool IsValidURLChar(wchar_t ch
)
923 return iswalnum(ch
) ||
924 ch
== L
'_' || ch
== L
'/' || ch
== L
';' || ch
== L
'?' || ch
== L
'&' || ch
== L
'=' ||
925 ch
== L
'%' || ch
== L
':' || ch
== L
'.' || ch
== L
'#' || ch
== L
'-' || ch
== L
'+' ||
926 ch
== L
'|' || ch
== L
'>' || ch
== L
'<';
929 bool IsUrl(const CString
& sText
)
931 if (!PathIsURLW(sText
))
933 if (sText
.Find(L
"://") >= 0)
939 BOOL
CAppUtils::StyleURLs(const CString
& msg
, CWnd
* pWnd
)
941 std::vector
<CHARRANGE
> positions
= FindURLMatches(msg
);
942 CAppUtils::SetCharFormat(pWnd
, CFM_LINK
, CFE_LINK
, positions
);
944 return positions
.empty() ? FALSE
: TRUE
;
948 * implements URL searching with the same logic as CSciEdit::StyleURLs
950 std::vector
<CHARRANGE
> CAppUtils::FindURLMatches(const CString
& msg
)
952 std::vector
<CHARRANGE
> result
;
954 int len
= msg
.GetLength();
957 for (int i
= 0; i
<= msg
.GetLength(); ++i
)
959 if ((i
< len
) && IsValidURLChar(msg
[i
]))
969 if (msg
[starturl
] == '<' && i
< len
) // try to detect and do not strip URLs put within <>
971 while (starturl
<= i
&& msg
[starturl
] == '<') // strip leading '<'
975 while (i
< len
&& msg
[i
] != '\r' && msg
[i
] != '\n' && msg
[i
] != '>') // find first '>' or new line after resetting i to start position
978 if (!IsUrl(msg
.Mid(starturl
, i
- starturl
)))
984 int skipTrailing
= 0;
985 while (strip
&& i
- skipTrailing
- 1 > starturl
&& (msg
[i
- skipTrailing
- 1] == '.' || msg
[i
- skipTrailing
- 1] == '-' || msg
[i
- skipTrailing
- 1] == '?' || msg
[i
- skipTrailing
- 1] == ';' || msg
[i
- skipTrailing
- 1] == ':' || msg
[i
- skipTrailing
- 1] == '>' || msg
[i
- skipTrailing
- 1] == '<'))
988 CHARRANGE range
= { starturl
, i
- skipTrailing
};
989 result
.push_back(range
);
998 bool CAppUtils::StartShowUnifiedDiff(HWND hWnd
, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
999 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
1000 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
1001 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */,
1002 bool /* blame = false */,
1006 int diffContext
= 0;
1007 if (GetMsysgitVersion() > 0x01080100)
1008 diffContext
= g_Git
.GetConfigValueInt32(_T("diff.context"), -1);
1009 CString tempfile
=GetTempFile();
1010 if (g_Git
.GetUnifiedDiff(url1
, rev1
, rev2
, tempfile
, bMerge
, bCombine
, diffContext
))
1012 CMessageBox::Show(hWnd
, g_Git
.GetGitLastErr(_T("Could not get unified diff."), CGit::GIT_CMD_DIFF
), _T("TortoiseGit"), MB_OK
);
1015 CAppUtils::StartUnifiedDiffViewer(tempfile
, rev1
+ _T(":") + rev2
);
1019 sCmd
.Format(_T("%s /command:showcompare /unified"),
1020 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseGitProc.exe")));
1021 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
1023 sCmd
+= _T(" /revision1:") + rev1
.ToString();
1024 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
1026 sCmd
+= _T(" /revision2:") + rev2
.ToString();
1028 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
1029 if (headpeg
.IsValid())
1030 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
1033 sCmd
+= _T(" /alternatediff");
1035 if (bIgnoreAncestry
)
1036 sCmd
+= _T(" /ignoreancestry");
1040 sCmd
+= _T(" /hwnd:");
1042 _stprintf_s(buf
, 30, _T("%p"), (void*)hWnd
);
1046 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
1051 bool CAppUtils::SetupDiffScripts(bool force
, const CString
& type
)
1053 CString scriptsdir
= CPathUtils::GetAppParentDirectory();
1054 scriptsdir
+= _T("Diff-Scripts");
1055 CSimpleFileFind
files(scriptsdir
);
1056 while (files
.FindNextFileNoDirectories())
1058 CString file
= files
.GetFilePath();
1059 CString filename
= files
.GetFileName();
1060 CString ext
= file
.Mid(file
.ReverseFind('-') + 1);
1061 ext
= _T(".") + ext
.Left(ext
.ReverseFind('.'));
1062 std::set
<CString
> extensions
;
1063 extensions
.insert(ext
);
1065 if (file
.Right(3).CompareNoCase(_T("vbs"))==0)
1067 kind
= _T(" //E:vbscript");
1069 if (file
.Right(2).CompareNoCase(_T("js"))==0)
1071 kind
= _T(" //E:javascript");
1073 // open the file, read the first line and find possible extensions
1074 // this script can handle
1077 CStdioFile
f(file
, CFile::modeRead
| CFile::shareDenyNone
);
1079 if (f
.ReadString(extline
))
1081 if ((extline
.GetLength() > 15 ) &&
1082 ((extline
.Left(15).Compare(_T("// extensions: ")) == 0) ||
1083 (extline
.Left(14).Compare(_T("' extensions: ")) == 0)))
1085 if (extline
[0] == '/')
1086 extline
= extline
.Mid(15);
1088 extline
= extline
.Mid(14);
1091 sToken
= extline
.Tokenize(_T(";"), curPos
);
1092 while (!sToken
.IsEmpty())
1094 if (!sToken
.IsEmpty())
1096 if (sToken
[0] != '.')
1097 sToken
= _T(".") + sToken
;
1098 extensions
.insert(sToken
);
1100 sToken
= extline
.Tokenize(_T(";"), curPos
);
1106 catch (CFileException
* e
)
1111 for (std::set
<CString
>::const_iterator it
= extensions
.begin(); it
!= extensions
.end(); ++it
)
1113 if (type
.IsEmpty() || (type
.Compare(_T("Diff")) == 0))
1115 if (filename
.Left(5).CompareNoCase(_T("diff-")) == 0)
1117 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + *it
);
1118 CString diffregstring
= diffreg
;
1119 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
1120 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %base %mine") + kind
;
1123 if (type
.IsEmpty() || (type
.Compare(_T("Merge"))==0))
1125 if (filename
.Left(6).CompareNoCase(_T("merge-"))==0)
1127 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\MergeTools\\") + *it
);
1128 CString diffregstring
= diffreg
;
1129 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
1130 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %merged %theirs %mine %base") + kind
;
1139 bool CAppUtils::Export(const CString
* BashHash
, const CTGitPath
* orgPath
)
1141 // ask from where the export has to be done
1144 dlg
.m_initialRefName
=*BashHash
;
1147 if (PathIsRelative(orgPath
->GetWinPath()))
1148 dlg
.m_orgPath
= g_Git
.CombinePath(orgPath
);
1150 dlg
.m_orgPath
= *orgPath
;
1153 if (dlg
.DoModal() == IDOK
)
1156 cmd
.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s --"),
1157 dlg
.m_strFile
, g_Git
.FixBranchName(dlg
.m_VersionName
));
1161 pro
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
1165 postCmdList
.push_back(PostCmd(IDI_EXPLORER
, IDS_STATUSLIST_CONTEXT_EXPLORE
, [&]{ CAppUtils::ExploreTo(hWndExplorer
, dlg
.m_strFile
); }));
1169 if (!dlg
.m_bWholeProject
&& !dlg
.m_orgPath
.IsEmpty() && PathIsDirectory(dlg
.m_orgPath
.GetWinPathString()))
1171 git
.m_CurrentDir
= dlg
.m_orgPath
.GetWinPathString();
1174 return (pro
.DoModal() == IDOK
);
1179 bool CAppUtils::CreateBranchTag(bool IsTag
, const CString
* CommitHash
, bool switch_new_brach
)
1181 CCreateBranchTagDlg dlg
;
1183 dlg
.m_bSwitch
=switch_new_brach
;
1186 dlg
.m_initialRefName
= *CommitHash
;
1188 if(dlg
.DoModal()==IDOK
)
1193 if(dlg
.m_bTrack
== TRUE
)
1194 track
=_T(" --track ");
1195 else if(dlg
.m_bTrack
== FALSE
)
1196 track
=_T(" --no-track");
1207 cmd
.Format(_T("git.exe tag %s %s %s %s"),
1210 dlg
.m_BranchTagName
,
1211 g_Git
.FixBranchName(dlg
.m_VersionName
)
1214 if(!dlg
.m_Message
.Trim().IsEmpty())
1216 CString tempfile
= ::GetTempFile();
1217 if (CAppUtils::SaveCommitUnicodeFile(tempfile
, dlg
.m_Message
))
1219 CMessageBox::Show(nullptr, _T("Could not save tag message"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1222 cmd
+= _T(" -F ")+tempfile
;
1227 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1230 dlg
.m_BranchTagName
,
1231 g_Git
.FixBranchName(dlg
.m_VersionName
)
1235 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1237 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1240 if( !IsTag
&& dlg
.m_bSwitch
)
1242 // it is a new branch and the user has requested to switch to it
1243 PerformSwitch(dlg
.m_BranchTagName
);
1251 bool CAppUtils::Switch(const CString
& initialRefName
)
1254 if(!initialRefName
.IsEmpty())
1255 dlg
.m_initialRefName
= initialRefName
;
1257 if (dlg
.DoModal() == IDOK
)
1261 branch
= dlg
.m_NewBranch
;
1263 // if refs/heads/ is not stripped, checkout will detach HEAD
1264 // checkout prefers branches on name clashes (with tags)
1265 if (dlg
.m_VersionName
.Left(11) ==_T("refs/heads/") && dlg
.m_bBranchOverride
!= TRUE
)
1266 dlg
.m_VersionName
= dlg
.m_VersionName
.Mid(11);
1268 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
, dlg
.m_bMerge
== TRUE
);
1273 bool CAppUtils::PerformSwitch(const CString
& ref
, bool bForce
/* false */, const CString
& sNewBranch
/* CString() */, bool bBranchOverride
/* false */, BOOL bTrack
/* 2 */, bool bMerge
/* false */)
1281 if(!sNewBranch
.IsEmpty()){
1282 if (bBranchOverride
)
1284 branch
.Format(_T("-B %s"), sNewBranch
);
1288 branch
.Format(_T("-b %s"), sNewBranch
);
1291 track
= _T("--track");
1292 else if (bTrack
== FALSE
)
1293 track
= _T("--no-track");
1298 merge
= _T("--merge");
1300 cmd
.Format(_T("git.exe checkout %s %s %s %s %s --"),
1305 g_Git
.FixBranchName(ref
));
1307 CProgressDlg progress
;
1308 progress
.m_GitCmd
= cmd
;
1310 CString currentBranch
;
1311 bool hasBranch
= CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, currentBranch
) == 0;
1312 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
1316 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1317 if (gitPath
.HasSubmodules())
1319 postCmdList
.push_back(PostCmd(IDI_UPDATE
, IDS_PROC_SUBMODULESUPDATE
, [&]
1322 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1323 RunTortoiseGitProc(sCmd
);
1327 postCmdList
.push_back(PostCmd(IDI_MERGE
, IDS_MENUMERGE
, [&]{ Merge(¤tBranch
); }));
1331 if (!CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, newBranch
))
1332 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUPULL
, [&]{ Pull(); }));
1334 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_MENUCOMMIT
, []{
1335 CTGitPathList pathlist
;
1336 CTGitPathList selectedlist
;
1337 bool bSelectFilesForCommit
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
1339 Commit(CString(), false, str
, pathlist
, selectedlist
, bSelectFilesForCommit
);
1344 postCmdList
.push_back(PostCmd(IDI_REFRESH
, IDS_MSGBOX_RETRY
, [&]{ PerformSwitch(ref
, bForce
, sNewBranch
, bBranchOverride
, bTrack
, bMerge
); }));
1346 postCmdList
.push_back(PostCmd(IDI_SWITCH
, IDS_SWITCH_WITH_MERGE
, [&]{ PerformSwitch(ref
, bForce
, sNewBranch
, bBranchOverride
, bTrack
, true); }));
1350 INT_PTR ret
= progress
.DoModal();
1355 class CIgnoreFile
: public CStdioFile
1358 STRING_VECTOR m_Items
;
1361 virtual BOOL
ReadString(CString
& rString
)
1363 if (GetPosition() == 0)
1365 unsigned char utf8bom
[] = { 0xEF, 0xBB, 0xBF };
1366 char buf
[3] = { 0, 0, 0 };
1368 if (memcpy(buf
, utf8bom
, sizeof(utf8bom
)))
1375 char lastChar
= '\0';
1376 for (char c
= '\0'; Read(&c
, 1) == 1; lastChar
= c
)
1382 m_eol
= lastChar
== '\r' ? _T("\r\n") : _T("\n");
1390 rString
= CUnicodeUtils::GetUnicode(strA
);
1401 bool CAppUtils::OpenIgnoreFile(CIgnoreFile
&file
, const CString
& filename
)
1404 if (!file
.Open(filename
, CFile::modeCreate
| CFile::modeReadWrite
| CFile::modeNoTruncate
| CFile::typeBinary
))
1406 CMessageBox::Show(NULL
, filename
+ _T(" Open Failure"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1410 if (file
.GetLength() > 0)
1413 while (file
.ReadString(fileText
))
1414 file
.m_Items
.push_back(fileText
);
1415 file
.Seek(file
.GetLength() - 1, 0);
1416 char lastchar
[1] = { 0 };
1417 file
.Read(lastchar
, 1);
1419 if (lastchar
[0] != '\n')
1421 CStringA eol
= CStringA(file
.m_eol
.IsEmpty() ? _T("\n") : file
.m_eol
);
1422 file
.Write(eol
, eol
.GetLength());
1431 bool CAppUtils::IgnoreFile(const CTGitPathList
& path
,bool IsMask
)
1433 CIgnoreDlg ignoreDlg
;
1434 if (ignoreDlg
.DoModal() == IDOK
)
1437 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\");
1439 switch (ignoreDlg
.m_IgnoreFile
)
1442 ignorefile
+= _T(".gitignore");
1445 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, ignorefile
);
1446 ignorefile
+= _T("info/exclude");
1453 if (ignoreDlg
.m_IgnoreFile
!= 1 && !OpenIgnoreFile(file
, ignorefile
))
1456 for (int i
= 0; i
< path
.GetCount(); ++i
)
1458 if (ignoreDlg
.m_IgnoreFile
== 1)
1460 ignorefile
= g_Git
.CombinePath(path
[i
].GetContainingDirectory()) + _T("\\.gitignore");
1461 if (!OpenIgnoreFile(file
, ignorefile
))
1465 CString ignorePattern
;
1466 if (ignoreDlg
.m_IgnoreType
== 0)
1468 if (ignoreDlg
.m_IgnoreFile
!= 1 && !path
[i
].GetContainingDirectory().GetGitPathString().IsEmpty())
1469 ignorePattern
+= _T("/") + path
[i
].GetContainingDirectory().GetGitPathString();
1471 ignorePattern
+= _T("/");
1475 ignorePattern
+= _T("*") + path
[i
].GetFileExtension();
1479 ignorePattern
+= path
[i
].GetFileOrDirectoryName();
1482 // escape [ and ] so that files get ignored correctly
1483 ignorePattern
.Replace(_T("["), _T("\\["));
1484 ignorePattern
.Replace(_T("]"), _T("\\]"));
1487 for (size_t j
= 0; j
< file
.m_Items
.size(); ++j
)
1489 if (file
.m_Items
[j
] == ignorePattern
)
1497 file
.m_Items
.push_back(ignorePattern
);
1498 ignorePattern
+= file
.m_eol
.IsEmpty() ? _T("\n") : file
.m_eol
;
1499 CStringA ignorePatternA
= CUnicodeUtils::GetUTF8(ignorePattern
);
1500 file
.Write(ignorePatternA
, ignorePatternA
.GetLength());
1503 if (ignoreDlg
.m_IgnoreFile
== 1)
1507 if (ignoreDlg
.m_IgnoreFile
!= 1)
1521 static bool Reset(const CString
& resetTo
, int resetType
)
1528 type
= _T("--soft");
1531 type
= _T("--mixed");
1534 type
= _T("--hard");
1538 type
= _T("--mixed");
1541 cmd
.Format(_T("git.exe reset %s %s --"), type
, resetTo
);
1543 CProgressDlg progress
;
1544 progress
.m_GitCmd
= cmd
;
1546 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
1550 postCmdList
.push_back(PostCmd(IDI_REFRESH
, IDS_MSGBOX_RETRY
, [&]{ Reset(resetTo
, resetType
); }));
1554 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1555 if (gitPath
.HasSubmodules() && resetType
== 2)
1557 postCmdList
.push_back(PostCmd(IDI_UPDATE
, IDS_PROC_SUBMODULESUPDATE
, [&]
1560 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1561 CAppUtils::RunTortoiseGitProc(sCmd
);
1567 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_RESET
))
1569 CGitProgressDlg gitdlg
;
1570 ResetProgressCommand resetProgressCommand
;
1571 gitdlg
.SetCommand(&resetProgressCommand
);
1572 resetProgressCommand
.m_PostCmdCallback
= progress
.m_PostCmdCallback
;
1573 resetProgressCommand
.SetRevision(resetTo
);
1574 resetProgressCommand
.SetResetType(resetType
);
1575 ret
= gitdlg
.DoModal();
1578 ret
= progress
.DoModal();
1583 bool CAppUtils::GitReset(const CString
* CommitHash
, int type
)
1586 dlg
.m_ResetType
=type
;
1587 dlg
.m_ResetToVersion
=*CommitHash
;
1588 dlg
.m_initialRefName
= *CommitHash
;
1589 if (dlg
.DoModal() == IDOK
)
1590 return Reset(dlg
.m_ResetToVersion
, dlg
.m_ResetType
);
1595 void CAppUtils::DescribeConflictFile(bool mode
, bool base
,CString
&descript
)
1599 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_DELETE
));
1604 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_MODIFIED
));
1607 descript
= CString(MAKEINTRESOURCE(IDS_PROC_CREATED
));
1611 void CAppUtils::RemoveTempMergeFile(const CTGitPath
& path
)
1613 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("LOCAL"), path
));
1614 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("REMOTE"), path
));
1615 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("BASE"), path
));
1617 CString
CAppUtils::GetMergeTempFile(const CString
& type
, const CTGitPath
&merge
)
1620 file
= g_Git
.CombinePath(merge
.GetWinPathString() + _T(".") + type
+ merge
.GetFileExtension());
1625 bool ParseHashesFromLsFile(const BYTE_VECTOR
& out
, CString
& hash1
, CString
& hash2
, CString
& hash3
)
1631 while (pos
>= 0 && pos
< (int)out
.size())
1635 g_Git
.StringAppend(&one
, &out
[pos
], CP_UTF8
);
1637 one
.Tokenize(_T("\t"), tabstart
);
1640 part
= one
.Tokenize(_T(" "), tabstart
); //Tag
1641 part
= one
.Tokenize(_T(" "), tabstart
); //Mode
1642 part
= one
.Tokenize(_T(" "), tabstart
); //Hash
1643 CString hash
= part
;
1644 part
= one
.Tokenize(_T("\t"), tabstart
); //Stage
1645 int stage
= _ttol(part
);
1648 else if (stage
== 2)
1650 else if (stage
== 3)
1656 pos
= out
.findNextString(pos
);
1662 bool CAppUtils::ConflictEdit(const CTGitPath
& path
, bool /*bAlternativeTool = false*/, bool revertTheirMy
/*= false*/, HWND resolveMsgHwnd
/*= nullptr*/)
1666 CTGitPath merge
=path
;
1667 CTGitPath directory
= merge
.GetDirectory();
1669 // we have the conflicted file (%merged)
1670 // now look for the other required files
1672 //stat.GetStatus(merge);
1673 //if (stat.status == NULL)
1679 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1681 if (g_Git
.Run(cmd
, &vector
))
1686 if (merge
.IsDirectory())
1688 CString baseHash
, realBaseHash(GIT_REV_ZERO
), localHash(GIT_REV_ZERO
), remoteHash(GIT_REV_ZERO
);
1689 if (merge
.HasAdminDir()) {
1691 subgit
.m_CurrentDir
= g_Git
.CombinePath(merge
);
1693 subgit
.GetHash(hash
, _T("HEAD"));
1696 if (ParseHashesFromLsFile(vector
, realBaseHash
, localHash
, remoteHash
)) // in base no submodule, but in remote submodule
1697 baseHash
= realBaseHash
;
1699 CGitDiff::ChangeType changeTypeMine
= CGitDiff::Unknown
;
1700 CGitDiff::ChangeType changeTypeTheirs
= CGitDiff::Unknown
;
1702 bool baseOK
= false, mineOK
= false, theirsOK
= false;
1703 CString baseSubject
, mineSubject
, theirsSubject
;
1704 if (merge
.HasAdminDir())
1707 subgit
.m_CurrentDir
= g_Git
.CombinePath(merge
);
1708 CGitDiff::GetSubmoduleChangeType(subgit
, baseHash
, localHash
, baseOK
, mineOK
, changeTypeMine
, baseSubject
, mineSubject
);
1709 CGitDiff::GetSubmoduleChangeType(subgit
, baseHash
, remoteHash
, baseOK
, theirsOK
, changeTypeTheirs
, baseSubject
, theirsSubject
);
1711 else if (baseHash
== GIT_REV_ZERO
&& localHash
== GIT_REV_ZERO
&& remoteHash
!= GIT_REV_ZERO
) // merge conflict with no submodule, but submodule in merged revision (not initialized)
1713 changeTypeMine
= CGitDiff::Identical
;
1714 changeTypeTheirs
= CGitDiff::NewSubmodule
;
1715 baseSubject
= _T("no submodule");
1716 mineSubject
= baseSubject
;
1717 theirsSubject
= _T("not initialized");
1719 else if (baseHash
.IsEmpty() && localHash
!= GIT_REV_ZERO
&& remoteHash
== GIT_REV_ZERO
) // merge conflict with no submodule initialized, but submodule exists in base and folder with no submodule is merged
1721 baseHash
= localHash
;
1722 baseSubject
= _T("not initialized");
1723 mineSubject
= baseSubject
;
1724 theirsSubject
= _T("not initialized");
1725 changeTypeMine
= CGitDiff::Identical
;
1726 changeTypeTheirs
= CGitDiff::DeleteSubmodule
;
1728 else if (baseHash
!= GIT_REV_ZERO
&& localHash
!= GIT_REV_ZERO
&& remoteHash
!= GIT_REV_ZERO
) // base has submodule, mine has submodule and theirs also, but not initialized
1730 baseSubject
= _T("not initialized");
1731 mineSubject
= baseSubject
;
1732 theirsSubject
= baseSubject
;
1733 if (baseHash
== localHash
)
1734 changeTypeMine
= CGitDiff::Identical
;
1739 CSubmoduleResolveConflictDlg resolveSubmoduleConflictDialog
;
1740 resolveSubmoduleConflictDialog
.SetDiff(merge
.GetGitPathString(), revertTheirMy
, baseHash
, baseSubject
, baseOK
, localHash
, mineSubject
, mineOK
, changeTypeMine
, remoteHash
, theirsSubject
, theirsOK
, changeTypeTheirs
);
1741 resolveSubmoduleConflictDialog
.DoModal();
1742 if (resolveSubmoduleConflictDialog
.m_bResolved
&& resolveMsgHwnd
)
1744 static UINT WM_REVERTMSG
= RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
1745 ::PostMessage(resolveMsgHwnd
, WM_REVERTMSG
, NULL
, NULL
);
1752 if (list
.ParserFromLsFile(vector
))
1754 CMessageBox::Show(NULL
, _T("Parse ls-files failed!"), _T("TortoiseGit"), MB_OK
);
1767 mine
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1768 theirs
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1772 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1773 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1775 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1779 //format=_T("git.exe cat-file blob \":%d:%s\"");
1780 format
= _T("git.exe checkout-index --temp --stage=%d -- \"%s\"");
1782 //create a empty file, incase stage is not three
1783 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1785 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1787 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1790 bool b_base
=false, b_local
=false, b_remote
=false;
1792 for (int i
= 0; i
< list
.GetCount(); ++i
)
1799 if( list
[i
].m_Stage
== 1)
1801 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1803 outfile
= base
.GetWinPathString();
1806 if( list
[i
].m_Stage
== 2 )
1808 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1810 outfile
= mine
.GetWinPathString();
1813 if( list
[i
].m_Stage
== 3 )
1815 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1817 outfile
= theirs
.GetWinPathString();
1819 CString output
, err
;
1820 if(!outfile
.IsEmpty())
1821 if (!g_Git
.Run(cmd
, &output
, &err
, CP_UTF8
))
1825 file
= output
.Tokenize(_T("\t"), start
);
1826 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1830 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1834 if(b_local
&& b_remote
)
1836 merge
.SetFromWin(g_Git
.CombinePath(merge
));
1838 bRet
= !!CAppUtils::StartExtMerge(base
, mine
, theirs
, merge
, _T("BASE"), _T("REMOTE"), _T("LOCAL"), CString(), false, resolveMsgHwnd
, true);
1840 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
, _T("BASE"), _T("REMOTE"), _T("LOCAL"), CString(), false, resolveMsgHwnd
, true);
1845 ::DeleteFile(mine
.GetWinPathString());
1846 ::DeleteFile(theirs
.GetWinPathString());
1847 ::DeleteFile(base
.GetWinPathString());
1849 CDeleteConflictDlg dlg
;
1850 DescribeConflictFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1851 DescribeConflictFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1852 CGitHash localHash
, remoteHash
;
1853 if (!g_Git
.GetHash(localHash
, _T("HEAD")))
1854 dlg
.m_LocalHash
= localHash
.ToString();
1855 if (!g_Git
.GetHash(remoteHash
, _T("MERGE_HEAD")))
1856 dlg
.m_RemoteHash
= remoteHash
.ToString();
1857 else if (!g_Git
.GetHash(remoteHash
, _T("rebase-apply/original-commit")))
1858 dlg
.m_RemoteHash
= remoteHash
.ToString();
1859 else if (!g_Git
.GetHash(remoteHash
, _T("CHERRY_PICK_HEAD")))
1860 dlg
.m_RemoteHash
= remoteHash
.ToString();
1861 else if (!g_Git
.GetHash(remoteHash
, _T("REVERT_HEAD")))
1862 dlg
.m_RemoteHash
= remoteHash
.ToString();
1863 dlg
.m_bShowModifiedButton
=b_base
;
1864 dlg
.m_File
=merge
.GetGitPathString();
1865 if(dlg
.DoModal() == IDOK
)
1870 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1873 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1875 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1877 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1887 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1888 base
, theirs
, mine
, merge
);
1891 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1893 // we have a text conflict, use our merge tool to resolve the conflict
1895 CTSVNPath
theirs(directory
);
1896 CTSVNPath
mine(directory
);
1897 CTSVNPath
base(directory
);
1898 bool bConflictData
= false;
1900 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1902 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1903 bConflictData
= true;
1905 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1907 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1908 bConflictData
= true;
1910 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1912 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1913 bConflictData
= true;
1920 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1921 base
, theirs
, mine
, merge
);
1924 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1926 // we have a property conflict
1927 CTSVNPath
prej(directory
);
1928 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1930 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1931 // there's a problem: the prej file contains a _description_ of the conflict, and
1932 // that description string might be translated. That means we have no way of parsing
1933 // the file to find out the conflicting values.
1934 // The only thing we can do: show a dialog with the conflict description, then
1935 // let the user either accept the existing property or open the property edit dialog
1936 // to manually change the properties and values. And a button to mark the conflict as
1938 CEditPropConflictDlg dlg
;
1939 dlg
.SetPrejFile(prej
);
1940 dlg
.SetConflictedItem(merge
);
1941 bRet
= (dlg
.DoModal() != IDCANCEL
);
1945 if (stat
.status
->tree_conflict
)
1947 // we have a tree conflict
1949 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1952 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1954 CTSVNPath
theirs(directory
);
1955 CTSVNPath
mine(directory
);
1956 CTSVNPath
base(directory
);
1957 bool bConflictData
= false;
1959 if (pInfoData
->treeconflict_theirfile
)
1961 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1962 bConflictData
= true;
1964 if (pInfoData
->treeconflict_basefile
)
1966 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1967 bConflictData
= true;
1969 if (pInfoData
->treeconflict_myfile
)
1971 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1972 bConflictData
= true;
1979 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1980 base
, theirs
, mine
, merge
);
1982 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1984 CString sConflictAction
;
1985 CString sConflictReason
;
1986 CString sResolveTheirs
;
1987 CString sResolveMine
;
1988 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1989 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1991 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1993 switch (pInfoData
->treeconflict_operation
)
1995 case svn_wc_operation_update
:
1996 switch (pInfoData
->treeconflict_action
)
1998 case svn_wc_conflict_action_edit
:
1999 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
2000 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
2002 case svn_wc_conflict_action_add
:
2003 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
2004 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
2006 case svn_wc_conflict_action_delete
:
2007 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
2008 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
2012 case svn_wc_operation_switch
:
2013 switch (pInfoData
->treeconflict_action
)
2015 case svn_wc_conflict_action_edit
:
2016 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
2017 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
2019 case svn_wc_conflict_action_add
:
2020 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
2021 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
2023 case svn_wc_conflict_action_delete
:
2024 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
2025 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
2029 case svn_wc_operation_merge
:
2030 switch (pInfoData
->treeconflict_action
)
2032 case svn_wc_conflict_action_edit
:
2033 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
2034 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
2036 case svn_wc_conflict_action_add
:
2037 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
2038 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
2040 case svn_wc_conflict_action_delete
:
2041 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
2042 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
2048 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
2050 switch (pInfoData
->treeconflict_operation
)
2052 case svn_wc_operation_update
:
2053 switch (pInfoData
->treeconflict_action
)
2055 case svn_wc_conflict_action_edit
:
2056 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
2057 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
2059 case svn_wc_conflict_action_add
:
2060 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
2061 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
2063 case svn_wc_conflict_action_delete
:
2064 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
2065 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
2069 case svn_wc_operation_switch
:
2070 switch (pInfoData
->treeconflict_action
)
2072 case svn_wc_conflict_action_edit
:
2073 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
2074 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
2076 case svn_wc_conflict_action_add
:
2077 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
2078 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
2080 case svn_wc_conflict_action_delete
:
2081 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
2082 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
2086 case svn_wc_operation_merge
:
2087 switch (pInfoData
->treeconflict_action
)
2089 case svn_wc_conflict_action_edit
:
2090 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
2091 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
2093 case svn_wc_conflict_action_add
:
2094 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
2095 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
2097 case svn_wc_conflict_action_delete
:
2098 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
2099 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
2107 switch (pInfoData
->treeconflict_reason
)
2109 case svn_wc_conflict_reason_edited
:
2110 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
2111 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
2113 case svn_wc_conflict_reason_obstructed
:
2114 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
2115 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
2117 case svn_wc_conflict_reason_deleted
:
2118 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
2119 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
2121 case svn_wc_conflict_reason_added
:
2122 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
2123 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
2125 case svn_wc_conflict_reason_missing
:
2126 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
2127 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
2129 case svn_wc_conflict_reason_unversioned
:
2130 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
2131 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
2134 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
2136 CTreeConflictEditorDlg dlg
;
2137 dlg
.SetConflictInfoText(sConflictReason
);
2138 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
2139 dlg
.SetPath(treeConflictPath
);
2140 INT_PTR dlgRet
= dlg
.DoModal();
2141 bRet
= (dlgRet
!= IDCANCEL
);
2149 bool CAppUtils::IsSSHPutty()
2151 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
2152 sshclient
=sshclient
.MakeLower();
2153 if(sshclient
.Find(_T("plink.exe"),0)>=0)
2160 CString
CAppUtils::GetClipboardLink(const CString
&skipGitPrefix
, int paramsCount
)
2162 if (!OpenClipboard(NULL
))
2165 CString sClipboardText
;
2166 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
2169 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
2170 sClipboardText
= CString(lpstr
);
2173 hglb
= GetClipboardData(CF_UNICODETEXT
);
2176 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
2177 sClipboardText
= lpstr
;
2182 if(!sClipboardText
.IsEmpty())
2184 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
2185 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
2187 if(sClipboardText
.Find( _T("http://")) == 0)
2188 return sClipboardText
;
2190 if(sClipboardText
.Find( _T("https://")) == 0)
2191 return sClipboardText
;
2193 if(sClipboardText
.Find( _T("git://")) == 0)
2194 return sClipboardText
;
2196 if(sClipboardText
.Find( _T("ssh://")) == 0)
2197 return sClipboardText
;
2199 if (sClipboardText
.Find(_T("git@")) == 0)
2200 return sClipboardText
;
2202 if(sClipboardText
.GetLength()>=2)
2203 if( sClipboardText
[1] == _T(':') )
2204 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
2205 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
2206 return sClipboardText
;
2208 // trim prefixes like "git clone "
2209 if (!skipGitPrefix
.IsEmpty() && sClipboardText
.Find(skipGitPrefix
) == 0)
2211 sClipboardText
= sClipboardText
.Mid(skipGitPrefix
.GetLength()).Trim();
2213 while (paramsCount
>= 0)
2216 spacePos
= sClipboardText
.Find(_T(' '), spacePos
+ 1);
2220 if (spacePos
> 0 && paramsCount
< 0)
2221 sClipboardText
= sClipboardText
.Left(spacePos
);
2222 return sClipboardText
;
2226 return CString(_T(""));
2229 CString
CAppUtils::ChooseRepository(const CString
* path
)
2231 CBrowseFolder browseFolder
;
2232 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
2234 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
2235 CString strCloneDirectory
;
2237 strCloneDirectory
=*path
;
2240 strCloneDirectory
= regLastResopitory
;
2244 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
2246 browseFolder
.SetInfo(title
);
2248 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
2250 regLastResopitory
= strCloneDirectory
;
2251 return strCloneDirectory
;
2259 bool CAppUtils::SendPatchMail(CTGitPathList
& list
, bool bIsMainWnd
)
2263 dlg
.m_PathList
= list
;
2265 if(dlg
.DoModal()==IDOK
)
2267 if (dlg
.m_PathList
.IsEmpty())
2270 CGitProgressDlg progDlg
;
2272 theApp
.m_pMainWnd
= &progDlg
;
2273 SendMailProgressCommand sendMailProgressCommand
;
2274 progDlg
.SetCommand(&sendMailProgressCommand
);
2276 sendMailProgressCommand
.SetPathList(dlg
.m_PathList
);
2277 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2279 CSendMailPatch
sendMailPatch(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
);
2280 sendMailProgressCommand
.SetSendMailOption(&sendMailPatch
);
2289 bool CAppUtils::SendPatchMail(const CString
& cmd
, const CString
& formatpatchoutput
, bool bIsMainWnd
)
2292 CString log
=formatpatchoutput
;
2293 int start
=log
.Find(cmd
);
2295 CString one
=log
.Tokenize(_T("\n"),start
);
2301 CString one
=log
.Tokenize(_T("\n"),start
);
2303 if(one
.IsEmpty() || one
.Find(_T("Success")) == 0)
2305 one
.Replace(_T('/'),_T('\\'));
2307 path
.SetFromWin(one
);
2310 if (!list
.IsEmpty())
2312 return SendPatchMail(list
, bIsMainWnd
);
2316 CMessageBox::Show(NULL
, IDS_ERR_NOPATCHES
, IDS_APPNAME
, MB_ICONINFORMATION
);
2322 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
2325 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
2326 if(output
.IsEmpty())
2327 return CUnicodeUtils::GetCPCode(pGit
->GetConfigValue(_T("i18n.commitencoding")));
2330 return CUnicodeUtils::GetCPCode(output
);
2333 int CAppUtils::SaveCommitUnicodeFile(const CString
& filename
, CString
&message
)
2337 CFile
file(filename
, CFile::modeReadWrite
| CFile::modeCreate
);
2338 int cp
= CUnicodeUtils::GetCPCode(g_Git
.GetConfigValue(_T("i18n.commitencoding")));
2340 bool stripComments
= (CRegDWORD(_T("Software\\TortoiseGit\\StripCommentedLines"), FALSE
) == TRUE
);
2342 if (CRegDWORD(_T("Software\\TortoiseGit\\SanitizeCommitMsg"), TRUE
) == TRUE
)
2343 message
.TrimRight(L
" \r\n");
2345 int len
= message
.GetLength();
2347 while (start
>= 0 && start
< len
)
2349 int oldStart
= start
;
2350 start
= message
.Find(L
"\n", oldStart
);
2351 CString line
= message
.Mid(oldStart
);
2354 line
= line
.Left(start
- oldStart
);
2355 ++start
; // move forward so we don't find the same char again
2357 if (stripComments
&& (line
.GetLength() >= 1 && line
.GetAt(0) == '#') || (start
< 0 && line
.IsEmpty()))
2359 line
.TrimRight(L
" \r");
2360 CStringA lineA
= CUnicodeUtils::GetMulti(line
+ L
"\n", cp
);
2361 file
.Write(lineA
.GetBuffer(), lineA
.GetLength());
2366 catch (CFileException
*e
)
2373 bool CAppUtils::Pull(bool showPush
, bool showStashPop
)
2376 dlg
.m_IsPull
= TRUE
;
2377 if (dlg
.DoModal() == IDOK
)
2379 // "git.exe pull --rebase" is not supported, never and ever. So, adapting it to Fetch & Rebase.
2381 return DoFetch(dlg
.m_RemoteURL
,
2382 FALSE
, // Fetch all remotes
2383 dlg
.m_bAutoLoad
== BST_CHECKED
,
2385 dlg
.m_bDepth
== BST_CHECKED
,
2388 dlg
.m_RemoteBranchName
,
2389 TRUE
); // Rebase after fetching
2391 CString url
= dlg
.m_RemoteURL
;
2393 if (dlg
.m_bAutoLoad
)
2395 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
2400 if (g_Git
.GetHash(hashOld
, _T("HEAD")))
2402 MessageBox(NULL
, g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
2415 if (!dlg
.m_bFetchTags
)
2416 notags
= _T("--no-tags ");
2418 if (dlg
.m_bFetchTags
== TRUE
)
2419 notags
= _T("--tags ");
2422 noff
=_T("--no-ff ");
2425 ffonly
= _T("--ff-only ");
2428 squash
= _T("--squash ");
2430 if (dlg
.m_bNoCommit
)
2431 nocommit
= _T("--no-commit ");
2434 depth
.Format(_T("--depth %d "), dlg
.m_nDepth
);
2436 int ver
= CAppUtils::GetMsysgitVersion();
2438 if (dlg
.m_bPrune
== TRUE
)
2439 prune
= _T("--prune ");
2440 else if (dlg
.m_bPrune
== FALSE
&& ver
>= 0x01080500)
2441 prune
= _T("--no-prune ");
2443 if(ver
>= 0x01070203) //above 1.7.0.2
2444 cmdRebase
+= _T("--progress ");
2446 cmd
.Format(_T("git.exe pull -v --no-rebase %s%s%s%s%s%s%s%s\"%s\" %s"), cmdRebase
, noff
, ffonly
, squash
, nocommit
, depth
, notags
, prune
, url
, dlg
.m_RemoteBranchName
);
2447 CProgressDlg progress
;
2448 progress
.m_GitCmd
= cmd
;
2450 CGitHash hashNew
; // declare outside lambda, because it is captured by reference
2451 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
2455 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUPULL
, [&]{ Pull(); }));
2456 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_MENUSTASHSAVE
, [&]{ StashSave(_T(""), true); }));
2461 postCmdList
.push_back(PostCmd(IDI_RELOCATE
, IDS_MENUSTASHPOP
, []{ StashPop(); }));
2463 if (g_Git
.GetHash(hashNew
, _T("HEAD")))
2464 MessageBox(nullptr, g_Git
.GetGitLastErr(_T("Could not get HEAD hash after pulling.")), _T("TortoiseGit"), MB_ICONERROR
);
2467 postCmdList
.push_back(PostCmd(IDI_DIFF
, IDS_PROC_PULL_DIFFS
, [&]
2470 dlg
.SetDiff(NULL
, hashNew
.ToString(), hashOld
.ToString());
2473 postCmdList
.push_back(PostCmd(IDI_LOG
, IDS_PROC_PULL_LOG
, [&]
2476 dlg
.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), hashOld
.ToString() + _T("..") + hashNew
.ToString(), 0);
2482 postCmdList
.push_back(PostCmd(IDI_PUSH
, IDS_MENUPUSH
, []{ Push(_T("")); }));
2484 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
2485 if (gitPath
.HasSubmodules())
2487 postCmdList
.push_back(PostCmd(IDI_UPDATE
, IDS_PROC_SUBMODULESUPDATE
, []
2490 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
2491 CAppUtils::RunTortoiseGitProc(sCmd
);
2496 INT_PTR ret
= progress
.DoModal();
2498 if (ret
== IDOK
&& progress
.m_GitStatus
== 1 && progress
.m_LogText
.Find(_T("CONFLICT")) >= 0 && CMessageBox::Show(NULL
, IDS_SEECHANGES
, IDS_APPNAME
, MB_YESNO
| MB_ICONINFORMATION
) == IDYES
)
2501 dlg
.m_pathList
.AddPath(CTGitPath());
2513 bool CAppUtils::RebaseAfterFetch(const CString
& upstream
)
2518 if (!upstream
.IsEmpty())
2519 dlg
.m_Upstream
= upstream
;
2520 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2521 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUDESSENDMAIL
)));
2522 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2523 INT_PTR response
= dlg
.DoModal();
2524 if (response
== IDOK
)
2528 else if (response
== IDC_REBASE_POST_BUTTON
)
2530 CString cmd
= _T("/command:log");
2531 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2532 CAppUtils::RunTortoiseGitProc(cmd
);
2535 else if (response
== IDC_REBASE_POST_BUTTON
+ 1)
2537 CString cmd
, out
, err
;
2538 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2540 g_Git
.FixBranchName(dlg
.m_Upstream
),
2541 g_Git
.FixBranchName(dlg
.m_Branch
));
2542 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
2544 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2547 CAppUtils::SendPatchMail(cmd
, out
);
2550 else if (response
== IDC_REBASE_POST_BUTTON
+ 2)
2552 else if (response
== IDCANCEL
)
2558 static bool DoFetch(const CString
& url
, const bool fetchAllRemotes
, const bool loadPuttyAgent
, const int prune
, const bool bDepth
, const int nDepth
, const int fetchTags
, const CString
& remoteBranch
, boolean runRebase
)
2562 if (fetchAllRemotes
)
2565 g_Git
.GetRemoteList(list
);
2567 STRING_VECTOR::const_iterator it
= list
.begin();
2568 while (it
!= list
.end())
2570 CString
remote(*it
);
2571 CAppUtils::LaunchPAgent(NULL
, &remote
);
2576 CAppUtils::LaunchPAgent(NULL
, &url
);
2580 int ver
= CAppUtils::GetMsysgitVersion();
2581 if (ver
>= 0x01070203) //above 1.7.0.2
2582 arg
+= _T(" --progress");
2585 arg
.AppendFormat(_T(" --depth %d"), nDepth
);
2588 arg
+= _T(" --prune");
2589 else if (prune
== FALSE
&& ver
>= 0x01080500)
2590 arg
+= _T(" --no-prune");
2593 arg
+= _T(" --tags");
2594 else if (fetchTags
== 0)
2595 arg
+= _T(" --no-tags");
2597 if (fetchAllRemotes
)
2598 cmd
.Format(_T("git.exe fetch --all -v%s"), arg
);
2600 cmd
.Format(_T("git.exe fetch -v%s \"%s\" %s"), arg
, url
, remoteBranch
);
2602 CProgressDlg progress
;
2603 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
2607 postCmdList
.push_back(PostCmd(IDI_REFRESH
, IDS_MSGBOX_RETRY
, [&]{ DoFetch(url
, fetchAllRemotes
, loadPuttyAgent
, prune
, bDepth
, nDepth
, fetchTags
, remoteBranch
, runRebase
); }));
2611 postCmdList
.push_back(PostCmd(IDI_LOG
, IDS_MENULOG
, []
2613 CString cmd
= _T("/command:log");
2614 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2615 CAppUtils::RunTortoiseGitProc(cmd
);
2618 postCmdList
.push_back(PostCmd(IDI_REVERT
, IDS_PROC_RESET
, []
2620 CString pullRemote
, pullBranch
;
2621 g_Git
.GetRemoteTrackedBranchForHEAD(pullRemote
, pullBranch
);
2622 CString defaultUpstream
;
2623 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
2624 defaultUpstream
.Format(_T("remotes/%s/%s"), pullRemote
, pullBranch
);
2625 CAppUtils::GitReset(&defaultUpstream
, 2);
2628 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUFETCH
, []{ CAppUtils::Fetch(); }));
2630 if (!runRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
2631 postCmdList
.push_back(PostCmd(IDI_REBASE
, IDS_MENUREBASE
, [&]{ runRebase
= false; CAppUtils::RebaseAfterFetch(); }));
2634 progress
.m_GitCmd
= cmd
;
2635 INT_PTR userResponse
;
2637 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
2639 CGitProgressDlg gitdlg
;
2640 FetchProgressCommand fetchProgressCommand
;
2641 if (!fetchAllRemotes
)
2642 fetchProgressCommand
.SetUrl(url
);
2643 gitdlg
.SetCommand(&fetchProgressCommand
);
2644 fetchProgressCommand
.m_PostCmdCallback
= progress
.m_PostCmdCallback
;
2645 fetchProgressCommand
.SetAutoTag(fetchTags
== 1 ? GIT_REMOTE_DOWNLOAD_TAGS_ALL
: fetchTags
== 2 ? GIT_REMOTE_DOWNLOAD_TAGS_AUTO
: GIT_REMOTE_DOWNLOAD_TAGS_NONE
);
2646 if (!fetchAllRemotes
)
2647 fetchProgressCommand
.SetRefSpec(remoteBranch
);
2648 userResponse
= gitdlg
.DoModal();
2649 return userResponse
== IDOK
;
2652 userResponse
= progress
.DoModal();
2653 if (!progress
.m_GitStatus
)
2656 return CAppUtils::RebaseAfterFetch();
2659 return userResponse
== IDOK
;
2662 bool CAppUtils::Fetch(const CString
& remoteName
, bool allRemotes
)
2665 dlg
.m_PreSelectRemote
= remoteName
;
2667 dlg
.m_bAllRemotes
= allRemotes
;
2669 if(dlg
.DoModal()==IDOK
)
2670 return DoFetch(dlg
.m_RemoteURL
, dlg
.m_bAllRemotes
== BST_CHECKED
, dlg
.m_bAutoLoad
== BST_CHECKED
, dlg
.m_bPrune
, dlg
.m_bDepth
== BST_CHECKED
, dlg
.m_nDepth
, dlg
.m_bFetchTags
, dlg
.m_RemoteBranchName
, dlg
.m_bRebase
== BST_CHECKED
);
2675 bool CAppUtils::Push(const CString
& selectLocalBranch
)
2678 dlg
.m_BranchSourceName
= selectLocalBranch
;
2680 if (dlg
.DoModal() == IDOK
)
2683 DWORD exitcode
= 0xFFFFFFFF;
2684 if (CHooks::Instance().PrePush(g_Git
.m_CurrentDir
, exitcode
, error
))
2689 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2690 CMessageBox::Show(nullptr, temp
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2698 arg
+= _T("--thin ");
2699 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2700 arg
+= _T("--tags ");
2702 arg
+= _T("--force ");
2703 if (dlg
.m_bForceWithLease
)
2704 arg
+= _T("--force-with-lease ");
2705 if (dlg
.m_bSetUpstream
)
2706 arg
+= _T("--set-upstream ");
2707 if (dlg
.m_RecurseSubmodules
== 1)
2708 arg
+= _T("--recurse-submodules=check ");
2709 if (dlg
.m_RecurseSubmodules
== 2)
2710 arg
+= _T("--recurse-submodules=on-demand ");
2712 int ver
= CAppUtils::GetMsysgitVersion();
2714 if(ver
>= 0x01070203) //above 1.7.0.2
2715 arg
+= _T("--progress ");
2717 CProgressDlg progress
;
2719 STRING_VECTOR remotesList
;
2720 if (dlg
.m_bPushAllRemotes
)
2721 g_Git
.GetRemoteList(remotesList
);
2723 remotesList
.push_back(dlg
.m_URL
);
2725 for (unsigned int i
= 0; i
< remotesList
.size(); ++i
)
2727 if (dlg
.m_bAutoLoad
)
2728 CAppUtils::LaunchPAgent(NULL
, &remotesList
[i
]);
2731 if (dlg
.m_bPushAllBranches
)
2733 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2739 progress
.m_GitCmdList
.push_back(cmd
);
2740 cmd
.Format(_T("git.exe push --tags %s \"%s\""), arg
, remotesList
[i
]);
2745 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2748 dlg
.m_BranchSourceName
);
2749 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2751 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2754 progress
.m_GitCmdList
.push_back(cmd
);
2757 CString superprojectRoot
;
2758 g_GitAdminDir
.HasAdminDir(g_Git
.m_CurrentDir
, false, &superprojectRoot
);
2759 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
2761 // need to execute hooks as those might be needed by post action commands
2762 DWORD exitcode
= 0xFFFFFFFF;
2764 if (CHooks::Instance().PostPush(g_Git
.m_CurrentDir
, exitcode
, error
))
2769 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2770 MessageBox(nullptr, temp
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2776 bool rejected
= progress
.GetLogText().Find(_T("! [rejected]")) > 0;
2779 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUPULL
, []{ Pull(true); }));
2780 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUFETCH
, [&]{ Fetch(dlg
.m_bPushAllRemotes
? _T("") : dlg
.m_URL
, !!dlg
.m_bPushAllRemotes
); }));
2782 postCmdList
.push_back(PostCmd(IDI_PUSH
, IDS_MENUPUSH
, [&]{ Push(selectLocalBranch
); }));
2786 postCmdList
.push_back(PostCmd(IDS_PROC_REQUESTPULL
, [&]{ RequestPull(dlg
.m_BranchRemoteName
); }));
2787 postCmdList
.push_back(PostCmd(IDI_PUSH
, IDS_MENUPUSH
, [&]{ Push(selectLocalBranch
); }));
2788 postCmdList
.push_back(PostCmd(IDI_SWITCH
, IDS_MENUSWITCH
, [&]{ Switch(); }));
2789 if (!superprojectRoot
.IsEmpty())
2791 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_PROC_COMMIT_SUPERPROJECT
, [&]
2794 sCmd
.Format(_T("/command:commit /path:\"%s\""), superprojectRoot
);
2795 RunTortoiseGitProc(sCmd
);
2800 INT_PTR ret
= progress
.DoModal();
2806 bool CAppUtils::RequestPull(const CString
& endrevision
, const CString
& repositoryUrl
, bool bIsMainWnd
)
2808 CRequestPullDlg dlg
;
2809 dlg
.m_RepositoryURL
= repositoryUrl
;
2810 dlg
.m_EndRevision
= endrevision
;
2811 if (dlg
.DoModal()==IDOK
)
2814 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2816 CSysProgressDlg sysProgressDlg
;
2817 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2818 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CREATINGPULLREUQEST
)));
2819 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2820 sysProgressDlg
.SetShowProgressBar(false);
2821 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2823 CString tempFileName
= GetTempFile();
2825 DeleteFile(tempFileName
);
2826 CreateDirectory(tempFileName
, NULL
);
2827 tempFileName
+= _T("\\pullrequest.txt");
2828 if (g_Git
.RunLogFile(cmd
, tempFileName
, &err
))
2831 msg
.LoadString(IDS_ERR_PULLREUQESTFAILED
);
2832 CMessageBox::Show(NULL
, msg
+ _T("\n") + err
, _T("TortoiseGit"), MB_OK
);
2836 if (sysProgressDlg
.HasUserCancelled())
2838 CMessageBox::Show(NULL
, IDS_SVN_USERCANCELLED
, IDS_APPNAME
, MB_OK
);
2839 ::DeleteFile(tempFileName
);
2843 sysProgressDlg
.Stop();
2845 if (dlg
.m_bSendMail
)
2848 dlg
.m_PathList
= CTGitPathList(CTGitPath(tempFileName
));
2849 dlg
.m_bCustomSubject
= true;
2851 if (dlg
.DoModal() == IDOK
)
2853 if (dlg
.m_PathList
.IsEmpty())
2856 CGitProgressDlg progDlg
;
2858 theApp
.m_pMainWnd
= &progDlg
;
2859 SendMailProgressCommand sendMailProgressCommand
;
2860 progDlg
.SetCommand(&sendMailProgressCommand
);
2862 sendMailProgressCommand
.SetPathList(dlg
.m_PathList
);
2863 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2865 CSendMailCombineable
sendMailCombineable(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
);
2866 sendMailProgressCommand
.SetSendMailOption(&sendMailCombineable
);
2875 CAppUtils::LaunchAlternativeEditor(tempFileName
);
2880 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2882 CString
strDir(szPath
);
2883 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2885 strDir
.AppendChar(_T('\\'));
2887 std::vector
<CString
> vPath
;
2889 bool bSuccess
= false;
2891 for (int i
=0;i
<strDir
.GetLength();++i
)
2893 if (strDir
.GetAt(i
) != _T('\\'))
2895 strTemp
.AppendChar(strDir
.GetAt(i
));
2899 vPath
.push_back(strTemp
);
2900 strTemp
.AppendChar(_T('\\'));
2904 for (auto vIter
= vPath
.begin(); vIter
!= vPath
.end(); ++vIter
)
2906 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2912 void CAppUtils::RemoveTrailSlash(CString
&path
)
2917 // For URL, do not trim the slash just after the host name component.
2918 int index
= path
.Find(_T("://"));
2922 index
= path
.Find(_T('/'), index
);
2923 if (index
== path
.GetLength() - 1)
2927 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2929 path
=path
.Left(path
.GetLength()-1);
2935 bool CAppUtils::CheckUserData()
2937 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
2939 if(CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
2941 CTGitPath
path(g_Git
.m_CurrentDir
);
2942 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2943 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2944 dlg
.SetTreeWidth(220);
2945 dlg
.m_DefaultPage
= _T("gitconfig");
2948 dlg
.HandleRestart();
2958 BOOL
CAppUtils::Commit(const CString
& bugid
, BOOL bWholeProject
, CString
&sLogMsg
,
2959 CTGitPathList
&pathList
,
2960 CTGitPathList
&selectedList
,
2961 bool bSelectFilesForCommit
)
2963 bool bFailed
= true;
2965 if (!CheckUserData())
2972 dlg
.m_sBugID
= bugid
;
2974 dlg
.m_bWholeProject
= bWholeProject
;
2976 dlg
.m_sLogMessage
= sLogMsg
;
2977 dlg
.m_pathList
= pathList
;
2978 dlg
.m_checkedPathList
= selectedList
;
2979 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2980 if (dlg
.DoModal() == IDOK
)
2982 if (dlg
.m_pathList
.IsEmpty())
2984 // if the user hasn't changed the list of selected items
2985 // we don't use that list. Because if we would use the list
2986 // of pre-checked items, the dialog would show different
2987 // checked items on the next startup: it would only try
2988 // to check the parent folder (which might not even show)
2989 // instead, we simply use an empty list and let the
2990 // default checking do its job.
2991 if (!dlg
.m_pathList
.IsEqual(pathList
))
2992 selectedList
= dlg
.m_pathList
;
2993 pathList
= dlg
.m_updatedPathList
;
2994 sLogMsg
= dlg
.m_sLogMessage
;
2995 bSelectFilesForCommit
= true;
2997 switch (dlg
.m_PostCmd
)
2999 case GIT_POSTCOMMIT_CMD_DCOMMIT
:
3000 CAppUtils::SVNDCommit();
3002 case GIT_POSTCOMMIT_CMD_PUSH
:
3005 case GIT_POSTCOMMIT_CMD_CREATETAG
:
3006 CAppUtils::CreateBranchTag(TRUE
);
3008 case GIT_POSTCOMMIT_CMD_PULL
:
3009 CAppUtils::Pull(true);
3015 // CGitProgressDlg progDlg;
3016 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
3017 // if (parser.HasVal(_T("closeonend")))
3018 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
3019 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
3020 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
3021 // progDlg.SetPathList(dlg.m_pathList);
3022 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
3023 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
3024 // progDlg.SetSelectedList(dlg.m_selectedPathList);
3025 // progDlg.SetItemCount(dlg.m_itemsCount);
3026 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
3027 // progDlg.DoModal();
3028 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
3029 // err = (DWORD)progDlg.DidErrorsOccur();
3030 // bFailed = progDlg.DidErrorsOccur();
3031 // bRet = progDlg.DidErrorsOccur();
3032 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
3033 // if (DWORD(bFailRepeat)==0)
3034 // bFailed = false; // do not repeat if the user chose not to in the settings.
3041 BOOL
CAppUtils::SVNDCommit()
3043 CSVNDCommitDlg dcommitdlg
;
3044 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
3045 if (gitSetting
== _T("")) {
3046 if (dcommitdlg
.DoModal() != IDOK
)
3052 if (dcommitdlg
.m_remember
)
3054 if (dcommitdlg
.m_rmdir
)
3056 gitSetting
= _T("true");
3060 gitSetting
= _T("false");
3062 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
3065 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, _T("svn.rmdir"), gitSetting
);
3066 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
3072 BOOL IsStash
= false;
3073 if(!g_Git
.CheckCleanWorkTree())
3075 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
3077 CSysProgressDlg sysProgressDlg
;
3078 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3079 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
3080 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
3081 sysProgressDlg
.SetShowProgressBar(false);
3082 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
3083 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
3086 cmd
=_T("git.exe stash");
3087 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3089 sysProgressDlg
.Stop();
3090 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
3093 sysProgressDlg
.Stop();
3103 CProgressDlg progress
;
3104 if (dcommitdlg
.m_rmdir
)
3106 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
3110 progress
.m_GitCmd
=_T("git.exe svn dcommit");
3112 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
3114 ::DeleteFile(g_Git
.m_CurrentDir
+ _T("\\sys$command"));
3117 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
3119 CSysProgressDlg sysProgressDlg
;
3120 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3121 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
3122 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
3123 sysProgressDlg
.SetShowProgressBar(false);
3124 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
3125 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
3128 cmd
=_T("git.exe stash pop");
3129 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3131 sysProgressDlg
.Stop();
3132 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
3135 sysProgressDlg
.Stop();
3147 BOOL
CAppUtils::Merge(const CString
* commit
, bool showStashPop
)
3149 if (!CheckUserData())
3154 dlg
.m_initialRefName
= *commit
;
3156 if(dlg
.DoModal()==IDOK
)
3162 args
+= _T(" --no-ff");
3165 args
+= _T(" --squash");
3168 args
+= _T(" --no-commit");
3173 fmt
.Format(_T(" --log=%d"), dlg
.m_nLog
);
3177 if (!dlg
.m_MergeStrategy
.IsEmpty())
3179 args
+= _T(" --strategy=") + dlg
.m_MergeStrategy
;
3180 if (!dlg
.m_StrategyOption
.IsEmpty())
3182 args
+= _T(" --strategy-option=") + dlg
.m_StrategyOption
;
3183 if (!dlg
.m_StrategyParam
.IsEmpty())
3184 args
+= _T("=") + dlg
.m_StrategyParam
;
3188 if(!dlg
.m_strLogMesage
.IsEmpty())
3190 CString logmsg
= dlg
.m_strLogMesage
;
3191 logmsg
.Replace(_T("\""), _T("\\\""));
3192 args
+= _T(" -m \"") + logmsg
+ _T("\"");
3194 cmd
.Format(_T("git.exe merge %s %s"), args
, g_Git
.FixBranchName(dlg
.m_VersionName
));
3196 CProgressDlg Prodlg
;
3197 Prodlg
.m_GitCmd
= cmd
;
3199 Prodlg
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
3204 if (!g_Git
.ListConflictFile(list
) && !list
.IsEmpty())
3206 // there are conflict files
3208 postCmdList
.push_back(PostCmd(IDI_RESOLVE
, IDS_PROGRS_CMD_RESOLVE
, []
3211 sCmd
.Format(_T("/command:commit /path:\"%s\""), g_Git
.m_CurrentDir
);
3212 CAppUtils::RunTortoiseGitProc(sCmd
);
3216 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_MENUSTASHSAVE
, [&]{ CAppUtils::StashSave(_T(""), false, false, true, g_Git
.FixBranchName(dlg
.m_VersionName
)); }));
3221 postCmdList
.push_back(PostCmd(IDI_RELOCATE
, IDS_MENUSTASHPOP
, []{ StashPop(); }));
3223 if (dlg
.m_bNoCommit
)
3225 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_MENUCOMMIT
, []
3228 sCmd
.Format(_T("/command:commit /path:\"%s\""), g_Git
.m_CurrentDir
);
3229 CAppUtils::RunTortoiseGitProc(sCmd
);
3234 if (dlg
.m_bIsBranch
&& dlg
.m_VersionName
.Find(L
"remotes/") == -1) // do not ask to remove remote branches
3236 postCmdList
.push_back(PostCmd(IDI_DELETE
, IDS_PROC_REMOVEBRANCH
, [&]
3239 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, dlg
.m_VersionName
);
3240 if (CMessageBox::Show(nullptr, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
3243 cmd
.Format(_T("git.exe branch -D -- %s"), dlg
.m_VersionName
);
3244 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3245 MessageBox(nullptr, out
, _T("TortoiseGit"), MB_OK
);
3249 if (dlg
.m_bIsBranch
)
3250 postCmdList
.push_back(PostCmd(IDI_PUSH
, IDS_MENUPUSH
, []{ Push(); }));
3252 BOOL hasGitSVN
= CTGitPath(g_Git
.m_CurrentDir
).GetAdminDirMask() & ITEMIS_GITSVN
;
3254 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_MENUSVNDCOMMIT
, []{ SVNDCommit(); }));
3258 return !Prodlg
.m_GitStatus
;
3263 BOOL
CAppUtils::MergeAbort()
3266 if (dlg
.DoModal() == IDOK
)
3267 return Reset(_T("HEAD"), dlg
.m_ResetType
+ 1);
3272 void CAppUtils::EditNote(GitRev
*rev
)
3274 if (!CheckUserData())
3278 dlg
.m_sHintText
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
3279 dlg
.m_sInputText
= rev
->m_Notes
;
3280 dlg
.m_sTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
3281 //dlg.m_pProjectProperties = &m_ProjectProperties;
3282 dlg
.m_bUseLogWidth
= true;
3283 if(dlg
.DoModal() == IDOK
)
3286 cmd
=_T("notes add -f -F \"");
3288 CString tempfile
=::GetTempFile();
3289 if (CAppUtils::SaveCommitUnicodeFile(tempfile
, dlg
.m_sInputText
))
3291 CMessageBox::Show(nullptr, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3296 cmd
+= rev
->m_CommitHash
.ToString();
3300 if (git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
3302 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3307 rev
->m_Notes
= dlg
.m_sInputText
;
3311 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3313 ::DeleteFile(tempfile
);
3318 int CAppUtils::GetMsysgitVersion()
3320 if (g_Git
.ms_LastMsysGitVersion
)
3321 return g_Git
.ms_LastMsysGitVersion
;
3324 CString versiondebug
;
3327 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
3328 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
3330 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
3333 if (!g_Git
.GetFileModifyTime(gitpath
, &time
))
3335 if((DWORD
)time
== regTime
)
3337 g_Git
.ms_LastMsysGitVersion
= regVersion
;
3343 cmd
= _T("git.exe --version");
3344 if (g_Git
.Run(cmd
, &version
, &err
, CP_UTF8
))
3346 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
);
3353 versiondebug
= version
;
3357 CString str
=version
.Tokenize(_T("."), start
);
3358 int space
= str
.ReverseFind(_T(' '));
3359 str
= str
.Mid(space
+1,start
);
3363 version
= version
.Mid(start
);
3366 str
= version
.Tokenize(_T("."), start
);
3368 ver
|= (_ttol(str
) & 0xFF) << 16;
3370 str
= version
.Tokenize(_T("."), start
);
3371 ver
|= (_ttol(str
) & 0xFF) << 8;
3373 str
= version
.Tokenize(_T("."), start
);
3374 ver
|= (_ttol(str
) & 0xFF);
3380 CMessageBox::Show(NULL
, _T("Could not parse git.exe version number: \"") + versiondebug
+ _T("\""), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
3385 regTime
= time
&0xFFFFFFFF;
3387 g_Git
.ms_LastMsysGitVersion
= ver
;
3392 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
3394 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
3396 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("Shell32.dll"));
3398 if (hShell
.IsValid()) {
3399 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
3401 IPropertyStore
*pps
;
3402 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
3403 if (SUCCEEDED(hr
)) {
3406 var
.boolVal
= VARIANT_TRUE
;
3407 pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
3414 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
3416 ASSERT(dialogname
.GetLength() < 70);
3417 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
3418 WCHAR pathbuf
[MAX_PATH
] = {0};
3420 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
3422 wcscat_s(pathbuf
, L
" - ");
3423 wcscat_s(pathbuf
, dialogname
);
3424 wcscat_s(pathbuf
, L
" - ");
3425 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3426 SetWindowText(hWnd
, pathbuf
);
3429 bool CAppUtils::BisectStart(const CString
& lastGood
, const CString
& firstBad
, bool bIsMainWnd
)
3431 if (!g_Git
.CheckCleanWorkTree())
3433 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
3435 CSysProgressDlg sysProgressDlg
;
3436 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3437 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
3438 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
3439 sysProgressDlg
.SetShowProgressBar(false);
3440 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
3441 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
3444 cmd
= _T("git.exe stash");
3445 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3447 sysProgressDlg
.Stop();
3448 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
);
3451 sysProgressDlg
.Stop();
3457 CBisectStartDlg bisectStartDlg
;
3459 if (!lastGood
.IsEmpty())
3460 bisectStartDlg
.m_sLastGood
= lastGood
;
3461 if (!firstBad
.IsEmpty())
3462 bisectStartDlg
.m_sFirstBad
= firstBad
;
3464 if (bisectStartDlg
.DoModal() == IDOK
)
3466 CProgressDlg progress
;
3468 theApp
.m_pMainWnd
= &progress
;
3469 progress
.m_GitCmdList
.push_back(_T("git.exe bisect start"));
3470 progress
.m_GitCmdList
.push_back(_T("git.exe bisect good ") + bisectStartDlg
.m_LastGoodRevision
);
3471 progress
.m_GitCmdList
.push_back(_T("git.exe bisect bad ") + bisectStartDlg
.m_FirstBadRevision
);
3473 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
3478 CTGitPath
path(g_Git
.m_CurrentDir
);
3479 if (path
.HasSubmodules())
3481 postCmdList
.push_back(PostCmd(IDI_UPDATE
, IDS_PROC_SUBMODULESUPDATE
, []
3484 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
3485 CAppUtils::RunTortoiseGitProc(sCmd
);
3492 INT_PTR ret
= progress
.DoModal();
3499 int CAppUtils::Git2GetUserPassword(git_cred
**out
, const char *url
, const char *username_from_url
, unsigned int /*allowed_types*/, void * /*payload*/)
3502 dlg
.m_URL
= CUnicodeUtils::GetUnicode(url
, CP_UTF8
);
3503 if (username_from_url
)
3504 dlg
.m_UserName
= CUnicodeUtils::GetUnicode(username_from_url
, CP_UTF8
);
3506 CStringA username
, password
;
3507 if (dlg
.DoModal() == IDOK
)
3509 username
= CUnicodeUtils::GetMulti(dlg
.m_UserName
, CP_UTF8
);
3510 password
= CUnicodeUtils::GetMulti(dlg
.m_Password
, CP_UTF8
);
3511 return git_cred_userpass_plaintext_new(out
, username
, password
);
3513 giterr_set_str(GITERR_NONE
, "User cancelled.");
3517 int CAppUtils::Git2CertificateCheck(git_cert
* base_cert
, int /*valid*/, const char* host
, void* /*payload*/)
3519 if (base_cert
->cert_type
== GIT_CERT_X509
)
3521 git_cert_x509
* cert
= (git_cert_x509
*)base_cert
;
3523 if (last_accepted_cert
.cmp(cert
))
3526 PCCERT_CONTEXT pServerCert
= CertCreateCertificateContext(X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
, (BYTE
*)cert
->data
, (DWORD
)cert
->len
);
3528 DWORD verificationError
= VerifyServerCertificate(pServerCert
, CUnicodeUtils::GetUnicode(host
).GetBuffer(), 0);
3529 if (!verificationError
)
3531 last_accepted_cert
.set(cert
);
3532 CertFreeCertificateContext(pServerCert
);
3536 CString servernameInCert
;
3537 CertGetNameString(pServerCert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, 0, nullptr, servernameInCert
.GetBuffer(128), 128);
3538 servernameInCert
.ReleaseBuffer();
3541 CertGetNameString(pServerCert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, CERT_NAME_ISSUER_FLAG
, nullptr, issuer
.GetBuffer(128), 128);
3542 issuer
.ReleaseBuffer();
3544 CertFreeCertificateContext(pServerCert
);
3546 CCheckCertificateDlg dlg
;
3548 dlg
.m_sCertificateCN
= servernameInCert
;
3549 dlg
.m_sCertificateIssuer
= issuer
;
3550 dlg
.m_sHostname
= CUnicodeUtils::GetUnicode(host
);
3551 dlg
.m_sError
= CFormatMessageWrapper(verificationError
);
3552 if (dlg
.DoModal() == IDOK
)
3554 last_accepted_cert
.set(cert
);
3558 return GIT_ECERTIFICATE
;
3561 void CAppUtils::ExploreTo(HWND hwnd
, CString path
)
3563 if (PathFileExists(path
))
3565 ITEMIDLIST __unaligned
* pidl
= ILCreateFromPath(path
);
3568 SHOpenFolderAndSelectItems(pidl
, 0, 0, 0);
3573 // if filepath does not exist any more, navigate to closest matching folder
3576 int pos
= path
.ReverseFind(_T('\\'));
3579 path
= path
.Left(pos
);
3580 } while (!PathFileExists(path
));
3581 ShellExecute(hwnd
, _T("explore"), path
, nullptr, nullptr, SW_SHOW
);
3584 int CAppUtils::ResolveConflict(CTGitPath
& path
, resolve_with resolveWith
)
3586 bool b_local
= false, b_remote
= false;
3590 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""), path
.GetGitPathString());
3591 if (g_Git
.Run(cmd
, &vector
))
3593 CMessageBox::Show(nullptr, _T("git ls-files failed!"), _T("TortoiseGit"), MB_OK
);
3598 if (list
.ParserFromLsFile(vector
))
3600 CMessageBox::Show(nullptr, _T("Parse ls-files failed!"), _T("TortoiseGit"), MB_OK
);
3606 for (int i
= 0; i
< list
.GetCount(); ++i
)
3608 if (list
[i
].m_Stage
== 2)
3610 if (list
[i
].m_Stage
== 3)
3615 CBlockCacheForPath
block(g_Git
.m_CurrentDir
);
3616 if (path
.IsDirectory()) // is submodule conflict
3618 CString err
= _T("We're sorry, but you hit a very rare conflict condition with a submodule which cannot be resolved by TortoiseGit. You have to use the command line git for this.");
3619 if (b_local
&& b_remote
)
3621 if (!path
.HasAdminDir()) // check if submodule is initialized
3623 err
+= _T("\n\nYou have to checkout the submodule manually into \"") + path
.GetGitPathString() + _T("\" and then reset HEAD to the right commit (see resolve submodule conflict dialog for this).");
3624 MessageBox(nullptr, err
, _T("TortoiseGit"), MB_ICONERROR
);
3628 subgit
.m_CurrentDir
= g_Git
.CombinePath(path
);
3629 CGitHash submoduleHead
;
3630 if (subgit
.GetHash(submoduleHead
, _T("HEAD")))
3632 MessageBox(nullptr, err
, _T("TortoiseGit"), MB_ICONERROR
);
3635 CString baseHash
, localHash
, remoteHash
;
3636 ParseHashesFromLsFile(vector
, baseHash
, localHash
, remoteHash
);
3637 if (resolveWith
== RESOLVE_WITH_THEIRS
&& submoduleHead
.ToString() != remoteHash
)
3639 CString origPath
= g_Git
.m_CurrentDir
;
3640 g_Git
.m_CurrentDir
= g_Git
.CombinePath(path
);
3641 if (!GitReset(&remoteHash
))
3643 g_Git
.m_CurrentDir
= origPath
;
3646 g_Git
.m_CurrentDir
= origPath
;
3648 else if (resolveWith
== RESOLVE_WITH_MINE
&& submoduleHead
.ToString() != localHash
)
3650 CString origPath
= g_Git
.m_CurrentDir
;
3651 g_Git
.m_CurrentDir
= g_Git
.CombinePath(path
);
3652 if (!GitReset(&localHash
))
3654 g_Git
.m_CurrentDir
= origPath
;
3657 g_Git
.m_CurrentDir
= origPath
;
3662 MessageBox(nullptr, err
, _T("TortoiseGit"), MB_ICONERROR
);
3667 if (resolveWith
== RESOLVE_WITH_THEIRS
)
3669 CString gitcmd
, output
;
3670 if (b_local
&& b_remote
)
3671 gitcmd
.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""), path
.GetGitPathString());
3673 gitcmd
.Format(_T("git.exe add -f -- \"%s\""), path
.GetGitPathString());
3675 gitcmd
.Format(_T("git.exe rm -f -- \"%s\""), path
.GetGitPathString());
3676 if (g_Git
.Run(gitcmd
, &output
, CP_UTF8
))
3678 CMessageBox::Show(nullptr, output
, _T("TortoiseGit"), MB_ICONERROR
);
3682 else if (resolveWith
== RESOLVE_WITH_MINE
)
3684 CString gitcmd
, output
;
3685 if (b_local
&& b_remote
)
3686 gitcmd
.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""), path
.GetGitPathString());
3688 gitcmd
.Format(_T("git.exe add -f -- \"%s\""), path
.GetGitPathString());
3690 gitcmd
.Format(_T("git.exe rm -f -- \"%s\""), path
.GetGitPathString());
3691 if (g_Git
.Run(gitcmd
, &output
, CP_UTF8
))
3693 CMessageBox::Show(nullptr, output
, _T("TortoiseGit"), MB_ICONERROR
);
3698 if (b_local
&& b_remote
&& path
.m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
3700 CString gitcmd
, output
;
3701 gitcmd
.Format(_T("git.exe add -f -- \"%s\""), path
.GetGitPathString());
3702 if (g_Git
.Run(gitcmd
, &output
, CP_UTF8
))
3703 CMessageBox::Show(nullptr, output
, _T("TortoiseGit"), MB_ICONERROR
);
3706 path
.m_Action
|= CTGitPath::LOGACTIONS_MODIFIED
;
3707 path
.m_Action
&= ~CTGitPath::LOGACTIONS_UNMERGED
;
3711 RemoveTempMergeFile(path
);
3715 bool CAppUtils::ShellOpen(const CString
& file
, HWND hwnd
/*= nullptr */)
3717 if ((int)ShellExecute(hwnd
, NULL
, file
, NULL
, NULL
, SW_SHOW
) > HINSTANCE_ERROR
)
3720 return ShowOpenWithDialog(file
, hwnd
);
3723 bool CAppUtils::ShowOpenWithDialog(const CString
& file
, HWND hwnd
/*= nullptr */)
3725 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("shell32.dll"));
3728 typedef HRESULT STDAPICALLTYPE
SHOpenWithDialoFN(_In_opt_ HWND hwndParent
, _In_
const OPENASINFO
*poainfo
);
3729 SHOpenWithDialoFN
*pfnSHOpenWithDialog
= (SHOpenWithDialoFN
*)GetProcAddress(hShell
, "SHOpenWithDialog");
3730 if (pfnSHOpenWithDialog
)
3732 OPENASINFO oi
= { 0 };
3734 oi
.oaifInFlags
= OAIF_EXEC
;
3735 return SUCCEEDED(pfnSHOpenWithDialog(hwnd
, &oi
));
3738 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
3740 return CAppUtils::LaunchApplication(cmd
, NULL
, false);