1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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 // RebaseDlg.cpp : implementation file
24 #include "TortoiseProc.h"
25 #include "RebaseDlg.h"
27 #include "LoglistUtils.h"
28 #include "MessageBox.h"
29 #include "UnicodeUtils.h"
30 #include "BrowseRefsDlg.h"
31 #include "ProgressDlg.h"
32 #include "SmartHandle.h"
33 #include "../TGitCache/CacheInterface.h"
34 #include "Settings\Settings.h"
35 #include "MassiveGitTask.h"
36 #include "CommitDlg.h"
40 IMPLEMENT_DYNAMIC(CRebaseDlg
, CResizableStandAloneDialog
)
42 CRebaseDlg::CRebaseDlg(CWnd
* pParent
/*=NULL*/)
43 : CResizableStandAloneDialog(CRebaseDlg::IDD
, pParent
)
44 , m_bAddCherryPickedFrom(FALSE
)
45 , m_bStatusWarning(false)
46 , m_bAutoSkipFailedCommit(FALSE
)
47 , m_bFinishedRebase(false)
49 , m_bSplitCommit(FALSE
)
51 m_RebaseStage
=CHOOSE_BRANCH
;
52 m_CurrentRebaseIndex
=-1;
53 m_bThreadRunning
=FALSE
;
54 this->m_IsCherryPick
= FALSE
;
56 m_IsFastForward
=FALSE
;
59 CRebaseDlg::~CRebaseDlg()
63 void CRebaseDlg::DoDataExchange(CDataExchange
* pDX
)
65 CDialog::DoDataExchange(pDX
);
66 DDX_Control(pDX
, IDC_REBASE_PROGRESS
, m_ProgressBar
);
67 DDX_Control(pDX
, IDC_STATUS_STATIC
, m_CtrlStatusText
);
68 DDX_Control(pDX
, IDC_REBASE_SPLIT
, m_wndSplitter
);
69 DDX_Control(pDX
,IDC_COMMIT_LIST
,m_CommitList
);
70 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_BRANCH
, this->m_BranchCtrl
);
71 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_UPSTREAM
, this->m_UpstreamCtrl
);
72 DDX_Check(pDX
, IDC_REBASE_CHECK_FORCE
,m_bForce
);
73 DDX_Check(pDX
, IDC_CHECK_CHERRYPICKED_FROM
, m_bAddCherryPickedFrom
);
74 DDX_Control(pDX
,IDC_REBASE_POST_BUTTON
,m_PostButton
);
75 DDX_Control(pDX
, IDC_SPLITALLOPTIONS
, m_SplitAllOptions
);
76 DDX_Check(pDX
, IDC_REBASE_SPLIT_COMMIT
, m_bSplitCommit
);
80 BEGIN_MESSAGE_MAP(CRebaseDlg
, CResizableStandAloneDialog
)
81 ON_BN_CLICKED(IDC_REBASE_SPLIT
, &CRebaseDlg::OnBnClickedRebaseSplit
)
82 ON_BN_CLICKED(IDC_REBASE_CONTINUE
,OnBnClickedContinue
)
83 ON_BN_CLICKED(IDC_REBASE_ABORT
, OnBnClickedAbort
)
85 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH
, &CRebaseDlg::OnCbnSelchangeBranch
)
86 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM
, &CRebaseDlg::OnCbnSelchangeUpstream
)
87 ON_MESSAGE(MSG_REBASE_UPDATE_UI
, OnRebaseUpdateUI
)
88 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
89 ON_BN_CLICKED(IDC_BUTTON_REVERSE
, OnBnClickedButtonReverse
)
90 ON_BN_CLICKED(IDC_BUTTON_BROWSE
, &CRebaseDlg::OnBnClickedButtonBrowse
)
91 ON_BN_CLICKED(IDC_REBASE_CHECK_FORCE
, &CRebaseDlg::OnBnClickedRebaseCheckForce
)
92 ON_BN_CLICKED(IDC_CHECK_CHERRYPICKED_FROM
, &CRebaseDlg::OnBnClickedCheckCherryPickedFrom
)
93 ON_BN_CLICKED(IDC_REBASE_POST_BUTTON
, &CRebaseDlg::OnBnClickedRebasePostButton
)
94 ON_BN_CLICKED(IDC_BUTTON_UP2
, &CRebaseDlg::OnBnClickedButtonUp2
)
95 ON_BN_CLICKED(IDC_BUTTON_DOWN2
, &CRebaseDlg::OnBnClickedButtonDown2
)
96 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
97 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_COMMIT_LIST
, OnLvnItemchangedLoglist
)
98 ON_REGISTERED_MESSAGE(CGitLogListBase::m_RebaseActionMessage
, OnRebaseActionMessage
)
100 ON_BN_CLICKED(IDC_SPLITALLOPTIONS
, &CRebaseDlg::OnBnClickedSplitAllOptions
)
101 ON_BN_CLICKED(IDC_REBASE_SPLIT_COMMIT
, &CRebaseDlg::OnBnClickedRebaseSplitCommit
)
104 void CRebaseDlg::AddRebaseAnchor()
106 AddAnchor(IDC_REBASE_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
107 AddAnchor(IDC_COMMIT_LIST
,TOP_LEFT
, TOP_RIGHT
);
108 AddAnchor(IDC_REBASE_SPLIT
,TOP_LEFT
, TOP_RIGHT
);
109 AddAnchor(IDC_STATUS_STATIC
, BOTTOM_LEFT
,BOTTOM_RIGHT
);
110 AddAnchor(IDC_REBASE_CONTINUE
,BOTTOM_RIGHT
);
111 AddAnchor(IDC_REBASE_ABORT
, BOTTOM_RIGHT
);
112 AddAnchor(IDC_REBASE_PROGRESS
,BOTTOM_LEFT
, BOTTOM_RIGHT
);
113 AddAnchor(IDC_SPLITALLOPTIONS
, TOP_LEFT
);
114 AddAnchor(IDC_BUTTON_UP2
,TOP_LEFT
);
115 AddAnchor(IDC_BUTTON_DOWN2
,TOP_LEFT
);
116 AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM
,TOP_LEFT
);
117 AddAnchor(IDC_REBASE_COMBOXEX_BRANCH
,TOP_LEFT
);
118 AddAnchor(IDC_REBASE_STATIC_UPSTREAM
,TOP_LEFT
);
119 AddAnchor(IDC_REBASE_STATIC_BRANCH
,TOP_LEFT
);
120 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
121 AddAnchor(IDC_REBASE_CHECK_FORCE
,TOP_RIGHT
);
122 AddAnchor(IDC_CHECK_CHERRYPICKED_FROM
, TOP_RIGHT
);
123 AddAnchor(IDC_REBASE_SPLIT_COMMIT
, BOTTOM_RIGHT
);
124 AddAnchor(IDC_REBASE_POST_BUTTON
,BOTTOM_LEFT
);
126 this->AddOthersToAnchor();
129 BOOL
CRebaseDlg::OnInitDialog()
131 CResizableStandAloneDialog::OnInitDialog();
132 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
134 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
135 // do this, Explorer would be unable to send that message to our window if we
136 // were running elevated. It's OK to make the call all the time, since if we're
137 // not elevated, this is a no-op.
138 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
139 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
140 CAutoLibrary hUser
= AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
143 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
144 if (pfnChangeWindowMessageFilterEx
)
146 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
149 m_pTaskbarList
.Release();
150 if (FAILED(m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
)))
151 m_pTaskbarList
= nullptr;
154 //IDC_REBASE_DUMY_TAB
156 GetClientRect(m_DlgOrigRect
);
157 m_CommitList
.GetClientRect(m_CommitListOrigRect
);
159 CWnd
*pwnd
=this->GetDlgItem(IDC_REBASE_DUMY_TAB
);
160 pwnd
->GetWindowRect(&rectDummy
);
161 this->ScreenToClient(rectDummy
);
163 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_REBASE_TAB
))
165 TRACE0("Failed to create output tab window\n");
166 return FALSE
; // fail to create
168 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
169 // Create output panes:
170 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
171 DWORD dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
173 if (! this->m_FileListCtrl
.Create(dwStyle
,rectDummy
,&this->m_ctrlTabCtrl
,0) )
175 TRACE0("Failed to create output windows\n");
176 return FALSE
; // fail to create
178 m_FileListCtrl
.m_hwndLogicalParent
= this;
180 if( ! this->m_LogMessageCtrl
.Create(_T("Scintilla"),_T("source"),0,rectDummy
,&m_ctrlTabCtrl
,0,0) )
182 TRACE0("Failed to create log message control");
185 m_ProjectProperties
.ReadProps();
186 m_LogMessageCtrl
.Init(m_ProjectProperties
);
187 m_LogMessageCtrl
.SetFont((CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
188 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);
190 dwStyle
= LBS_NOINTEGRALHEIGHT
| WS_CHILD
| WS_VISIBLE
| WS_HSCROLL
| WS_VSCROLL
;
192 if (!m_wndOutputRebase
.Create(_T("Scintilla"),_T("source"),0,rectDummy
, &m_ctrlTabCtrl
, 0,0) )
194 TRACE0("Failed to create output windows\n");
195 return -1; // fail to create
197 m_wndOutputRebase
.Init(0, FALSE
);
198 m_wndOutputRebase
.Call(SCI_SETREADONLY
, TRUE
);
200 m_tooltips
.Create(this);
202 m_tooltips
.AddTool(IDC_REBASE_CHECK_FORCE
,IDS_REBASE_FORCE_TT
);
203 m_tooltips
.AddTool(IDC_REBASE_ABORT
, IDS_REBASE_ABORT_TT
);
207 temp
.LoadString(IDS_PROC_REBASE_SELECTALL_PICK
);
208 m_SplitAllOptions
.AddEntry(temp
);
209 temp
.LoadString(IDS_PROC_REBASE_SELECTALL_SQUASH
);
210 m_SplitAllOptions
.AddEntry(temp
);
211 temp
.LoadString(IDS_PROC_REBASE_SELECTALL_EDIT
);
212 m_SplitAllOptions
.AddEntry(temp
);
215 m_FileListCtrl
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("RebaseDlg"),(GITSLC_POPALL
^ (GITSLC_POPCOMMIT
|GITSLC_POPRESTORE
)), false, true, GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
);
217 m_ctrlTabCtrl
.AddTab(&m_FileListCtrl
, CString(MAKEINTRESOURCE(IDS_PROC_REVISIONFILES
)));
218 m_ctrlTabCtrl
.AddTab(&m_LogMessageCtrl
, CString(MAKEINTRESOURCE(IDS_PROC_COMMITMESSAGE
)), 1);
221 AdjustControlSize(IDC_CHECK_CHERRYPICKED_FROM
);
222 AdjustControlSize(IDC_REBASE_SPLIT_COMMIT
);
224 CString sWindowTitle
;
225 GetWindowText(sWindowTitle
);
226 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
228 EnableSaveRestore(_T("RebaseDlg"));
230 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
231 RECT rcDlg
, rcLogMsg
, rcFileList
;
232 GetClientRect(&rcDlg
);
233 m_CommitList
.GetWindowRect(&rcLogMsg
);
234 ScreenToClient(&rcLogMsg
);
235 this->m_ctrlTabCtrl
.GetWindowRect(&rcFileList
);
236 ScreenToClient(&rcFileList
);
240 m_wndSplitter
.GetWindowRect(&rectSplitter
);
241 ScreenToClient(&rectSplitter
);
242 int delta
= yPos
- rectSplitter
.top
;
243 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
245 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
250 if( this->m_RebaseStage
== CHOOSE_BRANCH
)
252 this->LoadBranchInfo();
257 this->m_BranchCtrl
.EnableWindow(FALSE
);
258 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
259 GetDlgItem(IDC_BUTTON_REVERSE
)->EnableWindow(FALSE
);
262 m_CommitList
.m_ColumnRegKey
= _T("Rebase");
263 m_CommitList
.m_IsIDReplaceAction
= TRUE
;
264 // m_CommitList.m_IsOldFirst = TRUE;
265 m_CommitList
.m_IsRebaseReplaceGraph
= TRUE
;
266 m_CommitList
.m_bNoHightlightHead
= TRUE
;
268 m_CommitList
.InsertGitColumn();
270 this->SetControlEnable();
274 this->m_BranchCtrl
.SetCurSel(-1);
275 this->m_BranchCtrl
.EnableWindow(FALSE
);
276 GetDlgItem(IDC_REBASE_CHECK_FORCE
)->ShowWindow(SW_HIDE
);
277 GetDlgItem(IDC_BUTTON_BROWSE
)->EnableWindow(FALSE
);
278 GetDlgItem(IDC_BUTTON_REVERSE
)->EnableWindow(FALSE
);
279 this->m_UpstreamCtrl
.AddString(_T("HEAD"));
280 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
281 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CHERRYPICK
)));
282 this->m_CommitList
.StartFilter();
286 GetDlgItem(IDC_CHECK_CHERRYPICKED_FROM
)->ShowWindow(SW_HIDE
);
287 ((CButton
*)GetDlgItem(IDC_BUTTON_REVERSE
))->SetIcon((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SWITCHLEFTRIGHT
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
288 SetContinueButtonText();
289 m_CommitList
.DeleteAllItems();
293 m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_CHERRY_PICK
)|
294 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_SWITCHTOREV
)|
295 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_RESET
)|
296 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTREV
)|
297 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_MERGEREV
) |
298 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_TO_VERSION
)|
299 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV
)|
300 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_COMBINE_COMMIT
));
302 if(m_CommitList
.m_IsOldFirst
)
303 this->m_CurrentRebaseIndex
= -1;
305 this->m_CurrentRebaseIndex
= (int)m_CommitList
.m_logEntries
.size();
309 // CRebaseDlg message handlers
311 HBRUSH
CRebaseDlg::OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
)
313 if (pWnd
->GetDlgCtrlID() == IDC_STATUS_STATIC
&& nCtlColor
== CTLCOLOR_STATIC
&& m_bStatusWarning
)
315 pDC
->SetBkColor(RGB(255, 0, 0));
316 pDC
->SetTextColor(RGB(255, 255, 255));
317 return CreateSolidBrush(RGB(255, 0, 0));
320 return CResizableStandAloneDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
323 void CRebaseDlg::SetAllRebaseAction(int action
)
325 for (size_t i
= 0; i
< this->m_CommitList
.m_logEntries
.size(); ++i
)
327 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetRebaseAction() = action
;
329 m_CommitList
.Invalidate();
332 void CRebaseDlg::OnBnClickedRebaseSplit()
337 LRESULT
CRebaseDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
341 if (wParam
== IDC_REBASE_SPLIT
)
343 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
349 return __super::DefWindowProc(message
, wParam
, lParam
);
352 void CRebaseDlg::DoSize(int delta
)
354 this->RemoveAllAnchors();
356 CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST
), delta
, CW_TOPALIGN
);
357 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
358 CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB
), -delta
, CW_BOTTOMALIGN
);
359 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
360 CSplitterControl::ChangePos(GetDlgItem(IDC_SPLITALLOPTIONS
), 0, delta
);
361 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_UP2
),0,delta
);
362 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_DOWN2
),0,delta
);
363 CSplitterControl::ChangePos(GetDlgItem(IDC_REBASE_CHECK_FORCE
),0,delta
);
364 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_CHERRYPICKED_FROM
), 0, delta
);
366 this->AddRebaseAnchor();
367 // adjust the minimum size of the dialog to prevent the resizing from
368 // moving the list control too far down.
370 m_CommitList
.GetClientRect(rcLogMsg
);
371 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_CommitListOrigRect
.Height()+rcLogMsg
.Height()));
374 // m_CommitList.Invalidate();
376 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
378 this->m_ctrlTabCtrl
.Invalidate();
379 this->m_CommitList
.Invalidate();
380 this->m_FileListCtrl
.Invalidate();
381 this->m_LogMessageCtrl
.Invalidate();
385 void CRebaseDlg::SetSplitterRange()
387 if ((m_CommitList
)&&(m_ctrlTabCtrl
))
390 m_CommitList
.GetWindowRect(rcTop
);
391 ScreenToClient(rcTop
);
393 m_ctrlTabCtrl
.GetWindowRect(rcMiddle
);
394 ScreenToClient(rcMiddle
);
395 if (rcMiddle
.Height() && rcMiddle
.Width())
396 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
400 void CRebaseDlg::OnSize(UINT nType
,int cx
, int cy
)
402 // first, let the resizing take place
403 __super::OnSize(nType
, cx
, cy
);
409 void CRebaseDlg::SaveSplitterPos()
413 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
415 m_wndSplitter
.GetWindowRect(&rectSplitter
);
416 ScreenToClient(&rectSplitter
);
417 regPos
= rectSplitter
.top
;
421 void CRebaseDlg::LoadBranchInfo()
423 m_BranchCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
424 m_UpstreamCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
429 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_ALL
);
430 m_BranchCtrl
.SetList(list
);
432 m_BranchCtrl
.SetCurSel(current
);
434 m_BranchCtrl
.AddString(g_Git
.GetCurrentBranch(true));
436 g_Git
.GetBranchList(list
, NULL
, CGit::BRANCH_ALL_F
);
437 m_UpstreamCtrl
.SetList(list
);
439 AddBranchToolTips(&m_BranchCtrl
);
441 if(!m_Upstream
.IsEmpty())
443 m_UpstreamCtrl
.AddString(m_Upstream
);
447 //Select pull-remote from current branch
448 CString pullRemote
, pullBranch
;
449 g_Git
.GetRemoteTrackedBranchForHEAD(pullRemote
, pullBranch
);
451 CString defaultUpstream
;
452 defaultUpstream
.Format(L
"remotes/%s/%s", pullRemote
, pullBranch
);
453 int found
= m_UpstreamCtrl
.FindStringExact(0, defaultUpstream
);
455 m_UpstreamCtrl
.SetCurSel(found
);
457 m_UpstreamCtrl
.SetCurSel(-1);
459 AddBranchToolTips(&m_UpstreamCtrl
);
462 void CRebaseDlg::OnCbnSelchangeBranch()
467 void CRebaseDlg::OnCbnSelchangeUpstream()
472 void CRebaseDlg::FetchLogList()
474 CGitHash base
,hash
,upstream
;
475 m_IsFastForward
=FALSE
;
477 if (m_BranchCtrl
.GetString().IsEmpty())
479 m_CommitList
.ShowText(CString(MAKEINTRESOURCE(IDS_SELECTBRANCH
)));
480 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
484 if (g_Git
.GetHash(hash
, m_BranchCtrl
.GetString()))
486 m_CommitList
.ShowText(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl
.GetString() + _T("\".")));
487 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
491 if (m_UpstreamCtrl
.GetString().IsEmpty())
493 m_CommitList
.ShowText(CString(MAKEINTRESOURCE(IDS_SELECTUPSTREAM
)));
494 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
498 if (g_Git
.GetHash(upstream
, m_UpstreamCtrl
.GetString()))
500 m_CommitList
.ShowText(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl
.GetString() + _T("\".")));
501 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
505 if (hash
== upstream
)
507 m_CommitList
.Clear();
509 fmt
.LoadString(IDS_REBASE_EQUAL_FMT
);
510 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
512 m_CommitList
.ShowText(text
);
513 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
517 if (g_Git
.IsFastForward(m_BranchCtrl
.GetString(), m_UpstreamCtrl
.GetString(), &base
))
520 this->m_IsFastForward
=TRUE
;
522 m_CommitList
.Clear();
524 fmt
.LoadString(IDS_REBASE_FASTFORWARD_FMT
);
525 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString(),
526 m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
528 m_CommitList
.ShowText(text
);
529 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(true);
530 SetContinueButtonText();
537 if (base
== upstream
)
539 m_CommitList
.Clear();
541 fmt
.LoadString(IDS_REBASE_UPTODATE_FMT
);
542 text
.Format(fmt
,m_BranchCtrl
.GetString());
543 m_CommitList
.ShowText(text
);
544 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
545 SetContinueButtonText();
550 m_CommitList
.Clear();
551 CString refFrom
= g_Git
.FixBranchName(m_UpstreamCtrl
.GetString());
552 CString refTo
= g_Git
.FixBranchName(m_BranchCtrl
.GetString());
554 range
.Format(_T("%s..%s"), refFrom
, refTo
);
555 this->m_CommitList
.FillGitLog(nullptr, &range
, 0);
557 if( m_CommitList
.GetItemCount() == 0 )
558 m_CommitList
.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_NOTHINGTOREBASE
)));
561 if(m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
.size() >=0 )
563 if(upstream
== m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
[0])
565 m_CommitList
.Clear();
566 m_CommitList
.ShowText(_T("Nothing Rebase"));
572 AddBranchToolTips(&this->m_BranchCtrl
);
573 AddBranchToolTips(&this->m_UpstreamCtrl
);
575 // Default all actions to 'pick'
576 std::map
<CGitHash
, size_t> revIxMap
;
577 for (size_t i
= 0; i
< m_CommitList
.m_logEntries
.size(); ++i
)
579 GitRev
& rev
= m_CommitList
.m_logEntries
.GetGitRevAt(i
);
580 rev
.GetRebaseAction() = CGitLogListBase::LOGACTIONS_REBASE_PICK
;
581 revIxMap
[rev
.m_CommitHash
] = i
;
584 // Default to skip when already in upstream
586 cherryCmd
.Format(L
"git.exe cherry \"%s\" \"%s\"", refFrom
, refTo
);
587 bool bHasSKip
= false;
588 g_Git
.Run(cherryCmd
, [&](const CStringA
& line
)
590 if (line
.GetLength() < 2)
593 return; // Don't skip (only skip commits starting with a '-')
594 CString hash
= CUnicodeUtils::GetUnicode(line
.Mid(1));
596 auto itIx
= revIxMap
.find(CGitHash(hash
));
597 if (itIx
== revIxMap
.end())
598 return; // Not found?? Should not occur...
601 m_CommitList
.m_logEntries
.GetGitRevAt(itIx
->second
).GetRebaseAction() = CGitLogListBase::LOGACTIONS_REBASE_SKIP
;
605 m_CommitList
.Invalidate();
608 m_CtrlStatusText
.SetWindowText(CString(MAKEINTRESOURCE(IDS_REBASE_AUTOSKIPPED
)));
609 m_bStatusWarning
= true;
613 m_CtrlStatusText
.SetWindowText(m_sStatusText
);
614 m_bStatusWarning
= false;
616 m_CtrlStatusText
.Invalidate();
618 if(m_CommitList
.m_IsOldFirst
)
619 this->m_CurrentRebaseIndex
= -1;
621 this->m_CurrentRebaseIndex
= (int)m_CommitList
.m_logEntries
.size();
623 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
624 SetContinueButtonText();
627 void CRebaseDlg::AddBranchToolTips(CHistoryCombo
*pBranch
)
631 CString text
=pBranch
->GetString();
639 catch (const char *msg
)
641 CMessageBox::Show(m_hWnd
, _T("Could not get commit ") + text
+ _T("\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
644 tooltip
.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"),
645 CString(MAKEINTRESOURCE(IDS_LOG_REVISION
)),
646 rev
.m_CommitHash
.ToString(),
647 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
)),
649 rev
.GetAuthorEmail(),
650 CString(MAKEINTRESOURCE(IDS_LOG_DATE
)),
651 CLoglistUtils::FormatDateAndTime(rev
.GetAuthorDate(), DATE_LONGDATE
),
652 CString(MAKEINTRESOURCE(IDS_LOG_MESSAGE
)),
656 pBranch
->DisableTooltip();
657 this->m_tooltips
.AddTool(pBranch
->GetComboBoxCtrl(),tooltip
);
661 BOOL
CRebaseDlg::PreTranslateMessage(MSG
*pMsg
)
663 if (pMsg
->message
== WM_KEYDOWN
)
665 switch (pMsg
->wParam
)
668 if (LogListHasFocus(pMsg
->hwnd
)
669 && LogListHasMenuItem(CGitLogListBase::ID_REBASE_PICK
)
670 && LogListHasMenuItem(CGitLogListBase::ID_REBASE_SQUASH
)
671 && LogListHasMenuItem(CGitLogListBase::ID_REBASE_EDIT
)
672 && LogListHasMenuItem(CGitLogListBase::ID_REBASE_SKIP
))
674 m_CommitList
.ShiftSelectedRebaseAction();
679 if (LogListHasFocus(pMsg
->hwnd
) && LogListHasMenuItem(CGitLogListBase::ID_REBASE_PICK
))
681 m_CommitList
.SetSelectedRebaseAction(CGitLogListBase::LOGACTIONS_REBASE_PICK
);
686 if (LogListHasFocus(pMsg
->hwnd
) && LogListHasMenuItem(CGitLogListBase::ID_REBASE_SKIP
))
688 m_CommitList
.SetSelectedRebaseAction(CGitLogListBase::LOGACTIONS_REBASE_SKIP
);
693 if (LogListHasFocus(pMsg
->hwnd
) && LogListHasMenuItem(CGitLogListBase::ID_REBASE_SQUASH
))
695 m_CommitList
.SetSelectedRebaseAction(CGitLogListBase::LOGACTIONS_REBASE_SQUASH
);
700 if (LogListHasFocus(pMsg
->hwnd
) && LogListHasMenuItem(CGitLogListBase::ID_REBASE_EDIT
))
702 m_CommitList
.SetSelectedRebaseAction(CGitLogListBase::LOGACTIONS_REBASE_EDIT
);
707 if(LogListHasFocus(pMsg
->hwnd
) && GetAsyncKeyState(VK_CONTROL
) & 0x8000)
709 // select all entries
710 for (int i
= 0; i
< m_CommitList
.GetItemCount(); ++i
)
712 m_CommitList
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
725 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
727 if (GetDlgItem(IDC_REBASE_CONTINUE
)->IsWindowEnabled())
728 GetDlgItem(IDC_REBASE_CONTINUE
)->SetFocus();
729 else if (GetDlgItem(IDC_REBASE_ABORT
)->IsWindowEnabled())
730 GetDlgItem(IDC_REBASE_ABORT
)->SetFocus();
732 GetDlgItem(IDHELP
)->SetFocus();
737 /* Avoid TAB control destroy but dialog exist*/
741 TCHAR buff
[128] = { 0 };
742 ::GetClassName(pMsg
->hwnd
,buff
,128);
745 /* Use MSFTEDIT_CLASS http://msdn.microsoft.com/en-us/library/bb531344.aspx */
746 if (_tcsnicmp(buff
, MSFTEDIT_CLASS
, 128) == 0 || //Unicode and MFC 2012 and later
747 _tcsnicmp(buff
, RICHEDIT_CLASS
, 128) == 0 || //ANSI or MFC 2010
748 _tcsnicmp(buff
,_T("Scintilla"),128)==0 ||
749 _tcsnicmp(buff
,_T("SysListView32"),128)==0||
750 ::GetParent(pMsg
->hwnd
) == this->m_ctrlTabCtrl
.m_hWnd
)
752 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
758 else if (pMsg
->message
== WM_NEXTDLGCTL
)
760 HWND hwnd
= GetFocus()->GetSafeHwnd();
761 if (hwnd
== m_LogMessageCtrl
.GetSafeHwnd() || hwnd
== m_wndOutputRebase
.GetSafeHwnd())
763 if (GetDlgItem(IDC_REBASE_CONTINUE
)->IsWindowEnabled())
764 GetDlgItem(IDC_REBASE_CONTINUE
)->SetFocus();
765 else if (GetDlgItem(IDC_REBASE_ABORT
)->IsWindowEnabled())
766 GetDlgItem(IDC_REBASE_ABORT
)->SetFocus();
768 GetDlgItem(IDHELP
)->SetFocus();
772 m_tooltips
.RelayEvent(pMsg
);
773 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
776 bool CRebaseDlg::LogListHasFocus(HWND hwnd
)
778 TCHAR buff
[128] = { 0 };
779 ::GetClassName(hwnd
, buff
, 128);
781 if(_tcsnicmp(buff
, _T("SysListView32"), 128) == 0)
786 bool CRebaseDlg::LogListHasMenuItem(int i
)
788 return (m_CommitList
.m_ContextMenuMask
& m_CommitList
.GetContextMenuBit(i
)) != 0;
791 int CRebaseDlg::CheckRebaseCondition()
793 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
795 if( !g_Git
.CheckCleanWorkTree() )
797 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
800 cmd
=_T("git.exe stash");
801 this->AddLogString(cmd
);
802 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
804 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
812 //Todo Check $REBASE_ROOT
815 if (!CAppUtils::CheckUserData())
818 //Todo call pre_rebase_hook
822 void CRebaseDlg::CheckRestoreStash()
824 if (m_bStashed
&& CMessageBox::Show(nullptr, IDS_DCOMMIT_STASH_POP
, IDS_APPNAME
, MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
825 CAppUtils::StashPop();
829 int CRebaseDlg::StartRebase()
832 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
834 m_OrigHEADBranch
= g_Git
.GetCurrentBranch(true);
836 m_OrigHEADHash
.Empty();
837 if (g_Git
.GetHash(m_OrigHEADHash
, _T("HEAD")))
839 AddLogString(CString(MAKEINTRESOURCE(IDS_PROC_NOHEAD
)));
843 //git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
844 // echo "detached HEAD" > "$DOTEST"/head-name
846 cmd
.Format(_T("git.exe update-ref ORIG_HEAD ") + m_OrigHEADHash
.ToString());
847 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
849 AddLogString(_T("update ORIG_HEAD Fail"));
853 m_OrigUpstreamHash
.Empty();
854 if (g_Git
.GetHash(m_OrigUpstreamHash
, m_UpstreamCtrl
.GetString()))
856 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
860 if( !this->m_IsCherryPick
)
862 cmd
.Format(_T("git.exe checkout -f %s --"), m_OrigUpstreamHash
.ToString());
863 this->AddLogString(cmd
);
867 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
869 this->AddLogString(out
);
870 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
879 if( !this->m_IsCherryPick
)
881 if (g_Git
.GetHash(m_OrigBranchHash
, m_BranchCtrl
.GetString()))
883 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
886 log
.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTREBASE
)));
889 log
.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTCHERRYPICK
)));
891 this->AddLogString(log
);
894 int CRebaseDlg::VerifyNoConflict()
897 if(g_Git
.ListConflictFile(list
))
899 AddLogString(_T("Get conflict files fail"));
904 CMessageBox::Show(NULL
, IDS_PROGRS_CONFLICTSOCCURED
, IDS_APPNAME
, MB_OK
);
911 static bool IsLocalBranch(CString ref
)
914 g_Git
.GetBranchList(list
, nullptr, CGit::BRANCH_LOCAL
);
915 return std::find(list
.begin(), list
.end(), ref
) != list
.end();
918 int CRebaseDlg::FinishRebase()
920 if (m_bFinishedRebase
)
923 m_bFinishedRebase
= true;
924 if(this->m_IsCherryPick
) //cherry pick mode no "branch", working at upstream branch
926 m_sStatusText
.LoadString(IDS_DONE
);
927 m_CtrlStatusText
.SetWindowText(m_sStatusText
);
928 m_bStatusWarning
= false;
929 m_CtrlStatusText
.Invalidate();
934 if (g_Git
.GetHash(head
, _T("HEAD")))
936 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
941 if (IsLocalBranch(m_BranchCtrl
.GetString()))
943 cmd
.Format(_T("git.exe checkout -f -B %s %s --"), m_BranchCtrl
.GetString(), head
.ToString());
948 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
951 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
960 cmd
.Format(_T("git.exe reset --hard %s --"), head
.ToString());
965 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
968 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
976 while (m_ctrlTabCtrl
.GetTabsNum() > 1)
977 m_ctrlTabCtrl
.RemoveTab(0);
978 m_CtrlStatusText
.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_REBASEFINISHED
)));
979 m_sStatusText
= CString(MAKEINTRESOURCE(IDS_PROC_REBASEFINISHED
));
980 m_bStatusWarning
= false;
981 m_CtrlStatusText
.Invalidate();
985 void CRebaseDlg::OnBnClickedContinue()
987 if( m_RebaseStage
== REBASE_DONE
)
994 if (m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
996 if (CheckRebaseCondition())
1000 if( this->m_IsFastForward
)
1003 if (g_Git
.GetHash(m_OrigBranchHash
, m_BranchCtrl
.GetString()))
1005 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
1008 if (g_Git
.GetHash(m_OrigUpstreamHash
, m_UpstreamCtrl
.GetString()))
1010 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
1014 if(!g_Git
.IsFastForward(this->m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString()))
1016 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1017 AddLogString(_T("No fast forward possible.\r\nMaybe repository changed"));
1021 if (IsLocalBranch(m_BranchCtrl
.GetString()))
1023 cmd
.Format(_T("git.exe checkout --no-track -f -B %s %s --"), m_BranchCtrl
.GetString(), m_UpstreamCtrl
.GetString());
1028 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1030 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1032 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1041 cmd
.Format(_T("git.exe reset --hard %s --"), g_Git
.FixBranchName(this->m_UpstreamCtrl
.GetString()));
1043 log
.Format(IDS_PROC_REBASE_FFTO
, m_UpstreamCtrl
.GetString());
1044 this->AddLogString(log
);
1047 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1051 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1053 AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL
)));
1055 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1062 AddLogString(CString(MAKEINTRESOURCE(IDS_DONE
)));
1063 m_RebaseStage
= REBASE_DONE
;
1064 UpdateCurrentStatus();
1068 if( m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
1070 if(CheckRebaseCondition())
1072 m_RebaseStage
= REBASE_START
;
1073 m_FileListCtrl
.Clear();
1074 m_FileListCtrl
.SetHasCheckboxes(false);
1075 m_FileListCtrl
.m_CurrentVersion
= L
"";
1076 m_ctrlTabCtrl
.SetTabLabel(REBASE_TAB_CONFLICT
, CString(MAKEINTRESOURCE(IDS_PROC_CONFLICTFILES
)));
1077 m_ctrlTabCtrl
.AddTab(&m_wndOutputRebase
, CString(MAKEINTRESOURCE(IDS_LOG
)), 2);
1080 if( m_RebaseStage
== REBASE_FINISH
)
1088 if( m_RebaseStage
== REBASE_SQUASH_CONFLICT
)
1090 if(VerifyNoConflict())
1092 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1093 if(this->CheckNextCommitIsSquash())
1094 {//next commit is not squash;
1095 m_RebaseStage
= REBASE_SQUASH_EDIT
;
1096 this->OnRebaseUpdateUI(0,0);
1097 this->UpdateCurrentStatus();
1101 m_RebaseStage
=REBASE_CONTINUE
;
1102 curRev
->GetRebaseAction() |= CGitLogListBase::LOGACTIONS_REBASE_DONE
;
1103 this->UpdateCurrentStatus();
1107 if( m_RebaseStage
== REBASE_CONFLICT
)
1109 if(VerifyNoConflict())
1112 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1113 // ***************************************************
1114 // ATTENTION: Similar code in CommitDlg.cpp!!!
1115 // ***************************************************
1116 CMassiveGitTask
mgtReAddAfterCommit(_T("add --ignore-errors -f"));
1117 CMassiveGitTask
mgtAdd(_T("add -f"));
1118 CMassiveGitTask
mgtUpdateIndexForceRemove(_T("update-index --force-remove"));
1119 CMassiveGitTask
mgtUpdateIndex(_T("update-index"));
1120 CMassiveGitTask
mgtRm(_T("rm --ignore-unmatch"));
1121 CMassiveGitTask
mgtRmFCache(_T("rm -f --cache"));
1122 CMassiveGitTask
mgtReset(_T("reset"), TRUE
, true);
1123 for (int i
= 0; i
< m_FileListCtrl
.GetItemCount(); i
++)
1125 CTGitPath
*entry
= (CTGitPath
*)m_FileListCtrl
.GetItemData(i
);
1126 if (entry
->m_Checked
)
1128 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1129 mgtAdd
.AddFile(entry
->GetGitPathString());
1130 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
1131 mgtUpdateIndexForceRemove
.AddFile(entry
->GetGitPathString());
1133 mgtUpdateIndex
.AddFile(entry
->GetGitPathString());
1135 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
1136 mgtRm
.AddFile(entry
->GetGitOldPathString());
1140 if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
1142 mgtRmFCache
.AddFile(entry
->GetGitPathString());
1143 mgtReAddAfterCommit
.AddFile(*entry
);
1145 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
&& !entry
->GetGitOldPathString().IsEmpty())
1146 mgtReset
.AddFile(entry
->GetGitOldPathString());
1148 else if(!(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
1149 mgtReset
.AddFile(entry
->GetGitPathString());
1153 BOOL cancel
= FALSE
;
1154 bool successful
= true;
1155 successful
= successful
&& mgtAdd
.Execute(cancel
);
1156 successful
= successful
&& mgtUpdateIndexForceRemove
.Execute(cancel
);
1157 successful
= successful
&& mgtUpdateIndex
.Execute(cancel
);
1158 successful
= successful
&& mgtRm
.Execute(cancel
);
1159 successful
= successful
&& mgtRmFCache
.Execute(cancel
);
1160 successful
= successful
&& mgtReset
.Execute(cancel
);
1164 AddLogString(_T("An error occurred while updating the index."));
1168 CString out
=_T("");
1170 cmd
.Format(_T("git.exe commit -C %s"), curRev
->m_CommitHash
.ToString());
1174 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1177 if(!g_Git
.CheckCleanWorkTree())
1179 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1186 // update commit message if needed
1187 CString str
= m_LogMessageCtrl
.GetText().Trim();
1188 if (str
!= (curRev
->GetSubject() + _T("\n") + curRev
->GetBody()).Trim())
1190 if (str
.Trim().IsEmpty())
1192 CMessageBox::Show(NULL
, IDS_PROC_COMMITMESSAGE_EMPTY
,IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1195 CString tempfile
= ::GetTempFile();
1196 if (CAppUtils::SaveCommitUnicodeFile(tempfile
, str
))
1198 CMessageBox::Show(nullptr, _T("Could not save commit message"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1203 cmd
.Format(_T("git.exe commit --amend -F \"%s\""), tempfile
);
1206 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1209 if (!g_Git
.CheckCleanWorkTree())
1211 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1219 if (((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit"), TRUE
)) == TRUE
)
1221 BOOL cancel
= FALSE
;
1222 mgtReAddAfterCommit
.Execute(cancel
);
1225 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1226 if (curRev
->GetRebaseAction() & CGitLogListBase::LOGACTIONS_REBASE_EDIT
)
1228 m_RebaseStage
=REBASE_EDIT
;
1229 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1230 this->UpdateCurrentStatus();
1235 m_RebaseStage
=REBASE_CONTINUE
;
1236 curRev
->GetRebaseAction() |= CGitLogListBase::LOGACTIONS_REBASE_DONE
;
1237 this->UpdateCurrentStatus();
1239 if (CheckNextCommitIsSquash() == 0) // remember commit msg after edit if next commit if squash
1240 ResetParentForSquash(str
);
1242 m_SquashMessage
.Empty();
1246 if ((m_RebaseStage
== REBASE_EDIT
|| m_RebaseStage
== REBASE_CONTINUE
|| m_bSplitCommit
) && CheckNextCommitIsSquash() && (m_bSplitCommit
|| !g_Git
.CheckCleanWorkTree(true)))
1248 if (!m_bSplitCommit
&& CMessageBox::Show(nullptr, IDS_PROC_REBASE_CONTINUE_NOTCLEAN
, IDS_APPNAME
, 1, IDI_ERROR
, IDS_MSGBOX_OK
, IDS_ABORTBUTTON
) == 2)
1250 BOOL isFirst
= TRUE
;
1255 dlg
.m_sLogMessage
= m_LogMessageCtrl
.GetText();
1256 dlg
.m_bWholeProject
= true;
1257 dlg
.m_bSelectFilesForCommit
= true;
1258 dlg
.m_bCommitAmend
= isFirst
&& (m_RebaseStage
!= REBASE_SQUASH_EDIT
); // do not amend on squash_edit stage, we need a normal commit there
1260 gpl
.AddPath(CTGitPath(g_Git
.m_CurrentDir
));
1261 dlg
.m_pathList
= gpl
;
1262 dlg
.m_bAmendDiffToLastCommit
= !m_bSplitCommit
;
1263 dlg
.m_bNoPostActions
= true;
1264 if (dlg
.m_bCommitAmend
)
1265 dlg
.m_AmendStr
= dlg
.m_sLogMessage
;
1266 dlg
.m_bWarnDetachedHead
= false;
1268 if (dlg
.DoModal() != IDOK
)
1271 isFirst
= !m_bSplitCommit
; // only select amend on second+ runs if not in split commit mode
1273 m_SquashMessage
.Empty();
1274 } while (!g_Git
.CheckCleanWorkTree() || (m_bSplitCommit
&& MessageBox(_T("Add another commit?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
) == IDYES
));
1276 m_bSplitCommit
= FALSE
;
1279 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1280 m_RebaseStage
= REBASE_CONTINUE
;
1281 GitRev
* curRev
= (GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1282 curRev
->GetRebaseAction() |= CGitLogListBase::LOGACTIONS_REBASE_DONE
;
1283 this->UpdateCurrentStatus();
1286 if( m_RebaseStage
== REBASE_EDIT
|| m_RebaseStage
== REBASE_SQUASH_EDIT
)
1289 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1291 str
=this->m_LogMessageCtrl
.GetText();
1292 if(str
.Trim().IsEmpty())
1294 CMessageBox::Show(NULL
, IDS_PROC_COMMITMESSAGE_EMPTY
,IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1298 CString tempfile
=::GetTempFile();
1299 if (CAppUtils::SaveCommitUnicodeFile(tempfile
, str
))
1301 CMessageBox::Show(nullptr, _T("Could not save commit message"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1307 if( m_RebaseStage
== REBASE_SQUASH_EDIT
)
1308 cmd
.Format(_T("git.exe commit %s-F \"%s\""), m_SquashFirstMetaData
, tempfile
);
1312 int isEmpty
= IsCommitEmpty(curRev
->m_CommitHash
);
1314 options
= _T("--allow-empty ");
1315 else if (isEmpty
< 0)
1317 cmd
.Format(_T("git.exe commit --amend %s-F \"%s\""), options
, tempfile
);
1320 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1322 if(!g_Git
.CheckCleanWorkTree())
1324 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1329 ::DeleteFile(tempfile
);
1331 if (CheckNextCommitIsSquash() == 0 && m_RebaseStage
!= REBASE_SQUASH_EDIT
) // remember commit msg after edit if next commit if squash; but don't do this if ...->squash(reset here)->pick->squash
1333 ResetParentForSquash(str
);
1336 m_SquashMessage
.Empty();
1337 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1338 m_RebaseStage
=REBASE_CONTINUE
;
1339 curRev
->GetRebaseAction() |= CGitLogListBase::LOGACTIONS_REBASE_DONE
;
1340 this->UpdateCurrentStatus();
1344 InterlockedExchange(&m_bThreadRunning
, TRUE
);
1347 if (AfxBeginThread(RebaseThreadEntry
, this)==NULL
)
1349 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1350 CMessageBox::Show(NULL
, _T("Create Rebase Thread Fail"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1354 void CRebaseDlg::ResetParentForSquash(const CString
& commitMessage
)
1356 m_SquashMessage
= commitMessage
;
1357 // reset parent so that we can do "git cherry-pick --no-commit" w/o introducing an unwanted commit
1358 CString cmd
= _T("git.exe reset --soft HEAD~1");
1359 m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1363 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1366 AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL
)));
1368 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1375 int CRebaseDlg::CheckNextCommitIsSquash()
1378 if(m_CommitList
.m_IsOldFirst
)
1379 index
=m_CurrentRebaseIndex
+1;
1381 index
=m_CurrentRebaseIndex
-1;
1388 if(index
>= m_CommitList
.GetItemCount())
1391 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[index
];
1393 if (curRev
->GetRebaseAction() & CGitLogListBase::LOGACTIONS_REBASE_SQUASH
)
1395 if (curRev
->GetRebaseAction() & CGitLogListBase::LOGACTIONS_REBASE_SKIP
)
1397 if(m_CommitList
.m_IsOldFirst
)
1405 } while(curRev
->GetRebaseAction() & CGitLogListBase::LOGACTIONS_REBASE_SKIP
);
1410 int CRebaseDlg::GoNext()
1412 if(m_CommitList
.m_IsOldFirst
)
1413 ++m_CurrentRebaseIndex
;
1415 --m_CurrentRebaseIndex
;
1419 int CRebaseDlg::StateAction()
1421 switch(this->m_RebaseStage
)
1424 case CHOOSE_COMMIT_PICK_MODE
:
1427 m_RebaseStage
= REBASE_START
;
1434 void CRebaseDlg::SetContinueButtonText()
1437 switch(this->m_RebaseStage
)
1440 case CHOOSE_COMMIT_PICK_MODE
:
1441 if(this->m_IsFastForward
)
1442 Text
.LoadString(IDS_PROC_STARTREBASEFFBUTTON
);
1444 Text
.LoadString(IDS_PROC_STARTREBASEBUTTON
);
1449 case REBASE_CONTINUE
:
1450 case REBASE_SQUASH_CONFLICT
:
1451 Text
.LoadString(IDS_CONTINUEBUTTON
);
1454 case REBASE_CONFLICT
:
1455 Text
.LoadString(IDS_COMMITBUTTON
);
1458 Text
.LoadString(IDS_AMENDBUTTON
);
1461 case REBASE_SQUASH_EDIT
:
1462 Text
.LoadString(IDS_COMMITBUTTON
);
1467 Text
.LoadString(IDS_FINISHBUTTON
);
1471 Text
.LoadString(IDS_DONE
);
1474 this->GetDlgItem(IDC_REBASE_CONTINUE
)->SetWindowText(Text
);
1477 void CRebaseDlg::SetControlEnable()
1479 switch(this->m_RebaseStage
)
1482 case CHOOSE_COMMIT_PICK_MODE
:
1484 this->GetDlgItem(IDC_SPLITALLOPTIONS
)->EnableWindow(TRUE
);
1485 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(TRUE
);
1486 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(TRUE
);
1490 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(TRUE
);
1491 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(TRUE
);
1492 this->GetDlgItem(IDC_BUTTON_REVERSE
)->EnableWindow(TRUE
);
1493 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(TRUE
);
1495 this->m_CommitList
.m_ContextMenuMask
|= m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1496 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1497 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1498 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
);
1502 case REBASE_CONTINUE
:
1506 case REBASE_CONFLICT
:
1508 case REBASE_SQUASH_CONFLICT
:
1510 this->GetDlgItem(IDC_SPLITALLOPTIONS
)->EnableWindow(FALSE
);
1511 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(FALSE
);
1512 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(FALSE
);
1513 this->GetDlgItem(IDC_BUTTON_REVERSE
)->EnableWindow(FALSE
);
1514 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(FALSE
);
1515 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(FALSE
);
1516 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(FALSE
);
1518 if( m_RebaseStage
== REBASE_DONE
&& (this->m_PostButtonTexts
.GetCount() != 0) )
1520 this->GetDlgItem(IDC_STATUS_STATIC
)->ShowWindow(SW_HIDE
);
1521 this->GetDlgItem(IDC_REBASE_POST_BUTTON
)->ShowWindow(SW_SHOWNORMAL
);
1522 this->m_PostButton
.RemoveAll();
1523 this->m_PostButton
.AddEntries(m_PostButtonTexts
);
1524 //this->GetDlgItem(IDC_REBASE_POST_BUTTON)->SetWindowText(this->m_PostButtonText);
1529 GetDlgItem(IDC_REBASE_SPLIT_COMMIT
)->ShowWindow((m_RebaseStage
== REBASE_EDIT
|| m_RebaseStage
== REBASE_SQUASH_EDIT
) ? SW_SHOW
: SW_HIDE
);
1531 if(m_bThreadRunning
)
1533 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1536 else if (m_RebaseStage
!= REBASE_ERROR
)
1538 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(TRUE
);
1542 void CRebaseDlg::UpdateProgress()
1547 if(m_CommitList
.m_IsOldFirst
)
1548 index
= m_CurrentRebaseIndex
+1;
1550 index
= m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1552 int finishedCommits
= index
- 1; // introduced an variable which shows the number handled revisions for the progress bars
1553 if (m_RebaseStage
== REBASE_FINISH
|| finishedCommits
== -1)
1554 finishedCommits
= index
;
1556 m_ProgressBar
.SetRange32(0, m_CommitList
.GetItemCount());
1557 m_ProgressBar
.SetPos(finishedCommits
);
1560 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1561 m_pTaskbarList
->SetProgressValue(m_hWnd
, finishedCommits
, m_CommitList
.GetItemCount());
1564 if(m_CurrentRebaseIndex
>=0 && m_CurrentRebaseIndex
< m_CommitList
.GetItemCount())
1567 text
.Format(IDS_PROC_REBASING_PROGRESS
, index
, m_CommitList
.GetItemCount());
1568 m_sStatusText
= text
;
1569 m_CtrlStatusText
.SetWindowText(text
);
1570 m_bStatusWarning
= false;
1571 m_CtrlStatusText
.Invalidate();
1574 GitRev
*prevRev
=NULL
, *curRev
=NULL
;
1576 if( m_CurrentRebaseIndex
>= 0 && m_CurrentRebaseIndex
< m_CommitList
.m_arShownList
.GetSize())
1578 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1581 for (int i
= 0; i
< m_CommitList
.m_arShownList
.GetSize(); ++i
)
1583 prevRev
=(GitRev
*)m_CommitList
.m_arShownList
[i
];
1584 if (prevRev
->GetRebaseAction() & CGitLogListBase::LOGACTIONS_REBASE_CURRENT
)
1586 prevRev
->GetRebaseAction() &= ~CGitLogListBase::LOGACTIONS_REBASE_CURRENT
;
1587 m_CommitList
.GetItemRect(i
,&rect
,LVIR_BOUNDS
);
1588 m_CommitList
.InvalidateRect(rect
);
1594 curRev
->GetRebaseAction() |= CGitLogListBase::LOGACTIONS_REBASE_CURRENT
;
1595 m_CommitList
.GetItemRect(m_CurrentRebaseIndex
,&rect
,LVIR_BOUNDS
);
1596 m_CommitList
.InvalidateRect(rect
);
1598 m_CommitList
.EnsureVisible(m_CurrentRebaseIndex
,FALSE
);
1601 void CRebaseDlg::UpdateCurrentStatus()
1603 SetContinueButtonText();
1606 if (m_RebaseStage
== REBASE_DONE
)
1607 GetDlgItem(IDC_REBASE_CONTINUE
)->SetFocus();
1610 void CRebaseDlg::AddLogString(CString str
)
1612 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, FALSE
);
1613 CStringA sTextA
= m_wndOutputRebase
.StringForControl(str
);//CUnicodeUtils::GetUTF8(str);
1614 this->m_wndOutputRebase
.SendMessage(SCI_DOCUMENTEND
);
1615 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)sTextA
);
1616 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n");
1617 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, TRUE
);
1620 int CRebaseDlg::GetCurrentCommitID()
1622 if(m_CommitList
.m_IsOldFirst
)
1624 return this->m_CurrentRebaseIndex
+1;
1629 return m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1633 int CRebaseDlg::IsCommitEmpty(const CGitHash
& hash
)
1635 CString cmd
, tree
, ptree
;
1636 cmd
.Format(_T("git.exe rev-parse -q --verify %s^{tree}"), hash
.ToString());
1637 if (g_Git
.Run(cmd
, &tree
, CP_UTF8
))
1643 cmd
.Format(_T("git.exe rev-parse -q --verify %s^^{tree}"), hash
.ToString());
1644 if (g_Git
.Run(cmd
, &ptree
, CP_UTF8
))
1645 ptree
= _T("4b825dc642cb6eb9a060e54bf8d69288fbee4904"); // empty tree
1646 return tree
== ptree
;
1649 int CRebaseDlg::DoRebase()
1652 if(m_CurrentRebaseIndex
<0)
1654 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1657 GitRev
*pRev
= (GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1658 int mode
= pRev
->GetRebaseAction() & CGitLogListBase::LOGACTIONS_REBASE_MODE_MASK
;
1661 if (mode
== CGitLogListBase::LOGACTIONS_REBASE_SKIP
)
1663 pRev
->GetRebaseAction() |= CGitLogListBase::LOGACTIONS_REBASE_DONE
;
1667 bool nextCommitIsSquash
= (CheckNextCommitIsSquash() == 0);
1668 if (nextCommitIsSquash
|| mode
!= CGitLogListBase::LOGACTIONS_REBASE_PICK
)
1669 { // next commit is squash or not pick
1670 if (!this->m_SquashMessage
.IsEmpty())
1671 this->m_SquashMessage
+= _T("\n\n");
1672 this->m_SquashMessage
+= pRev
->GetSubject();
1673 this->m_SquashMessage
+= _T("\n");
1674 this->m_SquashMessage
+= pRev
->GetBody().TrimRight();
1675 if (m_bAddCherryPickedFrom
)
1677 if (!pRev
->GetBody().IsEmpty())
1678 m_SquashMessage
+= _T("\n");
1679 m_SquashMessage
+= _T("(cherry picked from commit ");
1680 m_SquashMessage
+= pRev
->m_CommitHash
.ToString();
1681 m_SquashMessage
+= _T(")");
1686 this->m_SquashMessage
.Empty();
1687 m_SquashFirstMetaData
.Empty();
1690 if ((nextCommitIsSquash
&& mode
!= CGitLogListBase::LOGACTIONS_REBASE_EDIT
) || mode
== CGitLogListBase::LOGACTIONS_REBASE_SQUASH
)
1691 { // next or this commit is squash (don't do this on edit->squash sequence)
1692 nocommit
=_T(" --no-commit ");
1695 if (nextCommitIsSquash
&& mode
!= CGitLogListBase::LOGACTIONS_REBASE_SQUASH
)
1696 m_SquashFirstMetaData
.Format(_T("--date=%s --author=\"%s <%s>\" "), pRev
->GetAuthorDate().Format(_T("%Y-%m-%dT%H:%M:%S")), pRev
->GetAuthorName(), pRev
->GetAuthorEmail());
1699 log
.Format(_T("%s %d: %s"), CGitLogListBase::GetRebaseActionName(mode
), GetCurrentCommitID(), pRev
->m_CommitHash
.ToString());
1701 AddLogString(pRev
->GetSubject());
1702 if (pRev
->GetSubject().IsEmpty())
1704 CMessageBox::Show(m_hWnd
, IDS_PROC_REBASE_EMPTYCOMMITMSG
, IDS_APPNAME
, MB_OK
| MB_ICONEXCLAMATION
);
1705 mode
= CGitLogListBase::LOGACTIONS_REBASE_EDIT
;
1708 CString cherryPickedFrom
;
1709 if (m_bAddCherryPickedFrom
)
1710 cherryPickedFrom
= _T("-x ");
1711 else if (!m_IsCherryPick
&& nocommit
.IsEmpty())
1712 cherryPickedFrom
= _T("--ff "); // for issue #1833: "If the current HEAD is the same as the parent of the cherry-pick’ed commit, then a fast forward to this commit will be performed."
1714 int isEmpty
= IsCommitEmpty(pRev
->m_CommitHash
);
1716 cherryPickedFrom
+= _T("--allow-empty ");
1717 else if (isEmpty
< 0)
1722 cmd
.Format(_T("git.exe cherry-pick %s%s %s"), cherryPickedFrom
, nocommit
, pRev
->m_CommitHash
.ToString());
1724 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1728 if(g_Git
.ListConflictFile(list
))
1730 AddLogString(_T("Get conflict files fail"));
1735 if (mode
== CGitLogListBase::LOGACTIONS_REBASE_PICK
)
1738 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
1740 if (!m_bAutoSkipFailedCommit
)
1742 choose
= CMessageBox::ShowCheck(m_hWnd
, IDS_CHERRYPICKFAILEDSKIP
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_SKIPBUTTON
, IDS_MSGBOX_RETRY
, IDS_MSGBOX_CANCEL
, NULL
, IDS_DO_SAME_FOR_REST
, &m_bAutoSkipFailedCommit
);
1745 m_bAutoSkipFailedCommit
= FALSE
;
1746 continue; // retry cherry pick
1749 if (m_bAutoSkipFailedCommit
|| choose
== 1)
1751 bool resetOK
= false;
1755 if (g_Git
.Run(_T("git.exe reset --hard"), &out
, CP_UTF8
))
1758 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1767 pRev
->GetRebaseAction() = CGitLogListBase::LOGACTIONS_REBASE_SKIP
;
1768 m_CommitList
.Invalidate();
1773 m_RebaseStage
= REBASE_ERROR
;
1774 AddLogString(_T("An unrecoverable error occurred."));
1777 if (mode
== CGitLogListBase::LOGACTIONS_REBASE_EDIT
)
1779 this->m_RebaseStage
= REBASE_EDIT
;
1780 return -1; // Edit return -1 to stop rebase.
1783 if(CheckNextCommitIsSquash())
1785 // let user edit last commmit message
1786 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1792 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
1793 if (mode
== CGitLogListBase::LOGACTIONS_REBASE_SQUASH
)
1794 m_RebaseStage
= REBASE_SQUASH_CONFLICT
;
1796 m_RebaseStage
= REBASE_CONFLICT
;
1803 if (mode
== CGitLogListBase::LOGACTIONS_REBASE_PICK
)
1805 pRev
->GetRebaseAction() |= CGitLogListBase::LOGACTIONS_REBASE_DONE
;
1808 if (mode
== CGitLogListBase::LOGACTIONS_REBASE_EDIT
)
1810 this->m_RebaseStage
= REBASE_EDIT
;
1811 return -1; // Edit return -1 to stop rebase.
1815 if(CheckNextCommitIsSquash())
1817 // let user edit last commmit message
1818 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1821 else if (mode
== CGitLogListBase::LOGACTIONS_REBASE_SQUASH
)
1822 pRev
->GetRebaseAction() |= CGitLogListBase::LOGACTIONS_REBASE_DONE
;
1829 BOOL
CRebaseDlg::IsEnd()
1831 if(m_CommitList
.m_IsOldFirst
)
1832 return m_CurrentRebaseIndex
>= this->m_CommitList
.GetItemCount();
1834 return m_CurrentRebaseIndex
<0;
1837 int CRebaseDlg::RebaseThread()
1839 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
1844 if( m_RebaseStage
== REBASE_START
)
1846 if( this->StartRebase() )
1851 m_RebaseStage
= REBASE_CONTINUE
;
1854 else if( m_RebaseStage
== REBASE_CONTINUE
)
1857 SendMessage(MSG_REBASE_UPDATE_UI
);
1861 m_RebaseStage
= REBASE_FINISH
;
1875 else if( m_RebaseStage
== REBASE_FINISH
)
1877 SendMessage(MSG_REBASE_UPDATE_UI
);
1878 m_RebaseStage
= REBASE_DONE
;
1886 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1889 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1890 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1894 void CRebaseDlg::ListConflictFile()
1896 this->m_FileListCtrl
.Clear();
1897 m_FileListCtrl
.SetHasCheckboxes(true);
1902 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
1904 this->m_FileListCtrl
.GetStatus(&list
,true);
1905 this->m_FileListCtrl
.Show(CTGitPath::LOGACTIONS_UNMERGED
|CTGitPath::LOGACTIONS_MODIFIED
|CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_DELETED
,
1906 CTGitPath::LOGACTIONS_UNMERGED
);
1908 m_FileListCtrl
.Check(GITSLC_SHOWFILES
);
1909 bool hasSubmoduleChange
= false;
1910 for (int i
= 0; i
< m_FileListCtrl
.GetItemCount(); i
++)
1912 CTGitPath
*entry
= (CTGitPath
*)m_FileListCtrl
.GetItemData(i
);
1913 if (entry
->IsDirectory())
1915 hasSubmoduleChange
= true;
1920 if (hasSubmoduleChange
)
1922 m_CtrlStatusText
.SetWindowText(m_sStatusText
+ _T(", ") + CString(MAKEINTRESOURCE(IDS_CARE_SUBMODULE_CHANGES
)));
1923 m_bStatusWarning
= true;
1924 m_CtrlStatusText
.Invalidate();
1928 m_CtrlStatusText
.SetWindowText(m_sStatusText
);
1929 m_bStatusWarning
= false;
1930 m_CtrlStatusText
.Invalidate();
1934 LRESULT
CRebaseDlg::OnRebaseUpdateUI(WPARAM
,LPARAM
)
1936 if (m_RebaseStage
== REBASE_FINISH
)
1941 UpdateCurrentStatus();
1942 if (m_RebaseStage
== REBASE_DONE
&& m_pTaskbarList
)
1943 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
); // do not show progress on taskbar any more to show we finished
1944 if(m_CurrentRebaseIndex
<0)
1946 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1948 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1950 switch(m_RebaseStage
)
1952 case REBASE_CONFLICT
:
1953 case REBASE_SQUASH_CONFLICT
:
1956 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_CONFLICT
);
1958 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
1959 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1964 g_GitAdminDir
.GetAdminDirPath(g_Git
.m_CurrentDir
, dotGitPath
);
1965 // vanilla git also re-uses MERGE_MSG on conflict (listing all conflicted files)
1966 // and it's also needed for cherry-pick in order to get cherry-picked-from included on conflicts
1967 CGit::LoadTextFile(dotGitPath
+ _T("MERGE_MSG"), logMessage
);
1969 if (logMessage
.IsEmpty())
1970 logMessage
= curRev
->GetSubject() + _T("\n") + curRev
->GetBody();
1971 this->m_LogMessageCtrl
.SetText(logMessage
);
1975 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1977 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1978 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1979 if (m_bAddCherryPickedFrom
)
1981 // Since the new commit is done and the HEAD points to it,
1982 // just using the new body modified by git self.
1983 GitRev headRevision
;
1984 headRevision
.GetCommit(_T("HEAD"));
1985 m_LogMessageCtrl
.SetText(headRevision
.GetSubject() + _T("\n") + headRevision
.GetBody());
1988 m_LogMessageCtrl
.SetText(curRev
->GetSubject() + _T("\n") + curRev
->GetBody());
1990 case REBASE_SQUASH_EDIT
:
1991 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1992 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1993 this->m_LogMessageCtrl
.SetText(this->m_SquashMessage
);
1995 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1998 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
2002 void CRebaseDlg::OnCancel()
2006 void CRebaseDlg::OnBnClickedAbort()
2009 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
2014 CString pron
= m_OrigUpstreamHash
.ToString();
2015 if(m_OrigUpstreamHash
.IsEmpty())
2017 __super::OnCancel();
2020 if(m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
2025 if(CMessageBox::Show(NULL
, IDS_PROC_REBASE_ABORT
, IDS_APPNAME
, MB_YESNO
) != IDYES
)
2028 if(this->m_IsFastForward
)
2030 cmd
.Format(_T("git.exe reset --hard %s --"),this->m_OrigBranchHash
.ToString());
2034 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2037 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
2043 __super::OnCancel();
2047 if (m_IsCherryPick
) // there are not "branch" at cherry pick mode
2049 cmd
.Format(_T("git.exe reset --hard %s --"), m_OrigUpstreamHash
.ToString());
2053 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2056 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
2063 __super::OnCancel();
2067 if (m_OrigHEADBranch
== m_BranchCtrl
.GetString())
2069 if (IsLocalBranch(m_OrigHEADBranch
))
2070 cmd
.Format(_T("git.exe checkout -f -B %s %s --"), m_BranchCtrl
.GetString(), m_OrigBranchHash
.ToString());
2072 cmd
.Format(_T("git.exe checkout -f %s --"), m_OrigBranchHash
.ToString());
2073 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2076 ::MessageBox(m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
2077 __super::OnCancel();
2081 cmd
.Format(_T("git.exe reset --hard %s --"), m_OrigBranchHash
.ToString());
2085 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2088 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
2097 if (m_OrigHEADBranch
!= g_Git
.GetCurrentBranch(true))
2099 if (IsLocalBranch(m_OrigHEADBranch
))
2100 cmd
.Format(_T("git.exe checkout -f -B %s %s --"), m_OrigHEADBranch
, m_OrigHEADHash
.ToString());
2102 cmd
.Format(_T("git.exe checkout -f %s --"), m_OrigHEADHash
.ToString());
2103 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2106 ::MessageBox(m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
2107 // continue to restore moved branch
2111 cmd
.Format(_T("git.exe reset --hard %s --"), m_OrigHEADHash
.ToString());
2115 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2118 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
2125 // restore moved branch
2126 if (IsLocalBranch(m_BranchCtrl
.GetString()))
2128 cmd
.Format(_T("git.exe branch -f %s %s --"), m_BranchCtrl
.GetString(), m_OrigBranchHash
.ToString());
2129 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
2132 ::MessageBox(m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
2133 __super::OnCancel();
2138 __super::OnCancel();
2140 CheckRestoreStash();
2143 void CRebaseDlg::OnBnClickedButtonReverse()
2145 CString temp
= m_BranchCtrl
.GetString();
2146 m_BranchCtrl
.AddString(m_UpstreamCtrl
.GetString());
2147 m_UpstreamCtrl
.AddString(temp
);
2148 OnCbnSelchangeUpstream();
2151 void CRebaseDlg::OnBnClickedButtonBrowse()
2153 if(CBrowseRefsDlg::PickRefForCombo(&m_UpstreamCtrl
, gPickRef_NoTag
))
2154 OnCbnSelchangeUpstream();
2157 void CRebaseDlg::OnBnClickedRebaseCheckForce()
2160 this->FetchLogList();
2163 void CRebaseDlg::OnBnClickedRebasePostButton()
2165 this->m_Upstream
=this->m_UpstreamCtrl
.GetString();
2166 this->m_Branch
=this->m_BranchCtrl
.GetString();
2168 this->EndDialog((int)(IDC_REBASE_POST_BUTTON
+this->m_PostButton
.GetCurrentEntry()));
2171 LRESULT
CRebaseDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
2177 void CRebaseDlg::Refresh()
2179 if (m_RebaseStage
== REBASE_CONFLICT
|| m_RebaseStage
== REBASE_SQUASH_CONFLICT
)
2185 if(this->m_IsCherryPick
)
2188 if(this->m_RebaseStage
== CHOOSE_BRANCH
)
2191 this->FetchLogList();
2195 void CRebaseDlg::OnBnClickedButtonUp2()
2198 pos
= m_CommitList
.GetFirstSelectedItemPosition();
2200 // do nothing if the first selected item is the first item in the list
2201 int idx
= m_CommitList
.GetNextSelectedItem(pos
);
2205 bool moveToTop
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
2206 int move
= moveToTop
? idx
: 1;
2207 pos
= m_CommitList
.GetFirstSelectedItemPosition();
2209 bool changed
= false;
2212 int index
=m_CommitList
.GetNextSelectedItem(pos
);
2215 CGitHash old
= m_CommitList
.m_logEntries
[index
- move
];
2216 m_CommitList
.m_logEntries
[index
- move
] = m_CommitList
.m_logEntries
[index
];
2217 m_CommitList
.m_logEntries
[index
] = old
;
2218 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
2219 m_CommitList
.SetItemState(index
- move
, LVIS_SELECTED
, LVIS_SELECTED
);
2220 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
2226 pos
= m_CommitList
.GetFirstSelectedItemPosition();
2227 m_CommitList
.EnsureVisible(m_CommitList
.GetNextSelectedItem(pos
), false);
2228 m_CommitList
.Invalidate();
2229 m_CommitList
.SetFocus();
2233 void CRebaseDlg::OnBnClickedButtonDown2()
2235 if (m_CommitList
.GetSelectedCount() == 0)
2238 bool moveToBottom
= !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000);
2240 pos
= m_CommitList
.GetFirstSelectedItemPosition();
2241 bool changed
= false;
2242 // use an array to store all selected item indexes; the user won't select too much items
2243 int* indexes
= NULL
;
2244 indexes
= new int[m_CommitList
.GetSelectedCount()];
2248 indexes
[i
++] = m_CommitList
.GetNextSelectedItem(pos
);
2250 int distanceToBottom
= m_CommitList
.GetItemCount() - 1 - indexes
[m_CommitList
.GetSelectedCount() - 1];
2251 int move
= moveToBottom
? distanceToBottom
: 1;
2252 // don't move any item if the last selected item is the last item in the m_CommitList
2253 // (that would change the order of the selected items)
2254 if (distanceToBottom
> 0)
2256 // iterate over the indexes backwards in order to correctly move multiselected items
2257 for (i
= m_CommitList
.GetSelectedCount() - 1; i
>= 0; i
--)
2259 int index
= indexes
[i
];
2260 CGitHash old
= m_CommitList
.m_logEntries
[index
+ move
];
2261 m_CommitList
.m_logEntries
[index
+ move
] = m_CommitList
.m_logEntries
[index
];
2262 m_CommitList
.m_logEntries
[index
] = old
;
2263 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
2264 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
2265 m_CommitList
.SetItemState(index
+ move
, LVIS_SELECTED
, LVIS_SELECTED
);
2269 m_CommitList
.EnsureVisible(indexes
[m_CommitList
.GetSelectedCount() - 1] + move
, false);
2274 m_CommitList
.Invalidate();
2275 m_CommitList
.SetFocus();
2279 LRESULT
CRebaseDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
2281 m_pTaskbarList
.Release();
2282 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
2283 SetUUIDOverlayIcon(m_hWnd
);
2287 void CRebaseDlg::OnLvnItemchangedLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2289 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
2291 if(m_CommitList
.m_bNoDispUpdates
)
2293 if (pNMLV
->iItem
>= 0)
2295 this->m_CommitList
.m_nSearchIndex
= pNMLV
->iItem
;
2296 if (pNMLV
->iSubItem
!= 0)
2298 if ((pNMLV
->iItem
== m_CommitList
.m_arShownList
.GetCount()))
2300 // remove the selected state
2301 if (pNMLV
->uChanged
& LVIF_STATE
)
2303 m_CommitList
.SetItemState(pNMLV
->iItem
, 0, LVIS_SELECTED
);
2304 FillLogMessageCtrl();
2308 if (pNMLV
->uChanged
& LVIF_STATE
)
2310 FillLogMessageCtrl();
2315 FillLogMessageCtrl();
2319 void CRebaseDlg::FillLogMessageCtrl()
2321 int selCount
= m_CommitList
.GetSelectedCount();
2322 if (selCount
== 1 && (m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
))
2324 POSITION pos
= m_CommitList
.GetFirstSelectedItemPosition();
2325 int selIndex
= m_CommitList
.GetNextSelectedItem(pos
);
2326 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_CommitList
.m_arShownList
.SafeGetAt(selIndex
));
2327 m_FileListCtrl
.UpdateWithGitPathList(pLogEntry
->GetFiles(&m_CommitList
));
2328 m_FileListCtrl
.m_CurrentVersion
= pLogEntry
->m_CommitHash
;
2329 m_FileListCtrl
.Show(GITSLC_SHOWVERSIONED
);
2330 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
2331 m_LogMessageCtrl
.SetText(pLogEntry
->GetSubject() + _T("\n") + pLogEntry
->GetBody());
2332 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);
2335 void CRebaseDlg::OnBnClickedCheckCherryPickedFrom()
2340 LRESULT
CRebaseDlg::OnRebaseActionMessage(WPARAM
, LPARAM
)
2342 if (m_RebaseStage
== REBASE_ERROR
|| m_RebaseStage
== REBASE_CONFLICT
)
2344 GitRev
*pRev
= (GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
2345 int mode
= pRev
->GetRebaseAction() & CGitLogListBase::LOGACTIONS_REBASE_MODE_MASK
;
2346 if (mode
== CGitLogListBase::LOGACTIONS_REBASE_SKIP
)
2349 bool resetOK
= false;
2353 if (g_Git
.Run(_T("git.exe reset --hard"), &out
, CP_UTF8
))
2356 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
2365 m_FileListCtrl
.Clear();
2366 m_RebaseStage
= REBASE_CONTINUE
;
2367 UpdateCurrentStatus();
2375 void CRebaseDlg::OnBnClickedSplitAllOptions()
2377 switch (m_SplitAllOptions
.GetCurrentEntry())
2380 SetAllRebaseAction(CGitLogListBase::LOGACTIONS_REBASE_PICK
);
2383 SetAllRebaseAction(CGitLogListBase::LOGACTIONS_REBASE_SQUASH
);
2386 SetAllRebaseAction(CGitLogListBase::LOGACTIONS_REBASE_EDIT
);
2393 void CRebaseDlg::OnBnClickedRebaseSplitCommit()