Fix typos
[TortoiseGit.git] / src / TortoiseProc / Commands / SVNRebaseCommand.cpp
blob5230ab3a7aac4526efc3ca56e4df1c087555dd4a
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.
19 #include "stdafx.h"
20 #include "SVNRebaseCommand.h"
22 #include "SysProgressDlg.h"
23 #include "ProgressDlg.h"
24 #include "MessageBox.h"
25 #include "Git.h"
26 #include "RebaseDlg.h"
27 #include "AppUtils.h"
29 bool SVNRebaseCommand::Execute()
31 if (!GitAdminDir::HasAdminDir(g_Git.m_CurrentDir))
33 CMessageBox::Show(GetExplorerHWND(), IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR);
34 return false;
37 bool isStash = false;
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);
51 CString out;
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);
56 return false;
58 sysProgressDlg.Stop();
59 isStash = true;
61 else
63 return false;
67 CRebaseDlg dlg;
69 // dlg.m_PreCmd=L"git.exe svn fetch";
71 CString out, err;
72 if (!g_Git.Run(L"git.exe config svn-remote.svn.fetch", &out, &err, CP_UTF8))
74 int start = out.Find(L':');
75 if( start >=0 )
76 out=out.Mid(start);
78 if (CStringUtils::StartsWith(out, L":refs"))
79 out = out.Mid(static_cast<int>(wcslen(L":refs")) + 1);
81 start = 0;
82 out = out.Tokenize(L"\n", start);
84 else
86 MessageBox(GetExplorerHWND(), L"Could not get \"svn-remote.svn.fetch\" config value.\n" + out + L'\n' + err, L"TortoiseGit", MB_OK | MB_ICONERROR);
87 return false;
90 dlg.m_Upstream=out;
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);
96 return false;
98 if (g_Git.GetHash(HeadHash, L"HEAD"))
100 MessageBox(GetExplorerHWND(), g_Git.GetGitLastErr(L"Could not get HEAD hash."), L"TortoiseGit", MB_ICONERROR);
101 return false;
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)
108 return false;
110 if(progress.m_GitStatus)
111 return false;
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);
116 return false;
119 //everything updated
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);
123 if(isStash)
124 askIfUserWantsToStashPop();
126 return true;
129 //fast forward;
130 if (g_Git.IsFastForward(L"HEAD", out))
132 CProgressDlg progressReset;
133 CString cmd;
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)
142 return false;
143 else
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);
146 if(isStash)
147 askIfUserWantsToStashPop();
149 return true;
153 dlg.m_PostButtonTexts.Add(CString(MAKEINTRESOURCE(IDS_MENULOG)));
154 //need rebase
155 INT_PTR response = dlg.DoModal();
156 if (response == IDOK || response == IDC_REBASE_POST_BUTTON)
158 if(isStash)
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);
166 return true;
168 return false;
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());