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 "SVNProgressDlg.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"
61 CAppUtils::CAppUtils(void)
65 CAppUtils::~CAppUtils(void)
69 int CAppUtils::StashApply(CString ref
)
72 cmd
=_T("git.exe stash apply ");
75 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
77 CMessageBox::Show(NULL
,CString(_T("<ct=0x0000FF>Stash Apply Fail!!!</ct>\n"))+out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
82 if(CMessageBox::Show(NULL
,CString(_T("<ct=0xff0000>Stash Apply Success</ct>\nDo you want to show change?"))
83 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
86 dlg
.m_pathList
.AddPath(CTGitPath());
94 int CAppUtils::StashPop()
97 cmd
=_T("git.exe stash pop ");
99 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
101 CMessageBox::Show(NULL
,CString(_T("<ct=0x0000FF>Stash POP Fail!!!</ct>\n"))+out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
106 if(CMessageBox::Show(NULL
,CString(_T("<ct=0xff0000>Stash POP Success</ct>\nDo you want to show change?"))
107 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
110 dlg
.m_pathList
.AddPath(CTGitPath());
118 bool CAppUtils::GetMimeType(const CTGitPath
& /*file*/, CString
& /*mimetype*/)
121 GitProperties
props(file
, GitRev::REV_WC
, false);
122 for (int i
= 0; i
< props
.GetCount(); ++i
)
124 if (props
.GetItemName(i
).compare(_T("svn:mime-type"))==0)
126 mimetype
= props
.GetItemValue(i
).c_str();
134 BOOL
CAppUtils::StartExtMerge(
135 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
136 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
)
139 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
140 CString ext
= mergedfile
.GetFileExtension();
141 CString com
= regCom
;
142 bool bInternal
= false;
147 // is there an extension specific merge tool?
148 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
149 if (CString(mergetool
) != "")
154 if (GetMimeType(yourfile
, mimetype
) || GetMimeType(theirfile
, mimetype
) || GetMimeType(basefile
, mimetype
))
156 // is there a mime type specific merge tool?
157 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype
);
158 if (CString(mergetool
) != "")
164 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
168 CRegString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE
);
169 com
= tortoiseMergePath
;
172 com
= CPathUtils::GetAppDirectory();
173 com
+= _T("TortoiseMerge.exe");
175 com
= _T("\"") + com
+ _T("\"");
176 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
177 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
179 // check if the params are set. If not, just add the files to the command line
180 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
182 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
183 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
184 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
185 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
187 if (basefile
.IsEmpty())
189 com
.Replace(_T("/base:%base"), _T(""));
190 com
.Replace(_T("%base"), _T(""));
193 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
194 if (theirfile
.IsEmpty())
196 com
.Replace(_T("/theirs:%theirs"), _T(""));
197 com
.Replace(_T("%theirs"), _T(""));
200 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
201 if (yourfile
.IsEmpty())
203 com
.Replace(_T("/mine:%mine"), _T(""));
204 com
.Replace(_T("%mine"), _T(""));
207 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
208 if (mergedfile
.IsEmpty())
210 com
.Replace(_T("/merged:%merged"), _T(""));
211 com
.Replace(_T("%merged"), _T(""));
214 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
215 if (basename
.IsEmpty())
217 if (basefile
.IsEmpty())
219 com
.Replace(_T("/basename:%bname"), _T(""));
220 com
.Replace(_T("%bname"), _T(""));
224 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
228 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
229 if (theirname
.IsEmpty())
231 if (theirfile
.IsEmpty())
233 com
.Replace(_T("/theirsname:%tname"), _T(""));
234 com
.Replace(_T("%tname"), _T(""));
238 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
242 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
243 if (yourname
.IsEmpty())
245 if (yourfile
.IsEmpty())
247 com
.Replace(_T("/minename:%yname"), _T(""));
248 com
.Replace(_T("%yname"), _T(""));
252 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
256 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
257 if (mergedname
.IsEmpty())
259 if (mergedfile
.IsEmpty())
261 com
.Replace(_T("/mergedname:%mname"), _T(""));
262 com
.Replace(_T("%mname"), _T(""));
266 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
270 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
272 if ((bReadOnly
)&&(bInternal
))
273 com
+= _T(" /readonly");
275 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
283 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
287 viewer
= CPathUtils::GetAppDirectory();
288 viewer
+= _T("TortoiseMerge.exe");
290 viewer
= _T("\"") + viewer
+ _T("\"");
291 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
292 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
294 viewer
+= _T(" /reversedpatch");
295 if (!sOriginalDescription
.IsEmpty())
296 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
297 if (!sPatchedDescription
.IsEmpty())
298 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
299 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
306 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
308 // Is there a mime type specific diff tool?
310 if (GetMimeType(file1
, mimetype
) || GetMimeType(file2
, mimetype
))
312 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype
);
313 if (!difftool
.IsEmpty())
317 // Is there an extension specific diff tool?
318 CString ext
= file2
.GetFileExtension().MakeLower();
321 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
322 if (!difftool
.IsEmpty())
324 // Maybe we should use TortoiseIDiff?
325 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
326 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
327 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
328 (ext
== _T(".dib")) || (ext
== _T(".emf")))
331 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
332 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
336 // Finally, pick a generic external diff tool
337 CString difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
341 bool CAppUtils::StartExtDiff(
342 const CString
& file1
, const CString
& file2
,
343 const CString
& sName1
, const CString
& sName2
,
344 const DiffFlags
& flags
)
348 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
349 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
351 viewer
= PickDiffTool(file1
, file2
);
352 // If registry entry for a diff program is commented out, use TortoiseMerge.
353 bool bCommentedOut
= viewer
.Left(1) == _T("#");
354 if (flags
.bAlternativeTool
)
356 // Invert external vs. internal diff tool selection.
358 viewer
.Delete(0); // uncomment
362 else if (bCommentedOut
)
366 bool bInternal
= viewer
.IsEmpty();
370 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
371 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
373 viewer
+= _T(" /blame");
375 // check if the params are set. If not, just add the files to the command line
376 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
378 viewer
+= _T(" \"")+file1
+_T("\"");
379 viewer
+= _T(" \"")+file2
+_T("\"");
381 if (viewer
.Find(_T("%base")) >= 0)
383 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
385 if (viewer
.Find(_T("%mine")) >= 0)
387 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
390 if (sName1
.IsEmpty())
391 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
393 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
395 if (sName2
.IsEmpty())
396 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
398 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
400 if (flags
.bReadOnly
&& bInternal
)
401 viewer
+= _T(" /readonly");
403 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
406 BOOL
CAppUtils::StartExtDiffProps(const CTGitPath
& file1
, const CTGitPath
& file2
, const CString
& sName1
, const CString
& sName2
, BOOL bWait
, BOOL bReadOnly
)
408 CRegString
diffpropsexe(_T("Software\\TortoiseGit\\DiffProps"));
409 CString viewer
= diffpropsexe
;
410 bool bInternal
= false;
411 if (viewer
.IsEmpty()||(viewer
.Left(1).Compare(_T("#"))==0))
413 //no registry entry (or commented out) for a diff program
416 viewer
= CPathUtils::GetAppDirectory();
417 viewer
+= _T("TortoiseMerge.exe");
418 viewer
= _T("\"") + viewer
+ _T("\"");
419 viewer
= viewer
+ _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
421 // check if the params are set. If not, just add the files to the command line
422 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
424 viewer
+= _T(" \"")+file1
.GetWinPathString()+_T("\"");
425 viewer
+= _T(" \"")+file2
.GetWinPathString()+_T("\"");
427 if (viewer
.Find(_T("%base")) >= 0)
429 viewer
.Replace(_T("%base"), _T("\"")+file1
.GetWinPathString()+_T("\""));
431 if (viewer
.Find(_T("%mine")) >= 0)
433 viewer
.Replace(_T("%mine"), _T("\"")+file2
.GetWinPathString()+_T("\""));
436 if (sName1
.IsEmpty())
437 viewer
.Replace(_T("%bname"), _T("\"") + file1
.GetUIFileOrDirectoryName() + _T("\""));
439 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
441 if (sName2
.IsEmpty())
442 viewer
.Replace(_T("%yname"), _T("\"") + file2
.GetUIFileOrDirectoryName() + _T("\""));
444 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
446 if ((bReadOnly
)&&(bInternal
))
447 viewer
+= _T(" /readonly");
449 if(!LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, !!bWait
))
456 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
459 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
461 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
464 viewer
= CPathUtils::GetAppDirectory();
465 viewer
+= _T("TortoiseUDiff.exe");
466 // enquote the path to TortoiseUDiff
467 viewer
= _T("\"") + viewer
+ _T("\"");
469 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
472 if (viewer
.Find(_T("%1"))>=0)
474 if (viewer
.Find(_T("\"%1\"")) >= 0)
475 viewer
.Replace(_T("%1"), patchfile
);
477 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
480 viewer
+= _T(" \"") + patchfile
+ _T("\"");
481 if (viewer
.Find(_T("%title")) >= 0)
483 viewer
.Replace(_T("%title"), title
);
486 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
493 BOOL
CAppUtils::StartTextViewer(CString file
)
496 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
498 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
499 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
502 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
503 TCHAR
* buf
= new TCHAR
[len
+1];
504 ExpandEnvironmentStrings(viewer
, buf
, len
);
507 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
508 buf
= new TCHAR
[len
+1];
509 ExpandEnvironmentStrings(file
, buf
, len
);
512 file
= _T("\"")+file
+_T("\"");
513 if (viewer
.IsEmpty())
515 OPENFILENAME ofn
= {0}; // common dialog box structure
516 TCHAR szFile
[MAX_PATH
] = {0}; // buffer for file name. Explorer can't handle paths longer than MAX_PATH.
517 // Initialize OPENFILENAME
518 ofn
.lStructSize
= sizeof(OPENFILENAME
);
519 ofn
.hwndOwner
= NULL
;
520 ofn
.lpstrFile
= szFile
;
521 ofn
.nMaxFile
= _countof(szFile
);
523 sFilter
.LoadString(IDS_PROGRAMSFILEFILTER
);
524 TCHAR
* pszFilters
= new TCHAR
[sFilter
.GetLength()+4];
525 _tcscpy_s (pszFilters
, sFilter
.GetLength()+4, sFilter
);
526 // Replace '|' delimiters with '\0's
527 TCHAR
*ptr
= pszFilters
+ _tcslen(pszFilters
); //set ptr at the NULL
528 while (ptr
!= pszFilters
)
534 ofn
.lpstrFilter
= pszFilters
;
535 ofn
.nFilterIndex
= 1;
536 ofn
.lpstrFileTitle
= NULL
;
537 ofn
.nMaxFileTitle
= 0;
538 ofn
.lpstrInitialDir
= NULL
;
540 temp
.LoadString(IDS_UTILS_SELECTTEXTVIEWER
);
541 CStringUtils::RemoveAccelerators(temp
);
542 ofn
.lpstrTitle
= temp
;
543 ofn
.Flags
= OFN_PATHMUSTEXIST
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
545 // Display the Open dialog box.
547 if (GetOpenFileName(&ofn
)==TRUE
)
549 delete [] pszFilters
;
550 viewer
= CString(ofn
.lpstrFile
);
554 delete [] pszFilters
;
558 if (viewer
.Find(_T("\"%1\"")) >= 0)
560 viewer
.Replace(_T("\"%1\""), file
);
562 else if (viewer
.Find(_T("%1")) >= 0)
564 viewer
.Replace(_T("%1"), file
);
572 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
579 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
582 HANDLE hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
583 if (hFile
== INVALID_HANDLE_VALUE
)
585 length
= ::GetFileSize(hFile
, NULL
);
586 ::CloseHandle(hFile
);
593 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
596 HDC hScreenDC
= ::GetDC(NULL
);
597 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
598 ::ReleaseDC(NULL
, hScreenDC
);
600 logFont
.lfEscapement
= 0;
601 logFont
.lfOrientation
= 0;
602 logFont
.lfWeight
= FW_NORMAL
;
603 logFont
.lfItalic
= 0;
604 logFont
.lfUnderline
= 0;
605 logFont
.lfStrikeOut
= 0;
606 logFont
.lfCharSet
= DEFAULT_CHARSET
;
607 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
608 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
609 logFont
.lfQuality
= DRAFT_QUALITY
;
610 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
611 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
612 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
615 bool CAppUtils::LaunchApplication(const CString
& sCommandLine
, UINT idErrMessageFormat
, bool bWaitForStartup
)
618 PROCESS_INFORMATION process
;
619 memset(&startup
, 0, sizeof(startup
));
620 startup
.cb
= sizeof(startup
);
621 memset(&process
, 0, sizeof(process
));
623 CString
cleanCommandLine(sCommandLine
);
625 if (CreateProcess(NULL
, const_cast<TCHAR
*>((LPCTSTR
)cleanCommandLine
), NULL
, NULL
, FALSE
, 0, 0, g_Git
.m_CurrentDir
, &startup
, &process
)==0)
627 if(idErrMessageFormat
!= 0)
630 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
631 FORMAT_MESSAGE_FROM_SYSTEM
|
632 FORMAT_MESSAGE_IGNORE_INSERTS
,
635 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
641 temp
.Format(idErrMessageFormat
, lpMsgBuf
);
642 CMessageBox::Show(NULL
, temp
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
643 LocalFree( lpMsgBuf
);
650 WaitForInputIdle(process
.hProcess
, 10000);
653 CloseHandle(process
.hThread
);
654 CloseHandle(process
.hProcess
);
657 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
671 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
672 key
= g_Git
.GetConfigValue(cmd
);
674 key
= key
.Tokenize(_T("\n"),start
);
682 CString proc
=CPathUtils::GetAppDirectory();
683 proc
+= _T("pageant.exe \"");
687 CString tempfile
= GetTempFile();
688 ::DeleteFile(tempfile
);
690 proc
+= _T(" -c \"");
691 proc
+= CPathUtils::GetAppDirectory();
692 proc
+= _T("touch.exe\"");
697 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true);
702 while(!::PathFileExists(tempfile
))
707 break; //timeout 5 minutes
712 CMessageBox::Show(NULL
, _T("Fail wait for pageant finish load key"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
714 ::DeleteFile(tempfile
);
717 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
)
719 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
720 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
721 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
725 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
727 LaunchApplication(sCmd
, NULL
, false);
730 bool CAppUtils::LaunchRemoteSetting()
732 CTGitPath
path(g_Git
.m_CurrentDir
);
733 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
734 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
735 //dlg.SetTreeWidth(220);
736 dlg
.m_DefaultPage
= _T("gitremote");
743 * Launch the external blame viewer
745 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
747 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
748 viewer
+= _T("TortoiseGitBlame.exe");
749 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
750 //viewer += _T(" \"") + sLogFile + _T("\"");
751 //viewer += _T(" \"") + sOriginalFile + _T("\"");
752 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
753 viewer
+= CString(_T(" /rev:"))+Rev
;
754 viewer
+= _T(" ")+sParams
;
756 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
759 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
764 bool bStyled
= false;
765 pWnd
->GetWindowText(sText
);
766 // the rich edit control doesn't count the CR char!
767 // to be exact: CRLF is treated as one char.
770 // style each line separately
775 nNewlinePos
= sText
.Find('\n', offset
);
776 CString sLine
= sText
.Mid(offset
);
778 sLine
= sLine
.Left(nNewlinePos
-offset
);
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_BOLD
;
789 format
.dwEffects
= CFE_BOLD
;
790 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
796 while (FindStyleChars(sLine
, '^', start
, end
))
798 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
799 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
801 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
802 format
.cbSize
= sizeof(CHARFORMAT2
);
803 format
.dwMask
= CFM_ITALIC
;
804 format
.dwEffects
= CFE_ITALIC
;
805 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
811 while (FindStyleChars(sLine
, '_', start
, end
))
813 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
814 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
816 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
817 format
.cbSize
= sizeof(CHARFORMAT2
);
818 format
.dwMask
= CFM_UNDERLINE
;
819 format
.dwEffects
= CFE_UNDERLINE
;
820 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
824 offset
= nNewlinePos
+1;
825 } while(nNewlinePos
>=0);
829 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
832 bool bFoundMarker
= false;
833 // find a starting marker
834 while (sText
[i
] != 0)
836 if (sText
[i
] == stylechar
)
838 if (((i
+1)<sText
.GetLength())&&(IsCharAlphaNumeric(sText
[i
+1])) &&
839 (((i
>0)&&(!IsCharAlphaNumeric(sText
[i
-1])))||(i
==0)))
851 // find ending marker
852 bFoundMarker
= false;
853 while (sText
[i
] != 0)
855 if (sText
[i
] == stylechar
)
857 if ((IsCharAlphaNumeric(sText
[i
-1])) &&
858 ((((i
+1)<sText
.GetLength())&&(!IsCharAlphaNumeric(sText
[i
+1])))||(i
+1)==sText
.GetLength()))
871 bool CAppUtils::FileOpenSave(CString
& path
, int * filterindex
, UINT title
, UINT filter
, bool bOpen
, HWND hwndOwner
)
873 OPENFILENAME ofn
= {0}; // common dialog box structure
874 TCHAR szFile
[MAX_PATH
] = {0}; // buffer for file name. Explorer can't handle paths longer than MAX_PATH.
875 ofn
.lStructSize
= sizeof(OPENFILENAME
);
876 ofn
.hwndOwner
= hwndOwner
;
877 _tcscpy_s(szFile
, MAX_PATH
, (LPCTSTR
)path
);
878 ofn
.lpstrFile
= szFile
;
879 ofn
.nMaxFile
= _countof(szFile
);
881 TCHAR
* pszFilters
= NULL
;
884 sFilter
.LoadString(filter
);
885 pszFilters
= new TCHAR
[sFilter
.GetLength()+4];
886 _tcscpy_s (pszFilters
, sFilter
.GetLength()+4, sFilter
);
887 // Replace '|' delimiters with '\0's
888 TCHAR
*ptr
= pszFilters
+ _tcslen(pszFilters
); //set ptr at the NULL
889 while (ptr
!= pszFilters
)
895 ofn
.lpstrFilter
= pszFilters
;
897 ofn
.nFilterIndex
= 1;
898 ofn
.lpstrFileTitle
= NULL
;
899 ofn
.nMaxFileTitle
= 0;
900 ofn
.lpstrInitialDir
= NULL
;
904 temp
.LoadString(title
);
905 CStringUtils::RemoveAccelerators(temp
);
907 ofn
.lpstrTitle
= temp
;
909 ofn
.Flags
= OFN_PATHMUSTEXIST
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
| OFN_EXPLORER
;
911 ofn
.Flags
= OFN_OVERWRITEPROMPT
| OFN_EXPLORER
;
914 // Display the Open dialog box.
918 bRet
= !!GetOpenFileName(&ofn
);
922 bRet
= !!GetSaveFileName(&ofn
);
927 delete [] pszFilters
;
928 path
= CString(ofn
.lpstrFile
);
930 *filterindex
= ofn
.nFilterIndex
;
934 delete [] pszFilters
;
938 bool CAppUtils::SetListCtrlBackgroundImage(HWND hListCtrl
, UINT nID
, int width
/* = 128 */, int height
/* = 128 */)
940 ListView_SetTextBkColor(hListCtrl
, CLR_NONE
);
941 COLORREF bkColor
= ListView_GetBkColor(hListCtrl
);
942 // create a bitmap from the icon
943 HICON hIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(nID
), IMAGE_ICON
, width
, height
, LR_DEFAULTCOLOR
);
949 rect
.bottom
= height
;
952 HWND desktop
= ::GetDesktopWindow();
955 HDC screen_dev
= ::GetDC(desktop
);
958 // Create a compatible DC
959 HDC dst_hdc
= ::CreateCompatibleDC(screen_dev
);
962 // Create a new bitmap of icon size
963 bmp
= ::CreateCompatibleBitmap(screen_dev
, rect
.right
, rect
.bottom
);
966 // Select it into the compatible DC
967 HBITMAP old_dst_bmp
= (HBITMAP
)::SelectObject(dst_hdc
, bmp
);
968 // Fill the background of the compatible DC with the given color
969 ::SetBkColor(dst_hdc
, bkColor
);
970 ::ExtTextOut(dst_hdc
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
972 // Draw the icon into the compatible DC
973 ::DrawIconEx(dst_hdc
, 0, 0, hIcon
, rect
.right
, rect
.bottom
, 0, NULL
, DI_NORMAL
);
974 ::SelectObject(dst_hdc
, old_dst_bmp
);
979 ::ReleaseDC(desktop
, screen_dev
);
989 lv
.ulFlags
= LVBKIF_TYPE_WATERMARK
;
991 lv
.xOffsetPercent
= 100;
992 lv
.yOffsetPercent
= 100;
993 ListView_SetBkImage(hListCtrl
, &lv
);
997 CString
CAppUtils::GetProjectNameFromURL(CString url
)
1000 while (name
.IsEmpty() || (name
.CompareNoCase(_T("branches"))==0) ||
1001 (name
.CompareNoCase(_T("tags"))==0) ||
1002 (name
.CompareNoCase(_T("trunk"))==0))
1004 name
= url
.Mid(url
.ReverseFind('/')+1);
1005 url
= url
.Left(url
.ReverseFind('/'));
1007 if ((name
.Compare(_T("svn")) == 0)||(name
.Compare(_T("svnroot")) == 0))
1009 // a name of svn or svnroot indicates that it's not really the project name. In that
1010 // case, we try the first part of the URL
1011 // of course, this won't work in all cases (but it works for Google project hosting)
1012 url
.Replace(_T("http://"), _T(""));
1013 url
.Replace(_T("https://"), _T(""));
1014 url
.Replace(_T("svn://"), _T(""));
1015 url
.Replace(_T("svn+ssh://"), _T(""));
1016 url
.TrimLeft(_T("/"));
1017 name
= url
.Left(url
.Find('.'));
1022 bool CAppUtils::StartShowUnifiedDiff(HWND
/*hWnd*/, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
1023 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
1024 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
1025 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */, bool /* blame = false */, bool bMerge
)
1028 CString tempfile
=GetTempFile();
1030 if(rev1
== GitRev::GetWorkingCopy())
1032 cmd
.Format(_T("git.exe diff --stat -p %s "),rev2
);
1040 cmd
.Format(_T("git.exe diff-tree -r -p %s --stat %s %s"),merge
, rev1
,rev2
);
1043 if( !url1
.IsEmpty() )
1046 cmd
+= url1
.GetGitPathString();
1049 g_Git
.RunLogFile(cmd
,tempfile
);
1050 CAppUtils::StartUnifiedDiffViewer(tempfile
,rev1
.Left(6)+_T(":")+rev2
.Left(6));
1055 sCmd
.Format(_T("%s /command:showcompare /unified"),
1056 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
1057 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
1059 sCmd
+= _T(" /revision1:") + rev1
.ToString();
1060 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
1062 sCmd
+= _T(" /revision2:") + rev2
.ToString();
1064 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
1065 if (headpeg
.IsValid())
1066 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
1069 sCmd
+= _T(" /alternatediff");
1071 if (bIgnoreAncestry
)
1072 sCmd
+= _T(" /ignoreancestry");
1076 sCmd
+= _T(" /hwnd:");
1078 _stprintf_s(buf
, 30, _T("%d"), hWnd
);
1082 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
1088 bool CAppUtils::Export(CString
*BashHash
)
1092 // ask from where the export has to be done
1095 dlg
.m_Revision
=*BashHash
;
1097 if (dlg
.DoModal() == IDOK
)
1100 cmd
.Format(_T("git.exe archive --format=zip --verbose %s"),
1101 g_Git
.FixBranchName(dlg
.m_VersionName
));
1103 //g_Git.RunLogFile(cmd,dlg.m_strExportDirectory);
1106 pro
.m_LogFile
=dlg
.m_strExportDirectory
;
1113 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
, bool switch_new_brach
)
1115 CCreateBranchTagDlg dlg
;
1117 dlg
.m_bSwitch
=switch_new_brach
;
1120 dlg
.m_Base
= *CommitHash
;
1122 if(dlg
.DoModal()==IDOK
)
1128 track
=_T(" --track ");
1139 cmd
.Format(_T("git.exe tag %s %s %s %s %s"),
1143 dlg
.m_BranchTagName
,
1144 g_Git
.FixBranchName(dlg
.m_VersionName
)
1147 CString tempfile
=::GetTempFile();
1148 if(!dlg
.m_Message
.Trim().IsEmpty())
1150 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_Message
);
1151 cmd
+= _T(" -F ")+tempfile
;
1156 cmd
.Format(_T("git.exe branch %s %s %s %s"),
1159 dlg
.m_BranchTagName
,
1160 g_Git
.FixBranchName(dlg
.m_VersionName
)
1164 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1166 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1168 if( !IsTag
&& dlg
.m_bSwitch
)
1170 // it is a new branch and the user has requested to switch to it
1171 cmd
.Format(_T("git.exe checkout %s"), dlg
.m_BranchTagName
);
1172 g_Git
.Run(cmd
,&out
,CP_UTF8
);
1173 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1181 bool CAppUtils::Switch(CString
*CommitHash
, CString initialRefName
, bool autoclose
)
1185 dlg
.m_Base
=*CommitHash
;
1186 if(!initialRefName
.IsEmpty())
1187 dlg
.m_initialRefName
= initialRefName
;
1189 if (dlg
.DoModal() == IDOK
)
1198 if (dlg
.m_bBranchOverride
)
1200 branch
.Format(_T("-B %s"),dlg
.m_NewBranch
);
1204 branch
.Format(_T("-b %s"),dlg
.m_NewBranch
);
1210 track
=_T("--track");
1212 cmd
.Format(_T("git.exe checkout %s %s %s %s"),
1216 g_Git
.FixBranchName(dlg
.m_VersionName
));
1218 CProgressDlg progress
;
1219 progress
.m_bAutoCloseOnSuccess
= autoclose
;
1220 progress
.m_GitCmd
=cmd
;
1221 if(progress
.DoModal()==IDOK
)
1228 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1231 ignorefile
=g_Git
.m_CurrentDir
+_T("\\");
1235 ignorefile
+=path
.GetCommonRoot().GetDirectory().GetWinPathString()+_T("\\.gitignore");
1240 ignorefile
+= _T("\\.gitignore");
1244 if(!file
.Open(ignorefile
,CFile::modeCreate
|CFile::modeReadWrite
|CFile::modeNoTruncate
))
1246 CMessageBox::Show(NULL
,ignorefile
+_T(" Open Failure"),_T("TortoiseGit"),MB_OK
);
1254 //file.ReadString(ignorelist);
1256 for(int i
=0;i
<path
.GetCount();i
++)
1260 mask
=_T("*")+path
[i
].GetFileExtension();
1261 if(ignorelist
.Find(mask
)<0)
1262 ignorelist
+= _T("\n")+mask
;
1266 ignorelist
+= _T("\n/")+path
[i
].GetGitPathString();
1269 file
.WriteString(ignorelist
);
1283 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1286 dlg
.m_ResetType
=type
;
1287 dlg
.m_ResetToVersion
=*CommitHash
;
1288 if (dlg
.DoModal() == IDOK
)
1292 switch(dlg
.m_ResetType
)
1307 cmd
.Format(_T("git.exe reset %s %s"),type
, *CommitHash
);
1309 CProgressDlg progress
;
1310 progress
.m_GitCmd
=cmd
;
1311 if(progress
.DoModal()==IDOK
)
1318 void CAppUtils::DescribeFile(bool mode
, bool base
,CString
&descript
)
1322 descript
=_T("Deleted");
1327 descript
=_T("Modified");
1330 descript
=_T("Created");
1334 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1336 CString tempmergefile
;
1339 tempmergefile
= CAppUtils::GetMergeTempFile(_T("LOCAL"),path
);
1340 CFile::Remove(tempmergefile
);
1347 tempmergefile
= CAppUtils::GetMergeTempFile(_T("REMOTE"),path
);
1348 CFile::Remove(tempmergefile
);
1355 tempmergefile
= CAppUtils::GetMergeTempFile(_T("BASE"),path
);
1356 CFile::Remove(tempmergefile
);
1361 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1364 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1369 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool /*bAlternativeTool*/,bool revertTheirMy
)
1373 CTGitPath merge
=path
;
1374 CTGitPath directory
= merge
.GetDirectory();
1376 // we have the conflicted file (%merged)
1377 // now look for the other required files
1379 //stat.GetStatus(merge);
1380 //if (stat.status == NULL)
1386 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1388 if(g_Git
.Run(cmd
,&vector
))
1394 list
.ParserFromLsFile(vector
);
1396 if(list
.GetCount() == 0)
1403 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge
));
1404 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge
));
1405 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1409 //format=_T("git.exe cat-file blob \":%d:%s\"");
1410 format
= _T("git checkout-index --temp --stage=%d -- \"%s\"");
1412 //create a empty file, incase stage is not three
1413 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1415 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1417 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1420 bool b_base
=false, b_local
=false, b_remote
=false;
1422 for(int i
=0;i
<list
.GetCount();i
++)
1429 if( list
[i
].m_Stage
== 1)
1431 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1433 outfile
= base
.GetWinPathString();
1436 if( list
[i
].m_Stage
== 2 )
1438 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1440 outfile
= mine
.GetWinPathString();
1443 if( list
[i
].m_Stage
== 3 )
1445 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1447 outfile
= theirs
.GetWinPathString();
1450 if(!outfile
.IsEmpty())
1451 if(!g_Git
.Run(cmd
,&output
,CP_ACP
))
1455 file
= output
.Tokenize(_T("\t"), start
);
1456 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1460 CMessageBox::Show(NULL
,output
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1464 if(b_local
&& b_remote
)
1466 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1468 bRet
= !!CAppUtils::StartExtMerge(base
,mine
, theirs
, merge
,_T("BASE"),_T("LOCAL"),_T("REMOTE"));
1470 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1475 CFile::Remove(mine
.GetWinPathString());
1476 CFile::Remove(theirs
.GetWinPathString());
1477 CFile::Remove(base
.GetWinPathString());
1479 CDeleteConflictDlg dlg
;
1480 DescribeFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1481 DescribeFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1482 dlg
.m_bShowModifiedButton
=b_base
;
1483 dlg
.m_File
=merge
.GetGitPathString();
1484 if(dlg
.DoModal() == IDOK
)
1489 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1492 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1494 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
1496 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1506 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1507 base
, theirs
, mine
, merge
);
1510 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1512 // we have a text conflict, use our merge tool to resolve the conflict
1514 CTSVNPath
theirs(directory
);
1515 CTSVNPath
mine(directory
);
1516 CTSVNPath
base(directory
);
1517 bool bConflictData
= false;
1519 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1521 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1522 bConflictData
= true;
1524 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1526 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1527 bConflictData
= true;
1529 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1531 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1532 bConflictData
= true;
1539 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1540 base
, theirs
, mine
, merge
);
1543 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1545 // we have a property conflict
1546 CTSVNPath
prej(directory
);
1547 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1549 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1550 // there's a problem: the prej file contains a _description_ of the conflict, and
1551 // that description string might be translated. That means we have no way of parsing
1552 // the file to find out the conflicting values.
1553 // The only thing we can do: show a dialog with the conflict description, then
1554 // let the user either accept the existing property or open the property edit dialog
1555 // to manually change the properties and values. And a button to mark the conflict as
1557 CEditPropConflictDlg dlg
;
1558 dlg
.SetPrejFile(prej
);
1559 dlg
.SetConflictedItem(merge
);
1560 bRet
= (dlg
.DoModal() != IDCANCEL
);
1564 if (stat
.status
->tree_conflict
)
1566 // we have a tree conflict
1568 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1571 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1573 CTSVNPath
theirs(directory
);
1574 CTSVNPath
mine(directory
);
1575 CTSVNPath
base(directory
);
1576 bool bConflictData
= false;
1578 if (pInfoData
->treeconflict_theirfile
)
1580 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1581 bConflictData
= true;
1583 if (pInfoData
->treeconflict_basefile
)
1585 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1586 bConflictData
= true;
1588 if (pInfoData
->treeconflict_myfile
)
1590 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1591 bConflictData
= true;
1598 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1599 base
, theirs
, mine
, merge
);
1601 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1603 CString sConflictAction
;
1604 CString sConflictReason
;
1605 CString sResolveTheirs
;
1606 CString sResolveMine
;
1607 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1608 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1610 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1612 switch (pInfoData
->treeconflict_operation
)
1614 case svn_wc_operation_update
:
1615 switch (pInfoData
->treeconflict_action
)
1617 case svn_wc_conflict_action_edit
:
1618 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1619 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1621 case svn_wc_conflict_action_add
:
1622 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1623 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1625 case svn_wc_conflict_action_delete
:
1626 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1627 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1631 case svn_wc_operation_switch
:
1632 switch (pInfoData
->treeconflict_action
)
1634 case svn_wc_conflict_action_edit
:
1635 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1636 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1638 case svn_wc_conflict_action_add
:
1639 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1640 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1642 case svn_wc_conflict_action_delete
:
1643 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1644 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1648 case svn_wc_operation_merge
:
1649 switch (pInfoData
->treeconflict_action
)
1651 case svn_wc_conflict_action_edit
:
1652 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1653 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1655 case svn_wc_conflict_action_add
:
1656 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1657 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1659 case svn_wc_conflict_action_delete
:
1660 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1661 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1667 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1669 switch (pInfoData
->treeconflict_operation
)
1671 case svn_wc_operation_update
:
1672 switch (pInfoData
->treeconflict_action
)
1674 case svn_wc_conflict_action_edit
:
1675 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1676 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1678 case svn_wc_conflict_action_add
:
1679 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1680 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1682 case svn_wc_conflict_action_delete
:
1683 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1684 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1688 case svn_wc_operation_switch
:
1689 switch (pInfoData
->treeconflict_action
)
1691 case svn_wc_conflict_action_edit
:
1692 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1693 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1695 case svn_wc_conflict_action_add
:
1696 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1697 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1699 case svn_wc_conflict_action_delete
:
1700 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1701 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1705 case svn_wc_operation_merge
:
1706 switch (pInfoData
->treeconflict_action
)
1708 case svn_wc_conflict_action_edit
:
1709 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1710 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1712 case svn_wc_conflict_action_add
:
1713 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1714 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1716 case svn_wc_conflict_action_delete
:
1717 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1718 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1726 switch (pInfoData
->treeconflict_reason
)
1728 case svn_wc_conflict_reason_edited
:
1729 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1730 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1732 case svn_wc_conflict_reason_obstructed
:
1733 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1734 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1736 case svn_wc_conflict_reason_deleted
:
1737 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1738 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1740 case svn_wc_conflict_reason_added
:
1741 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1742 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1744 case svn_wc_conflict_reason_missing
:
1745 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1746 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1748 case svn_wc_conflict_reason_unversioned
:
1749 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1750 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1753 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1755 CTreeConflictEditorDlg dlg
;
1756 dlg
.SetConflictInfoText(sConflictReason
);
1757 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1758 dlg
.SetPath(treeConflictPath
);
1759 INT_PTR dlgRet
= dlg
.DoModal();
1760 bRet
= (dlgRet
!= IDCANCEL
);
1769 * FUNCTION : FormatDateAndTime
1770 * DESCRIPTION : Generates a displayable string from a CTime object in
1771 * system short or long format or as a relative value
1773 * option - DATE_SHORTDATE or DATE_LONGDATE
1774 * bIncluedeTime - whether to show time as well as date
1775 * bRelative - if true then relative time is shown if reasonable
1776 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
1777 * rather than locale
1778 * RETURN : CString containing date/time
1780 CString
CAppUtils::FormatDateAndTime( const CTime
& cTime
, DWORD option
, bool bIncludeTime
/*=true*/,
1781 bool bRelative
/*=false*/)
1786 datetime
= ToRelativeTimeString( cTime
);
1790 // should we use the locale settings for formatting the date/time?
1791 if (CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE
))
1795 cTime
.GetAsSystemTime( sysTime
);
1799 GetDateFormat(LOCALE_USER_DEFAULT
, option
, &sysTime
, NULL
, buf
,
1804 datetime
+= _T(" ");
1805 GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &sysTime
, NULL
, buf
, _countof(buf
) - 1);
1811 // no, so fixed format
1814 datetime
= cTime
.Format(_T("%Y-%m-%d %H:%M:%S"));
1818 datetime
= cTime
.Format(_T("%Y-%m-%d"));
1826 * Converts a given time to a relative display string (relative to current time)
1827 * Given time must be in local timezone
1829 CString
CAppUtils::ToRelativeTimeString(CTime time
)
1832 // convert to COleDateTime
1834 time
.GetAsSystemTime( sysTime
);
1835 COleDateTime
oleTime( sysTime
);
1836 answer
= ToRelativeTimeString(oleTime
, COleDateTime::GetCurrentTime());
1841 * Generates a display string showing the relative time between the two given times as COleDateTimes
1843 CString
CAppUtils::ToRelativeTimeString(COleDateTime time
,COleDateTime RelativeTo
)
1846 COleDateTimeSpan ts
= RelativeTo
- time
;
1848 if(fabs(ts
.GetTotalDays()) >= 3*365)
1850 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/365, IDS_YEAR_AGO
, IDS_YEARS_AGO
);
1853 if(fabs(ts
.GetTotalDays()) >= 60)
1855 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/30, IDS_MONTH_AGO
, IDS_MONTHS_AGO
);
1859 if(fabs(ts
.GetTotalDays()) >= 14)
1861 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays()/7, IDS_WEEK_AGO
, IDS_WEEKS_AGO
);
1865 if(fabs(ts
.GetTotalDays()) >= 2)
1867 answer
= ExpandRelativeTime( (int)ts
.GetTotalDays(), IDS_DAY_AGO
, IDS_DAYS_AGO
);
1871 if(fabs(ts
.GetTotalHours()) >= 2)
1873 answer
= ExpandRelativeTime( (int)ts
.GetTotalHours(), IDS_HOUR_AGO
, IDS_HOURS_AGO
);
1877 if(fabs(ts
.GetTotalMinutes()) >= 2)
1879 answer
= ExpandRelativeTime( (int)ts
.GetTotalMinutes(), IDS_MINUTE_AGO
, IDS_MINUTES_AGO
);
1883 answer
= ExpandRelativeTime( (int)ts
.GetTotalSeconds(), IDS_SECOND_AGO
, IDS_SECONDS_AGO
);
1888 * Passed a value and two resource string ids
1889 * if count is 1 then FormatString is called with format_1 and the value
1890 * otherwise format_2 is used
1891 * the formatted string is returned
1893 CString
CAppUtils::ExpandRelativeTime( int count
, UINT format_1
, UINT format_n
)
1898 answer
.FormatMessage( format_1
, count
);
1902 answer
.FormatMessage( format_n
, count
);
1907 bool CAppUtils::IsSSHPutty()
1909 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1910 sshclient
=sshclient
.MakeLower();
1911 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1918 CString
CAppUtils::GetClipboardLink()
1920 if (!OpenClipboard(NULL
))
1923 CString sClipboardText
;
1924 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1927 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1928 sClipboardText
= CString(lpstr
);
1931 hglb
= GetClipboardData(CF_UNICODETEXT
);
1934 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1935 sClipboardText
= lpstr
;
1940 if(!sClipboardText
.IsEmpty())
1942 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1943 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1945 if(sClipboardText
.Find( _T("http://")) == 0)
1946 return sClipboardText
;
1948 if(sClipboardText
.Find( _T("https://")) == 0)
1949 return sClipboardText
;
1951 if(sClipboardText
.Find( _T("git://")) == 0)
1952 return sClipboardText
;
1954 if(sClipboardText
.Find( _T("ssh://")) == 0)
1955 return sClipboardText
;
1957 if(sClipboardText
.GetLength()>=2)
1958 if( sClipboardText
[1] == _T(':') )
1959 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1960 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1961 return sClipboardText
;
1964 return CString(_T(""));
1967 CString
CAppUtils::ChooseRepository(CString
*path
)
1969 CBrowseFolder browseFolder
;
1970 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
1972 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
1973 CString strCloneDirectory
;
1975 strCloneDirectory
=*path
;
1978 strCloneDirectory
= regLastResopitory
;
1982 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
1984 browseFolder
.SetInfo(title
);
1986 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
1988 regLastResopitory
= strCloneDirectory
;
1989 return strCloneDirectory
;
1997 bool CAppUtils::SendPatchMail(CTGitPathList
&list
,bool autoclose
)
2001 dlg
.m_PathList
= list
;
2003 if(dlg
.DoModal()==IDOK
)
2005 if(dlg
.m_PathList
.GetCount() == 0)
2008 CGitProgressDlg progDlg
;
2010 theApp
.m_pMainWnd
= &progDlg
;
2011 progDlg
.SetCommand(CGitProgressDlg::GitProgress_SendMail
);
2013 progDlg
.SetAutoClose(autoclose
);
2015 progDlg
.SetPathList(dlg
.m_PathList
);
2016 //ProjectProperties props;
2017 //props.ReadPropsPathList(dlg.m_pathList);
2018 //progDlg.SetProjectProperties(props);
2019 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
2022 if(dlg
.m_bAttachment
)
2023 flags
|= SENDMAIL_ATTACHMENT
;
2025 flags
|= SENDMAIL_COMBINED
;
2027 flags
|= SENDMAIL_MAPI
;
2029 progDlg
.SetSendMailOption(dlg
.m_To
,dlg
.m_CC
,dlg
.m_Subject
,flags
);
2038 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
)
2041 CString log
=formatpatchoutput
;
2042 int start
=log
.Find(cmd
);
2044 CString one
=log
.Tokenize(_T("\n"),start
);
2050 CString one
=log
.Tokenize(_T("\n"),start
);
2052 if(one
.IsEmpty() || one
== _T("Success"))
2054 one
.Replace(_T('/'),_T('\\'));
2056 path
.SetFromWin(one
);
2059 if (list
.GetCount() > 0)
2061 return SendPatchMail(list
, autoclose
);
2065 CMessageBox::Show(NULL
, _T("Not patches generated."), _T("TortoiseGit"), MB_ICONINFORMATION
);
2071 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
2076 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
2077 if(output
.IsEmpty())
2079 output
= pGit
->GetConfigValue(_T("i18n.commitencoding"));
2080 if(output
.IsEmpty())
2084 output
=output
.Tokenize(_T("\n"),start
);
2085 return CUnicodeUtils::GetCPCode(output
);
2090 output
=output
.Tokenize(_T("\n"),start
);
2091 return CUnicodeUtils::GetCPCode(output
);
2094 int CAppUtils::GetCommitTemplate(CString
&temp
)
2098 output
= g_Git
.GetConfigValue(_T("commit.template"),CP_ACP
);
2099 if( output
.IsEmpty() )
2102 if( output
.GetLength()<1)
2105 if( output
[0] == _T('/'))
2107 if(output
.GetLength()>=3)
2108 if(output
[2] == _T('/'))
2110 output
.GetBuffer()[0] = output
[1];
2111 output
.GetBuffer()[1] = _T(':');
2116 output
=output
.Tokenize(_T("\n"),start
);
2118 output
.Replace(_T('/'),_T('\\'));
2122 CStdioFile
file(output
,CFile::modeRead
|CFile::typeText
);
2124 while(file
.ReadString(str
))
2135 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
2137 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
2141 output
= g_Git
.GetConfigValue(_T("i18n.commitencoding"));
2142 if(output
.IsEmpty())
2146 output
=output
.Tokenize(_T("\n"),start
);
2147 cp
=CUnicodeUtils::GetCPCode(output
);
2149 int len
=message
.GetLength();
2152 buf
= new char[len
*4 + 4];
2153 SecureZeroMemory(buf
, (len
*4 + 4));
2155 int lengthIncTerminator
= WideCharToMultiByte(cp
, 0, message
, -1, buf
, len
*4, NULL
, NULL
);
2157 file
.Write(buf
,lengthIncTerminator
-1);
2163 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
, bool autoClose
)
2166 dlg
.m_PreSelectRemote
= remoteName
;
2167 dlg
.m_bAllowRebase
= allowRebase
;
2170 if(dlg
.DoModal()==IDOK
)
2174 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_RemoteURL
);
2178 url
=dlg
.m_RemoteURL
;
2182 int ver
= CAppUtils::GetMsysgitVersion();
2184 if(ver
>= 0x01070203) //above 1.7.0.2
2185 arg
= _T("--progress ");
2188 arg
+= _T("--prune ");
2191 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"),arg
, url
,dlg
.m_RemoteBranchName
);
2192 CProgressDlg progress
;
2194 progress
.m_bAutoCloseOnSuccess
= autoClose
;
2198 progress
.m_PostCmdList
.Add(_T("&Rebase"));
2201 progress
.m_GitCmd
=cmd
;
2202 int userResponse
=progress
.DoModal();
2204 if( (userResponse
==IDC_PROGRESS_BUTTON1
) || ( progress
.m_GitStatus
==0 && dlg
.m_bRebase
) )
2209 dlg
.m_PostButtonTexts
.Add(_T("Email &Patch..."));
2210 dlg
.m_PostButtonTexts
.Add(_T("Restart Rebase"));
2211 int response
= dlg
.DoModal();
2212 if(response
== IDOK
)
2216 if(response
== IDC_REBASE_POST_BUTTON
)
2219 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2221 g_Git
.FixBranchName(dlg
.m_Upstream
),
2222 g_Git
.FixBranchName(dlg
.m_Branch
));
2223 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
2225 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2229 CAppUtils::SendPatchMail(cmd
,out
);
2233 if(response
== IDC_REBASE_POST_BUTTON
+1 )
2236 if(response
== IDCANCEL
)
2245 bool CAppUtils::Push(bool autoClose
)
2249 DWORD exitcode
= 0xFFFFFFFF;
2251 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
2252 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
2257 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2258 //ReportError(temp);
2259 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2264 if(dlg
.DoModal()==IDOK
)
2271 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_URL
);
2275 arg
+= _T("--thin ");
2276 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
2277 arg
+= _T("--tags ");
2279 arg
+= _T("--force ");
2281 int ver
= CAppUtils::GetMsysgitVersion();
2283 if(ver
>= 0x01070203) //above 1.7.0.2
2284 arg
+= _T("--progress ");
2286 if (dlg
.m_bPushAllBranches
)
2288 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2294 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2297 dlg
.m_BranchSourceName
);
2298 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2300 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2304 CProgressDlg progress
;
2305 progress
.m_bAutoCloseOnSuccess
=autoClose
;
2306 progress
.m_GitCmd
=cmd
;
2307 progress
.m_PostCmdList
.Add(_T("&Request pull"));
2308 progress
.m_PostCmdList
.Add(_T("Re&Push"));
2309 int ret
= progress
.DoModal();
2311 if(!progress
.m_GitStatus
)
2313 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2318 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2319 //ReportError(temp);
2320 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2324 if(ret
== IDC_PROGRESS_BUTTON1
)
2326 RequestPull(dlg
.m_BranchRemoteName
);
2328 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2339 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2341 CRequestPullDlg dlg
;
2342 dlg
.m_RepositoryURL
= repositoryUrl
;
2343 dlg
.m_EndRevision
= endrevision
;
2344 if (dlg
.DoModal()==IDOK
)
2347 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2349 CProgressDlg progress
;
2350 progress
.m_GitCmd
=cmd
;
2356 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2358 CString
strDir(szPath
);
2359 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2361 strDir
.AppendChar(_T('\\'));
2363 std::vector
<CString
> vPath
;
2365 bool bSuccess
= false;
2367 for (int i
=0;i
<strDir
.GetLength();++i
)
2369 if (strDir
.GetAt(i
) != _T('\\'))
2371 strTemp
.AppendChar(strDir
.GetAt(i
));
2375 vPath
.push_back(strTemp
);
2376 strTemp
.AppendChar(_T('\\'));
2380 std::vector
<CString
>::const_iterator vIter
;
2381 for (vIter
= vPath
.begin(); vIter
!= vPath
.end(); vIter
++)
2383 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2389 void CAppUtils::RemoveTrailSlash(CString
&path
)
2394 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2396 path
=path
.Left(path
.GetLength()-1);
2402 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2403 CTGitPathList
&pathList
,
2404 CTGitPathList
&selectedList
,
2405 bool bSelectFilesForCommit
,
2408 bool bFailed
= true;
2410 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetConfigValue(_T("user.email")).IsEmpty())
2412 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"),
2413 _T("TortoiseGit"),MB_YESNO
| MB_ICONERROR
) == IDYES
)
2415 CTGitPath
path(g_Git
.m_CurrentDir
);
2416 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2417 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2418 dlg
.SetTreeWidth(220);
2419 dlg
.m_DefaultPage
= _T("gitconfig");
2422 dlg
.HandleRestart();
2433 dlg
.m_sBugID
= bugid
;
2435 dlg
.m_bWholeProject
= bWholeProject
;
2437 dlg
.m_sLogMessage
= sLogMsg
;
2438 dlg
.m_pathList
= pathList
;
2439 dlg
.m_checkedPathList
= selectedList
;
2440 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2441 dlg
.m_bAutoClose
= autoClose
;
2442 if (dlg
.DoModal() == IDOK
)
2444 if (dlg
.m_pathList
.GetCount()==0)
2446 // if the user hasn't changed the list of selected items
2447 // we don't use that list. Because if we would use the list
2448 // of pre-checked items, the dialog would show different
2449 // checked items on the next startup: it would only try
2450 // to check the parent folder (which might not even show)
2451 // instead, we simply use an empty list and let the
2452 // default checking do its job.
2453 if (!dlg
.m_pathList
.IsEqual(pathList
))
2454 selectedList
= dlg
.m_pathList
;
2455 pathList
= dlg
.m_updatedPathList
;
2456 sLogMsg
= dlg
.m_sLogMessage
;
2457 bSelectFilesForCommit
= true;
2459 if( dlg
.m_bPushAfterCommit
)
2461 switch(dlg
.m_PostCmd
)
2463 case GIT_POST_CMD_DCOMMIT
:
2464 CAppUtils::SVNDCommit();
2470 // CGitProgressDlg progDlg;
2471 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2472 // if (parser.HasVal(_T("closeonend")))
2473 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2474 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2475 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2476 // progDlg.SetPathList(dlg.m_pathList);
2477 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2478 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2479 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2480 // progDlg.SetItemCount(dlg.m_itemsCount);
2481 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2482 // progDlg.DoModal();
2483 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2484 // err = (DWORD)progDlg.DidErrorsOccur();
2485 // bFailed = progDlg.DidErrorsOccur();
2486 // bRet = progDlg.DidErrorsOccur();
2487 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2488 // if (DWORD(bFailRepeat)==0)
2489 // bFailed = false; // do not repeat if the user chose not to in the settings.
2496 BOOL
CAppUtils::SVNDCommit()
2498 CSVNDCommitDlg dcommitdlg
;
2499 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2500 if (gitSetting
== _T("")) {
2501 if (dcommitdlg
.DoModal() != IDOK
)
2507 if (dcommitdlg
.m_remember
)
2509 if (dcommitdlg
.m_rmdir
)
2511 gitSetting
= _T("true");
2515 gitSetting
= _T("false");
2517 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2519 CMessageBox::Show(NULL
,_T("Fail to set config"),_T("TortoiseGit"),MB_OK
);
2525 BOOL IsStash
= false;
2526 if(!g_Git
.CheckCleanWorkTree())
2528 if(CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2531 cmd
=_T("git.exe stash");
2532 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
2534 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2546 CProgressDlg progress
;
2547 if (dcommitdlg
.m_rmdir
)
2549 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2553 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2555 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2559 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2562 cmd
=_T("git.exe stash pop");
2563 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
2565 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2580 BOOL
CAppUtils::Merge(CString
*commit
)
2584 dlg
.m_initialRefName
= *commit
;
2586 if(dlg
.DoModal()==IDOK
)
2598 squash
=_T("--squash");
2601 nocommit
=_T("--no-commit");
2603 if(!dlg
.m_strLogMesage
.IsEmpty())
2605 msg
+= _T("-m \"")+dlg
.m_strLogMesage
+_T("\"");
2607 cmd
.Format(_T("git.exe merge %s %s %s %s %s"),
2612 g_Git
.FixBranchName(dlg
.m_VersionName
));
2614 CProgressDlg Prodlg
;
2615 Prodlg
.m_GitCmd
= cmd
;
2619 return !Prodlg
.m_GitStatus
;
2624 void CAppUtils::EditNote(GitRev
*rev
)
2627 dlg
.m_sHintText
=_T("Edit Notes");
2628 dlg
.m_sInputText
= rev
->m_Notes
;
2629 dlg
.m_sTitle
=_T("Edit Notes");
2630 //dlg.m_pProjectProperties = &m_ProjectProperties;
2631 dlg
.m_bUseLogWidth
= true;
2632 if(dlg
.DoModal() == IDOK
)
2635 cmd
=_T("notes add -f -F \"");
2637 CString tempfile
=::GetTempFile();
2638 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
2641 cmd
+= rev
->m_CommitHash
.ToString();
2645 if(git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
,CP_ACP
).GetBuffer()))
2647 CMessageBox::Show(NULL
,_T("Edit Note Fail"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2652 rev
->m_Notes
= dlg
.m_sInputText
;
2656 CMessageBox::Show(NULL
,_T("Edit Note Fail"), _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2658 CFile::Remove(tempfile
);
2663 int CAppUtils::GetMsysgitVersion(CString
*versionstr
)
2666 CString progressarg
;
2669 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
2670 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
2672 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
2675 if(!g_Git
.GetFileModifyTime(gitpath
, &time
) && !versionstr
)
2677 if((DWORD
)time
== regTime
)
2684 version
= *versionstr
;
2687 cmd
= _T("git.exe --version");
2688 if(g_Git
.Run(cmd
, &version
, CP_ACP
))
2690 CMessageBox::Show(NULL
,_T("git have not installed"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2698 CString str
=version
.Tokenize(_T("."),start
);
2699 int space
= str
.ReverseFind(_T(' '));
2700 str
=str
.Mid(space
+1,start
);
2704 version
= version
.Mid(start
);
2706 str
= version
.Tokenize(_T("."),start
);
2708 ver
|= (_ttol(str
)&0xFF)<<16;
2710 str
= version
.Tokenize(_T("."),start
);
2711 ver
|= (_ttol(str
)&0xFF)<<8;
2713 str
= version
.Tokenize(_T("."),start
);
2714 ver
|= (_ttol(str
)&0xFF);
2716 regTime
= time
&0xFFFFFFFF;
2722 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
2724 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
2726 HMODULE hShell
= LoadLibrary(_T("Shell32.dll"));
2729 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
2731 IPropertyStore
*pps
;
2732 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
2733 if (SUCCEEDED(hr
)) {
2736 var
.boolVal
= VARIANT_TRUE
;
2737 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
2741 FreeLibrary(hShell
);
2745 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
2747 ASSERT(dialogname
.GetLength() < 70);
2748 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
2749 WCHAR pathbuf
[MAX_PATH
] = {0};
2751 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
2753 wcscat_s(pathbuf
, L
" - ");
2754 wcscat_s(pathbuf
, dialogname
);
2755 wcscat_s(pathbuf
, L
" - ");
2756 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2757 SetWindowText(hWnd
, pathbuf
);