1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2013, 2015-2018 - 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"
26 #include "RebaseDlg.h"
29 bool SVNRebaseCommand::Execute()
33 if(!g_Git
.CheckCleanWorkTree())
35 if (CMessageBox::Show(hwndExplorer
, g_Git
.m_CurrentDir
+ L
"\r\n" + CString(MAKEINTRESOURCE(IDS_ERROR_NOCLEAN_STASH
)), L
"TortoiseGit", 1, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_STASHBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
37 CSysProgressDlg sysProgressDlg
;
38 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
39 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
40 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
41 sysProgressDlg
.SetShowProgressBar(false);
42 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
43 sysProgressDlg
.ShowModeless((HWND
)nullptr, true);
46 if (g_Git
.Run(L
"git.exe stash", &out
, CP_UTF8
))
48 sysProgressDlg
.Stop();
49 MessageBox(hwndExplorer
, out
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
52 sysProgressDlg
.Stop();
63 // dlg.m_PreCmd=L"git.exe svn fetch";
66 if (!g_Git
.Run(L
"git.exe config svn-remote.svn.fetch", &out
, &err
, CP_UTF8
))
68 int start
= out
.Find(L
':');
72 if (CStringUtils::StartsWith(out
, L
":refs"))
76 out
= out
.Tokenize(L
"\n", start
);
80 MessageBox(hwndExplorer
, L
"Could not get \"svn-remote.svn.fetch\" config value.\n" + out
+ L
'\n' + err
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
86 CGitHash UpStreamOldHash
,HeadHash
,UpStreamNewHash
;
87 if (g_Git
.GetHash(UpStreamOldHash
, out
))
89 MessageBox(hwndExplorer
, g_Git
.GetGitLastErr(L
"Could not get hash of SVN branch."), L
"TortoiseGit", MB_ICONERROR
);
92 if (g_Git
.GetHash(HeadHash
, L
"HEAD"))
94 MessageBox(hwndExplorer
, g_Git
.GetGitLastErr(L
"Could not get HEAD hash."), L
"TortoiseGit", MB_ICONERROR
);
97 CProgressDlg progress
;
98 progress
.m_GitCmd
= L
"git.exe svn fetch";
99 progress
.m_AutoClose
= AUTOCLOSE_IF_NO_ERRORS
;
101 if(progress
.DoModal()!=IDOK
)
104 if(progress
.m_GitStatus
)
107 if (g_Git
.GetHash(UpStreamNewHash
, out
))
109 MessageBox(hwndExplorer
, g_Git
.GetGitLastErr(L
"Could not get upstream hash after fetching."), L
"TortoiseGit", MB_ICONERROR
);
114 if(UpStreamNewHash
==HeadHash
)
116 MessageBox(hwndExplorer
, g_Git
.m_CurrentDir
+ L
"\r\n" + CString(MAKEINTRESOURCE(IDS_PROC_EVERYTHINGUPDATED
)), L
"TortoiseGit", MB_OK
| MB_ICONQUESTION
);
118 askIfUserWantsToStashPop();
124 if (g_Git
.IsFastForward(L
"HEAD", out
))
126 CProgressDlg progressReset
;
128 cmd
.Format(L
"git.exe reset --hard %s --", (LPCTSTR
)out
);
129 progressReset
.m_GitCmd
= cmd
;
130 progressReset
.m_AutoClose
= AUTOCLOSE_IF_NO_ERRORS
;
132 if (progressReset
.DoModal() != IDOK
)
136 MessageBox(hwndExplorer
, g_Git
.m_CurrentDir
+ L
"\r\n" + CString(MAKEINTRESOURCE(IDS_PROC_FASTFORWARD
)) + L
":\n" + progressReset
.m_LogText
, L
"TortoiseGit", MB_OK
| MB_ICONQUESTION
);
138 askIfUserWantsToStashPop();
144 dlg
.m_PostButtonTexts
.Add(CString(MAKEINTRESOURCE(IDS_MENULOG
)));
146 INT_PTR response
= dlg
.DoModal();
147 if (response
== IDOK
|| response
== IDC_REBASE_POST_BUTTON
)
150 askIfUserWantsToStashPop();
151 if (response
== IDC_REBASE_POST_BUTTON
)
153 CString cmd
= L
"/command:log";
154 cmd
+= L
" /path:\"" + g_Git
.m_CurrentDir
+ L
'"';
155 CAppUtils::RunTortoiseGitProc(cmd
);
162 void SVNRebaseCommand::askIfUserWantsToStashPop()
164 if (MessageBox(hwndExplorer
, g_Git
.m_CurrentDir
+ L
"\r\n" + CString(MAKEINTRESOURCE(IDS_DCOMMIT_STASH_POP
)), L
"TortoiseGit", MB_YESNO
| MB_ICONINFORMATION
) == IDYES
)
165 CAppUtils::StashPop(hwndExplorer
);