1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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"
62 CAppUtils::CAppUtils(void)
66 CAppUtils::~CAppUtils(void)
70 bool CAppUtils::StashSave()
74 if (dlg
.DoModal() == IDOK
)
77 cmd
= _T("git.exe stash save");
79 if (dlg
.m_bIncludeUntracked
&& CAppUtils::GetMsysgitVersion() >= 0x01070700)
80 cmd
+= _T(" --include-untracked");
82 if (!dlg
.m_sMessage
.IsEmpty())
84 CString message
= dlg
.m_sMessage
;
85 message
.Replace(_T("\""), _T("\"\""));
86 cmd
+= _T(" \"") + message
+ _T("\"");
89 if (g_Git
.Run(cmd
, &out
, CP_ACP
))
91 CMessageBox::Show(NULL
, CString(_T("<ct=0x0000FF>Stash Fail!!!</ct>\n")) + out
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
95 CMessageBox::Show(NULL
, CString(_T("<ct=0xff0000>Stash Success</ct>\n")) + out
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
102 int CAppUtils::StashApply(CString ref
, bool showChanges
/* true */)
105 cmd
= _T("git.exe stash apply ");
106 if (ref
.Find(_T("refs/")) == 0)
108 if (ref
.Find(_T("stash{")) == 0)
109 ref
= _T("stash@") + ref
.Mid(5);
112 int ret
= g_Git
.Run(cmd
, &out
, CP_ACP
);
113 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
114 if (ret
&& !(ret
== 1 && hasConflicts
))
116 CMessageBox::Show(NULL
,CString(_T("<ct=0x0000FF>Stash Apply Fail!!!</ct>\n"))+out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
120 CString withConflicts
;
122 withConflicts
= _T(" with conflicts");
125 if(CMessageBox::Show(NULL
,CString(_T("<ct=0xff0000>Stash Apply Success") + withConflicts
+ _T("</ct>\nDo you want to show change?"))
126 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
129 dlg
.m_pathList
.AddPath(CTGitPath());
136 CMessageBox::Show(NULL
, _T("<ct=0xff0000>Stash Apply Success") + withConflicts
+ _T("</ct>") ,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
143 int CAppUtils::StashPop(bool showChanges
/* true */)
146 cmd
=_T("git.exe stash pop ");
148 int ret
= g_Git
.Run(cmd
, &out
, CP_ACP
);
149 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
150 if (ret
&& !(ret
== 1 && hasConflicts
))
152 CMessageBox::Show(NULL
,CString(_T("<ct=0x0000FF>Stash POP Fail!!!</ct>\n"))+out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
156 CString message
= _T("<ct=0xff0000>Stash POP Success</ct>");
158 message
= _T("<ct=0x000000ff>Stash POP Failed, there are conflicts</ct>");
161 if(CMessageBox::Show(NULL
,CString(message
+ _T("\nDo you want to show change?"))
162 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
165 dlg
.m_pathList
.AddPath(CTGitPath());
172 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
179 bool CAppUtils::GetMimeType(const CTGitPath
& /*file*/, CString
& /*mimetype*/)
182 GitProperties
props(file
, GitRev::REV_WC
, false);
183 for (int i
= 0; i
< props
.GetCount(); ++i
)
185 if (props
.GetItemName(i
).compare(_T("svn:mime-type"))==0)
187 mimetype
= props
.GetItemValue(i
).c_str();
195 BOOL
CAppUtils::StartExtMerge(
196 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
197 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
)
200 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
201 CString ext
= mergedfile
.GetFileExtension();
202 CString com
= regCom
;
203 bool bInternal
= false;
208 // is there an extension specific merge tool?
209 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
210 if (CString(mergetool
) != "")
215 if (GetMimeType(yourfile
, mimetype
) || GetMimeType(theirfile
, mimetype
) || GetMimeType(basefile
, mimetype
))
217 // is there a mime type specific merge tool?
218 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype
);
219 if (CString(mergetool
) != "")
225 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
229 CRegString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE
);
230 com
= tortoiseMergePath
;
233 com
= CPathUtils::GetAppDirectory();
234 com
+= _T("TortoiseMerge.exe");
236 com
= _T("\"") + com
+ _T("\"");
237 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
238 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
240 // check if the params are set. If not, just add the files to the command line
241 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
243 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
244 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
245 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
246 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
248 if (basefile
.IsEmpty())
250 com
.Replace(_T("/base:%base"), _T(""));
251 com
.Replace(_T("%base"), _T(""));
254 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
255 if (theirfile
.IsEmpty())
257 com
.Replace(_T("/theirs:%theirs"), _T(""));
258 com
.Replace(_T("%theirs"), _T(""));
261 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
262 if (yourfile
.IsEmpty())
264 com
.Replace(_T("/mine:%mine"), _T(""));
265 com
.Replace(_T("%mine"), _T(""));
268 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
269 if (mergedfile
.IsEmpty())
271 com
.Replace(_T("/merged:%merged"), _T(""));
272 com
.Replace(_T("%merged"), _T(""));
275 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
276 if (basename
.IsEmpty())
278 if (basefile
.IsEmpty())
280 com
.Replace(_T("/basename:%bname"), _T(""));
281 com
.Replace(_T("%bname"), _T(""));
285 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
289 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
290 if (theirname
.IsEmpty())
292 if (theirfile
.IsEmpty())
294 com
.Replace(_T("/theirsname:%tname"), _T(""));
295 com
.Replace(_T("%tname"), _T(""));
299 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
303 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
304 if (yourname
.IsEmpty())
306 if (yourfile
.IsEmpty())
308 com
.Replace(_T("/minename:%yname"), _T(""));
309 com
.Replace(_T("%yname"), _T(""));
313 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
317 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
318 if (mergedname
.IsEmpty())
320 if (mergedfile
.IsEmpty())
322 com
.Replace(_T("/mergedname:%mname"), _T(""));
323 com
.Replace(_T("%mname"), _T(""));
327 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
331 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
333 if ((bReadOnly
)&&(bInternal
))
334 com
+= _T(" /readonly");
336 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
344 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
348 viewer
= CPathUtils::GetAppDirectory();
349 viewer
+= _T("TortoiseMerge.exe");
351 viewer
= _T("\"") + viewer
+ _T("\"");
352 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
353 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
355 viewer
+= _T(" /reversedpatch");
356 if (!sOriginalDescription
.IsEmpty())
357 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
358 if (!sPatchedDescription
.IsEmpty())
359 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
360 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
367 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
369 // Is there a mime type specific diff tool?
371 if (GetMimeType(file1
, mimetype
) || GetMimeType(file2
, mimetype
))
373 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype
);
374 if (!difftool
.IsEmpty())
378 // Is there an extension specific diff tool?
379 CString ext
= file2
.GetFileExtension().MakeLower();
382 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
383 if (!difftool
.IsEmpty())
385 // Maybe we should use TortoiseIDiff?
386 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
387 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
388 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
389 (ext
== _T(".dib")) || (ext
== _T(".emf")))
392 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
393 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
397 // Finally, pick a generic external diff tool
398 CString difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
402 bool CAppUtils::StartExtDiff(
403 const CString
& file1
, const CString
& file2
,
404 const CString
& sName1
, const CString
& sName2
,
405 const DiffFlags
& flags
)
409 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
410 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
412 viewer
= PickDiffTool(file1
, file2
);
413 // If registry entry for a diff program is commented out, use TortoiseMerge.
414 bool bCommentedOut
= viewer
.Left(1) == _T("#");
415 if (flags
.bAlternativeTool
)
417 // Invert external vs. internal diff tool selection.
419 viewer
.Delete(0); // uncomment
423 else if (bCommentedOut
)
427 bool bInternal
= viewer
.IsEmpty();
431 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
432 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
434 viewer
+= _T(" /blame");
436 // check if the params are set. If not, just add the files to the command line
437 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
439 viewer
+= _T(" \"")+file1
+_T("\"");
440 viewer
+= _T(" \"")+file2
+_T("\"");
442 if (viewer
.Find(_T("%base")) >= 0)
444 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
446 if (viewer
.Find(_T("%mine")) >= 0)
448 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
451 if (sName1
.IsEmpty())
452 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
454 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
456 if (sName2
.IsEmpty())
457 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
459 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
461 if (flags
.bReadOnly
&& bInternal
)
462 viewer
+= _T(" /readonly");
464 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
467 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
470 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
472 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
475 viewer
= CPathUtils::GetAppDirectory();
476 viewer
+= _T("TortoiseUDiff.exe");
477 // enquote the path to TortoiseUDiff
478 viewer
= _T("\"") + viewer
+ _T("\"");
480 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
483 if (viewer
.Find(_T("%1"))>=0)
485 if (viewer
.Find(_T("\"%1\"")) >= 0)
486 viewer
.Replace(_T("%1"), patchfile
);
488 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
491 viewer
+= _T(" \"") + patchfile
+ _T("\"");
492 if (viewer
.Find(_T("%title")) >= 0)
494 viewer
.Replace(_T("%title"), title
);
497 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
504 BOOL
CAppUtils::StartTextViewer(CString file
)
507 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
509 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
510 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
513 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
514 TCHAR
* buf
= new TCHAR
[len
+1];
515 ExpandEnvironmentStrings(viewer
, buf
, len
);
518 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
519 buf
= new TCHAR
[len
+1];
520 ExpandEnvironmentStrings(file
, buf
, len
);
523 file
= _T("\"")+file
+_T("\"");
524 if (viewer
.IsEmpty())
526 viewer
= _T("RUNDLL32 Shell32,OpenAs_RunDLL");
528 if (viewer
.Find(_T("\"%1\"")) >= 0)
530 viewer
.Replace(_T("\"%1\""), file
);
532 else if (viewer
.Find(_T("%1")) >= 0)
534 viewer
.Replace(_T("%1"), file
);
542 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
549 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
552 HANDLE hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
553 if (hFile
== INVALID_HANDLE_VALUE
)
555 length
= ::GetFileSize(hFile
, NULL
);
556 ::CloseHandle(hFile
);
563 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
566 HDC hScreenDC
= ::GetDC(NULL
);
567 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
568 ::ReleaseDC(NULL
, hScreenDC
);
570 logFont
.lfEscapement
= 0;
571 logFont
.lfOrientation
= 0;
572 logFont
.lfWeight
= FW_NORMAL
;
573 logFont
.lfItalic
= 0;
574 logFont
.lfUnderline
= 0;
575 logFont
.lfStrikeOut
= 0;
576 logFont
.lfCharSet
= DEFAULT_CHARSET
;
577 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
578 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
579 logFont
.lfQuality
= DRAFT_QUALITY
;
580 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
581 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
582 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
585 bool CAppUtils::LaunchApplication(const CString
& sCommandLine
, UINT idErrMessageFormat
, bool bWaitForStartup
)
588 PROCESS_INFORMATION process
;
589 memset(&startup
, 0, sizeof(startup
));
590 startup
.cb
= sizeof(startup
);
591 memset(&process
, 0, sizeof(process
));
593 CString
cleanCommandLine(sCommandLine
);
595 if (CreateProcess(NULL
, const_cast<TCHAR
*>((LPCTSTR
)cleanCommandLine
), NULL
, NULL
, FALSE
, 0, 0, g_Git
.m_CurrentDir
, &startup
, &process
)==0)
597 if(idErrMessageFormat
!= 0)
600 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
601 FORMAT_MESSAGE_FROM_SYSTEM
|
602 FORMAT_MESSAGE_IGNORE_INSERTS
,
605 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
611 temp
.Format(idErrMessageFormat
, lpMsgBuf
);
612 CMessageBox::Show(NULL
, temp
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
613 LocalFree( lpMsgBuf
);
620 WaitForInputIdle(process
.hProcess
, 10000);
623 CloseHandle(process
.hThread
);
624 CloseHandle(process
.hProcess
);
627 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
641 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
642 key
= g_Git
.GetConfigValue(cmd
);
644 key
= key
.Tokenize(_T("\n"),start
);
652 CString proc
=CPathUtils::GetAppDirectory();
653 proc
+= _T("pageant.exe \"");
657 CString tempfile
= GetTempFile();
658 ::DeleteFile(tempfile
);
660 proc
+= _T(" -c \"");
661 proc
+= CPathUtils::GetAppDirectory();
662 proc
+= _T("touch.exe\"");
667 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true);
672 while(!::PathFileExists(tempfile
))
677 break; //timeout 5 minutes
682 CMessageBox::Show(NULL
, _T("Fail wait for pageant finish load key"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
684 ::DeleteFile(tempfile
);
687 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
)
689 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
690 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
691 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
695 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
697 LaunchApplication(sCmd
, NULL
, false);
700 bool CAppUtils::LaunchRemoteSetting()
702 CTGitPath
path(g_Git
.m_CurrentDir
);
703 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
704 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
705 //dlg.SetTreeWidth(220);
706 dlg
.m_DefaultPage
= _T("gitremote");
713 * Launch the external blame viewer
715 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
717 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
718 viewer
+= _T("TortoiseGitBlame.exe");
719 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
720 //viewer += _T(" \"") + sLogFile + _T("\"");
721 //viewer += _T(" \"") + sOriginalFile + _T("\"");
722 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
723 viewer
+= CString(_T(" /rev:"))+Rev
;
724 viewer
+= _T(" ")+sParams
;
726 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
729 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
734 bool bStyled
= false;
735 pWnd
->GetWindowText(sText
);
736 // the rich edit control doesn't count the CR char!
737 // to be exact: CRLF is treated as one char.
740 // style each line separately
745 nNewlinePos
= sText
.Find('\n', offset
);
746 CString sLine
= sText
.Mid(offset
);
748 sLine
= sLine
.Left(nNewlinePos
-offset
);
751 while (FindStyleChars(sLine
, '*', start
, end
))
753 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
754 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
756 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
757 format
.cbSize
= sizeof(CHARFORMAT2
);
758 format
.dwMask
= CFM_BOLD
;
759 format
.dwEffects
= CFE_BOLD
;
760 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
766 while (FindStyleChars(sLine
, '^', start
, end
))
768 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
769 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
771 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
772 format
.cbSize
= sizeof(CHARFORMAT2
);
773 format
.dwMask
= CFM_ITALIC
;
774 format
.dwEffects
= CFE_ITALIC
;
775 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
781 while (FindStyleChars(sLine
, '_', start
, end
))
783 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
784 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
786 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
787 format
.cbSize
= sizeof(CHARFORMAT2
);
788 format
.dwMask
= CFM_UNDERLINE
;
789 format
.dwEffects
= CFE_UNDERLINE
;
790 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
794 offset
= nNewlinePos
+1;
795 } while(nNewlinePos
>=0);
799 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
802 bool bFoundMarker
= false;
803 // find a starting marker
804 while (sText
[i
] != 0)
806 if (sText
[i
] == stylechar
)
808 if (((i
+1)<sText
.GetLength())&&(IsCharAlphaNumeric(sText
[i
+1])) &&
809 (((i
>0)&&(!IsCharAlphaNumeric(sText
[i
-1])))||(i
==0)))
821 // find ending marker
822 bFoundMarker
= false;
823 while (sText
[i
] != 0)
825 if (sText
[i
] == stylechar
)
827 if ((IsCharAlphaNumeric(sText
[i
-1])) &&
828 ((((i
+1)<sText
.GetLength())&&(!IsCharAlphaNumeric(sText
[i
+1])))||(i
+1)==sText
.GetLength()))
841 bool CAppUtils::FileOpenSave(CString
& path
, int * filterindex
, UINT title
, UINT filter
, bool bOpen
, HWND hwndOwner
)
843 OPENFILENAME ofn
= {0}; // common dialog box structure
844 TCHAR szFile
[MAX_PATH
] = {0}; // buffer for file name. Explorer can't handle paths longer than MAX_PATH.
845 ofn
.lStructSize
= sizeof(OPENFILENAME
);
846 ofn
.hwndOwner
= hwndOwner
;
847 _tcscpy_s(szFile
, MAX_PATH
, (LPCTSTR
)path
);
848 ofn
.lpstrFile
= szFile
;
849 ofn
.nMaxFile
= _countof(szFile
);
851 TCHAR
* pszFilters
= NULL
;
854 sFilter
.LoadString(filter
);
855 pszFilters
= new TCHAR
[sFilter
.GetLength()+4];
856 _tcscpy_s (pszFilters
, sFilter
.GetLength()+4, sFilter
);
857 // Replace '|' delimiters with '\0's
858 TCHAR
*ptr
= pszFilters
+ _tcslen(pszFilters
); //set ptr at the NULL
859 while (ptr
!= pszFilters
)
865 ofn
.lpstrFilter
= pszFilters
;
867 ofn
.nFilterIndex
= 1;
868 ofn
.lpstrFileTitle
= NULL
;
869 ofn
.nMaxFileTitle
= 0;
870 ofn
.lpstrInitialDir
= NULL
;
874 temp
.LoadString(title
);
875 CStringUtils::RemoveAccelerators(temp
);
877 ofn
.lpstrTitle
= temp
;
879 ofn
.Flags
= OFN_PATHMUSTEXIST
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_EXPLORER
;
881 ofn
.Flags
= OFN_OVERWRITEPROMPT
| OFN_EXPLORER
;
884 // Display the Open dialog box.
888 bRet
= !!GetOpenFileName(&ofn
);
892 bRet
= !!GetSaveFileName(&ofn
);
897 delete [] pszFilters
;
898 path
= CString(ofn
.lpstrFile
);
900 *filterindex
= ofn
.nFilterIndex
;
904 delete [] pszFilters
;
908 bool CAppUtils::SetListCtrlBackgroundImage(HWND hListCtrl
, UINT nID
, int width
/* = 128 */, int height
/* = 128 */)
910 ListView_SetTextBkColor(hListCtrl
, CLR_NONE
);
911 COLORREF bkColor
= ListView_GetBkColor(hListCtrl
);
912 // create a bitmap from the icon
913 HICON hIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(nID
), IMAGE_ICON
, width
, height
, LR_DEFAULTCOLOR
);
919 rect
.bottom
= height
;
922 HWND desktop
= ::GetDesktopWindow();
925 HDC screen_dev
= ::GetDC(desktop
);
928 // Create a compatible DC
929 HDC dst_hdc
= ::CreateCompatibleDC(screen_dev
);
932 // Create a new bitmap of icon size
933 bmp
= ::CreateCompatibleBitmap(screen_dev
, rect
.right
, rect
.bottom
);
936 // Select it into the compatible DC
937 HBITMAP old_dst_bmp
= (HBITMAP
)::SelectObject(dst_hdc
, bmp
);
938 // Fill the background of the compatible DC with the given color
939 ::SetBkColor(dst_hdc
, bkColor
);
940 ::ExtTextOut(dst_hdc
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
942 // Draw the icon into the compatible DC
943 ::DrawIconEx(dst_hdc
, 0, 0, hIcon
, rect
.right
, rect
.bottom
, 0, NULL
, DI_NORMAL
);
944 ::SelectObject(dst_hdc
, old_dst_bmp
);
949 ::ReleaseDC(desktop
, screen_dev
);
959 lv
.ulFlags
= LVBKIF_TYPE_WATERMARK
;
961 lv
.xOffsetPercent
= 100;
962 lv
.yOffsetPercent
= 100;
963 ListView_SetBkImage(hListCtrl
, &lv
);
967 CString
CAppUtils::GetProjectNameFromURL(CString url
)
970 while (name
.IsEmpty() || (name
.CompareNoCase(_T("branches"))==0) ||
971 (name
.CompareNoCase(_T("tags"))==0) ||
972 (name
.CompareNoCase(_T("trunk"))==0))
974 name
= url
.Mid(url
.ReverseFind('/')+1);
975 url
= url
.Left(url
.ReverseFind('/'));
977 if ((name
.Compare(_T("svn")) == 0)||(name
.Compare(_T("svnroot")) == 0))
979 // a name of svn or svnroot indicates that it's not really the project name. In that
980 // case, we try the first part of the URL
981 // of course, this won't work in all cases (but it works for Google project hosting)
982 url
.Replace(_T("http://"), _T(""));
983 url
.Replace(_T("https://"), _T(""));
984 url
.Replace(_T("svn://"), _T(""));
985 url
.Replace(_T("svn+ssh://"), _T(""));
986 url
.TrimLeft(_T("/"));
987 name
= url
.Left(url
.Find('.'));
992 bool CAppUtils::StartShowUnifiedDiff(HWND
/*hWnd*/, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
993 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
994 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
995 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */, bool /* blame = false */, bool bMerge
)
998 CString tempfile
=GetTempFile();
1000 if(rev1
== GitRev::GetWorkingCopy())
1002 cmd
.Format(_T("git.exe diff --stat -p %s "),rev2
);
1010 cmd
.Format(_T("git.exe diff-tree -r -p %s --stat %s %s"),merge
, rev1
,rev2
);
1013 if( !url1
.IsEmpty() )
1015 cmd
+= _T(" -- \"");
1016 cmd
+= url1
.GetGitPathString();
1019 g_Git
.RunLogFile(cmd
,tempfile
);
1020 CAppUtils::StartUnifiedDiffViewer(tempfile
,rev1
.Left(6)+_T(":")+rev2
.Left(6));
1025 sCmd
.Format(_T("%s /command:showcompare /unified"),
1026 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
1027 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
1029 sCmd
+= _T(" /revision1:") + rev1
.ToString();
1030 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
1032 sCmd
+= _T(" /revision2:") + rev2
.ToString();
1034 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
1035 if (headpeg
.IsValid())
1036 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
1039 sCmd
+= _T(" /alternatediff");
1041 if (bIgnoreAncestry
)
1042 sCmd
+= _T(" /ignoreancestry");
1046 sCmd
+= _T(" /hwnd:");
1048 _stprintf_s(buf
, 30, _T("%d"), hWnd
);
1052 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
1058 bool CAppUtils::Export(CString
*BashHash
)
1062 // ask from where the export has to be done
1065 dlg
.m_Revision
=*BashHash
;
1067 if (dlg
.DoModal() == IDOK
)
1070 cmd
.Format(_T("git.exe archive --format=zip --verbose %s"),
1071 g_Git
.FixBranchName(dlg
.m_VersionName
));
1073 //g_Git.RunLogFile(cmd,dlg.m_strExportDirectory);
1076 pro
.m_LogFile
=dlg
.m_strExportDirectory
;
1083 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
, bool switch_new_brach
)
1085 CCreateBranchTagDlg dlg
;
1087 dlg
.m_bSwitch
=switch_new_brach
;
1090 dlg
.m_Base
= *CommitHash
;
1092 if(dlg
.DoModal()==IDOK
)
1098 track
=_T(" --track ");
1109 cmd
.Format(_T("git.exe tag %s %s %s %s %s"),
1113 dlg
.m_BranchTagName
,
1114 g_Git
.FixBranchName(dlg
.m_VersionName
)
1117 CString tempfile
=::GetTempFile();
1118 if(!dlg
.m_Message
.Trim().IsEmpty())
1120 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_Message
);
1121 cmd
+= _T(" -F ")+tempfile
;
1126 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1129 dlg
.m_BranchTagName
,
1130 g_Git
.FixBranchName(dlg
.m_VersionName
)
1134 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1136 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1138 if( !IsTag
&& dlg
.m_bSwitch
)
1140 // it is a new branch and the user has requested to switch to it
1141 cmd
.Format(_T("git.exe checkout %s"), dlg
.m_BranchTagName
);
1142 g_Git
.Run(cmd
,&out
,CP_UTF8
);
1143 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1151 bool CAppUtils::Switch(CString
*CommitHash
, CString initialRefName
, bool autoclose
)
1155 dlg
.m_Base
=*CommitHash
;
1156 if(!initialRefName
.IsEmpty())
1157 dlg
.m_initialRefName
= initialRefName
;
1159 if (dlg
.DoModal() == IDOK
)
1163 branch
= dlg
.m_NewBranch
;
1165 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
== TRUE
, autoclose
);
1170 bool CAppUtils::PerformSwitch(CString ref
, bool bForce
/* false */, CString sNewBranch
/* CString() */, bool bBranchOverride
/* false */, bool bTrack
/* false */, bool autoClose
/* false */)
1177 if(!sNewBranch
.IsEmpty()){
1178 if (bBranchOverride
)
1180 branch
.Format(_T("-B %s"), sNewBranch
);
1184 branch
.Format(_T("-b %s"), sNewBranch
);
1187 track
= _T("--track");
1192 cmd
.Format(_T("git.exe checkout %s %s %s %s"),
1196 g_Git
.FixBranchName(ref
));
1198 CProgressDlg progress
;
1199 progress
.m_bAutoCloseOnSuccess
= autoClose
;
1200 progress
.m_GitCmd
= cmd
;
1202 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1203 if (gitPath
.HasSubmodules())
1204 progress
.m_PostCmdList
.Add(_T("Update Submodules"));
1206 int ret
= progress
.DoModal();
1207 if (gitPath
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
1210 sCmd
.Format(_T("\"%s\" /command:subupdate /bkpath:\"%s\""), (LPCTSTR
)(CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe")), (LPCTSTR
)g_Git
.m_CurrentDir
);
1212 LaunchApplication(sCmd
, NULL
, false);
1215 else if (ret
== IDOK
)
1221 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1224 ignorefile
=g_Git
.m_CurrentDir
+_T("\\");
1228 ignorefile
+=path
.GetCommonRoot().GetDirectory().GetWinPathString()+_T("\\.gitignore");
1233 ignorefile
+= _T("\\.gitignore");
1237 if(!file
.Open(ignorefile
,CFile::modeCreate
|CFile::modeReadWrite
|CFile::modeNoTruncate
))
1239 CMessageBox::Show(NULL
,ignorefile
+_T(" Open Failure"),_T("TortoiseGit"),MB_OK
);
1247 //file.ReadString(ignorelist);
1249 for(int i
=0;i
<path
.GetCount();i
++)
1253 mask
=_T("*")+path
[i
].GetFileExtension();
1254 if(ignorelist
.Find(mask
)<0)
1255 ignorelist
+= _T("\n")+mask
;
1259 ignorelist
+= _T("\n/")+path
[i
].GetGitPathString();
1262 file
.WriteString(ignorelist
);
1276 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1279 dlg
.m_ResetType
=type
;
1280 dlg
.m_ResetToVersion
=*CommitHash
;
1281 if (dlg
.DoModal() == IDOK
)
1285 switch(dlg
.m_ResetType
)
1300 cmd
.Format(_T("git.exe reset %s %s"),type
, *CommitHash
);
1302 CProgressDlg progress
;
1303 progress
.m_GitCmd
=cmd
;
1305 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1306 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2)
1307 progress
.m_PostCmdList
.Add(_T("Update Submodules"));
1309 int ret
= progress
.DoModal();
1310 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2 && ret
== IDC_PROGRESS_BUTTON1
)
1313 sCmd
.Format(_T("\"%s\" /command:subupdate /bkpath:\"%s\""), (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR
)g_Git
.m_CurrentDir
);
1315 LaunchApplication(sCmd
, NULL
, false);
1318 else if (ret
== IDOK
)
1325 void CAppUtils::DescribeFile(bool mode
, bool base
,CString
&descript
)
1329 descript
=_T("Deleted");
1334 descript
=_T("Modified");
1337 descript
=_T("Created");
1341 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1343 CString tempmergefile
;
1346 tempmergefile
= CAppUtils::GetMergeTempFile(_T("LOCAL"),path
);
1347 CFile::Remove(tempmergefile
);
1354 tempmergefile
= CAppUtils::GetMergeTempFile(_T("REMOTE"),path
);
1355 CFile::Remove(tempmergefile
);
1362 tempmergefile
= CAppUtils::GetMergeTempFile(_T("BASE"),path
);
1363 CFile::Remove(tempmergefile
);
1368 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1371 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1376 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool /*bAlternativeTool*/,bool revertTheirMy
)
1380 CTGitPath merge
=path
;
1381 CTGitPath directory
= merge
.GetDirectory();
1383 // we have the conflicted file (%merged)
1384 // now look for the other required files
1386 //stat.GetStatus(merge);
1387 //if (stat.status == NULL)
1393 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1395 if (g_Git
.Run(cmd
, &vector
))
1401 list
.ParserFromLsFile(vector
);
1403 if(list
.GetCount() == 0)
1410 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge
));
1411 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge
));
1412 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1416 //format=_T("git.exe cat-file blob \":%d:%s\"");
1417 format
= _T("git checkout-index --temp --stage=%d -- \"%s\"");
1419 //create a empty file, incase stage is not three
1420 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1422 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1424 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1427 bool b_base
=false, b_local
=false, b_remote
=false;
1429 for(int i
=0;i
<list
.GetCount();i
++)
1436 if( list
[i
].m_Stage
== 1)
1438 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1440 outfile
= base
.GetWinPathString();
1443 if( list
[i
].m_Stage
== 2 )
1445 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1447 outfile
= mine
.GetWinPathString();
1450 if( list
[i
].m_Stage
== 3 )
1452 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1454 outfile
= theirs
.GetWinPathString();
1456 CString output
, err
;
1457 if(!outfile
.IsEmpty())
1458 if (!g_Git
.Run(cmd
, &output
, &err
, CP_ACP
))
1462 file
= output
.Tokenize(_T("\t"), start
);
1463 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1467 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1471 if(b_local
&& b_remote
)
1473 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1475 bRet
= !!CAppUtils::StartExtMerge(base
,mine
, theirs
, merge
,_T("BASE"),_T("LOCAL"),_T("REMOTE"));
1477 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1482 CFile::Remove(mine
.GetWinPathString());
1483 CFile::Remove(theirs
.GetWinPathString());
1484 CFile::Remove(base
.GetWinPathString());
1486 CDeleteConflictDlg dlg
;
1487 DescribeFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1488 DescribeFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1489 dlg
.m_bShowModifiedButton
=b_base
;
1490 dlg
.m_File
=merge
.GetGitPathString();
1491 if(dlg
.DoModal() == IDOK
)
1496 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1499 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1501 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
1503 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1513 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1514 base
, theirs
, mine
, merge
);
1517 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1519 // we have a text conflict, use our merge tool to resolve the conflict
1521 CTSVNPath
theirs(directory
);
1522 CTSVNPath
mine(directory
);
1523 CTSVNPath
base(directory
);
1524 bool bConflictData
= false;
1526 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1528 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1529 bConflictData
= true;
1531 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1533 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1534 bConflictData
= true;
1536 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1538 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1539 bConflictData
= true;
1546 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1547 base
, theirs
, mine
, merge
);
1550 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1552 // we have a property conflict
1553 CTSVNPath
prej(directory
);
1554 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1556 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1557 // there's a problem: the prej file contains a _description_ of the conflict, and
1558 // that description string might be translated. That means we have no way of parsing
1559 // the file to find out the conflicting values.
1560 // The only thing we can do: show a dialog with the conflict description, then
1561 // let the user either accept the existing property or open the property edit dialog
1562 // to manually change the properties and values. And a button to mark the conflict as
1564 CEditPropConflictDlg dlg
;
1565 dlg
.SetPrejFile(prej
);
1566 dlg
.SetConflictedItem(merge
);
1567 bRet
= (dlg
.DoModal() != IDCANCEL
);
1571 if (stat
.status
->tree_conflict
)
1573 // we have a tree conflict
1575 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1578 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1580 CTSVNPath
theirs(directory
);
1581 CTSVNPath
mine(directory
);
1582 CTSVNPath
base(directory
);
1583 bool bConflictData
= false;
1585 if (pInfoData
->treeconflict_theirfile
)
1587 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1588 bConflictData
= true;
1590 if (pInfoData
->treeconflict_basefile
)
1592 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1593 bConflictData
= true;
1595 if (pInfoData
->treeconflict_myfile
)
1597 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1598 bConflictData
= true;
1605 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1606 base
, theirs
, mine
, merge
);
1608 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1610 CString sConflictAction
;
1611 CString sConflictReason
;
1612 CString sResolveTheirs
;
1613 CString sResolveMine
;
1614 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1615 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1617 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1619 switch (pInfoData
->treeconflict_operation
)
1621 case svn_wc_operation_update
:
1622 switch (pInfoData
->treeconflict_action
)
1624 case svn_wc_conflict_action_edit
:
1625 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1626 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1628 case svn_wc_conflict_action_add
:
1629 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1630 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1632 case svn_wc_conflict_action_delete
:
1633 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1634 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1638 case svn_wc_operation_switch
:
1639 switch (pInfoData
->treeconflict_action
)
1641 case svn_wc_conflict_action_edit
:
1642 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1643 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1645 case svn_wc_conflict_action_add
:
1646 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1647 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1649 case svn_wc_conflict_action_delete
:
1650 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1651 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1655 case svn_wc_operation_merge
:
1656 switch (pInfoData
->treeconflict_action
)
1658 case svn_wc_conflict_action_edit
:
1659 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1660 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1662 case svn_wc_conflict_action_add
:
1663 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1664 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1666 case svn_wc_conflict_action_delete
:
1667 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1668 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1674 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1676 switch (pInfoData
->treeconflict_operation
)
1678 case svn_wc_operation_update
:
1679 switch (pInfoData
->treeconflict_action
)
1681 case svn_wc_conflict_action_edit
:
1682 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1683 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1685 case svn_wc_conflict_action_add
:
1686 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1687 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1689 case svn_wc_conflict_action_delete
:
1690 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1691 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1695 case svn_wc_operation_switch
:
1696 switch (pInfoData
->treeconflict_action
)
1698 case svn_wc_conflict_action_edit
:
1699 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1700 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1702 case svn_wc_conflict_action_add
:
1703 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1704 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1706 case svn_wc_conflict_action_delete
:
1707 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1708 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1712 case svn_wc_operation_merge
:
1713 switch (pInfoData
->treeconflict_action
)
1715 case svn_wc_conflict_action_edit
:
1716 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1717 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1719 case svn_wc_conflict_action_add
:
1720 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1721 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1723 case svn_wc_conflict_action_delete
:
1724 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1725 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1733 switch (pInfoData
->treeconflict_reason
)
1735 case svn_wc_conflict_reason_edited
:
1736 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1737 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1739 case svn_wc_conflict_reason_obstructed
:
1740 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1741 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1743 case svn_wc_conflict_reason_deleted
:
1744 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1745 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1747 case svn_wc_conflict_reason_added
:
1748 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1749 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1751 case svn_wc_conflict_reason_missing
:
1752 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1753 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1755 case svn_wc_conflict_reason_unversioned
:
1756 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1757 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1760 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1762 CTreeConflictEditorDlg dlg
;
1763 dlg
.SetConflictInfoText(sConflictReason
);
1764 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1765 dlg
.SetPath(treeConflictPath
);
1766 INT_PTR dlgRet
= dlg
.DoModal();
1767 bRet
= (dlgRet
!= IDCANCEL
);
1776 * FUNCTION : FormatDateAndTime
1777 * DESCRIPTION : Generates a displayable string from a CTime object in
1778 * system short or long format or as a relative value
1780 * option - DATE_SHORTDATE or DATE_LONGDATE
1781 * bIncluedeTime - whether to show time as well as date
1782 * bRelative - if true then relative time is shown if reasonable
1783 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
1784 * rather than locale
1785 * RETURN : CString containing date/time
1787 CString
CAppUtils::FormatDateAndTime( const CTime
& cTime
, DWORD option
, bool bIncludeTime
/*=true*/,
1788 bool bRelative
/*=false*/)
1793 datetime
= ToRelativeTimeString( cTime
);
1797 // should we use the locale settings for formatting the date/time?
1798 if (CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE
))
1802 cTime
.GetAsSystemTime( sysTime
);
1806 GetDateFormat(LOCALE_USER_DEFAULT
, option
, &sysTime
, NULL
, buf
,
1811 datetime
+= _T(" ");
1812 GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &sysTime
, NULL
, buf
, _countof(buf
) - 1);
1818 // no, so fixed format
1821 datetime
= cTime
.Format(_T("%Y-%m-%d %H:%M:%S"));
1825 datetime
= cTime
.Format(_T("%Y-%m-%d"));
1833 * Converts a given time to a relative display string (relative to current time)
1834 * Given time must be in local timezone
1836 CString
CAppUtils::ToRelativeTimeString(CTime time
)
1839 // convert to COleDateTime
1841 time
.GetAsSystemTime( sysTime
);
1842 COleDateTime
oleTime( sysTime
);
1843 answer
= ToRelativeTimeString(oleTime
, COleDateTime::GetCurrentTime());
1848 * Generates a display string showing the relative time between the two given times as COleDateTimes
1850 CString
CAppUtils::ToRelativeTimeString(COleDateTime time
,COleDateTime RelativeTo
)
1853 COleDateTimeSpan ts
= RelativeTo
- time
;
1855 if(fabs(ts
.GetTotalDays()) >= 3*365)
1857 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/365, IDS_YEAR_AGO
, IDS_YEARS_AGO
);
1860 if(fabs(ts
.GetTotalDays()) >= 60)
1862 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/30, IDS_MONTH_AGO
, IDS_MONTHS_AGO
);
1866 if(fabs(ts
.GetTotalDays()) >= 14)
1868 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/7, IDS_WEEK_AGO
, IDS_WEEKS_AGO
);
1872 if(fabs(ts
.GetTotalDays()) >= 2)
1874 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays(), IDS_DAY_AGO
, IDS_DAYS_AGO
);
1878 if(fabs(ts
.GetTotalHours()) >= 2)
1880 answer
= ExpandRelativeTime( (int)ts
.GetTotalHours(), IDS_HOUR_AGO
, IDS_HOURS_AGO
);
1884 if(fabs(ts
.GetTotalMinutes()) >= 2)
1886 answer
= ExpandRelativeTime( (int)ts
.GetTotalMinutes(), IDS_MINUTE_AGO
, IDS_MINUTES_AGO
);
1890 answer
= ExpandRelativeTime( (int)ts
.GetTotalSeconds(), IDS_SECOND_AGO
, IDS_SECONDS_AGO
);
1895 * Passed a value and two resource string ids
1896 * if count is 1 then FormatString is called with format_1 and the value
1897 * otherwise format_2 is used
1898 * the formatted string is returned
1900 CString
CAppUtils::ExpandRelativeTime( int count
, UINT format_1
, UINT format_n
)
1905 answer
.FormatMessage( format_1
, count
);
1909 answer
.FormatMessage( format_n
, count
);
1914 bool CAppUtils::IsSSHPutty()
1916 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1917 sshclient
=sshclient
.MakeLower();
1918 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1925 CString
CAppUtils::GetClipboardLink()
1927 if (!OpenClipboard(NULL
))
1930 CString sClipboardText
;
1931 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1934 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1935 sClipboardText
= CString(lpstr
);
1938 hglb
= GetClipboardData(CF_UNICODETEXT
);
1941 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1942 sClipboardText
= lpstr
;
1947 if(!sClipboardText
.IsEmpty())
1949 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1950 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1952 if(sClipboardText
.Find( _T("http://")) == 0)
1953 return sClipboardText
;
1955 if(sClipboardText
.Find( _T("https://")) == 0)
1956 return sClipboardText
;
1958 if(sClipboardText
.Find( _T("git://")) == 0)
1959 return sClipboardText
;
1961 if(sClipboardText
.Find( _T("ssh://")) == 0)
1962 return sClipboardText
;
1964 if(sClipboardText
.GetLength()>=2)
1965 if( sClipboardText
[1] == _T(':') )
1966 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1967 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1968 return sClipboardText
;
1971 return CString(_T(""));
1974 CString
CAppUtils::ChooseRepository(CString
*path
)
1976 CBrowseFolder browseFolder
;
1977 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
1979 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
1980 CString strCloneDirectory
;
1982 strCloneDirectory
=*path
;
1985 strCloneDirectory
= regLastResopitory
;
1989 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
1991 browseFolder
.SetInfo(title
);
1993 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
1995 regLastResopitory
= strCloneDirectory
;
1996 return strCloneDirectory
;
2004 bool CAppUtils::SendPatchMail(CTGitPathList
&list
,bool autoclose
)
2008 dlg
.m_PathList
= list
;
2010 if(dlg
.DoModal()==IDOK
)
2012 if(dlg
.m_PathList
.GetCount() == 0)
2015 CGitProgressDlg progDlg
;
2017 theApp
.m_pMainWnd
= &progDlg
;
2018 progDlg
.SetCommand(CGitProgressDlg::GitProgress_SendMail
);
2020 progDlg
.SetAutoClose(autoclose
);
2022 progDlg
.SetPathList(dlg
.m_PathList
);
2023 //ProjectProperties props;
2024 //props.ReadPropsPathList(dlg.m_pathList);
2025 //progDlg.SetProjectProperties(props);
2026 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2029 if(dlg
.m_bAttachment
)
2030 flags
|= SENDMAIL_ATTACHMENT
;
2032 flags
|= SENDMAIL_COMBINED
;
2034 flags
|= SENDMAIL_MAPI
;
2036 progDlg
.SetSendMailOption(dlg
.m_To
,dlg
.m_CC
,dlg
.m_Subject
,flags
);
2045 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
)
2048 CString log
=formatpatchoutput
;
2049 int start
=log
.Find(cmd
);
2051 CString one
=log
.Tokenize(_T("\n"),start
);
2057 CString one
=log
.Tokenize(_T("\n"),start
);
2059 if(one
.IsEmpty() || one
== _T("Success"))
2061 one
.Replace(_T('/'),_T('\\'));
2063 path
.SetFromWin(one
);
2066 if (list
.GetCount() > 0)
2068 return SendPatchMail(list
, autoclose
);
2072 CMessageBox::Show(NULL
, _T("Not patches generated."), _T("TortoiseGit"), MB_ICONINFORMATION
);
2078 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
2083 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
2084 if(output
.IsEmpty())
2086 output
= pGit
->GetConfigValue(_T("i18n.commitencoding"));
2087 if(output
.IsEmpty())
2091 output
=output
.Tokenize(_T("\n"),start
);
2092 return CUnicodeUtils::GetCPCode(output
);
2097 output
=output
.Tokenize(_T("\n"),start
);
2098 return CUnicodeUtils::GetCPCode(output
);
2101 int CAppUtils::GetCommitTemplate(CString
&temp
)
2105 output
= g_Git
.GetConfigValue(_T("commit.template"),CP_ACP
);
2106 if( output
.IsEmpty() )
2109 if( output
.GetLength()<1)
2112 if( output
[0] == _T('/'))
2114 if(output
.GetLength()>=3)
2115 if(output
[2] == _T('/'))
2117 output
.GetBuffer()[0] = output
[1];
2118 output
.GetBuffer()[1] = _T(':');
2123 output
=output
.Tokenize(_T("\n"),start
);
2125 output
.Replace(_T('/'),_T('\\'));
2129 CStdioFile
file(output
,CFile::modeRead
|CFile::typeText
);
2131 while(file
.ReadString(str
))
2142 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
2144 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
2148 output
= g_Git
.GetConfigValue(_T("i18n.commitencoding"));
2149 if(output
.IsEmpty())
2153 output
=output
.Tokenize(_T("\n"),start
);
2154 cp
=CUnicodeUtils::GetCPCode(output
);
2156 int len
=message
.GetLength();
2159 buf
= new char[len
*4 + 4];
2160 SecureZeroMemory(buf
, (len
*4 + 4));
2162 int lengthIncTerminator
= WideCharToMultiByte(cp
, 0, message
, -1, buf
, len
*4, NULL
, NULL
);
2164 file
.Write(buf
,lengthIncTerminator
-1);
2170 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
, bool autoClose
)
2173 dlg
.m_PreSelectRemote
= remoteName
;
2174 dlg
.m_bAllowRebase
= allowRebase
;
2177 if(dlg
.DoModal()==IDOK
)
2181 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_RemoteURL
);
2185 url
=dlg
.m_RemoteURL
;
2189 int ver
= CAppUtils::GetMsysgitVersion();
2191 if(ver
>= 0x01070203) //above 1.7.0.2
2192 arg
= _T("--progress ");
2195 arg
+= _T("--prune ");
2198 if (dlg
.m_bFetchTags
) {
2199 arg
+= _T("--tags ");
2202 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"),arg
, url
,dlg
.m_RemoteBranchName
);
2203 CProgressDlg progress
;
2205 progress
.m_bAutoCloseOnSuccess
= autoClose
;
2207 progress
.m_PostCmdList
.Add(_T("Show Log"));
2209 if(!dlg
.m_bRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
2211 progress
.m_PostCmdList
.Add(_T("&Rebase"));
2214 progress
.m_GitCmd
=cmd
;
2215 int userResponse
=progress
.DoModal();
2217 if (userResponse
== IDC_PROGRESS_BUTTON1
)
2220 cmd
= CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe");
2221 cmd
+= _T(" /command:log");
2222 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
2223 CAppUtils::LaunchApplication(cmd
, IDS_ERR_PROC
, false);
2226 else if ((userResponse
== IDC_PROGRESS_BUTTON1
+ 1) || (progress
.m_GitStatus
== 0 && dlg
.m_bRebase
))
2231 dlg
.m_PostButtonTexts
.Add(_T("Email &Patch..."));
2232 dlg
.m_PostButtonTexts
.Add(_T("Restart Rebase"));
2233 int response
= dlg
.DoModal();
2234 if(response
== IDOK
)
2238 if(response
== IDC_REBASE_POST_BUTTON
)
2240 CString cmd
, out
, err
;
2241 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2243 g_Git
.FixBranchName(dlg
.m_Upstream
),
2244 g_Git
.FixBranchName(dlg
.m_Branch
));
2245 if (g_Git
.Run(cmd
, &out
, &err
, CP_ACP
))
2247 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2251 CAppUtils::SendPatchMail(cmd
,out
);
2255 if(response
== IDC_REBASE_POST_BUTTON
+1 )
2258 if(response
== IDCANCEL
)
2267 bool CAppUtils::Push(CString selectLocalBranch
, bool autoClose
)
2270 dlg
.m_BranchSourceName
= selectLocalBranch
;
2272 DWORD exitcode
= 0xFFFFFFFF;
2274 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
2275 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
2280 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2281 //ReportError(temp);
2282 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2287 if(dlg
.DoModal()==IDOK
)
2294 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_URL
);
2298 arg
+= _T("--thin ");
2299 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2300 arg
+= _T("--tags ");
2302 arg
+= _T("--force ");
2304 int ver
= CAppUtils::GetMsysgitVersion();
2306 if(ver
>= 0x01070203) //above 1.7.0.2
2307 arg
+= _T("--progress ");
2309 if (dlg
.m_bPushAllBranches
)
2311 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2317 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2320 dlg
.m_BranchSourceName
);
2321 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2323 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2327 CProgressDlg progress
;
2328 progress
.m_bAutoCloseOnSuccess
=autoClose
;
2329 progress
.m_GitCmd
=cmd
;
2330 progress
.m_PostCmdList
.Add(_T("&Request pull"));
2331 progress
.m_PostCmdList
.Add(_T("Re&Push"));
2332 int ret
= progress
.DoModal();
2334 if(!progress
.m_GitStatus
)
2336 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2341 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2342 //ReportError(temp);
2343 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2347 if(ret
== IDC_PROGRESS_BUTTON1
)
2349 RequestPull(dlg
.m_BranchRemoteName
);
2351 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2362 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2364 CRequestPullDlg dlg
;
2365 dlg
.m_RepositoryURL
= repositoryUrl
;
2366 dlg
.m_EndRevision
= endrevision
;
2367 if (dlg
.DoModal()==IDOK
)
2370 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2372 CProgressDlg progress
;
2373 progress
.m_GitCmd
=cmd
;
2379 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2381 CString
strDir(szPath
);
2382 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2384 strDir
.AppendChar(_T('\\'));
2386 std::vector
<CString
> vPath
;
2388 bool bSuccess
= false;
2390 for (int i
=0;i
<strDir
.GetLength();++i
)
2392 if (strDir
.GetAt(i
) != _T('\\'))
2394 strTemp
.AppendChar(strDir
.GetAt(i
));
2398 vPath
.push_back(strTemp
);
2399 strTemp
.AppendChar(_T('\\'));
2403 std::vector
<CString
>::const_iterator vIter
;
2404 for (vIter
= vPath
.begin(); vIter
!= vPath
.end(); vIter
++)
2406 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2412 void CAppUtils::RemoveTrailSlash(CString
&path
)
2417 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2419 path
=path
.Left(path
.GetLength()-1);
2425 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2426 CTGitPathList
&pathList
,
2427 CTGitPathList
&selectedList
,
2428 bool bSelectFilesForCommit
,
2431 bool bFailed
= true;
2433 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetConfigValue(_T("user.email")).IsEmpty())
2435 if(CMessageBox::Show(NULL
,_T("User name and email must be set before commit.\r\n Do you want to set these now?\r\n"),
2436 _T("TortoiseGit"),MB_YESNO
| MB_ICONERROR
) == IDYES
)
2438 CTGitPath
path(g_Git
.m_CurrentDir
);
2439 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2440 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2441 dlg
.SetTreeWidth(220);
2442 dlg
.m_DefaultPage
= _T("gitconfig");
2445 dlg
.HandleRestart();
2456 dlg
.m_sBugID
= bugid
;
2458 dlg
.m_bWholeProject
= bWholeProject
;
2460 dlg
.m_sLogMessage
= sLogMsg
;
2461 dlg
.m_pathList
= pathList
;
2462 dlg
.m_checkedPathList
= selectedList
;
2463 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2464 dlg
.m_bAutoClose
= autoClose
;
2465 if (dlg
.DoModal() == IDOK
)
2467 if (dlg
.m_pathList
.GetCount()==0)
2469 // if the user hasn't changed the list of selected items
2470 // we don't use that list. Because if we would use the list
2471 // of pre-checked items, the dialog would show different
2472 // checked items on the next startup: it would only try
2473 // to check the parent folder (which might not even show)
2474 // instead, we simply use an empty list and let the
2475 // default checking do its job.
2476 if (!dlg
.m_pathList
.IsEqual(pathList
))
2477 selectedList
= dlg
.m_pathList
;
2478 pathList
= dlg
.m_updatedPathList
;
2479 sLogMsg
= dlg
.m_sLogMessage
;
2480 bSelectFilesForCommit
= true;
2482 if( dlg
.m_bPushAfterCommit
)
2484 switch(dlg
.m_PostCmd
)
2486 case GIT_POST_CMD_DCOMMIT
:
2487 CAppUtils::SVNDCommit();
2493 // CGitProgressDlg progDlg;
2494 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2495 // if (parser.HasVal(_T("closeonend")))
2496 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2497 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2498 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2499 // progDlg.SetPathList(dlg.m_pathList);
2500 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2501 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2502 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2503 // progDlg.SetItemCount(dlg.m_itemsCount);
2504 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2505 // progDlg.DoModal();
2506 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2507 // err = (DWORD)progDlg.DidErrorsOccur();
2508 // bFailed = progDlg.DidErrorsOccur();
2509 // bRet = progDlg.DidErrorsOccur();
2510 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2511 // if (DWORD(bFailRepeat)==0)
2512 // bFailed = false; // do not repeat if the user chose not to in the settings.
2519 BOOL
CAppUtils::SVNDCommit()
2521 CSVNDCommitDlg dcommitdlg
;
2522 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2523 if (gitSetting
== _T("")) {
2524 if (dcommitdlg
.DoModal() != IDOK
)
2530 if (dcommitdlg
.m_remember
)
2532 if (dcommitdlg
.m_rmdir
)
2534 gitSetting
= _T("true");
2538 gitSetting
= _T("false");
2540 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2542 CMessageBox::Show(NULL
,_T("Fail to set config"),_T("TortoiseGit"),MB_OK
);
2548 BOOL IsStash
= false;
2549 if(!g_Git
.CheckCleanWorkTree())
2551 if(CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2554 cmd
=_T("git.exe stash");
2555 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
2557 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2569 CProgressDlg progress
;
2570 if (dcommitdlg
.m_rmdir
)
2572 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2576 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2578 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2582 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2585 cmd
=_T("git.exe stash pop");
2586 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
2588 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2603 BOOL
CAppUtils::Merge(CString
*commit
)
2607 dlg
.m_initialRefName
= *commit
;
2609 if(dlg
.DoModal()==IDOK
)
2621 squash
=_T("--squash");
2624 nocommit
=_T("--no-commit");
2626 if(!dlg
.m_strLogMesage
.IsEmpty())
2628 msg
+= _T("-m \"")+dlg
.m_strLogMesage
+_T("\"");
2630 cmd
.Format(_T("git.exe merge %s %s %s %s %s"),
2635 g_Git
.FixBranchName(dlg
.m_VersionName
));
2637 CProgressDlg Prodlg
;
2638 Prodlg
.m_GitCmd
= cmd
;
2640 if (dlg
.m_bNoCommit
)
2641 Prodlg
.m_PostCmdList
.Add(_T("Commit"));
2643 int ret
= Prodlg
.DoModal();
2645 if (ret
== IDC_PROGRESS_BUTTON1
)
2646 return Commit(_T(""), TRUE
, CString(), CTGitPathList(), CTGitPathList(), true);
2648 return !Prodlg
.m_GitStatus
;
2653 void CAppUtils::EditNote(GitRev
*rev
)
2656 dlg
.m_sHintText
=_T("Edit Notes");
2657 dlg
.m_sInputText
= rev
->m_Notes
;
2658 dlg
.m_sTitle
=_T("Edit Notes");
2659 //dlg.m_pProjectProperties = &m_ProjectProperties;
2660 dlg
.m_bUseLogWidth
= true;
2661 if(dlg
.DoModal() == IDOK
)
2664 cmd
=_T("notes add -f -F \"");
2666 CString tempfile
=::GetTempFile();
2667 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
2670 cmd
+= rev
->m_CommitHash
.ToString();
2674 if(git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
,CP_ACP
).GetBuffer()))
2676 CMessageBox::Show(NULL
,_T("Edit Note Fail"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2681 rev
->m_Notes
= dlg
.m_sInputText
;
2685 CMessageBox::Show(NULL
,_T("Edit Note Fail"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2687 CFile::Remove(tempfile
);
2692 int CAppUtils::GetMsysgitVersion(CString
*versionstr
)
2695 CString progressarg
;
2698 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
2699 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
2701 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
2704 if(!g_Git
.GetFileModifyTime(gitpath
, &time
) && !versionstr
)
2706 if((DWORD
)time
== regTime
)
2713 version
= *versionstr
;
2717 cmd
= _T("git.exe --version");
2718 if(g_Git
.Run(cmd
, &version
, &err
, CP_ACP
))
2720 CMessageBox::Show(NULL
, _T("git have not installed (") + err
+ _T(")"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2728 CString str
=version
.Tokenize(_T("."),start
);
2729 int space
= str
.ReverseFind(_T(' '));
2730 str
=str
.Mid(space
+1,start
);
2734 version
= version
.Mid(start
);
2736 str
= version
.Tokenize(_T("."),start
);
2738 ver
|= (_ttol(str
)&0xFF)<<16;
2740 str
= version
.Tokenize(_T("."),start
);
2741 ver
|= (_ttol(str
)&0xFF)<<8;
2743 str
= version
.Tokenize(_T("."),start
);
2744 ver
|= (_ttol(str
)&0xFF);
2746 regTime
= time
&0xFFFFFFFF;
2752 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
2754 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
2756 HMODULE hShell
= LoadLibrary(_T("Shell32.dll"));
2759 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
2761 IPropertyStore
*pps
;
2762 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
2763 if (SUCCEEDED(hr
)) {
2766 var
.boolVal
= VARIANT_TRUE
;
2767 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
2771 FreeLibrary(hShell
);
2775 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
2777 ASSERT(dialogname
.GetLength() < 70);
2778 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
2779 WCHAR pathbuf
[MAX_PATH
] = {0};
2781 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
2783 wcscat_s(pathbuf
, L
" - ");
2784 wcscat_s(pathbuf
, dialogname
);
2785 wcscat_s(pathbuf
, L
" - ");
2786 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2787 SetWindowText(hWnd
, pathbuf
);