1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2013, 2015-2019, 2023-2024 - 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()
31 if (!GitAdminDir::HasAdminDir(g_Git
.m_CurrentDir
))
33 CMessageBox::Show(GetExplorerHWND(), IDS_NOWORKINGCOPY
, IDS_APPNAME
, MB_ICONERROR
);
39 if(!g_Git
.CheckCleanWorkTree())
41 if (CMessageBox::Show(GetExplorerHWND(), 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)
43 CSysProgressDlg sysProgressDlg
;
44 sysProgressDlg
.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME
)));
45 sysProgressDlg
.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING
)));
46 sysProgressDlg
.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT
)));
47 sysProgressDlg
.SetShowProgressBar(false);
48 sysProgressDlg
.SetCancelMsg(IDS_PROGRS_INFOFAILED
);
49 sysProgressDlg
.ShowModeless(static_cast<HWND
>(nullptr), true);
52 if (g_Git
.Run(L
"git.exe stash", &out
, CP_UTF8
))
54 sysProgressDlg
.Stop();
55 MessageBox(GetExplorerHWND(), out
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
58 sysProgressDlg
.Stop();
69 // dlg.m_PreCmd=L"git.exe svn fetch";
72 if (!g_Git
.Run(L
"git.exe config svn-remote.svn.fetch", &out
, &err
, CP_UTF8
))
74 int start
= out
.Find(L
':');
78 if (CStringUtils::StartsWith(out
, L
":refs"))
79 out
= out
.Mid(static_cast<int>(wcslen(L
":refs")) + 1);
82 out
= out
.Tokenize(L
"\n", start
);
86 MessageBox(GetExplorerHWND(), L
"Could not get \"svn-remote.svn.fetch\" config value.\n" + out
+ L
'\n' + err
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
92 CGitHash UpStreamOldHash
,HeadHash
,UpStreamNewHash
;
93 if (g_Git
.GetHash(UpStreamOldHash
, out
))
95 MessageBox(GetExplorerHWND(), g_Git
.GetGitLastErr(L
"Could not get hash of SVN branch."), L
"TortoiseGit", MB_ICONERROR
);
98 if (g_Git
.GetHash(HeadHash
, L
"HEAD"))
100 MessageBox(GetExplorerHWND(), g_Git
.GetGitLastErr(L
"Could not get HEAD hash."), L
"TortoiseGit", MB_ICONERROR
);
103 CProgressDlg progress
;
104 progress
.m_GitCmd
= L
"git.exe svn fetch";
105 progress
.m_AutoClose
= GitProgressAutoClose::AUTOCLOSE_IF_NO_ERRORS
;
107 if(progress
.DoModal()!=IDOK
)
110 if(progress
.m_GitStatus
)
113 if (g_Git
.GetHash(UpStreamNewHash
, out
))
115 MessageBox(GetExplorerHWND(), g_Git
.GetGitLastErr(L
"Could not get upstream hash after fetching."), L
"TortoiseGit", MB_ICONERROR
);
120 if(UpStreamNewHash
==HeadHash
)
122 MessageBox(GetExplorerHWND(), g_Git
.m_CurrentDir
+ L
"\r\n" + CString(MAKEINTRESOURCE(IDS_PROC_EVERYTHINGUPDATED
)), L
"TortoiseGit", MB_OK
| MB_ICONQUESTION
);
124 askIfUserWantsToStashPop();
130 if (g_Git
.IsFastForward(L
"HEAD", out
))
132 CProgressDlg progressReset
;
134 CString endOfOptions
;
135 if (CGit::ms_LastMsysGitVersion
>= ConvertVersionToInt(2, 43, 1))
136 endOfOptions
= L
" --end-of-options";
137 cmd
.Format(L
"git.exe reset --hard%s %s --", static_cast<LPCWSTR
>(endOfOptions
), static_cast<LPCWSTR
>(out
));
138 progressReset
.m_GitCmd
= cmd
;
139 progressReset
.m_AutoClose
= GitProgressAutoClose::AUTOCLOSE_IF_NO_ERRORS
;
141 if (progressReset
.DoModal() != IDOK
)
145 MessageBox(GetExplorerHWND(), g_Git
.m_CurrentDir
+ L
"\r\n" + CString(MAKEINTRESOURCE(IDS_PROC_FASTFORWARD
)) + L
":\n" + progressReset
.m_LogText
, L
"TortoiseGit", MB_OK
| MB_ICONQUESTION
);
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
= L
"/command:log";
163 cmd
+= L
" /path:\"" + g_Git
.m_CurrentDir
+ L
'"';
164 CAppUtils::RunTortoiseGitProc(cmd
);
171 void SVNRebaseCommand::askIfUserWantsToStashPop()
173 if (MessageBox(GetExplorerHWND(), g_Git
.m_CurrentDir
+ L
"\r\n" + CString(MAKEINTRESOURCE(IDS_DCOMMIT_STASH_POP
)), L
"TortoiseGit", MB_YESNO
| MB_ICONINFORMATION
) == IDYES
)
174 CAppUtils::StashPop(GetExplorerHWND());