1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2011 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "TortoiseProc.h"
23 #include "PathUtils.h"
25 //#include "GitProperties.h"
26 #include "StringUtils.h"
27 #include "MessageBox.h"
31 //#include "RepositoryBrowser.h"
32 //#include "BrowseFolder.h"
33 #include "UnicodeUtils.h"
34 #include "ExportDlg.h"
35 #include "ProgressDlg.h"
36 #include "GitAdminDir.h"
37 #include "ProgressDlg.h"
38 #include "BrowseFolder.h"
39 #include "DirFileEnum.h"
40 #include "MessageBox.h"
41 #include "GitStatus.h"
42 #include "CreateBranchTagDlg.h"
43 #include "GitSwitchDlg.h"
45 #include "DeleteConflictDlg.h"
46 #include "ChangedDlg.h"
47 #include "SendMailDlg.h"
48 #include "GITProgressDlg.h"
50 #include "CommitDlg.h"
53 #include "..\Settings\Settings.h"
55 #include "SVNDCommitDlg.h"
56 #include "requestpulldlg.h"
57 #include "PullFetchDlg.h"
58 #include "RebaseDlg.h"
60 #include "StashSave.h"
61 #include "IgnoreDlg.h"
62 #include "FormatMessageWrapper.h"
63 #include "SmartHandle.h"
65 CAppUtils::CAppUtils(void)
69 CAppUtils::~CAppUtils(void)
73 bool CAppUtils::StashSave()
77 if (dlg
.DoModal() == IDOK
)
80 cmd
= _T("git.exe stash save");
82 if (dlg
.m_bIncludeUntracked
&& CAppUtils::GetMsysgitVersion() >= 0x01070700)
83 cmd
+= _T(" --include-untracked");
85 if (!dlg
.m_sMessage
.IsEmpty())
87 CString message
= dlg
.m_sMessage
;
88 message
.Replace(_T("\""), _T("\"\""));
89 cmd
+= _T(" \"") + message
+ _T("\"");
92 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
94 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
98 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHSUCCESS
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
105 int CAppUtils::StashApply(CString ref
, bool showChanges
/* true */)
108 cmd
= _T("git.exe stash apply ");
109 if (ref
.Find(_T("refs/")) == 0)
111 if (ref
.Find(_T("stash{")) == 0)
112 ref
= _T("stash@") + ref
.Mid(5);
115 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
116 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
117 if (ret
&& !(ret
== 1 && hasConflicts
))
119 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHAPPLYFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
124 message
.LoadString(IDS_PROC_STASHAPPLYSUCCESS
);
126 message
.LoadString(IDS_PROC_STASHAPPLYFAILEDCONFLICTS
);
129 if(CMessageBox::Show(NULL
,message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
))
130 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
133 dlg
.m_pathList
.AddPath(CTGitPath());
140 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
147 int CAppUtils::StashPop(bool showChanges
/* true */)
150 cmd
=_T("git.exe stash pop ");
152 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
153 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
154 if (ret
&& !(ret
== 1 && hasConflicts
))
156 CMessageBox::Show(NULL
,CString(MAKEINTRESOURCE(IDS_PROC_STASHPOPFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
161 message
.LoadString(IDS_PROC_STASHPOPSUCCESS
);
163 message
.LoadString(IDS_PROC_STASHPOPFAILEDCONFLICTS
);
166 if(CMessageBox::Show(NULL
,CString(message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
)))
167 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
170 dlg
.m_pathList
.AddPath(CTGitPath());
177 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
184 bool CAppUtils::GetMimeType(const CTGitPath
& /*file*/, CString
& /*mimetype*/)
187 GitProperties
props(file
, GitRev::REV_WC
, false);
188 for (int i
= 0; i
< props
.GetCount(); ++i
)
190 if (props
.GetItemName(i
).compare(_T("svn:mime-type"))==0)
192 mimetype
= props
.GetItemValue(i
).c_str();
200 BOOL
CAppUtils::StartExtMerge(
201 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
202 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
)
205 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
206 CString ext
= mergedfile
.GetFileExtension();
207 CString com
= regCom
;
208 bool bInternal
= false;
213 // is there an extension specific merge tool?
214 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
215 if (CString(mergetool
) != "")
220 if (GetMimeType(yourfile
, mimetype
) || GetMimeType(theirfile
, mimetype
) || GetMimeType(basefile
, mimetype
))
222 // is there a mime type specific merge tool?
223 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype
);
224 if (CString(mergetool
) != "")
230 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
234 CRegString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE
);
235 com
= tortoiseMergePath
;
238 com
= CPathUtils::GetAppDirectory();
239 com
+= _T("TortoiseMerge.exe");
241 com
= _T("\"") + com
+ _T("\"");
242 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
243 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
245 // check if the params are set. If not, just add the files to the command line
246 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
248 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
249 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
250 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
251 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
253 if (basefile
.IsEmpty())
255 com
.Replace(_T("/base:%base"), _T(""));
256 com
.Replace(_T("%base"), _T(""));
259 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
260 if (theirfile
.IsEmpty())
262 com
.Replace(_T("/theirs:%theirs"), _T(""));
263 com
.Replace(_T("%theirs"), _T(""));
266 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
267 if (yourfile
.IsEmpty())
269 com
.Replace(_T("/mine:%mine"), _T(""));
270 com
.Replace(_T("%mine"), _T(""));
273 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
274 if (mergedfile
.IsEmpty())
276 com
.Replace(_T("/merged:%merged"), _T(""));
277 com
.Replace(_T("%merged"), _T(""));
280 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
281 if (basename
.IsEmpty())
283 if (basefile
.IsEmpty())
285 com
.Replace(_T("/basename:%bname"), _T(""));
286 com
.Replace(_T("%bname"), _T(""));
290 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
294 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
295 if (theirname
.IsEmpty())
297 if (theirfile
.IsEmpty())
299 com
.Replace(_T("/theirsname:%tname"), _T(""));
300 com
.Replace(_T("%tname"), _T(""));
304 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
308 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
309 if (yourname
.IsEmpty())
311 if (yourfile
.IsEmpty())
313 com
.Replace(_T("/minename:%yname"), _T(""));
314 com
.Replace(_T("%yname"), _T(""));
318 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
322 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
323 if (mergedname
.IsEmpty())
325 if (mergedfile
.IsEmpty())
327 com
.Replace(_T("/mergedname:%mname"), _T(""));
328 com
.Replace(_T("%mname"), _T(""));
332 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
336 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
338 if ((bReadOnly
)&&(bInternal
))
339 com
+= _T(" /readonly");
341 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
349 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
353 viewer
= CPathUtils::GetAppDirectory();
354 viewer
+= _T("TortoiseMerge.exe");
356 viewer
= _T("\"") + viewer
+ _T("\"");
357 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
358 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
360 viewer
+= _T(" /reversedpatch");
361 if (!sOriginalDescription
.IsEmpty())
362 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
363 if (!sPatchedDescription
.IsEmpty())
364 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
365 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
372 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
374 // Is there a mime type specific diff tool?
376 if (GetMimeType(file1
, mimetype
) || GetMimeType(file2
, mimetype
))
378 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype
);
379 if (!difftool
.IsEmpty())
383 // Is there an extension specific diff tool?
384 CString ext
= file2
.GetFileExtension().MakeLower();
387 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
388 if (!difftool
.IsEmpty())
390 // Maybe we should use TortoiseIDiff?
391 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
392 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
393 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
394 (ext
== _T(".dib")) || (ext
== _T(".emf")))
397 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
398 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
402 // Finally, pick a generic external diff tool
403 CString difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
407 bool CAppUtils::StartExtDiff(
408 const CString
& file1
, const CString
& file2
,
409 const CString
& sName1
, const CString
& sName2
,
410 const DiffFlags
& flags
)
414 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
415 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
417 viewer
= PickDiffTool(file1
, file2
);
418 // If registry entry for a diff program is commented out, use TortoiseMerge.
419 bool bCommentedOut
= viewer
.Left(1) == _T("#");
420 if (flags
.bAlternativeTool
)
422 // Invert external vs. internal diff tool selection.
424 viewer
.Delete(0); // uncomment
428 else if (bCommentedOut
)
432 bool bInternal
= viewer
.IsEmpty();
436 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
437 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
439 viewer
+= _T(" /blame");
441 // check if the params are set. If not, just add the files to the command line
442 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
444 viewer
+= _T(" \"")+file1
+_T("\"");
445 viewer
+= _T(" \"")+file2
+_T("\"");
447 if (viewer
.Find(_T("%base")) >= 0)
449 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
451 if (viewer
.Find(_T("%mine")) >= 0)
453 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
456 if (sName1
.IsEmpty())
457 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
459 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
461 if (sName2
.IsEmpty())
462 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
464 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
466 if (flags
.bReadOnly
&& bInternal
)
467 viewer
+= _T(" /readonly");
469 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
472 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
475 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
477 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
480 viewer
= CPathUtils::GetAppDirectory();
481 viewer
+= _T("TortoiseUDiff.exe");
482 // enquote the path to TortoiseUDiff
483 viewer
= _T("\"") + viewer
+ _T("\"");
485 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
488 if (viewer
.Find(_T("%1"))>=0)
490 if (viewer
.Find(_T("\"%1\"")) >= 0)
491 viewer
.Replace(_T("%1"), patchfile
);
493 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
496 viewer
+= _T(" \"") + patchfile
+ _T("\"");
497 if (viewer
.Find(_T("%title")) >= 0)
499 viewer
.Replace(_T("%title"), title
);
502 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
509 BOOL
CAppUtils::StartTextViewer(CString file
)
512 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
514 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
515 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
518 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
519 TCHAR
* buf
= new TCHAR
[len
+1];
520 ExpandEnvironmentStrings(viewer
, buf
, len
);
523 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
524 buf
= new TCHAR
[len
+1];
525 ExpandEnvironmentStrings(file
, buf
, len
);
528 file
= _T("\"")+file
+_T("\"");
529 if (viewer
.IsEmpty())
531 viewer
= _T("RUNDLL32 Shell32,OpenAs_RunDLL");
533 if (viewer
.Find(_T("\"%1\"")) >= 0)
535 viewer
.Replace(_T("\"%1\""), file
);
537 else if (viewer
.Find(_T("%1")) >= 0)
539 viewer
.Replace(_T("%1"), file
);
547 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
554 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
557 CAutoFile hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
560 length
= ::GetFileSize(hFile
, NULL
);
567 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
570 HDC hScreenDC
= ::GetDC(NULL
);
571 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
572 ::ReleaseDC(NULL
, hScreenDC
);
574 logFont
.lfEscapement
= 0;
575 logFont
.lfOrientation
= 0;
576 logFont
.lfWeight
= FW_NORMAL
;
577 logFont
.lfItalic
= 0;
578 logFont
.lfUnderline
= 0;
579 logFont
.lfStrikeOut
= 0;
580 logFont
.lfCharSet
= DEFAULT_CHARSET
;
581 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
582 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
583 logFont
.lfQuality
= DRAFT_QUALITY
;
584 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
585 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
586 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
589 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
603 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
604 key
= g_Git
.GetConfigValue(cmd
);
606 key
= key
.Tokenize(_T("\n"),start
);
614 CString proc
=CPathUtils::GetAppDirectory();
615 proc
+= _T("pageant.exe \"");
619 CString tempfile
= GetTempFile();
620 ::DeleteFile(tempfile
);
622 proc
+= _T(" -c \"");
623 proc
+= CPathUtils::GetAppDirectory();
624 proc
+= _T("touch.exe\"");
629 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true, &CPathUtils::GetAppDirectory());
634 while(!::PathFileExists(tempfile
))
639 break; //timeout 5 minutes
644 CMessageBox::Show(NULL
, IDS_ERR_PAEGENTTIMEOUT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
646 ::DeleteFile(tempfile
);
649 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
)
651 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
652 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
653 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
657 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
659 LaunchApplication(sCmd
, NULL
, false);
662 bool CAppUtils::LaunchRemoteSetting()
664 CTGitPath
path(g_Git
.m_CurrentDir
);
665 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
666 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
667 //dlg.SetTreeWidth(220);
668 dlg
.m_DefaultPage
= _T("gitremote");
675 * Launch the external blame viewer
677 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
679 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
680 viewer
+= _T("TortoiseGitBlame.exe");
681 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
682 //viewer += _T(" \"") + sLogFile + _T("\"");
683 //viewer += _T(" \"") + sOriginalFile + _T("\"");
684 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
685 viewer
+= CString(_T(" /rev:"))+Rev
;
686 viewer
+= _T(" ")+sParams
;
688 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
691 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
696 bool bStyled
= false;
697 pWnd
->GetWindowText(sText
);
698 // the rich edit control doesn't count the CR char!
699 // to be exact: CRLF is treated as one char.
702 // style each line separately
707 nNewlinePos
= sText
.Find('\n', offset
);
708 CString sLine
= sText
.Mid(offset
);
710 sLine
= sLine
.Left(nNewlinePos
-offset
);
713 while (FindStyleChars(sLine
, '*', start
, end
))
715 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
716 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
718 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
719 format
.cbSize
= sizeof(CHARFORMAT2
);
720 format
.dwMask
= CFM_BOLD
;
721 format
.dwEffects
= CFE_BOLD
;
722 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
728 while (FindStyleChars(sLine
, '^', start
, end
))
730 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
731 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
733 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
734 format
.cbSize
= sizeof(CHARFORMAT2
);
735 format
.dwMask
= CFM_ITALIC
;
736 format
.dwEffects
= CFE_ITALIC
;
737 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
743 while (FindStyleChars(sLine
, '_', start
, end
))
745 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
746 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
748 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
749 format
.cbSize
= sizeof(CHARFORMAT2
);
750 format
.dwMask
= CFM_UNDERLINE
;
751 format
.dwEffects
= CFE_UNDERLINE
;
752 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
756 offset
= nNewlinePos
+1;
757 } while(nNewlinePos
>=0);
761 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
764 bool bFoundMarker
= false;
765 // find a starting marker
766 while (sText
[i
] != 0)
768 if (sText
[i
] == stylechar
)
770 if (((i
+1)<sText
.GetLength())&&(IsCharAlphaNumeric(sText
[i
+1])) &&
771 (((i
>0)&&(!IsCharAlphaNumeric(sText
[i
-1])))||(i
==0)))
783 // find ending marker
784 bFoundMarker
= false;
785 while (sText
[i
] != 0)
787 if (sText
[i
] == stylechar
)
789 if ((IsCharAlphaNumeric(sText
[i
-1])) &&
790 ((((i
+1)<sText
.GetLength())&&(!IsCharAlphaNumeric(sText
[i
+1])))||(i
+1)==sText
.GetLength()))
803 CString
CAppUtils::GetProjectNameFromURL(CString url
)
806 while (name
.IsEmpty() || (name
.CompareNoCase(_T("branches"))==0) ||
807 (name
.CompareNoCase(_T("tags"))==0) ||
808 (name
.CompareNoCase(_T("trunk"))==0))
810 name
= url
.Mid(url
.ReverseFind('/')+1);
811 url
= url
.Left(url
.ReverseFind('/'));
813 if ((name
.Compare(_T("svn")) == 0)||(name
.Compare(_T("svnroot")) == 0))
815 // a name of svn or svnroot indicates that it's not really the project name. In that
816 // case, we try the first part of the URL
817 // of course, this won't work in all cases (but it works for Google project hosting)
818 url
.Replace(_T("http://"), _T(""));
819 url
.Replace(_T("https://"), _T(""));
820 url
.Replace(_T("svn://"), _T(""));
821 url
.Replace(_T("svn+ssh://"), _T(""));
822 url
.TrimLeft(_T("/"));
823 name
= url
.Left(url
.Find('.'));
828 bool CAppUtils::StartShowUnifiedDiff(HWND
/*hWnd*/, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
829 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
830 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
831 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */, bool /* blame = false */, bool bMerge
)
834 CString tempfile
=GetTempFile();
836 if(rev2
== GitRev::GetWorkingCopy())
838 cmd
.Format(_T("git.exe diff --stat -p %s "), rev1
);
846 cmd
.Format(_T("git.exe diff-tree -r -p %s --stat %s %s"),merge
, rev1
,rev2
);
849 if( !url1
.IsEmpty() )
852 cmd
+= url1
.GetGitPathString();
855 g_Git
.RunLogFile(cmd
,tempfile
);
856 CAppUtils::StartUnifiedDiffViewer(tempfile
, rev1
+ _T(":") + rev2
);
861 sCmd
.Format(_T("%s /command:showcompare /unified"),
862 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
863 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
865 sCmd
+= _T(" /revision1:") + rev1
.ToString();
866 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
868 sCmd
+= _T(" /revision2:") + rev2
.ToString();
870 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
871 if (headpeg
.IsValid())
872 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
875 sCmd
+= _T(" /alternatediff");
878 sCmd
+= _T(" /ignoreancestry");
882 sCmd
+= _T(" /hwnd:");
884 _stprintf_s(buf
, 30, _T("%d"), hWnd
);
888 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
894 bool CAppUtils::Export(CString
*BashHash
)
898 // ask from where the export has to be done
901 dlg
.m_Revision
=*BashHash
;
903 if (dlg
.DoModal() == IDOK
)
906 cmd
.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s"),
907 dlg
.m_strExportDirectory
, g_Git
.FixBranchName(dlg
.m_VersionName
));
917 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
, bool switch_new_brach
)
919 CCreateBranchTagDlg dlg
;
921 dlg
.m_bSwitch
=switch_new_brach
;
924 dlg
.m_Base
= *CommitHash
;
926 if(dlg
.DoModal()==IDOK
)
931 if(dlg
.m_bTrack
== TRUE
)
932 track
=_T(" --track ");
933 else if(dlg
.m_bTrack
== FALSE
)
934 track
=_T(" --no-track");
945 cmd
.Format(_T("git.exe tag %s %s %s %s"),
949 g_Git
.FixBranchName(dlg
.m_VersionName
)
952 CString tempfile
=::GetTempFile();
953 if(!dlg
.m_Message
.Trim().IsEmpty())
955 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_Message
);
956 cmd
+= _T(" -F ")+tempfile
;
961 cmd
.Format(_T("git.exe branch %s %s %s %s"),
965 g_Git
.FixBranchName(dlg
.m_VersionName
)
969 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
971 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
973 if( !IsTag
&& dlg
.m_bSwitch
)
975 // it is a new branch and the user has requested to switch to it
976 cmd
.Format(_T("git.exe checkout %s"), dlg
.m_BranchTagName
);
977 g_Git
.Run(cmd
,&out
,CP_UTF8
);
978 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
986 bool CAppUtils::Switch(CString
*CommitHash
, CString initialRefName
, bool autoclose
)
990 dlg
.m_Base
=*CommitHash
;
991 if(!initialRefName
.IsEmpty())
992 dlg
.m_initialRefName
= initialRefName
;
994 if (dlg
.DoModal() == IDOK
)
998 branch
= dlg
.m_NewBranch
;
1000 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
== TRUE
, autoclose
);
1005 bool CAppUtils::PerformSwitch(CString ref
, bool bForce
/* false */, CString sNewBranch
/* CString() */, bool bBranchOverride
/* false */, bool bTrack
/* false */, bool autoClose
/* false */)
1012 if(!sNewBranch
.IsEmpty()){
1013 if (bBranchOverride
)
1015 branch
.Format(_T("-B %s"), sNewBranch
);
1019 branch
.Format(_T("-b %s"), sNewBranch
);
1022 track
= _T("--track");
1027 cmd
.Format(_T("git.exe checkout %s %s %s %s"),
1031 g_Git
.FixBranchName(ref
));
1033 CProgressDlg progress
;
1034 progress
.m_bAutoCloseOnSuccess
= autoClose
;
1035 progress
.m_GitCmd
= cmd
;
1037 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1038 if (gitPath
.HasSubmodules())
1039 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1041 int ret
= progress
.DoModal();
1042 if (gitPath
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
1045 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1047 RunTortoiseProc(sCmd
);
1050 else if (ret
== IDOK
)
1056 bool CAppUtils::OpenIgnoreFile(CStdioFile
&file
, const CString
& filename
)
1058 if (!file
.Open(filename
, CFile::modeCreate
| CFile::modeReadWrite
| CFile::modeNoTruncate
))
1060 CMessageBox::Show(NULL
, filename
+ _T(" Open Failure"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1064 if (file
.GetLength() > 0)
1066 file
.Seek(file
.GetLength() - 1, 0);
1067 auto_buffer
<TCHAR
> buf(1);
1070 if (buf
[0] != _T('\n'))
1071 file
.WriteString(_T("\n"));
1079 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1081 CIgnoreDlg ignoreDlg
;
1082 if (ignoreDlg
.DoModal() == IDOK
)
1085 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\");
1087 switch (ignoreDlg
.m_IgnoreFile
)
1090 ignorefile
+= _T(".gitignore");
1093 ignorefile
+= _T(".git/info/exclude");
1100 if (ignoreDlg
.m_IgnoreFile
!= 1 && !OpenIgnoreFile(file
, ignorefile
))
1103 for (int i
= 0; i
< path
.GetCount(); i
++)
1105 if (ignoreDlg
.m_IgnoreFile
== 1)
1107 ignorefile
= g_Git
.m_CurrentDir
+ _T("\\") + path
[i
].GetContainingDirectory().GetWinPathString() + _T("\\.gitignore");
1108 if (!OpenIgnoreFile(file
, ignorefile
))
1112 CString ignorePattern
;
1113 if (ignoreDlg
.m_IgnoreType
== 0)
1115 if (ignoreDlg
.m_IgnoreFile
!= 1 && !path
[i
].GetContainingDirectory().GetWinPathString().IsEmpty())
1116 ignorePattern
+= _T("/") + path
[i
].GetContainingDirectory().GetWinPathString();
1118 ignorePattern
+= _T("/");
1122 ignorePattern
+= _T("*") + path
[i
].GetFileExtension();
1126 ignorePattern
+= path
[i
].GetFileOrDirectoryName();
1128 file
.WriteString(ignorePattern
+ _T("\n"));
1130 if (ignoreDlg
.m_IgnoreFile
== 1)
1134 if (ignoreDlg
.m_IgnoreFile
!= 1)
1149 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1152 dlg
.m_ResetType
=type
;
1153 dlg
.m_ResetToVersion
=*CommitHash
;
1154 if (dlg
.DoModal() == IDOK
)
1158 switch(dlg
.m_ResetType
)
1173 cmd
.Format(_T("git.exe reset %s %s"),type
, *CommitHash
);
1175 CProgressDlg progress
;
1176 progress
.m_GitCmd
=cmd
;
1178 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1179 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2)
1180 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1182 int ret
= progress
.DoModal();
1183 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2 && ret
== IDC_PROGRESS_BUTTON1
)
1186 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1188 RunTortoiseProc(sCmd
);
1191 else if (ret
== IDOK
)
1198 void CAppUtils::DescribeFile(bool mode
, bool base
,CString
&descript
)
1202 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_DELETE
));
1207 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_MODIFIED
));
1210 descript
= CString(MAKEINTRESOURCE(IDS_PROC_CREATED
));
1214 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1216 CString tempmergefile
;
1219 tempmergefile
= CAppUtils::GetMergeTempFile(_T("LOCAL"),path
);
1220 CFile::Remove(tempmergefile
);
1227 tempmergefile
= CAppUtils::GetMergeTempFile(_T("REMOTE"),path
);
1228 CFile::Remove(tempmergefile
);
1235 tempmergefile
= CAppUtils::GetMergeTempFile(_T("BASE"),path
);
1236 CFile::Remove(tempmergefile
);
1241 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1244 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1249 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool /*bAlternativeTool*/,bool revertTheirMy
)
1253 CTGitPath merge
=path
;
1254 CTGitPath directory
= merge
.GetDirectory();
1256 // we have the conflicted file (%merged)
1257 // now look for the other required files
1259 //stat.GetStatus(merge);
1260 //if (stat.status == NULL)
1266 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1268 if (g_Git
.Run(cmd
, &vector
))
1274 list
.ParserFromLsFile(vector
);
1276 if(list
.GetCount() == 0)
1283 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge
));
1284 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge
));
1285 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1289 //format=_T("git.exe cat-file blob \":%d:%s\"");
1290 format
= _T("git checkout-index --temp --stage=%d -- \"%s\"");
1292 //create a empty file, incase stage is not three
1293 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1295 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1297 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1300 bool b_base
=false, b_local
=false, b_remote
=false;
1302 for(int i
=0;i
<list
.GetCount();i
++)
1309 if( list
[i
].m_Stage
== 1)
1311 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1313 outfile
= base
.GetWinPathString();
1316 if( list
[i
].m_Stage
== 2 )
1318 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1320 outfile
= mine
.GetWinPathString();
1323 if( list
[i
].m_Stage
== 3 )
1325 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1327 outfile
= theirs
.GetWinPathString();
1329 CString output
, err
;
1330 if(!outfile
.IsEmpty())
1331 if (!g_Git
.Run(cmd
, &output
, &err
, CP_UTF8
))
1335 file
= output
.Tokenize(_T("\t"), start
);
1336 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1340 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1344 if(b_local
&& b_remote
)
1346 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1348 bRet
= !!CAppUtils::StartExtMerge(base
,mine
, theirs
, merge
,_T("BASE"),_T("LOCAL"),_T("REMOTE"));
1350 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1355 CFile::Remove(mine
.GetWinPathString());
1356 CFile::Remove(theirs
.GetWinPathString());
1357 CFile::Remove(base
.GetWinPathString());
1359 CDeleteConflictDlg dlg
;
1360 DescribeFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1361 DescribeFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1362 dlg
.m_bShowModifiedButton
=b_base
;
1363 dlg
.m_File
=merge
.GetGitPathString();
1364 if(dlg
.DoModal() == IDOK
)
1369 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1372 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1374 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1376 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1386 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1387 base
, theirs
, mine
, merge
);
1390 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1392 // we have a text conflict, use our merge tool to resolve the conflict
1394 CTSVNPath
theirs(directory
);
1395 CTSVNPath
mine(directory
);
1396 CTSVNPath
base(directory
);
1397 bool bConflictData
= false;
1399 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1401 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1402 bConflictData
= true;
1404 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1406 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1407 bConflictData
= true;
1409 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1411 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1412 bConflictData
= true;
1419 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1420 base
, theirs
, mine
, merge
);
1423 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1425 // we have a property conflict
1426 CTSVNPath
prej(directory
);
1427 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1429 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1430 // there's a problem: the prej file contains a _description_ of the conflict, and
1431 // that description string might be translated. That means we have no way of parsing
1432 // the file to find out the conflicting values.
1433 // The only thing we can do: show a dialog with the conflict description, then
1434 // let the user either accept the existing property or open the property edit dialog
1435 // to manually change the properties and values. And a button to mark the conflict as
1437 CEditPropConflictDlg dlg
;
1438 dlg
.SetPrejFile(prej
);
1439 dlg
.SetConflictedItem(merge
);
1440 bRet
= (dlg
.DoModal() != IDCANCEL
);
1444 if (stat
.status
->tree_conflict
)
1446 // we have a tree conflict
1448 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1451 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1453 CTSVNPath
theirs(directory
);
1454 CTSVNPath
mine(directory
);
1455 CTSVNPath
base(directory
);
1456 bool bConflictData
= false;
1458 if (pInfoData
->treeconflict_theirfile
)
1460 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1461 bConflictData
= true;
1463 if (pInfoData
->treeconflict_basefile
)
1465 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1466 bConflictData
= true;
1468 if (pInfoData
->treeconflict_myfile
)
1470 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1471 bConflictData
= true;
1478 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1479 base
, theirs
, mine
, merge
);
1481 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1483 CString sConflictAction
;
1484 CString sConflictReason
;
1485 CString sResolveTheirs
;
1486 CString sResolveMine
;
1487 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1488 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1490 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1492 switch (pInfoData
->treeconflict_operation
)
1494 case svn_wc_operation_update
:
1495 switch (pInfoData
->treeconflict_action
)
1497 case svn_wc_conflict_action_edit
:
1498 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1499 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1501 case svn_wc_conflict_action_add
:
1502 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1503 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1505 case svn_wc_conflict_action_delete
:
1506 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1507 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1511 case svn_wc_operation_switch
:
1512 switch (pInfoData
->treeconflict_action
)
1514 case svn_wc_conflict_action_edit
:
1515 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1516 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1518 case svn_wc_conflict_action_add
:
1519 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1520 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1522 case svn_wc_conflict_action_delete
:
1523 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1524 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1528 case svn_wc_operation_merge
:
1529 switch (pInfoData
->treeconflict_action
)
1531 case svn_wc_conflict_action_edit
:
1532 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1533 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1535 case svn_wc_conflict_action_add
:
1536 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1537 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1539 case svn_wc_conflict_action_delete
:
1540 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1541 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1547 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1549 switch (pInfoData
->treeconflict_operation
)
1551 case svn_wc_operation_update
:
1552 switch (pInfoData
->treeconflict_action
)
1554 case svn_wc_conflict_action_edit
:
1555 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1556 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1558 case svn_wc_conflict_action_add
:
1559 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1560 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1562 case svn_wc_conflict_action_delete
:
1563 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1564 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1568 case svn_wc_operation_switch
:
1569 switch (pInfoData
->treeconflict_action
)
1571 case svn_wc_conflict_action_edit
:
1572 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1573 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1575 case svn_wc_conflict_action_add
:
1576 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1577 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1579 case svn_wc_conflict_action_delete
:
1580 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1581 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1585 case svn_wc_operation_merge
:
1586 switch (pInfoData
->treeconflict_action
)
1588 case svn_wc_conflict_action_edit
:
1589 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1590 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1592 case svn_wc_conflict_action_add
:
1593 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1594 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1596 case svn_wc_conflict_action_delete
:
1597 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1598 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1606 switch (pInfoData
->treeconflict_reason
)
1608 case svn_wc_conflict_reason_edited
:
1609 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1610 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1612 case svn_wc_conflict_reason_obstructed
:
1613 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1614 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1616 case svn_wc_conflict_reason_deleted
:
1617 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1618 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1620 case svn_wc_conflict_reason_added
:
1621 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1622 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1624 case svn_wc_conflict_reason_missing
:
1625 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1626 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1628 case svn_wc_conflict_reason_unversioned
:
1629 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1630 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1633 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1635 CTreeConflictEditorDlg dlg
;
1636 dlg
.SetConflictInfoText(sConflictReason
);
1637 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1638 dlg
.SetPath(treeConflictPath
);
1639 INT_PTR dlgRet
= dlg
.DoModal();
1640 bRet
= (dlgRet
!= IDCANCEL
);
1648 bool CAppUtils::IsSSHPutty()
1650 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1651 sshclient
=sshclient
.MakeLower();
1652 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1659 CString
CAppUtils::GetClipboardLink()
1661 if (!OpenClipboard(NULL
))
1664 CString sClipboardText
;
1665 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1668 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1669 sClipboardText
= CString(lpstr
);
1672 hglb
= GetClipboardData(CF_UNICODETEXT
);
1675 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1676 sClipboardText
= lpstr
;
1681 if(!sClipboardText
.IsEmpty())
1683 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1684 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1686 if(sClipboardText
.Find( _T("http://")) == 0)
1687 return sClipboardText
;
1689 if(sClipboardText
.Find( _T("https://")) == 0)
1690 return sClipboardText
;
1692 if(sClipboardText
.Find( _T("git://")) == 0)
1693 return sClipboardText
;
1695 if(sClipboardText
.Find( _T("ssh://")) == 0)
1696 return sClipboardText
;
1698 if(sClipboardText
.GetLength()>=2)
1699 if( sClipboardText
[1] == _T(':') )
1700 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1701 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1702 return sClipboardText
;
1705 return CString(_T(""));
1708 CString
CAppUtils::ChooseRepository(CString
*path
)
1710 CBrowseFolder browseFolder
;
1711 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
1713 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
1714 CString strCloneDirectory
;
1716 strCloneDirectory
=*path
;
1719 strCloneDirectory
= regLastResopitory
;
1723 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
1725 browseFolder
.SetInfo(title
);
1727 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
1729 regLastResopitory
= strCloneDirectory
;
1730 return strCloneDirectory
;
1738 bool CAppUtils::SendPatchMail(CTGitPathList
&list
,bool autoclose
)
1742 dlg
.m_PathList
= list
;
1744 if(dlg
.DoModal()==IDOK
)
1746 if(dlg
.m_PathList
.GetCount() == 0)
1749 CGitProgressDlg progDlg
;
1751 theApp
.m_pMainWnd
= &progDlg
;
1752 progDlg
.SetCommand(CGitProgressDlg::GitProgress_SendMail
);
1754 progDlg
.SetAutoClose(autoclose
);
1756 progDlg
.SetPathList(dlg
.m_PathList
);
1757 //ProjectProperties props;
1758 //props.ReadPropsPathList(dlg.m_pathList);
1759 //progDlg.SetProjectProperties(props);
1760 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
1763 if(dlg
.m_bAttachment
)
1764 flags
|= SENDMAIL_ATTACHMENT
;
1766 flags
|= SENDMAIL_COMBINED
;
1768 flags
|= SENDMAIL_MAPI
;
1770 progDlg
.SetSendMailOption(dlg
.m_To
,dlg
.m_CC
,dlg
.m_Subject
,flags
);
1779 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
)
1782 CString log
=formatpatchoutput
;
1783 int start
=log
.Find(cmd
);
1785 CString one
=log
.Tokenize(_T("\n"),start
);
1791 CString one
=log
.Tokenize(_T("\n"),start
);
1793 if(one
.IsEmpty() || one
== _T("Success"))
1795 one
.Replace(_T('/'),_T('\\'));
1797 path
.SetFromWin(one
);
1800 if (list
.GetCount() > 0)
1802 return SendPatchMail(list
, autoclose
);
1806 CMessageBox::Show(NULL
, IDS_ERR_NOPATCHES
, IDS_APPNAME
, MB_ICONINFORMATION
);
1812 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
1817 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
1818 if(output
.IsEmpty())
1820 output
= pGit
->GetConfigValue(_T("i18n.commitencoding"));
1821 if(output
.IsEmpty())
1825 output
=output
.Tokenize(_T("\n"),start
);
1826 return CUnicodeUtils::GetCPCode(output
);
1831 output
=output
.Tokenize(_T("\n"),start
);
1832 return CUnicodeUtils::GetCPCode(output
);
1835 int CAppUtils::GetCommitTemplate(CString
&temp
)
1839 output
= g_Git
.GetConfigValue(_T("commit.template"), CP_UTF8
);
1840 if( output
.IsEmpty() )
1843 if( output
.GetLength()<1)
1846 if( output
[0] == _T('/'))
1848 if(output
.GetLength()>=3)
1849 if(output
[2] == _T('/'))
1851 output
.GetBuffer()[0] = output
[1];
1852 output
.GetBuffer()[1] = _T(':');
1857 output
=output
.Tokenize(_T("\n"),start
);
1859 output
.Replace(_T('/'),_T('\\'));
1863 CStdioFile
file(output
,CFile::modeRead
|CFile::typeText
);
1865 while(file
.ReadString(str
))
1876 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
1878 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
1882 output
= g_Git
.GetConfigValue(_T("i18n.commitencoding"));
1883 if(output
.IsEmpty())
1887 output
=output
.Tokenize(_T("\n"),start
);
1888 cp
=CUnicodeUtils::GetCPCode(output
);
1890 int len
=message
.GetLength();
1893 buf
= new char[len
*4 + 4];
1894 SecureZeroMemory(buf
, (len
*4 + 4));
1896 int lengthIncTerminator
= WideCharToMultiByte(cp
, 0, message
, -1, buf
, len
*4, NULL
, NULL
);
1898 file
.Write(buf
,lengthIncTerminator
-1);
1904 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
, bool autoClose
)
1907 dlg
.m_PreSelectRemote
= remoteName
;
1908 dlg
.m_bAllowRebase
= allowRebase
;
1911 if(dlg
.DoModal()==IDOK
)
1915 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_RemoteURL
);
1919 url
=dlg
.m_RemoteURL
;
1923 int ver
= CAppUtils::GetMsysgitVersion();
1925 if(ver
>= 0x01070203) //above 1.7.0.2
1926 arg
= _T("--progress ");
1929 arg
+= _T("--prune ");
1932 if (dlg
.m_bFetchTags
== 1)
1934 arg
+= _T("--tags ");
1936 else if (dlg
.m_bFetchTags
== 0)
1938 arg
+= _T("--no-tags ");
1941 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"),arg
, url
,dlg
.m_RemoteBranchName
);
1942 CProgressDlg progress
;
1944 progress
.m_bAutoCloseOnSuccess
= autoClose
;
1946 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
1948 if(!dlg
.m_bRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
1950 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
1953 progress
.m_GitCmd
=cmd
;
1954 int userResponse
=progress
.DoModal();
1956 if (userResponse
== IDC_PROGRESS_BUTTON1
)
1958 CString cmd
= _T("/command:log");
1959 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
1960 RunTortoiseProc(cmd
);
1963 else if ((userResponse
== IDC_PROGRESS_BUTTON1
+ 1) || (progress
.m_GitStatus
== 0 && dlg
.m_bRebase
))
1968 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUDESSENDMAIL
)));
1969 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
1970 int response
= dlg
.DoModal();
1971 if(response
== IDOK
)
1975 if(response
== IDC_REBASE_POST_BUTTON
)
1977 CString cmd
, out
, err
;
1978 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
1980 g_Git
.FixBranchName(dlg
.m_Upstream
),
1981 g_Git
.FixBranchName(dlg
.m_Branch
));
1982 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
1984 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1988 CAppUtils::SendPatchMail(cmd
,out
);
1992 if(response
== IDC_REBASE_POST_BUTTON
+1 )
1995 if(response
== IDCANCEL
)
2000 else if (userResponse
!= IDCANCEL
)
2006 bool CAppUtils::Push(CString selectLocalBranch
, bool autoClose
)
2009 dlg
.m_BranchSourceName
= selectLocalBranch
;
2011 DWORD exitcode
= 0xFFFFFFFF;
2013 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
2014 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
2019 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2020 //ReportError(temp);
2021 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2026 if(dlg
.DoModal()==IDOK
)
2033 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_URL
);
2037 arg
+= _T("--thin ");
2038 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2039 arg
+= _T("--tags ");
2041 arg
+= _T("--force ");
2043 int ver
= CAppUtils::GetMsysgitVersion();
2045 if(ver
>= 0x01070203) //above 1.7.0.2
2046 arg
+= _T("--progress ");
2048 if (dlg
.m_bPushAllBranches
)
2050 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2056 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2059 dlg
.m_BranchSourceName
);
2060 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2062 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2066 CProgressDlg progress
;
2067 progress
.m_bAutoCloseOnSuccess
=autoClose
;
2068 progress
.m_GitCmd
=cmd
;
2069 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REQUESTPULL
)));
2070 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2071 int ret
= progress
.DoModal();
2073 if(!progress
.m_GitStatus
)
2075 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2080 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2081 //ReportError(temp);
2082 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2086 if(ret
== IDC_PROGRESS_BUTTON1
)
2088 RequestPull(dlg
.m_BranchRemoteName
);
2090 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2101 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2103 CRequestPullDlg dlg
;
2104 dlg
.m_RepositoryURL
= repositoryUrl
;
2105 dlg
.m_EndRevision
= endrevision
;
2106 if (dlg
.DoModal()==IDOK
)
2109 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2111 CString tempFileName
= GetTempFile();
2112 if (g_Git
.RunLogFile(cmd
, tempFileName
))
2114 CMessageBox::Show(NULL
, IDS_ERR_PULLREUQESTFAILED
, IDS_APPNAME
, MB_OK
);
2117 CAppUtils::LaunchAlternativeEditor(tempFileName
);
2122 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2124 CString
strDir(szPath
);
2125 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2127 strDir
.AppendChar(_T('\\'));
2129 std::vector
<CString
> vPath
;
2131 bool bSuccess
= false;
2133 for (int i
=0;i
<strDir
.GetLength();++i
)
2135 if (strDir
.GetAt(i
) != _T('\\'))
2137 strTemp
.AppendChar(strDir
.GetAt(i
));
2141 vPath
.push_back(strTemp
);
2142 strTemp
.AppendChar(_T('\\'));
2146 std::vector
<CString
>::const_iterator vIter
;
2147 for (vIter
= vPath
.begin(); vIter
!= vPath
.end(); vIter
++)
2149 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2155 void CAppUtils::RemoveTrailSlash(CString
&path
)
2160 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2162 path
=path
.Left(path
.GetLength()-1);
2168 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2169 CTGitPathList
&pathList
,
2170 CTGitPathList
&selectedList
,
2171 bool bSelectFilesForCommit
,
2174 bool bFailed
= true;
2176 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
2178 if(CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
2180 CTGitPath
path(g_Git
.m_CurrentDir
);
2181 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2182 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2183 dlg
.SetTreeWidth(220);
2184 dlg
.m_DefaultPage
= _T("gitconfig");
2187 dlg
.HandleRestart();
2198 dlg
.m_sBugID
= bugid
;
2200 dlg
.m_bWholeProject
= bWholeProject
;
2202 dlg
.m_sLogMessage
= sLogMsg
;
2203 dlg
.m_pathList
= pathList
;
2204 dlg
.m_checkedPathList
= selectedList
;
2205 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2206 dlg
.m_bAutoClose
= autoClose
;
2207 if (dlg
.DoModal() == IDOK
)
2209 if (dlg
.m_pathList
.GetCount()==0)
2211 // if the user hasn't changed the list of selected items
2212 // we don't use that list. Because if we would use the list
2213 // of pre-checked items, the dialog would show different
2214 // checked items on the next startup: it would only try
2215 // to check the parent folder (which might not even show)
2216 // instead, we simply use an empty list and let the
2217 // default checking do its job.
2218 if (!dlg
.m_pathList
.IsEqual(pathList
))
2219 selectedList
= dlg
.m_pathList
;
2220 pathList
= dlg
.m_updatedPathList
;
2221 sLogMsg
= dlg
.m_sLogMessage
;
2222 bSelectFilesForCommit
= true;
2224 if( dlg
.m_bPushAfterCommit
)
2226 switch(dlg
.m_PostCmd
)
2228 case GIT_POST_CMD_DCOMMIT
:
2229 CAppUtils::SVNDCommit();
2235 else if (dlg
.m_bCreateTagAfterCommit
)
2237 CAppUtils::CreateBranchTag(TRUE
);
2240 // CGitProgressDlg progDlg;
2241 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2242 // if (parser.HasVal(_T("closeonend")))
2243 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2244 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2245 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2246 // progDlg.SetPathList(dlg.m_pathList);
2247 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2248 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2249 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2250 // progDlg.SetItemCount(dlg.m_itemsCount);
2251 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2252 // progDlg.DoModal();
2253 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2254 // err = (DWORD)progDlg.DidErrorsOccur();
2255 // bFailed = progDlg.DidErrorsOccur();
2256 // bRet = progDlg.DidErrorsOccur();
2257 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2258 // if (DWORD(bFailRepeat)==0)
2259 // bFailed = false; // do not repeat if the user chose not to in the settings.
2266 BOOL
CAppUtils::SVNDCommit()
2268 CSVNDCommitDlg dcommitdlg
;
2269 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2270 if (gitSetting
== _T("")) {
2271 if (dcommitdlg
.DoModal() != IDOK
)
2277 if (dcommitdlg
.m_remember
)
2279 if (dcommitdlg
.m_rmdir
)
2281 gitSetting
= _T("true");
2285 gitSetting
= _T("false");
2287 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2290 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, _T("svn.rmdir"), gitSetting
);
2291 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2297 BOOL IsStash
= false;
2298 if(!g_Git
.CheckCleanWorkTree())
2300 if(CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2303 cmd
=_T("git.exe stash");
2304 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2306 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2318 CProgressDlg progress
;
2319 if (dcommitdlg
.m_rmdir
)
2321 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2325 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2327 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2331 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2334 cmd
=_T("git.exe stash pop");
2335 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2337 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2352 BOOL
CAppUtils::Merge(CString
*commit
)
2356 dlg
.m_initialRefName
= *commit
;
2358 if(dlg
.DoModal()==IDOK
)
2370 squash
=_T("--squash");
2373 nocommit
=_T("--no-commit");
2375 if(!dlg
.m_strLogMesage
.IsEmpty())
2377 msg
+= _T("-m \"")+dlg
.m_strLogMesage
+_T("\"");
2379 cmd
.Format(_T("git.exe merge %s %s %s %s %s"),
2384 g_Git
.FixBranchName(dlg
.m_VersionName
));
2386 CProgressDlg Prodlg
;
2387 Prodlg
.m_GitCmd
= cmd
;
2389 if (dlg
.m_bNoCommit
)
2390 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUCOMMIT
)));
2391 else if (dlg
.m_bIsBranch
)
2392 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REMOVEBRANCH
)));
2394 int ret
= Prodlg
.DoModal();
2396 if (ret
== IDC_PROGRESS_BUTTON1
)
2397 if (dlg
.m_bNoCommit
)
2398 return Commit(_T(""), TRUE
, CString(), CTGitPathList(), CTGitPathList(), true);
2399 else if (dlg
.m_bIsBranch
)
2402 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, dlg
.m_VersionName
);
2403 if (CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
2406 cmd
.Format(_T("git.exe branch -D -- %s"), dlg
.m_VersionName
);
2407 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2408 MessageBox(NULL
, out
, _T("TortoiseGit"), MB_OK
);
2412 return !Prodlg
.m_GitStatus
;
2417 void CAppUtils::EditNote(GitRev
*rev
)
2420 dlg
.m_sHintText
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2421 dlg
.m_sInputText
= rev
->m_Notes
;
2422 dlg
.m_sTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2423 //dlg.m_pProjectProperties = &m_ProjectProperties;
2424 dlg
.m_bUseLogWidth
= true;
2425 if(dlg
.DoModal() == IDOK
)
2428 cmd
=_T("notes add -f -F \"");
2430 CString tempfile
=::GetTempFile();
2431 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
2434 cmd
+= rev
->m_CommitHash
.ToString();
2438 if (git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2440 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2445 rev
->m_Notes
= dlg
.m_sInputText
;
2449 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2451 CFile::Remove(tempfile
);
2456 int CAppUtils::GetMsysgitVersion(CString
*versionstr
)
2459 CString progressarg
;
2462 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
2463 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
2465 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
2468 if(!g_Git
.GetFileModifyTime(gitpath
, &time
) && !versionstr
)
2470 if((DWORD
)time
== regTime
)
2477 version
= *versionstr
;
2481 cmd
= _T("git.exe --version");
2482 if (g_Git
.Run(cmd
, &version
, &err
, CP_UTF8
))
2484 CMessageBox::Show(NULL
, _T("git have not installed (") + err
+ _T(")"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2494 CString str
=version
.Tokenize(_T("."), start
);
2495 int space
= str
.ReverseFind(_T(' '));
2496 str
= str
.Mid(space
+1,start
);
2500 version
= version
.Mid(start
);
2503 str
= version
.Tokenize(_T("."), start
);
2505 ver
|= (_ttol(str
) & 0xFF) << 16;
2507 str
= version
.Tokenize(_T("."), start
);
2508 ver
|= (_ttol(str
) & 0xFF) << 8;
2510 str
= version
.Tokenize(_T("."), start
);
2511 ver
|= (_ttol(str
) & 0xFF);
2517 CMessageBox::Show(NULL
, _T("Could not parse git.exe version number."), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2522 regTime
= time
&0xFFFFFFFF;
2528 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
2530 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
2532 CAutoLibrary hShell
= LoadLibrary(_T("Shell32.dll"));
2534 if (hShell
.IsValid()) {
2535 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
2537 IPropertyStore
*pps
;
2538 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
2539 if (SUCCEEDED(hr
)) {
2542 var
.boolVal
= VARIANT_TRUE
;
2543 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
2550 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
2552 ASSERT(dialogname
.GetLength() < 70);
2553 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
2554 WCHAR pathbuf
[MAX_PATH
] = {0};
2556 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
2558 wcscat_s(pathbuf
, L
" - ");
2559 wcscat_s(pathbuf
, dialogname
);
2560 wcscat_s(pathbuf
, L
" - ");
2561 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2562 SetWindowText(hWnd
, pathbuf
);