1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2011 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "TortoiseProc.h"
23 #include "PathUtils.h"
25 //#include "GitProperties.h"
26 #include "StringUtils.h"
27 #include "MessageBox.h"
31 //#include "RepositoryBrowser.h"
32 //#include "BrowseFolder.h"
33 #include "UnicodeUtils.h"
34 #include "ExportDlg.h"
35 #include "ProgressDlg.h"
36 #include "GitAdminDir.h"
37 #include "ProgressDlg.h"
38 #include "BrowseFolder.h"
39 #include "DirFileEnum.h"
40 #include "MessageBox.h"
41 #include "GitStatus.h"
42 #include "CreateBranchTagDlg.h"
43 #include "GitSwitchDlg.h"
45 #include "DeleteConflictDlg.h"
46 #include "ChangedDlg.h"
47 #include "SendMailDlg.h"
48 #include "GITProgressDlg.h"
50 #include "CommitDlg.h"
53 #include "..\Settings\Settings.h"
55 #include "SVNDCommitDlg.h"
56 #include "requestpulldlg.h"
57 #include "PullFetchDlg.h"
58 #include "RebaseDlg.h"
60 #include "StashSave.h"
61 #include "FormatMessageWrapper.h"
62 #include "SmartHandle.h"
64 CAppUtils::CAppUtils(void)
68 CAppUtils::~CAppUtils(void)
72 bool CAppUtils::StashSave()
76 if (dlg
.DoModal() == IDOK
)
79 cmd
= _T("git.exe stash save");
81 if (dlg
.m_bIncludeUntracked
&& CAppUtils::GetMsysgitVersion() >= 0x01070700)
82 cmd
+= _T(" --include-untracked");
84 if (!dlg
.m_sMessage
.IsEmpty())
86 CString message
= dlg
.m_sMessage
;
87 message
.Replace(_T("\""), _T("\"\""));
88 cmd
+= _T(" \"") + message
+ _T("\"");
91 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
93 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
97 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHSUCCESS
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
104 int CAppUtils::StashApply(CString ref
, bool showChanges
/* true */)
107 cmd
= _T("git.exe stash apply ");
108 if (ref
.Find(_T("refs/")) == 0)
110 if (ref
.Find(_T("stash{")) == 0)
111 ref
= _T("stash@") + ref
.Mid(5);
114 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
115 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
116 if (ret
&& !(ret
== 1 && hasConflicts
))
118 CMessageBox::Show(NULL
, CString(MAKEINTRESOURCE(IDS_PROC_STASHAPPLYFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
123 message
.LoadString(IDS_PROC_STASHAPPLYSUCCESS
);
125 message
.LoadString(IDS_PROC_STASHAPPLYFAILEDCONFLICTS
);
128 if(CMessageBox::Show(NULL
,message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
))
129 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
132 dlg
.m_pathList
.AddPath(CTGitPath());
139 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
146 int CAppUtils::StashPop(bool showChanges
/* true */)
149 cmd
=_T("git.exe stash pop ");
151 int ret
= g_Git
.Run(cmd
, &out
, CP_UTF8
);
152 bool hasConflicts
= (out
.Find(_T("CONFLICT")) >= 0);
153 if (ret
&& !(ret
== 1 && hasConflicts
))
155 CMessageBox::Show(NULL
,CString(MAKEINTRESOURCE(IDS_PROC_STASHPOPFAILED
)) + _T("\n") + out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
160 message
.LoadString(IDS_PROC_STASHPOPSUCCESS
);
162 message
.LoadString(IDS_PROC_STASHPOPFAILEDCONFLICTS
);
165 if(CMessageBox::Show(NULL
,CString(message
+ _T("\n") + CString(MAKEINTRESOURCE(IDS_SEECHANGES
)))
166 ,_T("TortoiseGit"),MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
169 dlg
.m_pathList
.AddPath(CTGitPath());
176 CMessageBox::Show(NULL
, message
,_T("TortoiseGit"), MB_OK
| MB_ICONINFORMATION
);
183 bool CAppUtils::GetMimeType(const CTGitPath
& /*file*/, CString
& /*mimetype*/)
186 GitProperties
props(file
, GitRev::REV_WC
, false);
187 for (int i
= 0; i
< props
.GetCount(); ++i
)
189 if (props
.GetItemName(i
).compare(_T("svn:mime-type"))==0)
191 mimetype
= props
.GetItemValue(i
).c_str();
199 BOOL
CAppUtils::StartExtMerge(
200 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
201 const CString
& basename
, const CString
& theirname
, const CString
& yourname
, const CString
& mergedname
, bool bReadOnly
)
204 CRegString regCom
= CRegString(_T("Software\\TortoiseGit\\Merge"));
205 CString ext
= mergedfile
.GetFileExtension();
206 CString com
= regCom
;
207 bool bInternal
= false;
212 // is there an extension specific merge tool?
213 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext
.MakeLower());
214 if (CString(mergetool
) != "")
219 if (GetMimeType(yourfile
, mimetype
) || GetMimeType(theirfile
, mimetype
) || GetMimeType(basefile
, mimetype
))
221 // is there a mime type specific merge tool?
222 CRegString
mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype
);
223 if (CString(mergetool
) != "")
229 if (com
.IsEmpty()||(com
.Left(1).Compare(_T("#"))==0))
233 CRegString
tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE
);
234 com
= tortoiseMergePath
;
237 com
= CPathUtils::GetAppDirectory();
238 com
+= _T("TortoiseMerge.exe");
240 com
= _T("\"") + com
+ _T("\"");
241 com
= com
+ _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
242 com
= com
+ _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
244 // check if the params are set. If not, just add the files to the command line
245 if ((com
.Find(_T("%merged"))<0)&&(com
.Find(_T("%base"))<0)&&(com
.Find(_T("%theirs"))<0)&&(com
.Find(_T("%mine"))<0))
247 com
+= _T(" \"")+basefile
.GetWinPathString()+_T("\"");
248 com
+= _T(" \"")+theirfile
.GetWinPathString()+_T("\"");
249 com
+= _T(" \"")+yourfile
.GetWinPathString()+_T("\"");
250 com
+= _T(" \"")+mergedfile
.GetWinPathString()+_T("\"");
252 if (basefile
.IsEmpty())
254 com
.Replace(_T("/base:%base"), _T(""));
255 com
.Replace(_T("%base"), _T(""));
258 com
.Replace(_T("%base"), _T("\"") + basefile
.GetWinPathString() + _T("\""));
259 if (theirfile
.IsEmpty())
261 com
.Replace(_T("/theirs:%theirs"), _T(""));
262 com
.Replace(_T("%theirs"), _T(""));
265 com
.Replace(_T("%theirs"), _T("\"") + theirfile
.GetWinPathString() + _T("\""));
266 if (yourfile
.IsEmpty())
268 com
.Replace(_T("/mine:%mine"), _T(""));
269 com
.Replace(_T("%mine"), _T(""));
272 com
.Replace(_T("%mine"), _T("\"") + yourfile
.GetWinPathString() + _T("\""));
273 if (mergedfile
.IsEmpty())
275 com
.Replace(_T("/merged:%merged"), _T(""));
276 com
.Replace(_T("%merged"), _T(""));
279 com
.Replace(_T("%merged"), _T("\"") + mergedfile
.GetWinPathString() + _T("\""));
280 if (basename
.IsEmpty())
282 if (basefile
.IsEmpty())
284 com
.Replace(_T("/basename:%bname"), _T(""));
285 com
.Replace(_T("%bname"), _T(""));
289 com
.Replace(_T("%bname"), _T("\"") + basefile
.GetUIFileOrDirectoryName() + _T("\""));
293 com
.Replace(_T("%bname"), _T("\"") + basename
+ _T("\""));
294 if (theirname
.IsEmpty())
296 if (theirfile
.IsEmpty())
298 com
.Replace(_T("/theirsname:%tname"), _T(""));
299 com
.Replace(_T("%tname"), _T(""));
303 com
.Replace(_T("%tname"), _T("\"") + theirfile
.GetUIFileOrDirectoryName() + _T("\""));
307 com
.Replace(_T("%tname"), _T("\"") + theirname
+ _T("\""));
308 if (yourname
.IsEmpty())
310 if (yourfile
.IsEmpty())
312 com
.Replace(_T("/minename:%yname"), _T(""));
313 com
.Replace(_T("%yname"), _T(""));
317 com
.Replace(_T("%yname"), _T("\"") + yourfile
.GetUIFileOrDirectoryName() + _T("\""));
321 com
.Replace(_T("%yname"), _T("\"") + yourname
+ _T("\""));
322 if (mergedname
.IsEmpty())
324 if (mergedfile
.IsEmpty())
326 com
.Replace(_T("/mergedname:%mname"), _T(""));
327 com
.Replace(_T("%mname"), _T(""));
331 com
.Replace(_T("%mname"), _T("\"") + mergedfile
.GetUIFileOrDirectoryName() + _T("\""));
335 com
.Replace(_T("%mname"), _T("\"") + mergedname
+ _T("\""));
337 if ((bReadOnly
)&&(bInternal
))
338 com
+= _T(" /readonly");
340 if(!LaunchApplication(com
, IDS_ERR_EXTMERGESTART
, false))
348 BOOL
CAppUtils::StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
, const CString
& sOriginalDescription
, const CString
& sPatchedDescription
, BOOL bReversed
, BOOL bWait
)
352 viewer
= CPathUtils::GetAppDirectory();
353 viewer
+= _T("TortoiseMerge.exe");
355 viewer
= _T("\"") + viewer
+ _T("\"");
356 viewer
= viewer
+ _T(" /diff:\"") + patchfile
.GetWinPathString() + _T("\"");
357 viewer
= viewer
+ _T(" /patchpath:\"") + dir
.GetWinPathString() + _T("\"");
359 viewer
+= _T(" /reversedpatch");
360 if (!sOriginalDescription
.IsEmpty())
361 viewer
= viewer
+ _T(" /patchoriginal:\"") + sOriginalDescription
+ _T("\"");
362 if (!sPatchedDescription
.IsEmpty())
363 viewer
= viewer
+ _T(" /patchpatched:\"") + sPatchedDescription
+ _T("\"");
364 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
371 CString
CAppUtils::PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
)
373 // Is there a mime type specific diff tool?
375 if (GetMimeType(file1
, mimetype
) || GetMimeType(file2
, mimetype
))
377 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype
);
378 if (!difftool
.IsEmpty())
382 // Is there an extension specific diff tool?
383 CString ext
= file2
.GetFileExtension().MakeLower();
386 CString difftool
= CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext
);
387 if (!difftool
.IsEmpty())
389 // Maybe we should use TortoiseIDiff?
390 if ((ext
== _T(".jpg")) || (ext
== _T(".jpeg")) ||
391 (ext
== _T(".bmp")) || (ext
== _T(".gif")) ||
392 (ext
== _T(".png")) || (ext
== _T(".ico")) ||
393 (ext
== _T(".dib")) || (ext
== _T(".emf")))
396 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
397 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
401 // Finally, pick a generic external diff tool
402 CString difftool
= CRegString(_T("Software\\TortoiseGit\\Diff"));
406 bool CAppUtils::StartExtDiff(
407 const CString
& file1
, const CString
& file2
,
408 const CString
& sName1
, const CString
& sName2
,
409 const DiffFlags
& flags
)
413 CRegDWORD
blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE
);
414 if (!flags
.bBlame
|| !(DWORD
)blamediff
)
416 viewer
= PickDiffTool(file1
, file2
);
417 // If registry entry for a diff program is commented out, use TortoiseMerge.
418 bool bCommentedOut
= viewer
.Left(1) == _T("#");
419 if (flags
.bAlternativeTool
)
421 // Invert external vs. internal diff tool selection.
423 viewer
.Delete(0); // uncomment
427 else if (bCommentedOut
)
431 bool bInternal
= viewer
.IsEmpty();
435 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
436 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
438 viewer
+= _T(" /blame");
440 // check if the params are set. If not, just add the files to the command line
441 if ((viewer
.Find(_T("%base"))<0)&&(viewer
.Find(_T("%mine"))<0))
443 viewer
+= _T(" \"")+file1
+_T("\"");
444 viewer
+= _T(" \"")+file2
+_T("\"");
446 if (viewer
.Find(_T("%base")) >= 0)
448 viewer
.Replace(_T("%base"), _T("\"")+file1
+_T("\""));
450 if (viewer
.Find(_T("%mine")) >= 0)
452 viewer
.Replace(_T("%mine"), _T("\"")+file2
+_T("\""));
455 if (sName1
.IsEmpty())
456 viewer
.Replace(_T("%bname"), _T("\"") + file1
+ _T("\""));
458 viewer
.Replace(_T("%bname"), _T("\"") + sName1
+ _T("\""));
460 if (sName2
.IsEmpty())
461 viewer
.Replace(_T("%yname"), _T("\"") + file2
+ _T("\""));
463 viewer
.Replace(_T("%yname"), _T("\"") + sName2
+ _T("\""));
465 if (flags
.bReadOnly
&& bInternal
)
466 viewer
+= _T(" /readonly");
468 return LaunchApplication(viewer
, IDS_ERR_EXTDIFFSTART
, flags
.bWait
);
471 BOOL
CAppUtils::StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
)
474 CRegString v
= CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
476 if (viewer
.IsEmpty() || (viewer
.Left(1).Compare(_T("#"))==0))
479 viewer
= CPathUtils::GetAppDirectory();
480 viewer
+= _T("TortoiseUDiff.exe");
481 // enquote the path to TortoiseUDiff
482 viewer
= _T("\"") + viewer
+ _T("\"");
484 viewer
= viewer
+ _T(" /patchfile:%1 /title:\"%title\"");
487 if (viewer
.Find(_T("%1"))>=0)
489 if (viewer
.Find(_T("\"%1\"")) >= 0)
490 viewer
.Replace(_T("%1"), patchfile
);
492 viewer
.Replace(_T("%1"), _T("\"") + patchfile
+ _T("\""));
495 viewer
+= _T(" \"") + patchfile
+ _T("\"");
496 if (viewer
.Find(_T("%title")) >= 0)
498 viewer
.Replace(_T("%title"), title
);
501 if(!LaunchApplication(viewer
, IDS_ERR_DIFFVIEWSTART
, !!bWait
))
508 BOOL
CAppUtils::StartTextViewer(CString file
)
511 CRegString txt
= CRegString(_T(".txt\\"), _T(""), FALSE
, HKEY_CLASSES_ROOT
);
513 viewer
= viewer
+ _T("\\Shell\\Open\\Command\\");
514 CRegString txtexe
= CRegString(viewer
, _T(""), FALSE
, HKEY_CLASSES_ROOT
);
517 DWORD len
= ExpandEnvironmentStrings(viewer
, NULL
, 0);
518 TCHAR
* buf
= new TCHAR
[len
+1];
519 ExpandEnvironmentStrings(viewer
, buf
, len
);
522 len
= ExpandEnvironmentStrings(file
, NULL
, 0);
523 buf
= new TCHAR
[len
+1];
524 ExpandEnvironmentStrings(file
, buf
, len
);
527 file
= _T("\"")+file
+_T("\"");
528 if (viewer
.IsEmpty())
530 viewer
= _T("RUNDLL32 Shell32,OpenAs_RunDLL");
532 if (viewer
.Find(_T("\"%1\"")) >= 0)
534 viewer
.Replace(_T("\"%1\""), file
);
536 else if (viewer
.Find(_T("%1")) >= 0)
538 viewer
.Replace(_T("%1"), file
);
546 if(!LaunchApplication(viewer
, IDS_ERR_TEXTVIEWSTART
, false))
553 BOOL
CAppUtils::CheckForEmptyDiff(const CTGitPath
& sDiffPath
)
556 CAutoFile hFile
= ::CreateFile(sDiffPath
.GetWinPath(), GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, NULL
, NULL
);
559 length
= ::GetFileSize(hFile
, NULL
);
566 void CAppUtils::CreateFontForLogs(CFont
& fontToCreate
)
569 HDC hScreenDC
= ::GetDC(NULL
);
570 logFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC
, LOGPIXELSY
), 72);
571 ::ReleaseDC(NULL
, hScreenDC
);
573 logFont
.lfEscapement
= 0;
574 logFont
.lfOrientation
= 0;
575 logFont
.lfWeight
= FW_NORMAL
;
576 logFont
.lfItalic
= 0;
577 logFont
.lfUnderline
= 0;
578 logFont
.lfStrikeOut
= 0;
579 logFont
.lfCharSet
= DEFAULT_CHARSET
;
580 logFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
581 logFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
582 logFont
.lfQuality
= DRAFT_QUALITY
;
583 logFont
.lfPitchAndFamily
= FF_DONTCARE
| FIXED_PITCH
;
584 _tcscpy_s(logFont
.lfFaceName
, 32, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
585 VERIFY(fontToCreate
.CreateFontIndirect(&logFont
));
588 bool CAppUtils::LaunchPAgent(CString
*keyfile
,CString
* pRemote
)
602 cmd
.Format(_T("remote.%s.puttykeyfile"),remote
);
603 key
= g_Git
.GetConfigValue(cmd
);
605 key
= key
.Tokenize(_T("\n"),start
);
613 CString proc
=CPathUtils::GetAppDirectory();
614 proc
+= _T("pageant.exe \"");
618 CString tempfile
= GetTempFile();
619 ::DeleteFile(tempfile
);
621 proc
+= _T(" -c \"");
622 proc
+= CPathUtils::GetAppDirectory();
623 proc
+= _T("touch.exe\"");
628 bool b
= LaunchApplication(proc
, IDS_ERR_PAGEANT
, true, &CPathUtils::GetAppDirectory());
633 while(!::PathFileExists(tempfile
))
638 break; //timeout 5 minutes
643 CMessageBox::Show(NULL
, IDS_ERR_PAEGENTTIMEOUT
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
645 ::DeleteFile(tempfile
);
648 bool CAppUtils::LaunchAlternativeEditor(const CString
& filename
)
650 CString editTool
= CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
651 if (editTool
.IsEmpty() || (editTool
.Left(1).Compare(_T("#"))==0)) {
652 editTool
= CPathUtils::GetAppDirectory() + _T("notepad2.exe");
656 sCmd
.Format(_T("\"%s\" \"%s\""), editTool
, filename
);
658 LaunchApplication(sCmd
, NULL
, false);
661 bool CAppUtils::LaunchRemoteSetting()
663 CTGitPath
path(g_Git
.m_CurrentDir
);
664 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
665 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
666 //dlg.SetTreeWidth(220);
667 dlg
.m_DefaultPage
= _T("gitremote");
674 * Launch the external blame viewer
676 bool CAppUtils::LaunchTortoiseBlame(const CString
& sBlameFile
,CString Rev
,const CString
& sParams
)
678 CString viewer
= _T("\"") + CPathUtils::GetAppDirectory();
679 viewer
+= _T("TortoiseGitBlame.exe");
680 viewer
+= _T("\" \"") + sBlameFile
+ _T("\"");
681 //viewer += _T(" \"") + sLogFile + _T("\"");
682 //viewer += _T(" \"") + sOriginalFile + _T("\"");
683 if(!Rev
.IsEmpty() && Rev
!= GIT_REV_ZERO
)
684 viewer
+= CString(_T(" /rev:"))+Rev
;
685 viewer
+= _T(" ")+sParams
;
687 return LaunchApplication(viewer
, IDS_ERR_TGITBLAME
, false);
690 bool CAppUtils::FormatTextInRichEditControl(CWnd
* pWnd
)
695 bool bStyled
= false;
696 pWnd
->GetWindowText(sText
);
697 // the rich edit control doesn't count the CR char!
698 // to be exact: CRLF is treated as one char.
701 // style each line separately
706 nNewlinePos
= sText
.Find('\n', offset
);
707 CString sLine
= sText
.Mid(offset
);
709 sLine
= sLine
.Left(nNewlinePos
-offset
);
712 while (FindStyleChars(sLine
, '*', start
, end
))
714 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
715 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
717 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
718 format
.cbSize
= sizeof(CHARFORMAT2
);
719 format
.dwMask
= CFM_BOLD
;
720 format
.dwEffects
= CFE_BOLD
;
721 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
727 while (FindStyleChars(sLine
, '^', start
, end
))
729 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
730 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
732 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
733 format
.cbSize
= sizeof(CHARFORMAT2
);
734 format
.dwMask
= CFM_ITALIC
;
735 format
.dwEffects
= CFE_ITALIC
;
736 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
742 while (FindStyleChars(sLine
, '_', start
, end
))
744 CHARRANGE range
= {(LONG
)start
+offset
, (LONG
)end
+offset
};
745 pWnd
->SendMessage(EM_EXSETSEL
, NULL
, (LPARAM
)&range
);
747 SecureZeroMemory(&format
, sizeof(CHARFORMAT2
));
748 format
.cbSize
= sizeof(CHARFORMAT2
);
749 format
.dwMask
= CFM_UNDERLINE
;
750 format
.dwEffects
= CFE_UNDERLINE
;
751 pWnd
->SendMessage(EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
755 offset
= nNewlinePos
+1;
756 } while(nNewlinePos
>=0);
760 bool CAppUtils::FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
)
763 bool bFoundMarker
= false;
764 // find a starting marker
765 while (sText
[i
] != 0)
767 if (sText
[i
] == stylechar
)
769 if (((i
+1)<sText
.GetLength())&&(IsCharAlphaNumeric(sText
[i
+1])) &&
770 (((i
>0)&&(!IsCharAlphaNumeric(sText
[i
-1])))||(i
==0)))
782 // find ending marker
783 bFoundMarker
= false;
784 while (sText
[i
] != 0)
786 if (sText
[i
] == stylechar
)
788 if ((IsCharAlphaNumeric(sText
[i
-1])) &&
789 ((((i
+1)<sText
.GetLength())&&(!IsCharAlphaNumeric(sText
[i
+1])))||(i
+1)==sText
.GetLength()))
802 CString
CAppUtils::GetProjectNameFromURL(CString url
)
805 while (name
.IsEmpty() || (name
.CompareNoCase(_T("branches"))==0) ||
806 (name
.CompareNoCase(_T("tags"))==0) ||
807 (name
.CompareNoCase(_T("trunk"))==0))
809 name
= url
.Mid(url
.ReverseFind('/')+1);
810 url
= url
.Left(url
.ReverseFind('/'));
812 if ((name
.Compare(_T("svn")) == 0)||(name
.Compare(_T("svnroot")) == 0))
814 // a name of svn or svnroot indicates that it's not really the project name. In that
815 // case, we try the first part of the URL
816 // of course, this won't work in all cases (but it works for Google project hosting)
817 url
.Replace(_T("http://"), _T(""));
818 url
.Replace(_T("https://"), _T(""));
819 url
.Replace(_T("svn://"), _T(""));
820 url
.Replace(_T("svn+ssh://"), _T(""));
821 url
.TrimLeft(_T("/"));
822 name
= url
.Left(url
.Find('.'));
827 bool CAppUtils::StartShowUnifiedDiff(HWND
/*hWnd*/, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
828 const CTGitPath
& /*url2*/, const git_revnum_t
& rev2
,
829 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
830 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */, bool /* blame = false */, bool bMerge
)
833 CString tempfile
=GetTempFile();
835 if(rev2
== GitRev::GetWorkingCopy())
837 cmd
.Format(_T("git.exe diff --stat -p %s "), rev1
);
845 cmd
.Format(_T("git.exe diff-tree -r -p %s --stat %s %s"),merge
, rev1
,rev2
);
848 if( !url1
.IsEmpty() )
851 cmd
+= url1
.GetGitPathString();
854 g_Git
.RunLogFile(cmd
,tempfile
);
855 CAppUtils::StartUnifiedDiffViewer(tempfile
, rev1
+ _T(":") + rev2
);
860 sCmd
.Format(_T("%s /command:showcompare /unified"),
861 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
862 sCmd
+= _T(" /url1:\"") + url1
.GetGitPathString() + _T("\"");
864 sCmd
+= _T(" /revision1:") + rev1
.ToString();
865 sCmd
+= _T(" /url2:\"") + url2
.GetGitPathString() + _T("\"");
867 sCmd
+= _T(" /revision2:") + rev2
.ToString();
869 sCmd
+= _T(" /pegrevision:") + peg
.ToString();
870 if (headpeg
.IsValid())
871 sCmd
+= _T(" /headpegrevision:") + headpeg
.ToString();
874 sCmd
+= _T(" /alternatediff");
877 sCmd
+= _T(" /ignoreancestry");
881 sCmd
+= _T(" /hwnd:");
883 _stprintf_s(buf
, 30, _T("%d"), hWnd
);
887 return CAppUtils::LaunchApplication(sCmd
, NULL
, false);
893 bool CAppUtils::Export(CString
*BashHash
)
897 // ask from where the export has to be done
900 dlg
.m_Revision
=*BashHash
;
902 if (dlg
.DoModal() == IDOK
)
905 cmd
.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s"),
906 dlg
.m_strExportDirectory
, g_Git
.FixBranchName(dlg
.m_VersionName
));
916 bool CAppUtils::CreateBranchTag(bool IsTag
,CString
*CommitHash
, bool switch_new_brach
)
918 CCreateBranchTagDlg dlg
;
920 dlg
.m_bSwitch
=switch_new_brach
;
923 dlg
.m_Base
= *CommitHash
;
925 if(dlg
.DoModal()==IDOK
)
930 if(dlg
.m_bTrack
== TRUE
)
931 track
=_T(" --track ");
932 else if(dlg
.m_bTrack
== FALSE
)
933 track
=_T(" --no-track");
944 cmd
.Format(_T("git.exe tag %s %s %s %s"),
948 g_Git
.FixBranchName(dlg
.m_VersionName
)
951 CString tempfile
=::GetTempFile();
952 if(!dlg
.m_Message
.Trim().IsEmpty())
954 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_Message
);
955 cmd
+= _T(" -F ")+tempfile
;
960 cmd
.Format(_T("git.exe branch %s %s %s %s"),
964 g_Git
.FixBranchName(dlg
.m_VersionName
)
968 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
970 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
972 if( !IsTag
&& dlg
.m_bSwitch
)
974 // it is a new branch and the user has requested to switch to it
975 cmd
.Format(_T("git.exe checkout %s"), dlg
.m_BranchTagName
);
976 g_Git
.Run(cmd
,&out
,CP_UTF8
);
977 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
985 bool CAppUtils::Switch(CString
*CommitHash
, CString initialRefName
, bool autoclose
)
989 dlg
.m_Base
=*CommitHash
;
990 if(!initialRefName
.IsEmpty())
991 dlg
.m_initialRefName
= initialRefName
;
993 if (dlg
.DoModal() == IDOK
)
997 branch
= dlg
.m_NewBranch
;
999 return PerformSwitch(dlg
.m_VersionName
, dlg
.m_bForce
== TRUE
, branch
, dlg
.m_bBranchOverride
== TRUE
, dlg
.m_bTrack
== TRUE
, autoclose
);
1004 bool CAppUtils::PerformSwitch(CString ref
, bool bForce
/* false */, CString sNewBranch
/* CString() */, bool bBranchOverride
/* false */, bool bTrack
/* false */, bool autoClose
/* false */)
1011 if(!sNewBranch
.IsEmpty()){
1012 if (bBranchOverride
)
1014 branch
.Format(_T("-B %s"), sNewBranch
);
1018 branch
.Format(_T("-b %s"), sNewBranch
);
1021 track
= _T("--track");
1026 cmd
.Format(_T("git.exe checkout %s %s %s %s"),
1030 g_Git
.FixBranchName(ref
));
1032 CProgressDlg progress
;
1033 progress
.m_bAutoCloseOnSuccess
= autoClose
;
1034 progress
.m_GitCmd
= cmd
;
1036 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1037 if (gitPath
.HasSubmodules())
1038 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1040 int ret
= progress
.DoModal();
1041 if (gitPath
.HasSubmodules() && ret
== IDC_PROGRESS_BUTTON1
)
1044 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1046 RunTortoiseProc(sCmd
);
1049 else if (ret
== IDOK
)
1055 bool CAppUtils::IgnoreFile(CTGitPathList
&path
,bool IsMask
)
1058 ignorefile
=g_Git
.m_CurrentDir
+_T("\\");
1062 ignorefile
+=path
.GetCommonRoot().GetDirectory().GetWinPathString()+_T("\\.gitignore");
1067 ignorefile
+= _T("\\.gitignore");
1071 if(!file
.Open(ignorefile
,CFile::modeCreate
|CFile::modeReadWrite
|CFile::modeNoTruncate
))
1073 CMessageBox::Show(NULL
,ignorefile
+_T(" Open Failure"),_T("TortoiseGit"),MB_OK
);
1080 for(int i
=0;i
<path
.GetCount();i
++)
1082 CString ignorePattern
;
1085 ignorePattern
+= _T("*") + path
[i
].GetFileExtension();
1089 ignorePattern
+= _T("/") + path
[i
].GetGitPathString();
1091 file
.WriteString(_T("\n") + ignorePattern
);
1105 bool CAppUtils::GitReset(CString
*CommitHash
,int type
)
1108 dlg
.m_ResetType
=type
;
1109 dlg
.m_ResetToVersion
=*CommitHash
;
1110 if (dlg
.DoModal() == IDOK
)
1114 switch(dlg
.m_ResetType
)
1129 cmd
.Format(_T("git.exe reset %s %s"),type
, *CommitHash
);
1131 CProgressDlg progress
;
1132 progress
.m_GitCmd
=cmd
;
1134 CTGitPath gitPath
= g_Git
.m_CurrentDir
;
1135 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2)
1136 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE
)));
1138 int ret
= progress
.DoModal();
1139 if (gitPath
.HasSubmodules() && dlg
.m_ResetType
== 2 && ret
== IDC_PROGRESS_BUTTON1
)
1142 sCmd
.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git
.m_CurrentDir
);
1144 RunTortoiseProc(sCmd
);
1147 else if (ret
== IDOK
)
1154 void CAppUtils::DescribeFile(bool mode
, bool base
,CString
&descript
)
1158 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_DELETE
));
1163 descript
= CString(MAKEINTRESOURCE(IDS_SVNACTION_MODIFIED
));
1166 descript
= CString(MAKEINTRESOURCE(IDS_PROC_CREATED
));
1170 void CAppUtils::RemoveTempMergeFile(CTGitPath
&path
)
1172 CString tempmergefile
;
1175 tempmergefile
= CAppUtils::GetMergeTempFile(_T("LOCAL"),path
);
1176 CFile::Remove(tempmergefile
);
1183 tempmergefile
= CAppUtils::GetMergeTempFile(_T("REMOTE"),path
);
1184 CFile::Remove(tempmergefile
);
1191 tempmergefile
= CAppUtils::GetMergeTempFile(_T("BASE"),path
);
1192 CFile::Remove(tempmergefile
);
1197 CString
CAppUtils::GetMergeTempFile(CString type
,CTGitPath
&merge
)
1200 file
=g_Git
.m_CurrentDir
+_T("\\") + merge
.GetWinPathString()+_T(".")+type
+merge
.GetFileExtension();
1205 bool CAppUtils::ConflictEdit(CTGitPath
&path
,bool /*bAlternativeTool*/,bool revertTheirMy
)
1209 CTGitPath merge
=path
;
1210 CTGitPath directory
= merge
.GetDirectory();
1212 // we have the conflicted file (%merged)
1213 // now look for the other required files
1215 //stat.GetStatus(merge);
1216 //if (stat.status == NULL)
1222 cmd
.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge
.GetGitPathString());
1224 if (g_Git
.Run(cmd
, &vector
))
1230 list
.ParserFromLsFile(vector
);
1232 if(list
.GetCount() == 0)
1239 mine
.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge
));
1240 theirs
.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge
));
1241 base
.SetFromGit(GetMergeTempFile(_T("BASE"),merge
));
1245 //format=_T("git.exe cat-file blob \":%d:%s\"");
1246 format
= _T("git checkout-index --temp --stage=%d -- \"%s\"");
1248 //create a empty file, incase stage is not three
1249 tempfile
.Open(mine
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1251 tempfile
.Open(theirs
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1253 tempfile
.Open(base
.GetWinPathString(),CFile::modeCreate
|CFile::modeReadWrite
);
1256 bool b_base
=false, b_local
=false, b_remote
=false;
1258 for(int i
=0;i
<list
.GetCount();i
++)
1265 if( list
[i
].m_Stage
== 1)
1267 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1269 outfile
= base
.GetWinPathString();
1272 if( list
[i
].m_Stage
== 2 )
1274 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1276 outfile
= mine
.GetWinPathString();
1279 if( list
[i
].m_Stage
== 3 )
1281 cmd
.Format(format
, list
[i
].m_Stage
, list
[i
].GetGitPathString());
1283 outfile
= theirs
.GetWinPathString();
1285 CString output
, err
;
1286 if(!outfile
.IsEmpty())
1287 if (!g_Git
.Run(cmd
, &output
, &err
, CP_UTF8
))
1291 file
= output
.Tokenize(_T("\t"), start
);
1292 ::MoveFileEx(file
,outfile
,MOVEFILE_REPLACE_EXISTING
|MOVEFILE_COPY_ALLOWED
);
1296 CMessageBox::Show(NULL
, output
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1300 if(b_local
&& b_remote
)
1302 merge
.SetFromWin(g_Git
.m_CurrentDir
+_T("\\")+merge
.GetWinPathString());
1304 bRet
= !!CAppUtils::StartExtMerge(base
,mine
, theirs
, merge
,_T("BASE"),_T("LOCAL"),_T("REMOTE"));
1306 bRet
= !!CAppUtils::StartExtMerge(base
, theirs
, mine
, merge
,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1311 CFile::Remove(mine
.GetWinPathString());
1312 CFile::Remove(theirs
.GetWinPathString());
1313 CFile::Remove(base
.GetWinPathString());
1315 CDeleteConflictDlg dlg
;
1316 DescribeFile(b_local
, b_base
,dlg
.m_LocalStatus
);
1317 DescribeFile(b_remote
,b_base
,dlg
.m_RemoteStatus
);
1318 dlg
.m_bShowModifiedButton
=b_base
;
1319 dlg
.m_File
=merge
.GetGitPathString();
1320 if(dlg
.DoModal() == IDOK
)
1325 cmd
.Format(_T("git.exe rm -- \"%s\""),merge
.GetGitPathString());
1328 cmd
.Format(_T("git.exe add -- \"%s\""),merge
.GetGitPathString());
1330 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1332 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
1342 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1343 base
, theirs
, mine
, merge
);
1346 if (stat
.status
->text_status
== svn_wc_status_conflicted
)
1348 // we have a text conflict, use our merge tool to resolve the conflict
1350 CTSVNPath
theirs(directory
);
1351 CTSVNPath
mine(directory
);
1352 CTSVNPath
base(directory
);
1353 bool bConflictData
= false;
1355 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_new
))
1357 theirs
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_new
));
1358 bConflictData
= true;
1360 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_old
))
1362 base
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_old
));
1363 bConflictData
= true;
1365 if ((stat
.status
->entry
)&&(stat
.status
->entry
->conflict_wrk
))
1367 mine
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->conflict_wrk
));
1368 bConflictData
= true;
1375 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1376 base
, theirs
, mine
, merge
);
1379 if (stat
.status
->prop_status
== svn_wc_status_conflicted
)
1381 // we have a property conflict
1382 CTSVNPath
prej(directory
);
1383 if ((stat
.status
->entry
)&&(stat
.status
->entry
->prejfile
))
1385 prej
.AppendPathString(CUnicodeUtils::GetUnicode(stat
.status
->entry
->prejfile
));
1386 // there's a problem: the prej file contains a _description_ of the conflict, and
1387 // that description string might be translated. That means we have no way of parsing
1388 // the file to find out the conflicting values.
1389 // The only thing we can do: show a dialog with the conflict description, then
1390 // let the user either accept the existing property or open the property edit dialog
1391 // to manually change the properties and values. And a button to mark the conflict as
1393 CEditPropConflictDlg dlg
;
1394 dlg
.SetPrejFile(prej
);
1395 dlg
.SetConflictedItem(merge
);
1396 bRet
= (dlg
.DoModal() != IDCANCEL
);
1400 if (stat
.status
->tree_conflict
)
1402 // we have a tree conflict
1404 const SVNInfoData
* pInfoData
= info
.GetFirstFileInfo(merge
, SVNRev(), SVNRev());
1407 if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_text
)
1409 CTSVNPath
theirs(directory
);
1410 CTSVNPath
mine(directory
);
1411 CTSVNPath
base(directory
);
1412 bool bConflictData
= false;
1414 if (pInfoData
->treeconflict_theirfile
)
1416 theirs
.AppendPathString(pInfoData
->treeconflict_theirfile
);
1417 bConflictData
= true;
1419 if (pInfoData
->treeconflict_basefile
)
1421 base
.AppendPathString(pInfoData
->treeconflict_basefile
);
1422 bConflictData
= true;
1424 if (pInfoData
->treeconflict_myfile
)
1426 mine
.AppendPathString(pInfoData
->treeconflict_myfile
);
1427 bConflictData
= true;
1434 bRet
= !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool
),
1435 base
, theirs
, mine
, merge
);
1437 else if (pInfoData
->treeconflict_kind
== svn_wc_conflict_kind_tree
)
1439 CString sConflictAction
;
1440 CString sConflictReason
;
1441 CString sResolveTheirs
;
1442 CString sResolveMine
;
1443 CTSVNPath treeConflictPath
= CTSVNPath(pInfoData
->treeconflict_path
);
1444 CString sItemName
= treeConflictPath
.GetUIFileOrDirectoryName();
1446 if (pInfoData
->treeconflict_nodekind
== svn_node_file
)
1448 switch (pInfoData
->treeconflict_operation
)
1450 case svn_wc_operation_update
:
1451 switch (pInfoData
->treeconflict_action
)
1453 case svn_wc_conflict_action_edit
:
1454 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEEDIT
, (LPCTSTR
)sItemName
);
1455 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1457 case svn_wc_conflict_action_add
:
1458 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEADD
, (LPCTSTR
)sItemName
);
1459 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1461 case svn_wc_conflict_action_delete
:
1462 sConflictAction
.Format(IDS_TREECONFLICT_FILEUPDATEDELETE
, (LPCTSTR
)sItemName
);
1463 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1467 case svn_wc_operation_switch
:
1468 switch (pInfoData
->treeconflict_action
)
1470 case svn_wc_conflict_action_edit
:
1471 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHEDIT
, (LPCTSTR
)sItemName
);
1472 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1474 case svn_wc_conflict_action_add
:
1475 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHADD
, (LPCTSTR
)sItemName
);
1476 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1478 case svn_wc_conflict_action_delete
:
1479 sConflictAction
.Format(IDS_TREECONFLICT_FILESWITCHDELETE
, (LPCTSTR
)sItemName
);
1480 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1484 case svn_wc_operation_merge
:
1485 switch (pInfoData
->treeconflict_action
)
1487 case svn_wc_conflict_action_edit
:
1488 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEEDIT
, (LPCTSTR
)sItemName
);
1489 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1491 case svn_wc_conflict_action_add
:
1492 sResolveTheirs
.Format(IDS_TREECONFLICT_FILEMERGEADD
, (LPCTSTR
)sItemName
);
1493 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE
);
1495 case svn_wc_conflict_action_delete
:
1496 sConflictAction
.Format(IDS_TREECONFLICT_FILEMERGEDELETE
, (LPCTSTR
)sItemName
);
1497 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1503 else if (pInfoData
->treeconflict_nodekind
== svn_node_dir
)
1505 switch (pInfoData
->treeconflict_operation
)
1507 case svn_wc_operation_update
:
1508 switch (pInfoData
->treeconflict_action
)
1510 case svn_wc_conflict_action_edit
:
1511 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEEDIT
, (LPCTSTR
)sItemName
);
1512 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1514 case svn_wc_conflict_action_add
:
1515 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEADD
, (LPCTSTR
)sItemName
);
1516 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1518 case svn_wc_conflict_action_delete
:
1519 sConflictAction
.Format(IDS_TREECONFLICT_DIRUPDATEDELETE
, (LPCTSTR
)sItemName
);
1520 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1524 case svn_wc_operation_switch
:
1525 switch (pInfoData
->treeconflict_action
)
1527 case svn_wc_conflict_action_edit
:
1528 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHEDIT
, (LPCTSTR
)sItemName
);
1529 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1531 case svn_wc_conflict_action_add
:
1532 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHADD
, (LPCTSTR
)sItemName
);
1533 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1535 case svn_wc_conflict_action_delete
:
1536 sConflictAction
.Format(IDS_TREECONFLICT_DIRSWITCHDELETE
, (LPCTSTR
)sItemName
);
1537 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1541 case svn_wc_operation_merge
:
1542 switch (pInfoData
->treeconflict_action
)
1544 case svn_wc_conflict_action_edit
:
1545 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEEDIT
, (LPCTSTR
)sItemName
);
1546 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1548 case svn_wc_conflict_action_add
:
1549 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEADD
, (LPCTSTR
)sItemName
);
1550 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR
);
1552 case svn_wc_conflict_action_delete
:
1553 sConflictAction
.Format(IDS_TREECONFLICT_DIRMERGEDELETE
, (LPCTSTR
)sItemName
);
1554 sResolveTheirs
.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR
);
1562 switch (pInfoData
->treeconflict_reason
)
1564 case svn_wc_conflict_reason_edited
:
1565 uReasonID
= IDS_TREECONFLICT_REASON_EDITED
;
1566 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1568 case svn_wc_conflict_reason_obstructed
:
1569 uReasonID
= IDS_TREECONFLICT_REASON_OBSTRUCTED
;
1570 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1572 case svn_wc_conflict_reason_deleted
:
1573 uReasonID
= IDS_TREECONFLICT_REASON_DELETED
;
1574 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1576 case svn_wc_conflict_reason_added
:
1577 uReasonID
= IDS_TREECONFLICT_REASON_ADDED
;
1578 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1580 case svn_wc_conflict_reason_missing
:
1581 uReasonID
= IDS_TREECONFLICT_REASON_MISSING
;
1582 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_REMOVEDIR
: IDS_TREECONFLICT_RESOLVE_REMOVEFILE
);
1584 case svn_wc_conflict_reason_unversioned
:
1585 uReasonID
= IDS_TREECONFLICT_REASON_UNVERSIONED
;
1586 sResolveMine
.LoadString(pInfoData
->treeconflict_nodekind
== svn_node_dir
? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR
: IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE
);
1589 sConflictReason
.Format(uReasonID
, (LPCTSTR
)sConflictAction
);
1591 CTreeConflictEditorDlg dlg
;
1592 dlg
.SetConflictInfoText(sConflictReason
);
1593 dlg
.SetResolveTexts(sResolveTheirs
, sResolveMine
);
1594 dlg
.SetPath(treeConflictPath
);
1595 INT_PTR dlgRet
= dlg
.DoModal();
1596 bRet
= (dlgRet
!= IDCANCEL
);
1604 bool CAppUtils::IsSSHPutty()
1606 CString sshclient
=g_Git
.m_Environment
.GetEnv(_T("GIT_SSH"));
1607 sshclient
=sshclient
.MakeLower();
1608 if(sshclient
.Find(_T("plink.exe"),0)>=0)
1615 CString
CAppUtils::GetClipboardLink()
1617 if (!OpenClipboard(NULL
))
1620 CString sClipboardText
;
1621 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
1624 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
1625 sClipboardText
= CString(lpstr
);
1628 hglb
= GetClipboardData(CF_UNICODETEXT
);
1631 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
1632 sClipboardText
= lpstr
;
1637 if(!sClipboardText
.IsEmpty())
1639 if(sClipboardText
[0] == _T('\"') && sClipboardText
[sClipboardText
.GetLength()-1] == _T('\"'))
1640 sClipboardText
=sClipboardText
.Mid(1,sClipboardText
.GetLength()-2);
1642 if(sClipboardText
.Find( _T("http://")) == 0)
1643 return sClipboardText
;
1645 if(sClipboardText
.Find( _T("https://")) == 0)
1646 return sClipboardText
;
1648 if(sClipboardText
.Find( _T("git://")) == 0)
1649 return sClipboardText
;
1651 if(sClipboardText
.Find( _T("ssh://")) == 0)
1652 return sClipboardText
;
1654 if(sClipboardText
.GetLength()>=2)
1655 if( sClipboardText
[1] == _T(':') )
1656 if( (sClipboardText
[0] >= 'A' && sClipboardText
[0] <= 'Z')
1657 || (sClipboardText
[0] >= 'a' && sClipboardText
[0] <= 'z') )
1658 return sClipboardText
;
1661 return CString(_T(""));
1664 CString
CAppUtils::ChooseRepository(CString
*path
)
1666 CBrowseFolder browseFolder
;
1667 CRegString regLastResopitory
= CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
1669 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
1670 CString strCloneDirectory
;
1672 strCloneDirectory
=*path
;
1675 strCloneDirectory
= regLastResopitory
;
1679 title
.LoadString(IDS_CHOOSE_REPOSITORY
);
1681 browseFolder
.SetInfo(title
);
1683 if (browseFolder
.Show(NULL
, strCloneDirectory
) == CBrowseFolder::OK
)
1685 regLastResopitory
= strCloneDirectory
;
1686 return strCloneDirectory
;
1694 bool CAppUtils::SendPatchMail(CTGitPathList
&list
,bool autoclose
)
1698 dlg
.m_PathList
= list
;
1700 if(dlg
.DoModal()==IDOK
)
1702 if(dlg
.m_PathList
.GetCount() == 0)
1705 CGitProgressDlg progDlg
;
1707 theApp
.m_pMainWnd
= &progDlg
;
1708 progDlg
.SetCommand(CGitProgressDlg::GitProgress_SendMail
);
1710 progDlg
.SetAutoClose(autoclose
);
1712 progDlg
.SetPathList(dlg
.m_PathList
);
1713 //ProjectProperties props;
1714 //props.ReadPropsPathList(dlg.m_pathList);
1715 //progDlg.SetProjectProperties(props);
1716 progDlg
.SetItemCount(dlg
.m_PathList
.GetCount());
1719 if(dlg
.m_bAttachment
)
1720 flags
|= SENDMAIL_ATTACHMENT
;
1722 flags
|= SENDMAIL_COMBINED
;
1724 flags
|= SENDMAIL_MAPI
;
1726 progDlg
.SetSendMailOption(dlg
.m_To
,dlg
.m_CC
,dlg
.m_Subject
,flags
);
1735 bool CAppUtils::SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
,bool autoclose
)
1738 CString log
=formatpatchoutput
;
1739 int start
=log
.Find(cmd
);
1741 CString one
=log
.Tokenize(_T("\n"),start
);
1747 CString one
=log
.Tokenize(_T("\n"),start
);
1749 if(one
.IsEmpty() || one
== _T("Success"))
1751 one
.Replace(_T('/'),_T('\\'));
1753 path
.SetFromWin(one
);
1756 if (list
.GetCount() > 0)
1758 return SendPatchMail(list
, autoclose
);
1762 CMessageBox::Show(NULL
, IDS_ERR_NOPATCHES
, IDS_APPNAME
, MB_ICONINFORMATION
);
1768 int CAppUtils::GetLogOutputEncode(CGit
*pGit
)
1773 output
= pGit
->GetConfigValue(_T("i18n.logOutputEncoding"));
1774 if(output
.IsEmpty())
1776 output
= pGit
->GetConfigValue(_T("i18n.commitencoding"));
1777 if(output
.IsEmpty())
1781 output
=output
.Tokenize(_T("\n"),start
);
1782 return CUnicodeUtils::GetCPCode(output
);
1787 output
=output
.Tokenize(_T("\n"),start
);
1788 return CUnicodeUtils::GetCPCode(output
);
1791 int CAppUtils::GetCommitTemplate(CString
&temp
)
1795 output
= g_Git
.GetConfigValue(_T("commit.template"), CP_UTF8
);
1796 if( output
.IsEmpty() )
1799 if( output
.GetLength()<1)
1802 if( output
[0] == _T('/'))
1804 if(output
.GetLength()>=3)
1805 if(output
[2] == _T('/'))
1807 output
.GetBuffer()[0] = output
[1];
1808 output
.GetBuffer()[1] = _T(':');
1813 output
=output
.Tokenize(_T("\n"),start
);
1815 output
.Replace(_T('/'),_T('\\'));
1819 CStdioFile
file(output
,CFile::modeRead
|CFile::typeText
);
1821 while(file
.ReadString(str
))
1832 int CAppUtils::SaveCommitUnicodeFile(CString
&filename
, CString
&message
)
1834 CFile
file(filename
,CFile::modeReadWrite
|CFile::modeCreate
);
1838 output
= g_Git
.GetConfigValue(_T("i18n.commitencoding"));
1839 if(output
.IsEmpty())
1843 output
=output
.Tokenize(_T("\n"),start
);
1844 cp
=CUnicodeUtils::GetCPCode(output
);
1846 int len
=message
.GetLength();
1849 buf
= new char[len
*4 + 4];
1850 SecureZeroMemory(buf
, (len
*4 + 4));
1852 int lengthIncTerminator
= WideCharToMultiByte(cp
, 0, message
, -1, buf
, len
*4, NULL
, NULL
);
1854 file
.Write(buf
,lengthIncTerminator
-1);
1860 bool CAppUtils::Fetch(CString remoteName
, bool allowRebase
, bool autoClose
)
1863 dlg
.m_PreSelectRemote
= remoteName
;
1864 dlg
.m_bAllowRebase
= allowRebase
;
1867 if(dlg
.DoModal()==IDOK
)
1871 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_RemoteURL
);
1875 url
=dlg
.m_RemoteURL
;
1879 int ver
= CAppUtils::GetMsysgitVersion();
1881 if(ver
>= 0x01070203) //above 1.7.0.2
1882 arg
= _T("--progress ");
1885 arg
+= _T("--prune ");
1888 if (dlg
.m_bFetchTags
== 1)
1890 arg
+= _T("--tags ");
1892 else if (dlg
.m_bFetchTags
== 0)
1894 arg
+= _T("--no-tags ");
1897 cmd
.Format(_T("git.exe fetch -v %s \"%s\" %s"),arg
, url
,dlg
.m_RemoteBranchName
);
1898 CProgressDlg progress
;
1900 progress
.m_bAutoCloseOnSuccess
= autoClose
;
1902 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
1904 if(!dlg
.m_bRebase
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
1906 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
1909 progress
.m_GitCmd
=cmd
;
1910 int userResponse
=progress
.DoModal();
1912 if (userResponse
== IDC_PROGRESS_BUTTON1
)
1914 CString cmd
= _T("/command:log");
1915 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
1916 RunTortoiseProc(cmd
);
1919 else if ((userResponse
== IDC_PROGRESS_BUTTON1
+ 1) || (progress
.m_GitStatus
== 0 && dlg
.m_bRebase
))
1924 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUDESSENDMAIL
)));
1925 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENUREBASE
)));
1926 int response
= dlg
.DoModal();
1927 if(response
== IDOK
)
1931 if(response
== IDC_REBASE_POST_BUTTON
)
1933 CString cmd
, out
, err
;
1934 cmd
.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
1936 g_Git
.FixBranchName(dlg
.m_Upstream
),
1937 g_Git
.FixBranchName(dlg
.m_Branch
));
1938 if (g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
1940 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
1944 CAppUtils::SendPatchMail(cmd
,out
);
1948 if(response
== IDC_REBASE_POST_BUTTON
+1 )
1951 if(response
== IDCANCEL
)
1956 else if (userResponse
!= IDCANCEL
)
1962 bool CAppUtils::Push(CString selectLocalBranch
, bool autoClose
)
1965 dlg
.m_BranchSourceName
= selectLocalBranch
;
1967 DWORD exitcode
= 0xFFFFFFFF;
1969 list
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
1970 if (CHooks::Instance().PrePush(list
,exitcode
, error
))
1975 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
1976 //ReportError(temp);
1977 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1982 if(dlg
.DoModal()==IDOK
)
1989 CAppUtils::LaunchPAgent(NULL
,&dlg
.m_URL
);
1993 arg
+= _T("--thin ");
1994 if(dlg
.m_bTags
&& !dlg
.m_bPushAllBranches
)
1995 arg
+= _T("--tags ");
1997 arg
+= _T("--force ");
1999 int ver
= CAppUtils::GetMsysgitVersion();
2001 if(ver
>= 0x01070203) //above 1.7.0.2
2002 arg
+= _T("--progress ");
2004 if (dlg
.m_bPushAllBranches
)
2006 cmd
.Format(_T("git.exe push --all %s \"%s\""),
2012 cmd
.Format(_T("git.exe push %s \"%s\" %s"),
2015 dlg
.m_BranchSourceName
);
2016 if (!dlg
.m_BranchRemoteName
.IsEmpty())
2018 cmd
+= _T(":") + dlg
.m_BranchRemoteName
;
2022 CProgressDlg progress
;
2023 progress
.m_bAutoCloseOnSuccess
=autoClose
;
2024 progress
.m_GitCmd
=cmd
;
2025 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REQUESTPULL
)));
2026 progress
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH
)));
2027 int ret
= progress
.DoModal();
2029 if(!progress
.m_GitStatus
)
2031 if (CHooks::Instance().PostPush(list
,exitcode
, error
))
2036 temp
.Format(IDS_ERR_HOOKFAILED
, (LPCTSTR
)error
);
2037 //ReportError(temp);
2038 CMessageBox::Show(NULL
,temp
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
2042 if(ret
== IDC_PROGRESS_BUTTON1
)
2044 RequestPull(dlg
.m_BranchRemoteName
);
2046 else if(ret
== IDC_PROGRESS_BUTTON1
+ 1)
2057 bool CAppUtils::RequestPull(CString endrevision
, CString repositoryUrl
)
2059 CRequestPullDlg dlg
;
2060 dlg
.m_RepositoryURL
= repositoryUrl
;
2061 dlg
.m_EndRevision
= endrevision
;
2062 if (dlg
.DoModal()==IDOK
)
2065 cmd
.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg
.m_StartRevision
, dlg
.m_RepositoryURL
, dlg
.m_EndRevision
);
2067 CString tempFileName
= GetTempFile();
2068 if (g_Git
.RunLogFile(cmd
, tempFileName
))
2070 CMessageBox::Show(NULL
, IDS_ERR_PULLREUQESTFAILED
, IDS_APPNAME
, MB_OK
);
2073 CAppUtils::LaunchAlternativeEditor(tempFileName
);
2078 bool CAppUtils::CreateMultipleDirectory(const CString
& szPath
)
2080 CString
strDir(szPath
);
2081 if (strDir
.GetAt(strDir
.GetLength()-1)!=_T('\\'))
2083 strDir
.AppendChar(_T('\\'));
2085 std::vector
<CString
> vPath
;
2087 bool bSuccess
= false;
2089 for (int i
=0;i
<strDir
.GetLength();++i
)
2091 if (strDir
.GetAt(i
) != _T('\\'))
2093 strTemp
.AppendChar(strDir
.GetAt(i
));
2097 vPath
.push_back(strTemp
);
2098 strTemp
.AppendChar(_T('\\'));
2102 std::vector
<CString
>::const_iterator vIter
;
2103 for (vIter
= vPath
.begin(); vIter
!= vPath
.end(); vIter
++)
2105 bSuccess
= CreateDirectory(*vIter
, NULL
) ? true : false;
2111 void CAppUtils::RemoveTrailSlash(CString
&path
)
2116 while(path
[path
.GetLength()-1] == _T('\\') || path
[path
.GetLength()-1] == _T('/' ) )
2118 path
=path
.Left(path
.GetLength()-1);
2124 BOOL
CAppUtils::Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
2125 CTGitPathList
&pathList
,
2126 CTGitPathList
&selectedList
,
2127 bool bSelectFilesForCommit
,
2130 bool bFailed
= true;
2132 while(g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
2134 if(CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
2136 CTGitPath
path(g_Git
.m_CurrentDir
);
2137 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
,&path
);
2138 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
2139 dlg
.SetTreeWidth(220);
2140 dlg
.m_DefaultPage
= _T("gitconfig");
2143 dlg
.HandleRestart();
2154 dlg
.m_sBugID
= bugid
;
2156 dlg
.m_bWholeProject
= bWholeProject
;
2158 dlg
.m_sLogMessage
= sLogMsg
;
2159 dlg
.m_pathList
= pathList
;
2160 dlg
.m_checkedPathList
= selectedList
;
2161 dlg
.m_bSelectFilesForCommit
= bSelectFilesForCommit
;
2162 dlg
.m_bAutoClose
= autoClose
;
2163 if (dlg
.DoModal() == IDOK
)
2165 if (dlg
.m_pathList
.GetCount()==0)
2167 // if the user hasn't changed the list of selected items
2168 // we don't use that list. Because if we would use the list
2169 // of pre-checked items, the dialog would show different
2170 // checked items on the next startup: it would only try
2171 // to check the parent folder (which might not even show)
2172 // instead, we simply use an empty list and let the
2173 // default checking do its job.
2174 if (!dlg
.m_pathList
.IsEqual(pathList
))
2175 selectedList
= dlg
.m_pathList
;
2176 pathList
= dlg
.m_updatedPathList
;
2177 sLogMsg
= dlg
.m_sLogMessage
;
2178 bSelectFilesForCommit
= true;
2180 if( dlg
.m_bPushAfterCommit
)
2182 switch(dlg
.m_PostCmd
)
2184 case GIT_POST_CMD_DCOMMIT
:
2185 CAppUtils::SVNDCommit();
2191 else if (dlg
.m_bCreateTagAfterCommit
)
2193 CAppUtils::CreateBranchTag(TRUE
);
2196 // CGitProgressDlg progDlg;
2197 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2198 // if (parser.HasVal(_T("closeonend")))
2199 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2200 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2201 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2202 // progDlg.SetPathList(dlg.m_pathList);
2203 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2204 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2205 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2206 // progDlg.SetItemCount(dlg.m_itemsCount);
2207 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2208 // progDlg.DoModal();
2209 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2210 // err = (DWORD)progDlg.DidErrorsOccur();
2211 // bFailed = progDlg.DidErrorsOccur();
2212 // bRet = progDlg.DidErrorsOccur();
2213 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2214 // if (DWORD(bFailRepeat)==0)
2215 // bFailed = false; // do not repeat if the user chose not to in the settings.
2222 BOOL
CAppUtils::SVNDCommit()
2224 CSVNDCommitDlg dcommitdlg
;
2225 CString gitSetting
= g_Git
.GetConfigValue(_T("svn.rmdir"));
2226 if (gitSetting
== _T("")) {
2227 if (dcommitdlg
.DoModal() != IDOK
)
2233 if (dcommitdlg
.m_remember
)
2235 if (dcommitdlg
.m_rmdir
)
2237 gitSetting
= _T("true");
2241 gitSetting
= _T("false");
2243 if(g_Git
.SetConfigValue(_T("svn.rmdir"),gitSetting
))
2246 msg
.Format(IDS_PROC_SAVECONFIGFAILED
, _T("svn.rmdir"), gitSetting
);
2247 CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
2253 BOOL IsStash
= false;
2254 if(!g_Git
.CheckCleanWorkTree())
2256 if(CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2259 cmd
=_T("git.exe stash");
2260 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2262 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2274 CProgressDlg progress
;
2275 if (dcommitdlg
.m_rmdir
)
2277 progress
.m_GitCmd
=_T("git.exe svn dcommit --rmdir");
2281 progress
.m_GitCmd
=_T("git.exe svn dcommit");
2283 if(progress
.DoModal()==IDOK
&& progress
.m_GitStatus
== 0)
2287 if(CMessageBox::Show(NULL
,IDS_DCOMMIT_STASH_POP
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
2290 cmd
=_T("git.exe stash pop");
2291 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2293 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
2308 BOOL
CAppUtils::Merge(CString
*commit
)
2312 dlg
.m_initialRefName
= *commit
;
2314 if(dlg
.DoModal()==IDOK
)
2326 squash
=_T("--squash");
2329 nocommit
=_T("--no-commit");
2331 if(!dlg
.m_strLogMesage
.IsEmpty())
2333 msg
+= _T("-m \"")+dlg
.m_strLogMesage
+_T("\"");
2335 cmd
.Format(_T("git.exe merge %s %s %s %s %s"),
2340 g_Git
.FixBranchName(dlg
.m_VersionName
));
2342 CProgressDlg Prodlg
;
2343 Prodlg
.m_GitCmd
= cmd
;
2345 if (dlg
.m_bNoCommit
)
2346 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_MENUCOMMIT
)));
2347 else if (dlg
.m_bIsBranch
)
2348 Prodlg
.m_PostCmdList
.Add(CString(MAKEINTRESOURCE(IDS_PROC_REMOVEBRANCH
)));
2350 int ret
= Prodlg
.DoModal();
2352 if (ret
== IDC_PROGRESS_BUTTON1
)
2353 if (dlg
.m_bNoCommit
)
2354 return Commit(_T(""), TRUE
, CString(), CTGitPathList(), CTGitPathList(), true);
2355 else if (dlg
.m_bIsBranch
)
2358 msg
.Format(IDS_PROC_DELETEBRANCHTAG
, dlg
.m_VersionName
);
2359 if (CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
2362 cmd
.Format(_T("git.exe branch -D -- %s"), dlg
.m_VersionName
);
2363 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2364 MessageBox(NULL
, out
, _T("TortoiseGit"), MB_OK
);
2368 return !Prodlg
.m_GitStatus
;
2373 void CAppUtils::EditNote(GitRev
*rev
)
2376 dlg
.m_sHintText
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2377 dlg
.m_sInputText
= rev
->m_Notes
;
2378 dlg
.m_sTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_EDITNOTES
));
2379 //dlg.m_pProjectProperties = &m_ProjectProperties;
2380 dlg
.m_bUseLogWidth
= true;
2381 if(dlg
.DoModal() == IDOK
)
2384 cmd
=_T("notes add -f -F \"");
2386 CString tempfile
=::GetTempFile();
2387 CAppUtils::SaveCommitUnicodeFile(tempfile
,dlg
.m_sInputText
);
2390 cmd
+= rev
->m_CommitHash
.ToString();
2394 if (git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2396 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2401 rev
->m_Notes
= dlg
.m_sInputText
;
2405 CMessageBox::Show(NULL
, IDS_PROC_FAILEDSAVINGNOTES
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2407 CFile::Remove(tempfile
);
2412 int CAppUtils::GetMsysgitVersion(CString
*versionstr
)
2415 CString progressarg
;
2418 CRegDWORD regTime
= CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
2419 CRegDWORD regVersion
= CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
2421 CString gitpath
= CGit::ms_LastMsysGitDir
+_T("\\git.exe");
2424 if(!g_Git
.GetFileModifyTime(gitpath
, &time
) && !versionstr
)
2426 if((DWORD
)time
== regTime
)
2433 version
= *versionstr
;
2437 cmd
= _T("git.exe --version");
2438 if (g_Git
.Run(cmd
, &version
, &err
, CP_UTF8
))
2440 CMessageBox::Show(NULL
, _T("git have not installed (") + err
+ _T(")"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
2448 CString str
=version
.Tokenize(_T("."),start
);
2449 int space
= str
.ReverseFind(_T(' '));
2450 str
=str
.Mid(space
+1,start
);
2454 version
= version
.Mid(start
);
2456 str
= version
.Tokenize(_T("."),start
);
2458 ver
|= (_ttol(str
)&0xFF)<<16;
2460 str
= version
.Tokenize(_T("."),start
);
2461 ver
|= (_ttol(str
)&0xFF)<<8;
2463 str
= version
.Tokenize(_T("."),start
);
2464 ver
|= (_ttol(str
)&0xFF);
2466 regTime
= time
&0xFFFFFFFF;
2472 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd
)
2474 typedef HRESULT (WINAPI
*SHGPSFW
) (HWND hwnd
,REFIID riid
,void** ppv
);
2476 CAutoLibrary hShell
= LoadLibrary(_T("Shell32.dll"));
2478 if (hShell
.IsValid()) {
2479 SHGPSFW pfnSHGPSFW
= (SHGPSFW
)::GetProcAddress(hShell
, "SHGetPropertyStoreForWindow");
2481 IPropertyStore
*pps
;
2482 HRESULT hr
= pfnSHGPSFW(hWnd
, IID_PPV_ARGS(&pps
));
2483 if (SUCCEEDED(hr
)) {
2486 var
.boolVal
= VARIANT_TRUE
;
2487 hr
= pps
->SetValue(PKEY_AppUserModel_PreventPinning
, var
);
2494 void CAppUtils::SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
)
2496 ASSERT(dialogname
.GetLength() < 70);
2497 ASSERT(urlorpath
.GetLength() < MAX_PATH
);
2498 WCHAR pathbuf
[MAX_PATH
] = {0};
2500 PathCompactPathEx(pathbuf
, urlorpath
, 70 - dialogname
.GetLength(), 0);
2502 wcscat_s(pathbuf
, L
" - ");
2503 wcscat_s(pathbuf
, dialogname
);
2504 wcscat_s(pathbuf
, L
" - ");
2505 wcscat_s(pathbuf
, CString(MAKEINTRESOURCE(IDS_APPNAME
)));
2506 SetWindowText(hWnd
, pathbuf
);