1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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
)
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 return (progress
.DoModal() == IDOK
);
148 bool CAppUtils::StashApply(CString ref
, bool showChanges
/* true */)
151 cmd
= _T("git.exe stash apply ");
152 if (ref
.Find(_T("refs/")) == 0)
154 if (ref
.Find(_T("stash{")) == 0)
155 ref
= _T("stash@") + ref
.Mid(5);
158 CSysProgressDlg sysProgressDlg
;
159 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
160 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
161 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
162 sysProgressDlg
.SetShowProgressBar(false);
163 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
164 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
166 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
168 sysProgressDlg
.Stop();
170 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
171 if (ret
&& !(ret
== 1 && hasConflicts
))
173 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHAPPLYFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
178 message
.LoadString(IDS_PROC_STASHAPPLYSUCCESS
);
180 message
.LoadString(IDS_PROC_STASHAPPLYFAILEDCONFLICTS
);
183 if(CMessageBox::Show(NULL
,message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
))
184 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
187 dlg
.m_pathList
.AddPath(CTGitPath());
194 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
201 bool CAppUtils::StashPop(bool showChanges
/* true */)
204 cmd
=_T("git.exe stash pop ");
206 CSysProgressDlg sysProgressDlg
;
207 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
208 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
209 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
210 sysProgressDlg
.SetShowProgressBar(false);
211 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
212 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
214 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
216 sysProgressDlg
.Stop();
218 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
219 if (ret
&& !(ret
== 1 && hasConflicts
))
221 CMessageBox::Show(NULL
,CString(MAKEINTRESOURCE(IDS_PROC_STASHPOPFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
226 message
.LoadString(IDS_PROC_STASHPOPSUCCESS
);
228 message
.LoadString(IDS_PROC_STASHPOPFAILEDCONFLICTS
);
231 if(CMessageBox::Show(NULL
,CString(message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
)))
232 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
235 dlg
.m_pathList
.AddPath(CTGitPath());
242 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
249 BOOL
CAppUtils::StartExtMerge(
250 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
251 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
,
252 HWND resolveMsgHwnd
, bool bDeleteBaseTheirsMineOnClose
)
255 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
256 CString ext
= mergedfile
.GetFileExtension();
257 CString com
= regCom
;
258 bool bInternal
= false;
262 // is there an extension specific merge tool?
263 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
264 if (!CString(mergetool
).IsEmpty())
269 // is there a filename specific merge tool?
270 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\.") + mergedfile
.GetFilename().MakeLower());
271 if (!CString(mergetool
).IsEmpty())
276 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
278 // Maybe we should use TortoiseIDiff?
279 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
280 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
281 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
282 (ext
== _T(".tif")) || (ext
== _T(".tiff")) ||
283 (ext
== _T(".dib")) || (ext
== _T(".emf")) ||
286 com
= CPathUtils::GetAppDirectory() + _T("TortoiseGitIDiff.exe");
287 com
= _T("\"") + com
+ _T("\"");
288 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /result:%merged");
289 com
= com
+ _T(" /basetitle:%bname /theirstitle:%tname /minetitle:%yname");
293 // use TortoiseGitMerge
295 com
= CPathUtils::GetAppDirectory() + _T("TortoiseGitMerge.exe");
296 com
= _T("\"") + com
+ _T("\"");
297 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
298 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
299 com
+= _T(" /saverequired");
303 s
.Format(L
" /resolvemsghwnd:%I64d", (__int64
)resolveMsgHwnd
);
306 if (bDeleteBaseTheirsMineOnClose
)
307 com
+= _T(" /deletebasetheirsmineonclose");
309 if (!g_sGroupingUUID
.IsEmpty())
311 com
+= L
" /groupuuid:\"";
312 com
+= g_sGroupingUUID
;
316 // check if the params are set. If not, just add the files to the command line
317 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
319 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
320 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
321 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
322 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
324 if (basefile
.IsEmpty())
326 com
.Replace(_T("/base:%base"), _T(""));
327 com
.Replace(_T("%base"), _T(""));
330 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
331 if (theirfile
.IsEmpty())
333 com
.Replace(_T("/theirs:%theirs"), _T(""));
334 com
.Replace(_T("%theirs"), _T(""));
337 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
338 if (yourfile
.IsEmpty())
340 com
.Replace(_T("/mine:%mine"), _T(""));
341 com
.Replace(_T("%mine"), _T(""));
344 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
345 if (mergedfile
.IsEmpty())
347 com
.Replace(_T("/merged:%merged"), _T(""));
348 com
.Replace(_T("%merged"), _T(""));
351 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
352 if (basename
.IsEmpty())
354 if (basefile
.IsEmpty())
356 com
.Replace(_T("/basename:%bname"), _T(""));
357 com
.Replace(_T("%bname"), _T(""));
361 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
365 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
366 if (theirname
.IsEmpty())
368 if (theirfile
.IsEmpty())
370 com
.Replace(_T("/theirsname:%tname"), _T(""));
371 com
.Replace(_T("%tname"), _T(""));
375 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
379 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
380 if (yourname
.IsEmpty())
382 if (yourfile
.IsEmpty())
384 com
.Replace(_T("/minename:%yname"), _T(""));
385 com
.Replace(_T("%yname"), _T(""));
389 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
393 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
394 if (mergedname
.IsEmpty())
396 if (mergedfile
.IsEmpty())
398 com
.Replace(_T("/mergedname:%mname"), _T(""));
399 com
.Replace(_T("%mname"), _T(""));
403 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
407 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
409 if ((bReadOnly
)&&(bInternal
))
410 com
+= _T(" /readonly");
412 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
420 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
423 // use TortoiseGitMerge
424 viewer
= CPathUtils::GetAppDirectory();
425 viewer
+= _T("TortoiseGitMerge.exe");
427 viewer
= _T("\"") + viewer
+ _T("\"");
428 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
429 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
431 viewer
+= _T(" /reversedpatch");
432 if (!sOriginalDescription
.IsEmpty())
433 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
434 if (!sPatchedDescription
.IsEmpty())
435 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
436 if (!g_sGroupingUUID
.IsEmpty())
438 viewer
+= L
" /groupuuid:\"";
439 viewer
+= g_sGroupingUUID
;
442 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
449 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
451 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file2
.GetFilename().MakeLower());
452 if (!difftool
.IsEmpty())
454 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\.") + file1
.GetFilename().MakeLower());
455 if (!difftool
.IsEmpty())
458 // Is there an extension specific diff tool?
459 CString ext
= file2
.GetFileExtension().MakeLower();
462 difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
463 if (!difftool
.IsEmpty())
465 // Maybe we should use TortoiseIDiff?
466 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
467 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
468 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
469 (ext
== _T(".tif")) || (ext
== _T(".tiff")) ||
470 (ext
== _T(".dib")) || (ext
== _T(".emf")) ||
474 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitIDiff.exe") + _T("\"") +
475 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname") +
476 L
" /groupuuid:\"" + g_sGroupingUUID
+ L
"\"";
480 // Finally, pick a generic external diff tool
481 difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
485 bool CAppUtils::StartExtDiff(
486 const CString
& file1
, const CString
& file2
,
487 const CString
& sName1
, const CString
& sName2
,
488 const CString
& originalFile1
, const CString
& originalFile2
,
489 const git_revnum_t
& hash1
, const git_revnum_t
& hash2
,
490 const DiffFlags
& flags
, int jumpToLine
)
494 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
495 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
497 viewer
= PickDiffTool(file1
, file2
);
498 // If registry entry for a diff program is commented out, use TortoiseGitMerge.
499 bool bCommentedOut
= viewer
.Left(1) == _T("#");
500 if (flags
.bAlternativeTool
)
502 // Invert external vs. internal diff tool selection.
504 viewer
.Delete(0); // uncomment
508 else if (bCommentedOut
)
512 bool bInternal
= viewer
.IsEmpty();
516 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseGitMerge.exe") + _T("\"") +
517 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname") +
518 _T(" /basereflectedname:%bpath /minereflectedname:%ypath");
519 if (!g_sGroupingUUID
.IsEmpty())
521 viewer
+= L
" /groupuuid:\"";
522 viewer
+= g_sGroupingUUID
;
526 viewer
+= _T(" /blame");
528 // check if the params are set. If not, just add the files to the command line
529 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
531 viewer
+= _T(" \"")+file1
+_T("\"");
532 viewer
+= _T(" \"")+file2
+_T("\"");
534 if (viewer
.Find(_T("%base")) >= 0)
536 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
538 if (viewer
.Find(_T("%mine")) >= 0)
540 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
543 if (sName1
.IsEmpty())
544 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
546 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
548 if (sName2
.IsEmpty())
549 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
551 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
553 viewer
.Replace(_T("%bpath"), _T("\"") + originalFile1
+ _T("\""));
554 viewer
.Replace(_T("%ypath"), _T("\"") + originalFile2
+ _T("\""));
556 viewer
.Replace(_T("%brev"), _T("\"") + hash1
+ _T("\""));
557 viewer
.Replace(_T("%yrev"), _T("\"") + hash2
+ _T("\""));
559 if (flags
.bReadOnly
&& bInternal
)
560 viewer
+= _T(" /readonly");
565 temp
.Format(_T(" /line:%d"), jumpToLine
);
569 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
572 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
575 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
577 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
579 // use TortoiseGitUDiff
580 viewer
= CPathUtils::GetAppDirectory();
581 viewer
+= _T("TortoiseGitUDiff.exe");
582 // enquote the path to TortoiseGitUDiff
583 viewer
= _T("\"") + viewer
+ _T("\"");
585 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
586 if (!g_sGroupingUUID
.IsEmpty())
588 viewer
+= L
" /groupuuid:\"";
589 viewer
+= g_sGroupingUUID
;
593 if (viewer
.Find(_T("%1"))>=0)
595 if (viewer
.Find(_T("\"%1\"")) >= 0)
596 viewer
.Replace(_T("%1"), patchfile
);
598 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
601 viewer
+= _T(" \"") + patchfile
+ _T("\"");
602 if (viewer
.Find(_T("%title")) >= 0)
604 viewer
.Replace(_T("%title"), title
);
607 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
614 BOOL
CAppUtils::StartTextViewer(CString file
)
617 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
619 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
620 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
623 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
624 std::unique_ptr
<TCHAR
[]> buf(new TCHAR
[len
+ 1]);
625 ExpandEnvironmentStrings(viewer
, buf
.get(), len
);
627 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
628 std::unique_ptr
<TCHAR
[]> buf2(new TCHAR
[len
+ 1]);
629 ExpandEnvironmentStrings(file
, buf2
.get(), len
);
631 file
= _T("\"")+file
+_T("\"");
632 if (viewer
.IsEmpty())
634 return CAppUtils::ShowOpenWithDialog(file
) ? TRUE
: FALSE
;
636 if (viewer
.Find(_T("\"%1\"")) >= 0)
638 viewer
.Replace(_T("\"%1\""), file
);
640 else if (viewer
.Find(_T("%1")) >= 0)
642 viewer
.Replace(_T("%1"), file
);
650 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
657 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
660 CAutoFile hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
663 length
= ::GetFileSize(hFile
, NULL
);
670 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
673 HDC hScreenDC
= ::GetDC(NULL
);
674 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
675 ::ReleaseDC(NULL
, hScreenDC
);
677 logFont
.lfEscapement
= 0;
678 logFont
.lfOrientation
= 0;
679 logFont
.lfWeight
= FW_NORMAL
;
680 logFont
.lfItalic
= 0;
681 logFont
.lfUnderline
= 0;
682 logFont
.lfStrikeOut
= 0;
683 logFont
.lfCharSet
= DEFAULT_CHARSET
;
684 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
685 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
686 logFont
.lfQuality
= DRAFT_QUALITY
;
687 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
688 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
689 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
692 bool CAppUtils::LaunchPAgent(const CString
* keyfile
, const CString
* pRemote
)
706 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
707 key
= g_Git
.GetConfigValue(cmd
);
715 CString proc
=CPathUtils::GetAppDirectory();
716 proc
+= _T("pageant.exe \"");
720 CString tempfile
= GetTempFile();
721 ::DeleteFile(tempfile
);
723 proc
+= _T(" -c \"");
724 proc
+= CPathUtils::GetAppDirectory();
725 proc
+= _T("tgittouch.exe\"");
730 CString appDir
= CPathUtils::GetAppDirectory();
731 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true, &appDir
);
736 while(!::PathFileExists(tempfile
))
741 break; //timeout 5 minutes
746 CMessageBox::Show(NULL
, IDS_ERR_PAEGENTTIMEOUT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
748 ::DeleteFile(tempfile
);
751 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
, bool uac
)
753 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
754 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
755 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
759 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
761 LaunchApplication(sCmd
, NULL
, false, NULL
, uac
);
764 bool CAppUtils::LaunchRemoteSetting()
766 CTGitPath
path(g_Git
.m_CurrentDir
);
767 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
768 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
769 dlg
.SetTreeWidth(220);
770 dlg
.m_DefaultPage
= _T("gitremote");
777 * Launch the external blame viewer
779 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
, const CString
& Rev
, const CString
& sParams
)
781 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
782 viewer
+= _T("TortoiseGitBlame.exe");
783 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
784 //viewer += _T(" \"") + sLogFile + _T("\"");
785 //viewer += _T(" \"") + sOriginalFile + _T("\"");
786 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
787 viewer
+= CString(_T(" /rev:"))+Rev
;
788 if (!g_sGroupingUUID
.IsEmpty())
790 viewer
+= L
" /groupuuid:\"";
791 viewer
+= g_sGroupingUUID
;
794 viewer
+= _T(" ")+sParams
;
796 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
799 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
804 bool bStyled
= false;
805 pWnd
->GetWindowText(sText
);
806 // the rich edit control doesn't count the CR char!
807 // to be exact: CRLF is treated as one char.
808 sText
.Remove(_T('\r'));
810 // style each line separately
815 nNewlinePos
= sText
.Find('\n', offset
);
816 CString sLine
= nNewlinePos
>= 0 ? sText
.Mid(offset
, nNewlinePos
- offset
) : sText
.Mid(offset
);
820 while (FindStyleChars(sLine
, '*', start
, end
))
822 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
823 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
824 SetCharFormat(pWnd
, CFM_BOLD
, CFE_BOLD
);
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_ITALIC
, CFE_ITALIC
);
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_UNDERLINE
, CFE_UNDERLINE
);
848 offset
= nNewlinePos
+1;
849 } while(nNewlinePos
>=0);
853 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
856 int last
= sText
.GetLength() - 1;
857 bool bFoundMarker
= false;
858 TCHAR c
= i
== 0 ? _T('\0') : sText
[i
- 1];
859 TCHAR nextChar
= i
>= last
? _T('\0') : sText
[i
+ 1];
861 // find a starting marker
866 nextChar
= sText
[i
+ 1];
868 // IsCharAlphaNumeric can be somewhat expensive.
869 // Long lines of "*****" or "----" will be pre-empted efficiently
870 // by the (c != nextChar) condition.
872 if ((c
== stylechar
) && (c
!= nextChar
))
874 if (IsCharAlphaNumeric(nextChar
) && !IsCharAlphaNumeric(prevChar
))
886 // find ending marker
889 bFoundMarker
= false;
896 if ((i
== last
) || (!IsCharAlphaNumeric(sText
[i
+ 1]) && IsCharAlphaNumeric(prevChar
)))
909 bool CAppUtils::StartShowUnifiedDiff(HWND hWnd
, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
910 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
911 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
912 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */,
913 bool /* blame = false */,
918 if (GetMsysgitVersion() > 0x01080100)
919 diffContext
= g_Git
.GetConfigValueInt32(_T("diff.context"), -1);
920 CString tempfile
=GetTempFile();
921 if (g_Git
.GetUnifiedDiff(url1
, rev1
, rev2
, tempfile
, bMerge
, bCombine
, diffContext
))
923 CMessageBox::Show(hWnd
, g_Git
.GetGitLastErr(_T("Could not get unified diff."), CGit::GIT_CMD_DIFF
), _T("TortoiseGit"), MB_OK
);
926 CAppUtils::StartUnifiedDiffViewer(tempfile
, rev1
+ _T(":") + rev2
);
930 sCmd
.Format(_T("%s /command:showcompare /unified"),
931 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseGitProc.exe")));
932 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
934 sCmd
+= _T(" /revision1:") + rev1
.ToString();
935 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
937 sCmd
+= _T(" /revision2:") + rev2
.ToString();
939 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
940 if (headpeg
.IsValid())
941 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
944 sCmd
+= _T(" /alternatediff");
947 sCmd
+= _T(" /ignoreancestry");
951 sCmd
+= _T(" /hwnd:");
953 _stprintf_s(buf
, 30, _T("%p"), (void*)hWnd
);
957 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
962 bool CAppUtils::SetupDiffScripts(bool force
, const CString
& type
)
964 CString scriptsdir
= CPathUtils::GetAppParentDirectory();
965 scriptsdir
+= _T("Diff-Scripts");
966 CSimpleFileFind
files(scriptsdir
);
967 while (files
.FindNextFileNoDirectories())
969 CString file
= files
.GetFilePath();
970 CString filename
= files
.GetFileName();
971 CString ext
= file
.Mid(file
.ReverseFind('-') + 1);
972 ext
= _T(".") + ext
.Left(ext
.ReverseFind('.'));
973 std::set
<CString
> extensions
;
974 extensions
.insert(ext
);
976 if (file
.Right(3).CompareNoCase(_T("vbs"))==0)
978 kind
= _T(" //E:vbscript");
980 if (file
.Right(2).CompareNoCase(_T("js"))==0)
982 kind
= _T(" //E:javascript");
984 // open the file, read the first line and find possible extensions
985 // this script can handle
988 CStdioFile
f(file
, CFile::modeRead
| CFile::shareDenyNone
);
990 if (f
.ReadString(extline
))
992 if ((extline
.GetLength() > 15 ) &&
993 ((extline
.Left(15).Compare(_T("// extensions: ")) == 0) ||
994 (extline
.Left(14).Compare(_T("' extensions: ")) == 0)))
996 if (extline
[0] == '/')
997 extline
= extline
.Mid(15);
999 extline
= extline
.Mid(14);
1002 sToken
= extline
.Tokenize(_T(";"), curPos
);
1003 while (!sToken
.IsEmpty())
1005 if (!sToken
.IsEmpty())
1007 if (sToken
[0] != '.')
1008 sToken
= _T(".") + sToken
;
1009 extensions
.insert(sToken
);
1011 sToken
= extline
.Tokenize(_T(";"), curPos
);
1017 catch (CFileException
* e
)
1022 for (std::set
<CString
>::const_iterator it
= extensions
.begin(); it
!= extensions
.end(); ++it
)
1024 if (type
.IsEmpty() || (type
.Compare(_T("Diff")) == 0))
1026 if (filename
.Left(5).CompareNoCase(_T("diff-")) == 0)
1028 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + *it
);
1029 CString diffregstring
= diffreg
;
1030 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
1031 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %base %mine") + kind
;
1034 if (type
.IsEmpty() || (type
.Compare(_T("Merge"))==0))
1036 if (filename
.Left(6).CompareNoCase(_T("merge-"))==0)
1038 CRegString diffreg
= CRegString(_T("Software\\TortoiseGit\\MergeTools\\") + *it
);
1039 CString diffregstring
= diffreg
;
1040 if (force
|| (diffregstring
.IsEmpty()) || (diffregstring
.Find(filename
) >= 0))
1041 diffreg
= _T("wscript.exe \"") + file
+ _T("\" %merged %theirs %mine %base") + kind
;
1050 bool CAppUtils::Export(const CString
* BashHash
, const CTGitPath
* orgPath
)
1052 // ask from where the export has to be done
1055 dlg
.m_initialRefName
=*BashHash
;
1058 if (PathIsRelative(orgPath
->GetWinPath()))
1059 dlg
.m_orgPath
= g_Git
.CombinePath(orgPath
);
1061 dlg
.m_orgPath
= *orgPath
;
1064 if (dlg
.DoModal() == IDOK
)
1067 cmd
.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s --"),
1068 dlg
.m_strFile
, g_Git
.FixBranchName(dlg
.m_VersionName
));
1072 pro
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
1076 postCmdList
.push_back(PostCmd(IDI_EXPLORER
, IDS_STATUSLIST_CONTEXT_EXPLORE
, [&]{ CAppUtils::ExploreTo(hWndExplorer
, dlg
.m_strFile
); }));
1080 if (!dlg
.m_bWholeProject
&& !dlg
.m_orgPath
.IsEmpty() && PathIsDirectory(dlg
.m_orgPath
.GetWinPathString()))
1082 git
.m_CurrentDir
= dlg
.m_orgPath
.GetWinPathString();
1085 return (pro
.DoModal() == IDOK
);
1090 bool CAppUtils::CreateBranchTag(bool IsTag
, const CString
* CommitHash
, bool switch_new_brach
)
1092 CCreateBranchTagDlg dlg
;
1094 dlg
.m_bSwitch
=switch_new_brach
;
1097 dlg
.m_initialRefName
= *CommitHash
;
1099 if(dlg
.DoModal()==IDOK
)
1104 if(dlg
.m_bTrack
== TRUE
)
1105 track
=_T(" --track ");
1106 else if(dlg
.m_bTrack
== FALSE
)
1107 track
=_T(" --no-track");
1118 cmd
.Format(_T("git.exe tag %s %s %s %s"),
1121 dlg
.m_BranchTagName
,
1122 g_Git
.FixBranchName(dlg
.m_VersionName
)
1125 if(!dlg
.m_Message
.Trim().IsEmpty())
1127 CString tempfile
= ::GetTempFile();
1128 if (CAppUtils::SaveCommitUnicodeFile(tempfile
, dlg
.m_Message
))
1130 CMessageBox::Show(nullptr, _T("Could not save tag message"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1133 cmd
+= _T(" -F ")+tempfile
;
1138 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1141 dlg
.m_BranchTagName
,
1142 g_Git
.FixBranchName(dlg
.m_VersionName
)
1146 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1148 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1151 if( !IsTag
&& dlg
.m_bSwitch
)
1153 // it is a new branch and the user has requested to switch to it
1154 PerformSwitch(dlg
.m_BranchTagName
);
1162 bool CAppUtils::Switch(const CString
& initialRefName
)
1165 if(!initialRefName
.IsEmpty())
1166 dlg
.m_initialRefName
= initialRefName
;
1168 if (dlg
.DoModal() == IDOK
)
1172 branch
= dlg
.m_NewBranch
;
1174 // if refs/heads/ is not stripped, checkout will detach HEAD
1175 // checkout prefers branches on name clashes (with tags)
1176 if (dlg
.m_VersionName
.Left(11) ==_T("refs/heads/") && dlg
.m_bBranchOverride
!= TRUE
)
1177 dlg
.m_VersionName
= dlg
.m_VersionName
.Mid(11);
1179 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
, dlg
.m_bMerge
== TRUE
);
1184 bool CAppUtils::PerformSwitch(const CString
& ref
, bool bForce
/* false */, const CString
& sNewBranch
/* CString() */, bool bBranchOverride
/* false */, BOOL bTrack
/* 2 */, bool bMerge
/* false */)
1192 if(!sNewBranch
.IsEmpty()){
1193 if (bBranchOverride
)
1195 branch
.Format(_T("-B %s"), sNewBranch
);
1199 branch
.Format(_T("-b %s"), sNewBranch
);
1202 track
= _T("--track");
1203 else if (bTrack
== FALSE
)
1204 track
= _T("--no-track");
1209 merge
= _T("--merge");
1211 cmd
.Format(_T("git.exe checkout %s %s %s %s %s --"),
1216 g_Git
.FixBranchName(ref
));
1218 CProgressDlg progress
;
1219 progress
.m_GitCmd
= cmd
;
1221 CString currentBranch
;
1222 bool hasBranch
= CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, currentBranch
) == 0;
1223 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
1227 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1228 if (gitPath
.HasSubmodules())
1230 postCmdList
.push_back(PostCmd(IDI_UPDATE
, IDS_PROC_SUBMODULESUPDATE
, [&]
1233 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1234 RunTortoiseGitProc(sCmd
);
1238 postCmdList
.push_back(PostCmd(IDI_MERGE
, IDS_MENUMERGE
, [&]{ Merge(¤tBranch
); }));
1242 if (!CGit::GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, newBranch
))
1243 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUPULL
, [&]{ Pull(); }));
1245 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_MENUCOMMIT
, []{
1246 CTGitPathList pathlist
;
1247 CTGitPathList selectedlist
;
1248 bool bSelectFilesForCommit
= !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
1250 Commit(CString(), false, str
, pathlist
, selectedlist
, bSelectFilesForCommit
);
1255 postCmdList
.push_back(PostCmd(IDI_REFRESH
, IDS_MSGBOX_RETRY
, [&]{ PerformSwitch(ref
, bForce
, sNewBranch
, bBranchOverride
, bTrack
, bMerge
); }));
1257 postCmdList
.push_back(PostCmd(IDI_SWITCH
, IDS_SWITCH_WITH_MERGE
, [&]{ PerformSwitch(ref
, bForce
, sNewBranch
, bBranchOverride
, bTrack
, true); }));
1261 INT_PTR ret
= progress
.DoModal();
1266 class CIgnoreFile
: public CStdioFile
1269 STRING_VECTOR m_Items
;
1272 virtual BOOL
ReadString(CString
& rString
)
1274 if (GetPosition() == 0)
1276 unsigned char utf8bom
[] = { 0xEF, 0xBB, 0xBF };
1277 char buf
[3] = { 0, 0, 0 };
1279 if (memcpy(buf
, utf8bom
, sizeof(utf8bom
)))
1286 char lastChar
= '\0';
1287 for (char c
= '\0'; Read(&c
, 1) == 1; lastChar
= c
)
1293 m_eol
= lastChar
== '\r' ? _T("\r\n") : _T("\n");
1301 rString
= CUnicodeUtils::GetUnicode(strA
);
1312 bool CAppUtils::OpenIgnoreFile(CIgnoreFile
&file
, const CString
& filename
)
1315 if (!file
.Open(filename
, CFile::modeCreate
| CFile::modeReadWrite
| CFile::modeNoTruncate
| CFile::typeBinary
))
1317 CMessageBox::Show(NULL
, filename
+ _T(" Open Failure"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1321 if (file
.GetLength() > 0)
1324 while (file
.ReadString(fileText
))
1325 file
.m_Items
.push_back(fileText
);
1326 file
.Seek(file
.GetLength() - 1, 0);
1327 char lastchar
[1] = { 0 };
1328 file
.Read(lastchar
, 1);
1330 if (lastchar
[0] != '\n')
1332 CStringA eol
= CStringA(file
.m_eol
.IsEmpty() ? _T("\n") : file
.m_eol
);
1333 file
.Write(eol
, eol
.GetLength());
1342 bool CAppUtils::IgnoreFile(const CTGitPathList
& path
,bool IsMask
)
1344 CIgnoreDlg ignoreDlg
;
1345 if (ignoreDlg
.DoModal() == IDOK
)
1348 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\");
1350 switch (ignoreDlg
.m_IgnoreFile
)
1353 ignorefile
+= _T(".gitignore");
1356 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, ignorefile
);
1357 ignorefile
+= _T("info/exclude");
1364 if (ignoreDlg
.m_IgnoreFile
!= 1 && !OpenIgnoreFile(file
, ignorefile
))
1367 for (int i
= 0; i
< path
.GetCount(); ++i
)
1369 if (ignoreDlg
.m_IgnoreFile
== 1)
1371 ignorefile
= g_Git
.CombinePath(path
[i
].GetContainingDirectory()) + _T("\\.gitignore");
1372 if (!OpenIgnoreFile(file
, ignorefile
))
1376 CString ignorePattern
;
1377 if (ignoreDlg
.m_IgnoreType
== 0)
1379 if (ignoreDlg
.m_IgnoreFile
!= 1 && !path
[i
].GetContainingDirectory().GetGitPathString().IsEmpty())
1380 ignorePattern
+= _T("/") + path
[i
].GetContainingDirectory().GetGitPathString();
1382 ignorePattern
+= _T("/");
1386 ignorePattern
+= _T("*") + path
[i
].GetFileExtension();
1390 ignorePattern
+= path
[i
].GetFileOrDirectoryName();
1393 // escape [ and ] so that files get ignored correctly
1394 ignorePattern
.Replace(_T("["), _T("\\["));
1395 ignorePattern
.Replace(_T("]"), _T("\\]"));
1398 for (size_t j
= 0; j
< file
.m_Items
.size(); ++j
)
1400 if (file
.m_Items
[j
] == ignorePattern
)
1408 file
.m_Items
.push_back(ignorePattern
);
1409 ignorePattern
+= file
.m_eol
.IsEmpty() ? _T("\n") : file
.m_eol
;
1410 CStringA ignorePatternA
= CUnicodeUtils::GetUTF8(ignorePattern
);
1411 file
.Write(ignorePatternA
, ignorePatternA
.GetLength());
1414 if (ignoreDlg
.m_IgnoreFile
== 1)
1418 if (ignoreDlg
.m_IgnoreFile
!= 1)
1432 static bool Reset(const CString
& resetTo
, int resetType
)
1439 type
= _T("--soft");
1442 type
= _T("--mixed");
1445 type
= _T("--hard");
1449 type
= _T("--mixed");
1452 cmd
.Format(_T("git.exe reset %s %s --"), type
, resetTo
);
1454 CProgressDlg progress
;
1455 progress
.m_GitCmd
= cmd
;
1457 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
1461 postCmdList
.push_back(PostCmd(IDI_REFRESH
, IDS_MSGBOX_RETRY
, [&]{ Reset(resetTo
, resetType
); }));
1465 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1466 if (gitPath
.HasSubmodules() && resetType
== 2)
1468 postCmdList
.push_back(PostCmd(IDI_UPDATE
, IDS_PROC_SUBMODULESUPDATE
, [&]
1471 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1472 CAppUtils::RunTortoiseGitProc(sCmd
);
1478 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_RESET
))
1480 CGitProgressDlg gitdlg
;
1481 ResetProgressCommand resetProgressCommand
;
1482 gitdlg
.SetCommand(&resetProgressCommand
);
1483 resetProgressCommand
.m_PostCmdCallback
= progress
.m_PostCmdCallback
;
1484 resetProgressCommand
.SetRevision(resetTo
);
1485 resetProgressCommand
.SetResetType(resetType
);
1486 ret
= gitdlg
.DoModal();
1489 ret
= progress
.DoModal();
1494 bool CAppUtils::GitReset(const CString
* CommitHash
, int type
)
1497 dlg
.m_ResetType
=type
;
1498 dlg
.m_ResetToVersion
=*CommitHash
;
1499 dlg
.m_initialRefName
= *CommitHash
;
1500 if (dlg
.DoModal() == IDOK
)
1501 return Reset(dlg
.m_ResetToVersion
, dlg
.m_ResetType
);
1506 void CAppUtils::DescribeConflictFile(bool mode
, bool base
,CString
&descript
)
1510 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_DELETE
));
1515 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_MODIFIED
));
1518 descript
= CString(MAKEINTRESOURCE(IDS_PROC_CREATED
));
1522 void CAppUtils::RemoveTempMergeFile(const CTGitPath
& path
)
1524 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("LOCAL"), path
));
1525 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("REMOTE"), path
));
1526 ::DeleteFile(CAppUtils::GetMergeTempFile(_T("BASE"), path
));
1528 CString
CAppUtils::GetMergeTempFile(const CString
& type
, const CTGitPath
&merge
)
1531 file
= g_Git
.CombinePath(merge
.GetWinPathString() + _T(".") + type
+ merge
.GetFileExtension());
1536 bool ParseHashesFromLsFile(const BYTE_VECTOR
& out
, CString
& hash1
, CString
& hash2
, CString
& hash3
)
1542 while (pos
>= 0 && pos
< (int)out
.size())
1546 g_Git
.StringAppend(&one
, &out
[pos
], CP_UTF8
);
1548 one
.Tokenize(_T("\t"), tabstart
);
1551 part
= one
.Tokenize(_T(" "), tabstart
); //Tag
1552 part
= one
.Tokenize(_T(" "), tabstart
); //Mode
1553 part
= one
.Tokenize(_T(" "), tabstart
); //Hash
1554 CString hash
= part
;
1555 part
= one
.Tokenize(_T("\t"), tabstart
); //Stage
1556 int stage
= _ttol(part
);
1559 else if (stage
== 2)
1561 else if (stage
== 3)
1567 pos
= out
.findNextString(pos
);
1573 bool CAppUtils::ConflictEdit(const CTGitPath
& path
, bool /*bAlternativeTool = false*/, bool revertTheirMy
/*= false*/, HWND resolveMsgHwnd
/*= nullptr*/)
1577 CTGitPath merge
=path
;
1578 CTGitPath directory
= merge
.GetDirectory();
1580 // we have the conflicted file (%merged)
1581 // now look for the other required files
1583 //stat.GetStatus(merge);
1584 //if (stat.status == NULL)
1590 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1592 if (g_Git
.Run(cmd
, &vector
))
1597 if (merge
.IsDirectory())
1599 CString baseHash
, realBaseHash(GIT_REV_ZERO
), localHash(GIT_REV_ZERO
), remoteHash(GIT_REV_ZERO
);
1600 if (merge
.HasAdminDir()) {
1602 subgit
.m_CurrentDir
= g_Git
.CombinePath(merge
);
1604 subgit
.GetHash(hash
, _T("HEAD"));
1607 if (ParseHashesFromLsFile(vector
, realBaseHash
, localHash
, remoteHash
)) // in base no submodule, but in remote submodule
1608 baseHash
= realBaseHash
;
1610 CGitDiff::ChangeType changeTypeMine
= CGitDiff::Unknown
;
1611 CGitDiff::ChangeType changeTypeTheirs
= CGitDiff::Unknown
;
1613 bool baseOK
= false, mineOK
= false, theirsOK
= false;
1614 CString baseSubject
, mineSubject
, theirsSubject
;
1615 if (merge
.HasAdminDir())
1618 subgit
.m_CurrentDir
= g_Git
.CombinePath(merge
);
1619 CGitDiff::GetSubmoduleChangeType(subgit
, baseHash
, localHash
, baseOK
, mineOK
, changeTypeMine
, baseSubject
, mineSubject
);
1620 CGitDiff::GetSubmoduleChangeType(subgit
, baseHash
, remoteHash
, baseOK
, theirsOK
, changeTypeTheirs
, baseSubject
, theirsSubject
);
1622 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)
1624 changeTypeMine
= CGitDiff::Identical
;
1625 changeTypeTheirs
= CGitDiff::NewSubmodule
;
1626 baseSubject
= _T("no submodule");
1627 mineSubject
= baseSubject
;
1628 theirsSubject
= _T("not initialized");
1630 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
1632 baseHash
= localHash
;
1633 baseSubject
= _T("not initialized");
1634 mineSubject
= baseSubject
;
1635 theirsSubject
= _T("not initialized");
1636 changeTypeMine
= CGitDiff::Identical
;
1637 changeTypeTheirs
= CGitDiff::DeleteSubmodule
;
1639 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
1641 baseSubject
= _T("not initialized");
1642 mineSubject
= baseSubject
;
1643 theirsSubject
= baseSubject
;
1644 if (baseHash
== localHash
)
1645 changeTypeMine
= CGitDiff::Identical
;
1650 CSubmoduleResolveConflictDlg resolveSubmoduleConflictDialog
;
1651 resolveSubmoduleConflictDialog
.SetDiff(merge
.GetGitPathString(), revertTheirMy
, baseHash
, baseSubject
, baseOK
, localHash
, mineSubject
, mineOK
, changeTypeMine
, remoteHash
, theirsSubject
, theirsOK
, changeTypeTheirs
);
1652 resolveSubmoduleConflictDialog
.DoModal();
1653 if (resolveSubmoduleConflictDialog
.m_bResolved
&& resolveMsgHwnd
)
1655 static UINT WM_REVERTMSG
= RegisterWindowMessage(_T("GITSLNM_NEEDSREFRESH"));
1656 ::PostMessage(resolveMsgHwnd
, WM_REVERTMSG
, NULL
, NULL
);
1663 if (list
.ParserFromLsFile(vector
))
1665 CMessageBox::Show(NULL
, _T("Parse ls-files failed!"), _T("TortoiseGit"), MB_OK
);
1678 mine
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1679 theirs
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1683 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"), merge
));
1684 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"), merge
));
1686 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1690 //format=_T("git.exe cat-file blob \":%d:%s\"");
1691 format
= _T("git.exe checkout-index --temp --stage=%d -- \"%s\"");
1693 //create a empty file, incase stage is not three
1694 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1696 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1698 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1701 bool b_base
=false, b_local
=false, b_remote
=false;
1703 for (int i
= 0; i
< list
.GetCount(); ++i
)
1710 if( list
[i
].m_Stage
== 1)
1712 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1714 outfile
= base
.GetWinPathString();
1717 if( list
[i
].m_Stage
== 2 )
1719 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1721 outfile
= mine
.GetWinPathString();
1724 if( list
[i
].m_Stage
== 3 )
1726 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1728 outfile
= theirs
.GetWinPathString();
1730 CString output
, err
;
1731 if(!outfile
.IsEmpty())
1732 if (!g_Git
.Run(cmd
, &output
, &err
, CP_UTF8
))
1736 file
= output
.Tokenize(_T("\t"), start
);
1737 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1741 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1745 if(b_local
&& b_remote
)
1747 merge
.SetFromWin(g_Git
.CombinePath(merge
));
1749 bRet
= !!CAppUtils::StartExtMerge(base
, mine
, theirs
, merge
, _T("BASE"), _T("REMOTE"), _T("LOCAL"), CString(), false, resolveMsgHwnd
, true);
1751 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
, _T("BASE"), _T("REMOTE"), _T("LOCAL"), CString(), false, resolveMsgHwnd
, true);
1756 ::DeleteFile(mine
.GetWinPathString());
1757 ::DeleteFile(theirs
.GetWinPathString());
1758 ::DeleteFile(base
.GetWinPathString());
1760 CDeleteConflictDlg dlg
;
1761 DescribeConflictFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1762 DescribeConflictFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1763 CGitHash localHash
, remoteHash
;
1764 if (!g_Git
.GetHash(localHash
, _T("HEAD")))
1765 dlg
.m_LocalHash
= localHash
.ToString();
1766 if (!g_Git
.GetHash(remoteHash
, _T("MERGE_HEAD")))
1767 dlg
.m_RemoteHash
= remoteHash
.ToString();
1768 else if (!g_Git
.GetHash(remoteHash
, _T("rebase-apply/original-commit")))
1769 dlg
.m_RemoteHash
= remoteHash
.ToString();
1770 else if (!g_Git
.GetHash(remoteHash
, _T("CHERRY_PICK_HEAD")))
1771 dlg
.m_RemoteHash
= remoteHash
.ToString();
1772 else if (!g_Git
.GetHash(remoteHash
, _T("REVERT_HEAD")))
1773 dlg
.m_RemoteHash
= remoteHash
.ToString();
1774 dlg
.m_bShowModifiedButton
=b_base
;
1775 dlg
.m_File
=merge
.GetGitPathString();
1776 if(dlg
.DoModal() == IDOK
)
1781 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1784 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1786 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1788 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1798 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1799 base
, theirs
, mine
, merge
);
1802 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1804 // we have a text conflict, use our merge tool to resolve the conflict
1806 CTSVNPath
theirs(directory
);
1807 CTSVNPath
mine(directory
);
1808 CTSVNPath
base(directory
);
1809 bool bConflictData
= false;
1811 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1813 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1814 bConflictData
= true;
1816 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1818 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1819 bConflictData
= true;
1821 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1823 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1824 bConflictData
= true;
1831 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1832 base
, theirs
, mine
, merge
);
1835 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1837 // we have a property conflict
1838 CTSVNPath
prej(directory
);
1839 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1841 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1842 // there's a problem: the prej file contains a _description_ of the conflict, and
1843 // that description string might be translated. That means we have no way of parsing
1844 // the file to find out the conflicting values.
1845 // The only thing we can do: show a dialog with the conflict description, then
1846 // let the user either accept the existing property or open the property edit dialog
1847 // to manually change the properties and values. And a button to mark the conflict as
1849 CEditPropConflictDlg dlg
;
1850 dlg
.SetPrejFile(prej
);
1851 dlg
.SetConflictedItem(merge
);
1852 bRet
= (dlg
.DoModal() != IDCANCEL
);
1856 if (stat
.status
->tree_conflict
)
1858 // we have a tree conflict
1860 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1863 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1865 CTSVNPath
theirs(directory
);
1866 CTSVNPath
mine(directory
);
1867 CTSVNPath
base(directory
);
1868 bool bConflictData
= false;
1870 if (pInfoData
->treeconflict_theirfile
)
1872 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1873 bConflictData
= true;
1875 if (pInfoData
->treeconflict_basefile
)
1877 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1878 bConflictData
= true;
1880 if (pInfoData
->treeconflict_myfile
)
1882 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1883 bConflictData
= true;
1890 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1891 base
, theirs
, mine
, merge
);
1893 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1895 CString sConflictAction
;
1896 CString sConflictReason
;
1897 CString sResolveTheirs
;
1898 CString sResolveMine
;
1899 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1900 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1902 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1904 switch (pInfoData
->treeconflict_operation
)
1906 case svn_wc_operation_update
:
1907 switch (pInfoData
->treeconflict_action
)
1909 case svn_wc_conflict_action_edit
:
1910 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1911 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1913 case svn_wc_conflict_action_add
:
1914 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1915 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1917 case svn_wc_conflict_action_delete
:
1918 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1919 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1923 case svn_wc_operation_switch
:
1924 switch (pInfoData
->treeconflict_action
)
1926 case svn_wc_conflict_action_edit
:
1927 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1928 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1930 case svn_wc_conflict_action_add
:
1931 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1932 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1934 case svn_wc_conflict_action_delete
:
1935 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1936 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1940 case svn_wc_operation_merge
:
1941 switch (pInfoData
->treeconflict_action
)
1943 case svn_wc_conflict_action_edit
:
1944 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1945 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1947 case svn_wc_conflict_action_add
:
1948 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1949 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1951 case svn_wc_conflict_action_delete
:
1952 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1953 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1959 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1961 switch (pInfoData
->treeconflict_operation
)
1963 case svn_wc_operation_update
:
1964 switch (pInfoData
->treeconflict_action
)
1966 case svn_wc_conflict_action_edit
:
1967 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1968 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1970 case svn_wc_conflict_action_add
:
1971 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1972 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1974 case svn_wc_conflict_action_delete
:
1975 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1976 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1980 case svn_wc_operation_switch
:
1981 switch (pInfoData
->treeconflict_action
)
1983 case svn_wc_conflict_action_edit
:
1984 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1985 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1987 case svn_wc_conflict_action_add
:
1988 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1989 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1991 case svn_wc_conflict_action_delete
:
1992 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1993 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1997 case svn_wc_operation_merge
:
1998 switch (pInfoData
->treeconflict_action
)
2000 case svn_wc_conflict_action_edit
:
2001 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
2002 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
2004 case svn_wc_conflict_action_add
:
2005 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
2006 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
2008 case svn_wc_conflict_action_delete
:
2009 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
2010 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
2018 switch (pInfoData
->treeconflict_reason
)
2020 case svn_wc_conflict_reason_edited
:
2021 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
2022 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
2024 case svn_wc_conflict_reason_obstructed
:
2025 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
2026 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
2028 case svn_wc_conflict_reason_deleted
:
2029 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
2030 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
2032 case svn_wc_conflict_reason_added
:
2033 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
2034 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
2036 case svn_wc_conflict_reason_missing
:
2037 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
2038 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
2040 case svn_wc_conflict_reason_unversioned
:
2041 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
2042 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
2045 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
2047 CTreeConflictEditorDlg dlg
;
2048 dlg
.SetConflictInfoText(sConflictReason
);
2049 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
2050 dlg
.SetPath(treeConflictPath
);
2051 INT_PTR dlgRet
= dlg
.DoModal();
2052 bRet
= (dlgRet
!= IDCANCEL
);
2060 bool CAppUtils::IsSSHPutty()
2062 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
2063 sshclient
=sshclient
.MakeLower();
2064 if(sshclient
.Find(_T("plink.exe"),0)>=0)
2071 CString
CAppUtils::GetClipboardLink(const CString
&skipGitPrefix
, int paramsCount
)
2073 if (!OpenClipboard(NULL
))
2076 CString sClipboardText
;
2077 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
2080 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
2081 sClipboardText
= CString(lpstr
);
2084 hglb
= GetClipboardData(CF_UNICODETEXT
);
2087 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
2088 sClipboardText
= lpstr
;
2093 if(!sClipboardText
.IsEmpty())
2095 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
2096 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
2098 if(sClipboardText
.Find( _T("http://")) == 0)
2099 return sClipboardText
;
2101 if(sClipboardText
.Find( _T("https://")) == 0)
2102 return sClipboardText
;
2104 if(sClipboardText
.Find( _T("git://")) == 0)
2105 return sClipboardText
;
2107 if(sClipboardText
.Find( _T("ssh://")) == 0)
2108 return sClipboardText
;
2110 if (sClipboardText
.Find(_T("git@")) == 0)
2111 return sClipboardText
;
2113 if(sClipboardText
.GetLength()>=2)
2114 if( sClipboardText
[1] == _T(':') )
2115 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
2116 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
2117 return sClipboardText
;
2119 // trim prefixes like "git clone "
2120 if (!skipGitPrefix
.IsEmpty() && sClipboardText
.Find(skipGitPrefix
) == 0)
2122 sClipboardText
= sClipboardText
.Mid(skipGitPrefix
.GetLength()).Trim();
2124 while (paramsCount
>= 0)
2127 spacePos
= sClipboardText
.Find(_T(' '), spacePos
+ 1);
2131 if (spacePos
> 0 && paramsCount
< 0)
2132 sClipboardText
= sClipboardText
.Left(spacePos
);
2133 return sClipboardText
;
2137 return CString(_T(""));
2140 CString
CAppUtils::ChooseRepository(const CString
* path
)
2142 CBrowseFolder browseFolder
;
2143 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
2145 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
2146 CString strCloneDirectory
;
2148 strCloneDirectory
=*path
;
2151 strCloneDirectory
= regLastResopitory
;
2155 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
2157 browseFolder
.SetInfo(title
);
2159 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
2161 regLastResopitory
= strCloneDirectory
;
2162 return strCloneDirectory
;
2170 bool CAppUtils::SendPatchMail(CTGitPathList
& list
, bool bIsMainWnd
)
2174 dlg
.m_PathList
= list
;
2176 if(dlg
.DoModal()==IDOK
)
2178 if (dlg
.m_PathList
.IsEmpty())
2181 CGitProgressDlg progDlg
;
2183 theApp
.m_pMainWnd
= &progDlg
;
2184 SendMailProgressCommand sendMailProgressCommand
;
2185 progDlg
.SetCommand(&sendMailProgressCommand
);
2187 sendMailProgressCommand
.SetPathList(dlg
.m_PathList
);
2188 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2190 CSendMailPatch
sendMailPatch(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
);
2191 sendMailProgressCommand
.SetSendMailOption(&sendMailPatch
);
2200 bool CAppUtils::SendPatchMail(const CString
& cmd
, const CString
& formatpatchoutput
, bool bIsMainWnd
)
2203 CString log
=formatpatchoutput
;
2204 int start
=log
.Find(cmd
);
2206 CString one
=log
.Tokenize(_T("\n"),start
);
2212 CString one
=log
.Tokenize(_T("\n"),start
);
2214 if(one
.IsEmpty() || one
.Find(_T("Success")) == 0)
2216 one
.Replace(_T('/'),_T('\\'));
2218 path
.SetFromWin(one
);
2221 if (!list
.IsEmpty())
2223 return SendPatchMail(list
, bIsMainWnd
);
2227 CMessageBox::Show(NULL
, IDS_ERR_NOPATCHES
, IDS_APPNAME
, MB_ICONINFORMATION
);
2233 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
2236 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
2237 if(output
.IsEmpty())
2238 return CUnicodeUtils::GetCPCode(pGit
->GetConfigValue(_T("i18n.commitencoding")));
2241 return CUnicodeUtils::GetCPCode(output
);
2244 int CAppUtils::SaveCommitUnicodeFile(const CString
& filename
, CString
&message
)
2248 CFile
file(filename
, CFile::modeReadWrite
| CFile::modeCreate
);
2249 int cp
= CUnicodeUtils::GetCPCode(g_Git
.GetConfigValue(_T("i18n.commitencoding")));
2251 bool stripComments
= (CRegDWORD(_T("Software\\TortoiseGit\\StripCommentedLines"), FALSE
) == TRUE
);
2253 if (CRegDWORD(_T("Software\\TortoiseGit\\SanitizeCommitMsg"), TRUE
) == TRUE
)
2254 message
.TrimRight(L
" \r\n");
2256 int len
= message
.GetLength();
2258 while (start
>= 0 && start
< len
)
2260 int oldStart
= start
;
2261 start
= message
.Find(L
"\n", oldStart
);
2262 CString line
= message
.Mid(oldStart
);
2265 line
= line
.Left(start
- oldStart
);
2266 ++start
; // move forward so we don't find the same char again
2268 if (stripComments
&& (line
.GetLength() >= 1 && line
.GetAt(0) == '#') || (start
< 0 && line
.IsEmpty()))
2270 line
.TrimRight(L
" \r");
2271 CStringA lineA
= CUnicodeUtils::GetMulti(line
+ L
"\n", cp
);
2272 file
.Write(lineA
.GetBuffer(), lineA
.GetLength());
2277 catch (CFileException
*e
)
2284 bool CAppUtils::Pull(bool showPush
)
2287 dlg
.m_IsPull
= TRUE
;
2288 if (dlg
.DoModal() == IDOK
)
2290 // "git.exe pull --rebase" is not supported, never and ever. So, adapting it to Fetch & Rebase.
2292 return DoFetch(dlg
.m_RemoteURL
,
2293 FALSE
, // Fetch all remotes
2294 dlg
.m_bAutoLoad
== BST_CHECKED
,
2296 dlg
.m_bDepth
== BST_CHECKED
,
2299 dlg
.m_RemoteBranchName
,
2300 TRUE
); // Rebase after fetching
2302 CString url
= dlg
.m_RemoteURL
;
2304 if (dlg
.m_bAutoLoad
)
2306 CAppUtils::LaunchPAgent(NULL
, &dlg
.m_RemoteURL
);
2311 if (g_Git
.GetHash(hashOld
, _T("HEAD")))
2313 MessageBox(NULL
, g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
2326 if (!dlg
.m_bFetchTags
)
2327 notags
= _T("--no-tags ");
2329 if (dlg
.m_bFetchTags
== TRUE
)
2330 notags
= _T("--tags ");
2333 noff
=_T("--no-ff ");
2336 ffonly
= _T("--ff-only ");
2339 squash
= _T("--squash ");
2341 if (dlg
.m_bNoCommit
)
2342 nocommit
= _T("--no-commit ");
2345 depth
.Format(_T("--depth %d "), dlg
.m_nDepth
);
2347 int ver
= CAppUtils::GetMsysgitVersion();
2349 if (dlg
.m_bPrune
== TRUE
)
2350 prune
= _T("--prune ");
2351 else if (dlg
.m_bPrune
== FALSE
&& ver
>= 0x01080500)
2352 prune
= _T("--no-prune ");
2354 if(ver
>= 0x01070203) //above 1.7.0.2
2355 cmdRebase
+= _T("--progress ");
2357 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
);
2358 CProgressDlg progress
;
2359 progress
.m_GitCmd
= cmd
;
2361 CGitHash hashNew
; // declare outside lambda, because it is captured by reference
2362 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
2366 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUPULL
, [&]{ Pull(); }));
2370 if (g_Git
.GetHash(hashNew
, _T("HEAD")))
2371 MessageBox(nullptr, g_Git
.GetGitLastErr(_T("Could not get HEAD hash after pulling.")), _T("TortoiseGit"), MB_ICONERROR
);
2374 postCmdList
.push_back(PostCmd(IDI_DIFF
, IDS_PROC_PULL_DIFFS
, [&]
2377 dlg
.SetDiff(NULL
, hashNew
.ToString(), hashOld
.ToString());
2380 postCmdList
.push_back(PostCmd(IDI_LOG
, IDS_PROC_PULL_LOG
, [&]
2383 dlg
.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), hashOld
.ToString() + _T("..") + hashNew
.ToString(), 0);
2389 postCmdList
.push_back(PostCmd(IDI_PUSH
, IDS_MENUPUSH
, []{ Push(_T("")); }));
2391 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
2392 if (gitPath
.HasSubmodules())
2394 postCmdList
.push_back(PostCmd(IDI_UPDATE
, IDS_PROC_SUBMODULESUPDATE
, []
2397 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
2398 CAppUtils::RunTortoiseGitProc(sCmd
);
2403 INT_PTR ret
= progress
.DoModal();
2405 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
)
2408 dlg
.m_pathList
.AddPath(CTGitPath());
2420 bool CAppUtils::RebaseAfterFetch(const CString
& upstream
)
2425 if (!upstream
.IsEmpty())
2426 dlg
.m_Upstream
= upstream
;
2427 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
2428 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUDESSENDMAIL
)));
2429 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
2430 INT_PTR response
= dlg
.DoModal();
2431 if (response
== IDOK
)
2435 else if (response
== IDC_REBASE_POST_BUTTON
)
2437 CString cmd
= _T("/command:log");
2438 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2439 CAppUtils::RunTortoiseGitProc(cmd
);
2442 else if (response
== IDC_REBASE_POST_BUTTON
+ 1)
2444 CString cmd
, out
, err
;
2445 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2447 g_Git
.FixBranchName(dlg
.m_Upstream
),
2448 g_Git
.FixBranchName(dlg
.m_Branch
));
2449 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
2451 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2454 CAppUtils::SendPatchMail(cmd
, out
);
2457 else if (response
== IDC_REBASE_POST_BUTTON
+ 2)
2459 else if (response
== IDCANCEL
)
2465 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
)
2469 if (fetchAllRemotes
)
2472 g_Git
.GetRemoteList(list
);
2474 STRING_VECTOR::const_iterator it
= list
.begin();
2475 while (it
!= list
.end())
2477 CString
remote(*it
);
2478 CAppUtils::LaunchPAgent(NULL
, &remote
);
2483 CAppUtils::LaunchPAgent(NULL
, &url
);
2487 int ver
= CAppUtils::GetMsysgitVersion();
2488 if (ver
>= 0x01070203) //above 1.7.0.2
2489 arg
+= _T(" --progress");
2492 arg
.AppendFormat(_T(" --depth %d"), nDepth
);
2495 arg
+= _T(" --prune");
2496 else if (prune
== FALSE
&& ver
>= 0x01080500)
2497 arg
+= _T(" --no-prune");
2500 arg
+= _T(" --tags");
2501 else if (fetchTags
== 0)
2502 arg
+= _T(" --no-tags");
2504 if (fetchAllRemotes
)
2505 cmd
.Format(_T("git.exe fetch --all -v%s"), arg
);
2507 cmd
.Format(_T("git.exe fetch -v%s \"%s\" %s"), arg
, url
, remoteBranch
);
2509 CProgressDlg progress
;
2510 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
2514 postCmdList
.push_back(PostCmd(IDI_REFRESH
, IDS_MSGBOX_RETRY
, [&]{ DoFetch(url
, fetchAllRemotes
, loadPuttyAgent
, prune
, bDepth
, nDepth
, fetchTags
, remoteBranch
, runRebase
); }));
2518 postCmdList
.push_back(PostCmd(IDI_LOG
, IDS_MENULOG
, []
2520 CString cmd
= _T("/command:log");
2521 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2522 CAppUtils::RunTortoiseGitProc(cmd
);
2525 postCmdList
.push_back(PostCmd(IDI_REVERT
, IDS_PROC_RESET
, []
2527 CString pullRemote
, pullBranch
;
2528 g_Git
.GetRemoteTrackedBranchForHEAD(pullRemote
, pullBranch
);
2529 CString defaultUpstream
;
2530 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
2531 defaultUpstream
.Format(_T("remotes/%s/%s"), pullRemote
, pullBranch
);
2532 CAppUtils::GitReset(&defaultUpstream
, 2);
2535 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUFETCH
, []{ CAppUtils::Fetch(); }));
2537 if (!runRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
2538 postCmdList
.push_back(PostCmd(IDI_REBASE
, IDS_MENUREBASE
, [&]{ runRebase
= false; CAppUtils::RebaseAfterFetch(); }));
2541 progress
.m_GitCmd
= cmd
;
2542 INT_PTR userResponse
;
2544 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_FETCH
))
2546 CGitProgressDlg gitdlg
;
2547 FetchProgressCommand fetchProgressCommand
;
2548 if (!fetchAllRemotes
)
2549 fetchProgressCommand
.SetUrl(url
);
2550 gitdlg
.SetCommand(&fetchProgressCommand
);
2551 fetchProgressCommand
.m_PostCmdCallback
= progress
.m_PostCmdCallback
;
2552 fetchProgressCommand
.SetAutoTag(fetchTags
== 1 ? GIT_REMOTE_DOWNLOAD_TAGS_ALL
: fetchTags
== 2 ? GIT_REMOTE_DOWNLOAD_TAGS_AUTO
: GIT_REMOTE_DOWNLOAD_TAGS_NONE
);
2553 if (!fetchAllRemotes
)
2554 fetchProgressCommand
.SetRefSpec(remoteBranch
);
2555 userResponse
= gitdlg
.DoModal();
2556 return userResponse
== IDOK
;
2559 userResponse
= progress
.DoModal();
2560 if (!progress
.m_GitStatus
)
2563 return CAppUtils::RebaseAfterFetch();
2566 return userResponse
== IDOK
;
2569 bool CAppUtils::Fetch(const CString
& remoteName
, bool allRemotes
)
2572 dlg
.m_PreSelectRemote
= remoteName
;
2574 dlg
.m_bAllRemotes
= allRemotes
;
2576 if(dlg
.DoModal()==IDOK
)
2577 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
);
2582 bool CAppUtils::Push(const CString
& selectLocalBranch
)
2585 dlg
.m_BranchSourceName
= selectLocalBranch
;
2587 if (dlg
.DoModal() == IDOK
)
2590 DWORD exitcode
= 0xFFFFFFFF;
2591 if (CHooks::Instance().PrePush(g_Git
.m_CurrentDir
, exitcode
, error
))
2596 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2597 CMessageBox::Show(nullptr, temp
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2605 arg
+= _T("--thin ");
2606 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2607 arg
+= _T("--tags ");
2609 arg
+= _T("--force ");
2610 if (dlg
.m_bForceWithLease
)
2611 arg
+= _T("--force-with-lease ");
2612 if (dlg
.m_bSetUpstream
)
2613 arg
+= _T("--set-upstream ");
2614 if (dlg
.m_RecurseSubmodules
== 1)
2615 arg
+= _T("--recurse-submodules=check ");
2616 if (dlg
.m_RecurseSubmodules
== 2)
2617 arg
+= _T("--recurse-submodules=on-demand ");
2619 int ver
= CAppUtils::GetMsysgitVersion();
2621 if(ver
>= 0x01070203) //above 1.7.0.2
2622 arg
+= _T("--progress ");
2624 CProgressDlg progress
;
2626 STRING_VECTOR remotesList
;
2627 if (dlg
.m_bPushAllRemotes
)
2628 g_Git
.GetRemoteList(remotesList
);
2630 remotesList
.push_back(dlg
.m_URL
);
2632 for (unsigned int i
= 0; i
< remotesList
.size(); ++i
)
2634 if (dlg
.m_bAutoLoad
)
2635 CAppUtils::LaunchPAgent(NULL
, &remotesList
[i
]);
2638 if (dlg
.m_bPushAllBranches
)
2640 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2646 progress
.m_GitCmdList
.push_back(cmd
);
2647 cmd
.Format(_T("git.exe push --tags %s \"%s\""), arg
, remotesList
[i
]);
2652 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2655 dlg
.m_BranchSourceName
);
2656 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2658 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2661 progress
.m_GitCmdList
.push_back(cmd
);
2664 CString superprojectRoot
;
2665 g_GitAdminDir
.HasAdminDir(g_Git
.m_CurrentDir
, false, &superprojectRoot
);
2666 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
2668 // need to execute hooks as those might be needed by post action commands
2669 DWORD exitcode
= 0xFFFFFFFF;
2671 if (CHooks::Instance().PostPush(g_Git
.m_CurrentDir
, exitcode
, error
))
2676 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2677 MessageBox(nullptr, temp
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2683 bool rejected
= progress
.GetLogText().Find(_T("! [rejected]")) > 0;
2686 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUPULL
, []{ Pull(true); }));
2687 postCmdList
.push_back(PostCmd(IDI_PULL
, IDS_MENUFETCH
, [&]{ Fetch(dlg
.m_bPushAllRemotes
? _T("") : dlg
.m_URL
, !!dlg
.m_bPushAllRemotes
); }));
2689 postCmdList
.push_back(PostCmd(IDI_PUSH
, IDS_MENUPUSH
, [&]{ Push(selectLocalBranch
); }));
2693 postCmdList
.push_back(PostCmd(IDS_PROC_REQUESTPULL
, [&]{ RequestPull(dlg
.m_BranchRemoteName
); }));
2694 postCmdList
.push_back(PostCmd(IDI_PUSH
, IDS_MENUPUSH
, [&]{ Push(selectLocalBranch
); }));
2695 postCmdList
.push_back(PostCmd(IDI_SWITCH
, IDS_MENUSWITCH
, [&]{ Switch(); }));
2696 if (!superprojectRoot
.IsEmpty())
2698 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_PROC_COMMIT_SUPERPROJECT
, [&]
2701 sCmd
.Format(_T("/command:commit /path:\"%s\""), superprojectRoot
);
2702 RunTortoiseGitProc(sCmd
);
2707 INT_PTR ret
= progress
.DoModal();
2713 bool CAppUtils::RequestPull(const CString
& endrevision
, const CString
& repositoryUrl
, bool bIsMainWnd
)
2715 CRequestPullDlg dlg
;
2716 dlg
.m_RepositoryURL
= repositoryUrl
;
2717 dlg
.m_EndRevision
= endrevision
;
2718 if (dlg
.DoModal()==IDOK
)
2721 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2723 CSysProgressDlg sysProgressDlg
;
2724 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2725 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CREATINGPULLREUQEST
)));
2726 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2727 sysProgressDlg
.SetShowProgressBar(false);
2728 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2730 CString tempFileName
= GetTempFile();
2732 DeleteFile(tempFileName
);
2733 CreateDirectory(tempFileName
, NULL
);
2734 tempFileName
+= _T("\\pullrequest.txt");
2735 if (g_Git
.RunLogFile(cmd
, tempFileName
, &err
))
2738 msg
.LoadString(IDS_ERR_PULLREUQESTFAILED
);
2739 CMessageBox::Show(NULL
, msg
+ _T("\n") + err
, _T("TortoiseGit"), MB_OK
);
2743 if (sysProgressDlg
.HasUserCancelled())
2745 CMessageBox::Show(NULL
, IDS_SVN_USERCANCELLED
, IDS_APPNAME
, MB_OK
);
2746 ::DeleteFile(tempFileName
);
2750 sysProgressDlg
.Stop();
2752 if (dlg
.m_bSendMail
)
2755 dlg
.m_PathList
= CTGitPathList(CTGitPath(tempFileName
));
2756 dlg
.m_bCustomSubject
= true;
2758 if (dlg
.DoModal() == IDOK
)
2760 if (dlg
.m_PathList
.IsEmpty())
2763 CGitProgressDlg progDlg
;
2765 theApp
.m_pMainWnd
= &progDlg
;
2766 SendMailProgressCommand sendMailProgressCommand
;
2767 progDlg
.SetCommand(&sendMailProgressCommand
);
2769 sendMailProgressCommand
.SetPathList(dlg
.m_PathList
);
2770 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2772 CSendMailCombineable
sendMailCombineable(dlg
.m_To
, dlg
.m_CC
, dlg
.m_Subject
, !!dlg
.m_bAttachment
, !!dlg
.m_bCombine
);
2773 sendMailProgressCommand
.SetSendMailOption(&sendMailCombineable
);
2782 CAppUtils::LaunchAlternativeEditor(tempFileName
);
2787 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2789 CString
strDir(szPath
);
2790 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2792 strDir
.AppendChar(_T('\\'));
2794 std::vector
<CString
> vPath
;
2796 bool bSuccess
= false;
2798 for (int i
=0;i
<strDir
.GetLength();++i
)
2800 if (strDir
.GetAt(i
) != _T('\\'))
2802 strTemp
.AppendChar(strDir
.GetAt(i
));
2806 vPath
.push_back(strTemp
);
2807 strTemp
.AppendChar(_T('\\'));
2811 for (auto vIter
= vPath
.begin(); vIter
!= vPath
.end(); ++vIter
)
2813 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2819 void CAppUtils::RemoveTrailSlash(CString
&path
)
2824 // For URL, do not trim the slash just after the host name component.
2825 int index
= path
.Find(_T("://"));
2829 index
= path
.Find(_T('/'), index
);
2830 if (index
== path
.GetLength() - 1)
2834 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2836 path
=path
.Left(path
.GetLength()-1);
2842 bool CAppUtils::CheckUserData()
2844 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
2846 if(CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
2848 CTGitPath
path(g_Git
.m_CurrentDir
);
2849 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2850 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2851 dlg
.SetTreeWidth(220);
2852 dlg
.m_DefaultPage
= _T("gitconfig");
2855 dlg
.HandleRestart();
2865 BOOL
CAppUtils::Commit(const CString
& bugid
, BOOL bWholeProject
, CString
&sLogMsg
,
2866 CTGitPathList
&pathList
,
2867 CTGitPathList
&selectedList
,
2868 bool bSelectFilesForCommit
)
2870 bool bFailed
= true;
2872 if (!CheckUserData())
2879 dlg
.m_sBugID
= bugid
;
2881 dlg
.m_bWholeProject
= bWholeProject
;
2883 dlg
.m_sLogMessage
= sLogMsg
;
2884 dlg
.m_pathList
= pathList
;
2885 dlg
.m_checkedPathList
= selectedList
;
2886 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2887 if (dlg
.DoModal() == IDOK
)
2889 if (dlg
.m_pathList
.IsEmpty())
2891 // if the user hasn't changed the list of selected items
2892 // we don't use that list. Because if we would use the list
2893 // of pre-checked items, the dialog would show different
2894 // checked items on the next startup: it would only try
2895 // to check the parent folder (which might not even show)
2896 // instead, we simply use an empty list and let the
2897 // default checking do its job.
2898 if (!dlg
.m_pathList
.IsEqual(pathList
))
2899 selectedList
= dlg
.m_pathList
;
2900 pathList
= dlg
.m_updatedPathList
;
2901 sLogMsg
= dlg
.m_sLogMessage
;
2902 bSelectFilesForCommit
= true;
2904 switch (dlg
.m_PostCmd
)
2906 case GIT_POSTCOMMIT_CMD_DCOMMIT
:
2907 CAppUtils::SVNDCommit();
2909 case GIT_POSTCOMMIT_CMD_PUSH
:
2912 case GIT_POSTCOMMIT_CMD_CREATETAG
:
2913 CAppUtils::CreateBranchTag(TRUE
);
2915 case GIT_POSTCOMMIT_CMD_PULL
:
2916 CAppUtils::Pull(true);
2922 // CGitProgressDlg progDlg;
2923 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2924 // if (parser.HasVal(_T("closeonend")))
2925 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2926 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2927 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2928 // progDlg.SetPathList(dlg.m_pathList);
2929 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2930 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2931 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2932 // progDlg.SetItemCount(dlg.m_itemsCount);
2933 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2934 // progDlg.DoModal();
2935 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2936 // err = (DWORD)progDlg.DidErrorsOccur();
2937 // bFailed = progDlg.DidErrorsOccur();
2938 // bRet = progDlg.DidErrorsOccur();
2939 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2940 // if (DWORD(bFailRepeat)==0)
2941 // bFailed = false; // do not repeat if the user chose not to in the settings.
2948 BOOL
CAppUtils::SVNDCommit()
2950 CSVNDCommitDlg dcommitdlg
;
2951 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2952 if (gitSetting
== _T("")) {
2953 if (dcommitdlg
.DoModal() != IDOK
)
2959 if (dcommitdlg
.m_remember
)
2961 if (dcommitdlg
.m_rmdir
)
2963 gitSetting
= _T("true");
2967 gitSetting
= _T("false");
2969 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2972 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, _T("svn.rmdir"), gitSetting
);
2973 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2979 BOOL IsStash
= false;
2980 if(!g_Git
.CheckCleanWorkTree())
2982 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
2984 CSysProgressDlg sysProgressDlg
;
2985 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2986 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
2987 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
2988 sysProgressDlg
.SetShowProgressBar(false);
2989 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
2990 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
2993 cmd
=_T("git.exe stash");
2994 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2996 sysProgressDlg
.Stop();
2997 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
3000 sysProgressDlg
.Stop();
3010 CProgressDlg progress
;
3011 if (dcommitdlg
.m_rmdir
)
3013 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
3017 progress
.m_GitCmd
=_T("git.exe svn dcommit");
3019 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
3021 ::DeleteFile(g_Git
.m_CurrentDir
+ _T("\\sys$command"));
3024 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
3026 CSysProgressDlg sysProgressDlg
;
3027 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3028 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
3029 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
3030 sysProgressDlg
.SetShowProgressBar(false);
3031 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
3032 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
3035 cmd
=_T("git.exe stash pop");
3036 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3038 sysProgressDlg
.Stop();
3039 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
3042 sysProgressDlg
.Stop();
3054 BOOL
CAppUtils::Merge(const CString
* commit
)
3056 if (!CheckUserData())
3061 dlg
.m_initialRefName
= *commit
;
3063 if(dlg
.DoModal()==IDOK
)
3069 args
+= _T(" --no-ff");
3072 args
+= _T(" --squash");
3075 args
+= _T(" --no-commit");
3080 fmt
.Format(_T(" --log=%d"), dlg
.m_nLog
);
3084 if (!dlg
.m_MergeStrategy
.IsEmpty())
3086 args
+= _T(" --strategy=") + dlg
.m_MergeStrategy
;
3087 if (!dlg
.m_StrategyOption
.IsEmpty())
3089 args
+= _T(" --strategy-option=") + dlg
.m_StrategyOption
;
3090 if (!dlg
.m_StrategyParam
.IsEmpty())
3091 args
+= _T("=") + dlg
.m_StrategyParam
;
3095 if(!dlg
.m_strLogMesage
.IsEmpty())
3097 CString logmsg
= dlg
.m_strLogMesage
;
3098 logmsg
.Replace(_T("\""), _T("\\\""));
3099 args
+= _T(" -m \"") + logmsg
+ _T("\"");
3101 cmd
.Format(_T("git.exe merge %s %s"), args
, g_Git
.FixBranchName(dlg
.m_VersionName
));
3103 CProgressDlg Prodlg
;
3104 Prodlg
.m_GitCmd
= cmd
;
3106 Prodlg
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
3111 if (!g_Git
.ListConflictFile(list
) && !list
.IsEmpty())
3113 // there are conflict files
3115 postCmdList
.push_back(PostCmd(IDI_RESOLVE
, IDS_PROGRS_CMD_RESOLVE
, []
3118 sCmd
.Format(_T("/command:commit /path:\"%s\""), g_Git
.m_CurrentDir
);
3119 CAppUtils::RunTortoiseGitProc(sCmd
);
3125 if (dlg
.m_bNoCommit
)
3127 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_MENUCOMMIT
, []
3130 sCmd
.Format(_T("/command:commit /path:\"%s\""), g_Git
.m_CurrentDir
);
3131 CAppUtils::RunTortoiseGitProc(sCmd
);
3136 if (dlg
.m_bIsBranch
&& dlg
.m_VersionName
.Find(L
"remotes/") == -1) // do not ask to remove remote branches
3138 postCmdList
.push_back(PostCmd(IDI_DELETE
, IDS_PROC_REMOVEBRANCH
, [&]
3141 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, dlg
.m_VersionName
);
3142 if (CMessageBox::Show(nullptr, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
3145 cmd
.Format(_T("git.exe branch -D -- %s"), dlg
.m_VersionName
);
3146 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3147 MessageBox(nullptr, out
, _T("TortoiseGit"), MB_OK
);
3151 if (dlg
.m_bIsBranch
)
3152 postCmdList
.push_back(PostCmd(IDI_PUSH
, IDS_MENUPUSH
, []{ Push(); }));
3154 BOOL hasGitSVN
= CTGitPath(g_Git
.m_CurrentDir
).GetAdminDirMask() & ITEMIS_GITSVN
;
3156 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_MENUSVNDCOMMIT
, []{ SVNDCommit(); }));
3160 return !Prodlg
.m_GitStatus
;
3165 BOOL
CAppUtils::MergeAbort()
3168 if (dlg
.DoModal() == IDOK
)
3169 return Reset(_T("HEAD"), dlg
.m_ResetType
+ 1);
3174 void CAppUtils::EditNote(GitRev
*rev
)
3176 if (!CheckUserData())
3180 dlg
.m_sHintText
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
3181 dlg
.m_sInputText
= rev
->m_Notes
;
3182 dlg
.m_sTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
3183 //dlg.m_pProjectProperties = &m_ProjectProperties;
3184 dlg
.m_bUseLogWidth
= true;
3185 if(dlg
.DoModal() == IDOK
)
3188 cmd
=_T("notes add -f -F \"");
3190 CString tempfile
=::GetTempFile();
3191 if (CAppUtils::SaveCommitUnicodeFile(tempfile
, dlg
.m_sInputText
))
3193 CMessageBox::Show(nullptr, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3198 cmd
+= rev
->m_CommitHash
.ToString();
3202 if (git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
3204 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3209 rev
->m_Notes
= dlg
.m_sInputText
;
3213 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3215 ::DeleteFile(tempfile
);
3220 int CAppUtils::GetMsysgitVersion()
3222 if (g_Git
.ms_LastMsysGitVersion
)
3223 return g_Git
.ms_LastMsysGitVersion
;
3226 CString versiondebug
;
3229 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
3230 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
3232 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
3235 if (!g_Git
.GetFileModifyTime(gitpath
, &time
))
3237 if((DWORD
)time
== regTime
)
3239 g_Git
.ms_LastMsysGitVersion
= regVersion
;
3245 cmd
= _T("git.exe --version");
3246 if (g_Git
.Run(cmd
, &version
, &err
, CP_UTF8
))
3248 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
);
3255 versiondebug
= version
;
3259 CString str
=version
.Tokenize(_T("."), start
);
3260 int space
= str
.ReverseFind(_T(' '));
3261 str
= str
.Mid(space
+1,start
);
3265 version
= version
.Mid(start
);
3268 str
= version
.Tokenize(_T("."), start
);
3270 ver
|= (_ttol(str
) & 0xFF) << 16;
3272 str
= version
.Tokenize(_T("."), start
);
3273 ver
|= (_ttol(str
) & 0xFF) << 8;
3275 str
= version
.Tokenize(_T("."), start
);
3276 ver
|= (_ttol(str
) & 0xFF);
3282 CMessageBox::Show(NULL
, _T("Could not parse git.exe version number: \"") + versiondebug
+ _T("\""), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
3287 regTime
= time
&0xFFFFFFFF;
3289 g_Git
.ms_LastMsysGitVersion
= ver
;
3294 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
3296 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
3298 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("Shell32.dll"));
3300 if (hShell
.IsValid()) {
3301 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
3303 IPropertyStore
*pps
;
3304 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
3305 if (SUCCEEDED(hr
)) {
3308 var
.boolVal
= VARIANT_TRUE
;
3309 pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
3316 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
3318 ASSERT(dialogname
.GetLength() < 70);
3319 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
3320 WCHAR pathbuf
[MAX_PATH
] = {0};
3322 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
3324 wcscat_s(pathbuf
, L
" - ");
3325 wcscat_s(pathbuf
, dialogname
);
3326 wcscat_s(pathbuf
, L
" - ");
3327 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3328 SetWindowText(hWnd
, pathbuf
);
3331 bool CAppUtils::BisectStart(const CString
& lastGood
, const CString
& firstBad
, bool bIsMainWnd
)
3333 if (!g_Git
.CheckCleanWorkTree())
3335 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
3337 CSysProgressDlg sysProgressDlg
;
3338 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
3339 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
3340 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
3341 sysProgressDlg
.SetShowProgressBar(false);
3342 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
3343 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
3346 cmd
= _T("git.exe stash");
3347 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
3349 sysProgressDlg
.Stop();
3350 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
);
3353 sysProgressDlg
.Stop();
3359 CBisectStartDlg bisectStartDlg
;
3361 if (!lastGood
.IsEmpty())
3362 bisectStartDlg
.m_sLastGood
= lastGood
;
3363 if (!firstBad
.IsEmpty())
3364 bisectStartDlg
.m_sFirstBad
= firstBad
;
3366 if (bisectStartDlg
.DoModal() == IDOK
)
3368 CProgressDlg progress
;
3370 theApp
.m_pMainWnd
= &progress
;
3371 progress
.m_GitCmdList
.push_back(_T("git.exe bisect start"));
3372 progress
.m_GitCmdList
.push_back(_T("git.exe bisect good ") + bisectStartDlg
.m_LastGoodRevision
);
3373 progress
.m_GitCmdList
.push_back(_T("git.exe bisect bad ") + bisectStartDlg
.m_FirstBadRevision
);
3375 progress
.m_PostCmdCallback
= [&](DWORD status
, PostCmdList
& postCmdList
)
3380 CTGitPath
path(g_Git
.m_CurrentDir
);
3381 if (path
.HasSubmodules())
3383 postCmdList
.push_back(PostCmd(IDI_UPDATE
, IDS_PROC_SUBMODULESUPDATE
, []
3386 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
3387 CAppUtils::RunTortoiseGitProc(sCmd
);
3394 INT_PTR ret
= progress
.DoModal();
3401 int CAppUtils::Git2GetUserPassword(git_cred
**out
, const char *url
, const char *username_from_url
, unsigned int /*allowed_types*/, void * /*payload*/)
3404 dlg
.m_URL
= CUnicodeUtils::GetUnicode(url
, CP_UTF8
);
3405 if (username_from_url
)
3406 dlg
.m_UserName
= CUnicodeUtils::GetUnicode(username_from_url
, CP_UTF8
);
3408 CStringA username
, password
;
3409 if (dlg
.DoModal() == IDOK
)
3411 username
= CUnicodeUtils::GetMulti(dlg
.m_UserName
, CP_UTF8
);
3412 password
= CUnicodeUtils::GetMulti(dlg
.m_Password
, CP_UTF8
);
3413 return git_cred_userpass_plaintext_new(out
, username
, password
);
3415 giterr_set_str(GITERR_NONE
, "User cancelled.");
3419 int CAppUtils::Git2CertificateCheck(git_cert
* base_cert
, int /*valid*/, const char* host
, void* /*payload*/)
3421 if (base_cert
->cert_type
== GIT_CERT_X509
)
3423 git_cert_x509
* cert
= (git_cert_x509
*)base_cert
;
3425 if (last_accepted_cert
.cmp(cert
))
3428 PCCERT_CONTEXT pServerCert
= CertCreateCertificateContext(X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
, (BYTE
*)cert
->data
, (DWORD
)cert
->len
);
3430 DWORD verificationError
= VerifyServerCertificate(pServerCert
, CUnicodeUtils::GetUnicode(host
).GetBuffer(), 0);
3431 if (!verificationError
)
3433 last_accepted_cert
.set(cert
);
3434 CertFreeCertificateContext(pServerCert
);
3438 CString servernameInCert
;
3439 CertGetNameString(pServerCert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, 0, nullptr, servernameInCert
.GetBuffer(128), 128);
3440 servernameInCert
.ReleaseBuffer();
3443 CertGetNameString(pServerCert
, CERT_NAME_SIMPLE_DISPLAY_TYPE
, CERT_NAME_ISSUER_FLAG
, nullptr, issuer
.GetBuffer(128), 128);
3444 issuer
.ReleaseBuffer();
3446 CertFreeCertificateContext(pServerCert
);
3448 CCheckCertificateDlg dlg
;
3450 dlg
.m_sCertificateCN
= servernameInCert
;
3451 dlg
.m_sCertificateIssuer
= issuer
;
3452 dlg
.m_sHostname
= CUnicodeUtils::GetUnicode(host
);
3453 dlg
.m_sError
= CFormatMessageWrapper(verificationError
);
3454 if (dlg
.DoModal() == IDOK
)
3456 last_accepted_cert
.set(cert
);
3460 return GIT_ECERTIFICATE
;
3463 void CAppUtils::ExploreTo(HWND hwnd
, CString path
)
3465 if (PathFileExists(path
))
3467 ITEMIDLIST __unaligned
* pidl
= ILCreateFromPath(path
);
3470 SHOpenFolderAndSelectItems(pidl
, 0, 0, 0);
3475 // if filepath does not exist any more, navigate to closest matching folder
3478 int pos
= path
.ReverseFind(_T('\\'));
3481 path
= path
.Left(pos
);
3482 } while (!PathFileExists(path
));
3483 ShellExecute(hwnd
, _T("explore"), path
, nullptr, nullptr, SW_SHOW
);
3486 int CAppUtils::ResolveConflict(CTGitPath
& path
, resolve_with resolveWith
)
3488 bool b_local
= false, b_remote
= false;
3492 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""), path
.GetGitPathString());
3493 if (g_Git
.Run(cmd
, &vector
))
3495 CMessageBox::Show(nullptr, _T("git ls-files failed!"), _T("TortoiseGit"), MB_OK
);
3500 if (list
.ParserFromLsFile(vector
))
3502 CMessageBox::Show(nullptr, _T("Parse ls-files failed!"), _T("TortoiseGit"), MB_OK
);
3508 for (int i
= 0; i
< list
.GetCount(); ++i
)
3510 if (list
[i
].m_Stage
== 2)
3512 if (list
[i
].m_Stage
== 3)
3517 CBlockCacheForPath
block(g_Git
.m_CurrentDir
);
3518 if (path
.IsDirectory()) // is submodule conflict
3520 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.");
3521 if (b_local
&& b_remote
)
3523 if (!path
.HasAdminDir()) // check if submodule is initialized
3525 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).");
3526 MessageBox(nullptr, err
, _T("TortoiseGit"), MB_ICONERROR
);
3530 subgit
.m_CurrentDir
= g_Git
.CombinePath(path
);
3531 CGitHash submoduleHead
;
3532 if (subgit
.GetHash(submoduleHead
, _T("HEAD")))
3534 MessageBox(nullptr, err
, _T("TortoiseGit"), MB_ICONERROR
);
3537 CString baseHash
, localHash
, remoteHash
;
3538 ParseHashesFromLsFile(vector
, baseHash
, localHash
, remoteHash
);
3539 if (resolveWith
== RESOLVE_WITH_THEIRS
&& submoduleHead
.ToString() != remoteHash
)
3541 CString origPath
= g_Git
.m_CurrentDir
;
3542 g_Git
.m_CurrentDir
= g_Git
.CombinePath(path
);
3543 if (!GitReset(&remoteHash
))
3545 g_Git
.m_CurrentDir
= origPath
;
3548 g_Git
.m_CurrentDir
= origPath
;
3550 else if (resolveWith
== RESOLVE_WITH_MINE
&& submoduleHead
.ToString() != localHash
)
3552 CString origPath
= g_Git
.m_CurrentDir
;
3553 g_Git
.m_CurrentDir
= g_Git
.CombinePath(path
);
3554 if (!GitReset(&localHash
))
3556 g_Git
.m_CurrentDir
= origPath
;
3559 g_Git
.m_CurrentDir
= origPath
;
3564 MessageBox(nullptr, err
, _T("TortoiseGit"), MB_ICONERROR
);
3569 if (resolveWith
== RESOLVE_WITH_THEIRS
)
3571 CString gitcmd
, output
;
3572 if (b_local
&& b_remote
)
3573 gitcmd
.Format(_T("git.exe checkout-index -f --stage=3 -- \"%s\""), path
.GetGitPathString());
3575 gitcmd
.Format(_T("git.exe add -f -- \"%s\""), path
.GetGitPathString());
3577 gitcmd
.Format(_T("git.exe rm -f -- \"%s\""), path
.GetGitPathString());
3578 if (g_Git
.Run(gitcmd
, &output
, CP_UTF8
))
3580 CMessageBox::Show(nullptr, output
, _T("TortoiseGit"), MB_ICONERROR
);
3584 else if (resolveWith
== RESOLVE_WITH_MINE
)
3586 CString gitcmd
, output
;
3587 if (b_local
&& b_remote
)
3588 gitcmd
.Format(_T("git.exe checkout-index -f --stage=2 -- \"%s\""), path
.GetGitPathString());
3590 gitcmd
.Format(_T("git.exe add -f -- \"%s\""), path
.GetGitPathString());
3592 gitcmd
.Format(_T("git.exe rm -f -- \"%s\""), path
.GetGitPathString());
3593 if (g_Git
.Run(gitcmd
, &output
, CP_UTF8
))
3595 CMessageBox::Show(nullptr, output
, _T("TortoiseGit"), MB_ICONERROR
);
3600 if (b_local
&& b_remote
&& path
.m_Action
& CTGitPath::LOGACTIONS_UNMERGED
)
3602 CString gitcmd
, output
;
3603 gitcmd
.Format(_T("git.exe add -f -- \"%s\""), path
.GetGitPathString());
3604 if (g_Git
.Run(gitcmd
, &output
, CP_UTF8
))
3605 CMessageBox::Show(nullptr, output
, _T("TortoiseGit"), MB_ICONERROR
);
3608 path
.m_Action
|= CTGitPath::LOGACTIONS_MODIFIED
;
3609 path
.m_Action
&= ~CTGitPath::LOGACTIONS_UNMERGED
;
3613 RemoveTempMergeFile(path
);
3617 bool CAppUtils::ShowOpenWithDialog(const CString
& file
, HWND hwnd
/*= nullptr */)
3619 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("shell32.dll"));
3622 typedef HRESULT STDAPICALLTYPE
SHOpenWithDialoFN(_In_opt_ HWND hwndParent
, _In_
const OPENASINFO
*poainfo
);
3623 SHOpenWithDialoFN
*pfnSHOpenWithDialog
= (SHOpenWithDialoFN
*)GetProcAddress(hShell
, "SHOpenWithDialog");
3624 if (pfnSHOpenWithDialog
)
3626 OPENASINFO oi
= { 0 };
3628 oi
.oaifInFlags
= OAIF_EXEC
;
3629 return SUCCEEDED(pfnSHOpenWithDialog(hwnd
, &oi
));
3632 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
3634 return CAppUtils::LaunchApplication(cmd
, NULL
, false);