Unbreak /logmsg and /logmsgfile params of commit command
[TortoiseGit.git] / src / TortoiseProc / Commands / SVNRebaseCommand.cpp
blobf42fd77a27bd687d673ca9101bab3185ad497069
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.
19 #include "stdafx.h"
20 #include "SVNRebaseCommand.h"
22 #include "SysProgressDlg.h"
23 #include "ProgressDlg.h"
24 #include "MessageBox.h"
25 #include "RenameDlg.h"
26 #include "Git.h"
27 #include "ShellUpdater.h"
28 #include "rebasedlg.h"
29 #include "SysProgressDlg.h"
30 #include "AppUtils.h"
32 bool SVNRebaseCommand::Execute()
34 bool isStash = false;
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);
48 CString cmd,out;
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);
54 return false;
56 sysProgressDlg.Stop();
57 isStash = true;
59 else
61 return false;
65 CRebaseDlg dlg;
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(':'));
75 if( start >=0 )
76 out=out.Mid(start);
78 if(out.Left(5) == _T(":refs"))
79 out=out.Mid(6);
81 start = 0;
82 out=out.Tokenize(_T("\n"),start);
84 else
86 CMessageBox::Show(NULL, out + L"\n" + err, _T("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(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get hash of SVN branch.")), _T("TortoiseGit"), MB_ICONERROR);
96 return false;
98 if (g_Git.GetHash(HeadHash, _T("HEAD")))
100 MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR);
101 return false;
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"));
110 return false;
112 ::DeleteFile(g_Git.m_CurrentDir + _T("\\sys$command"));
114 if(progress.m_GitStatus)
115 return false;
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);
120 return false;
123 //everything updated
124 if(UpStreamNewHash==HeadHash)
126 CMessageBox::Show(NULL, g_Git.m_CurrentDir + _T("\r\n") + CString(MAKEINTRESOURCE(IDS_PROC_EVERYTHINGUPDATED)), _T("TortoiseGit"), MB_OK);
127 if(isStash)
128 askIfUserWantsToStashPop();
130 return true;
133 //fast forward;
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)
142 return false;
143 else
145 MessageBox(NULL, g_Git.m_CurrentDir + _T("\r\n") + CString(MAKEINTRESOURCE(IDS_PROC_FASTFORWARD)) + _T(":\n") + progressReset.m_LogText, _T("TortoiseGit"), MB_OK);
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 = _T("/command:log");
163 cmd += _T(" /path:\"") + g_Git.m_CurrentDir + _T("\"");
164 CAppUtils::RunTortoiseGitProc(cmd);
166 return true;
168 return false;
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();