1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2013 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "SVNRebaseCommand.h"
22 #include "SysProgressDlg.h"
23 #include "ProgressDlg.h"
24 #include "MessageBox.h"
25 #include "RenameDlg.h"
27 #include "ShellUpdater.h"
28 #include "rebasedlg.h"
29 #include "SysProgressDlg.h"
32 bool SVNRebaseCommand::Execute()
36 if(!g_Git
.CheckCleanWorkTree())
38 if (CMessageBox::Show(NULL
, g_Git
.m_CurrentDir
+ _T("\r\n") + CString(MAKEINTRESOURCE(IDS_ERROR_NOCLEAN_STASH
)), _T("TortoiseGit"), 1, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_STASHBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
40 CSysProgressDlg sysProgressDlg
;
41 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
42 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
43 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
44 sysProgressDlg
.SetShowProgressBar(false);
45 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
46 sysProgressDlg
.ShowModeless((HWND
)NULL
, true);
49 cmd
=_T("git.exe stash");
50 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
52 sysProgressDlg
.Stop();
53 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
56 sysProgressDlg
.Stop();
67 // dlg.m_PreCmd=_T("git.exe svn fetch");
69 CString cmd
, out
, err
;
70 cmd
= _T("git.exe config svn-remote.svn.fetch");
72 if (!g_Git
.Run(cmd
, &out
, &err
, CP_UTF8
))
74 int start
= out
.Find(_T(':'));
78 if(out
.Left(5) == _T(":refs"))
82 out
=out
.Tokenize(_T("\n"),start
);
86 CMessageBox::Show(NULL
, out
+ L
"\n" + err
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
92 CGitHash UpStreamOldHash
,HeadHash
,UpStreamNewHash
;
93 if (g_Git
.GetHash(UpStreamOldHash
, out
))
95 MessageBox(hwndExplorer
, g_Git
.GetGitLastErr(_T("Could not get hash of SVN branch.")), _T("TortoiseGit"), MB_ICONERROR
);
98 if (g_Git
.GetHash(HeadHash
, _T("HEAD")))
100 MessageBox(hwndExplorer
, g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
103 CProgressDlg progress
;
104 progress
.m_GitCmd
=_T("git.exe svn fetch");
105 progress
.m_AutoClose
= AUTOCLOSE_IF_NO_ERRORS
;
107 if(progress
.DoModal()!=IDOK
)
109 ::DeleteFile(g_Git
.m_CurrentDir
+ _T("\\sys$command"));
112 ::DeleteFile(g_Git
.m_CurrentDir
+ _T("\\sys$command"));
114 if(progress
.m_GitStatus
)
117 if (g_Git
.GetHash(UpStreamNewHash
, out
))
119 MessageBox(hwndExplorer
, g_Git
.GetGitLastErr(_T("Could not get upstream hash after fetching.")), _T("TortoiseGit"), MB_ICONERROR
);
124 if(UpStreamNewHash
==HeadHash
)
126 CMessageBox::Show(NULL
, g_Git
.m_CurrentDir
+ _T("\r\n") + CString(MAKEINTRESOURCE(IDS_PROC_EVERYTHINGUPDATED
)), _T("TortoiseGit"), MB_OK
);
128 askIfUserWantsToStashPop();
134 if(g_Git
.IsFastForward(CString(_T("HEAD")),out
))
136 CProgressDlg progressReset
;
137 cmd
.Format(_T("git.exe reset --hard %s --"), out
);
138 progressReset
.m_GitCmd
= cmd
;
139 progressReset
.m_AutoClose
= AUTOCLOSE_IF_NO_ERRORS
;
141 if (progressReset
.DoModal() != IDOK
)
145 MessageBox(NULL
, g_Git
.m_CurrentDir
+ _T("\r\n") + CString(MAKEINTRESOURCE(IDS_PROC_FASTFORWARD
)) + _T(":\n") + progressReset
.m_LogText
, _T("TortoiseGit"), MB_OK
);
147 askIfUserWantsToStashPop();
153 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
155 INT_PTR response
= dlg
.DoModal();
156 if (response
== IDOK
|| response
== IDC_REBASE_POST_BUTTON
)
159 askIfUserWantsToStashPop();
160 if (response
== IDC_REBASE_POST_BUTTON
)
162 CString cmd
= _T("/command:log");
163 cmd
+= _T(" /path:\"") + g_Git
.m_CurrentDir
+ _T("\"");
164 CAppUtils::RunTortoiseGitProc(cmd
);
171 void SVNRebaseCommand::askIfUserWantsToStashPop()
173 if (CMessageBox::Show(NULL
, g_Git
.m_CurrentDir
+ _T("\r\n") + CString(MAKEINTRESOURCE(IDS_DCOMMIT_STASH_POP
)), _T("TortoiseGit"), MB_YESNO
|MB_ICONINFORMATION
) == IDYES
)
175 CAppUtils::StashPop();