1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2011-2012 - Sven Strickroth <email@cs-ware.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // RebaseDlg.cpp : implementation file
25 #include "TortoiseProc.h"
26 #include "RebaseDlg.h"
28 #include "LoglistUtils.h"
29 #include "MessageBox.h"
30 #include "UnicodeUtils.h"
31 #include "BrowseRefsDlg.h"
32 #include "ProgressDlg.h"
33 #include "SmartHandle.h"
34 #include "../TGitCache/CacheInterface.h"
35 #include "Settings\Settings.h"
39 IMPLEMENT_DYNAMIC(CRebaseDlg
, CResizableStandAloneDialog
)
41 CRebaseDlg::CRebaseDlg(CWnd
* pParent
/*=NULL*/)
42 : CResizableStandAloneDialog(CRebaseDlg::IDD
, pParent
)
46 , m_bAddCherryPickedFrom(FALSE
)
48 m_RebaseStage
=CHOOSE_BRANCH
;
49 m_CurrentRebaseIndex
=-1;
50 m_bThreadRunning
=FALSE
;
51 this->m_IsCherryPick
= FALSE
;
53 m_IsFastForward
=FALSE
;
56 CRebaseDlg::~CRebaseDlg()
60 void CRebaseDlg::DoDataExchange(CDataExchange
* pDX
)
62 CDialog::DoDataExchange(pDX
);
63 DDX_Control(pDX
, IDC_REBASE_PROGRESS
, m_ProgressBar
);
64 DDX_Control(pDX
, IDC_STATUS_STATIC
, m_CtrlStatusText
);
65 DDX_Check(pDX
, IDC_PICK_ALL
, m_bPickAll
);
66 DDX_Check(pDX
, IDC_SQUASH_ALL
, m_bSquashAll
);
67 DDX_Check(pDX
, IDC_EDIT_ALL
, m_bEditAll
);
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
);
78 BEGIN_MESSAGE_MAP(CRebaseDlg
, CResizableStandAloneDialog
)
79 ON_BN_CLICKED(IDC_PICK_ALL
, &CRebaseDlg::OnBnClickedPickAll
)
80 ON_BN_CLICKED(IDC_SQUASH_ALL
, &CRebaseDlg::OnBnClickedSquashAll
)
81 ON_BN_CLICKED(IDC_EDIT_ALL
, &CRebaseDlg::OnBnClickedEditAll
)
82 ON_BN_CLICKED(IDC_REBASE_SPLIT
, &CRebaseDlg::OnBnClickedRebaseSplit
)
83 ON_BN_CLICKED(IDC_REBASE_CONTINUE
,OnBnClickedContinue
)
84 ON_BN_CLICKED(IDC_REBASE_ABORT
, OnBnClickedAbort
)
86 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH
, &CRebaseDlg::OnCbnSelchangeBranch
)
87 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM
, &CRebaseDlg::OnCbnSelchangeUpstream
)
88 ON_MESSAGE(MSG_REBASE_UPDATE_UI
, OnRebaseUpdateUI
)
89 ON_BN_CLICKED(IDC_BUTTON_BROWSE
, &CRebaseDlg::OnBnClickedButtonBrowse
)
90 ON_BN_CLICKED(IDC_REBASE_CHECK_FORCE
, &CRebaseDlg::OnBnClickedRebaseCheckForce
)
91 ON_BN_CLICKED(IDC_CHECK_CHERRYPICKED_FROM
, &CRebaseDlg::OnBnClickedCheckCherryPickedFrom
)
92 ON_BN_CLICKED(IDC_REBASE_POST_BUTTON
, &CRebaseDlg::OnBnClickedRebasePostButton
)
93 ON_BN_CLICKED(IDC_BUTTON_UP2
, &CRebaseDlg::OnBnClickedButtonUp2
)
94 ON_BN_CLICKED(IDC_BUTTON_DOWN2
, &CRebaseDlg::OnBnClickedButtonDown2
)
95 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
96 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_COMMIT_LIST
, OnLvnItemchangedLoglist
)
99 void CRebaseDlg::AddRebaseAnchor()
101 AddAnchor(IDC_REBASE_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
102 AddAnchor(IDC_COMMIT_LIST
,TOP_LEFT
, TOP_RIGHT
);
103 AddAnchor(IDC_REBASE_SPLIT
,TOP_LEFT
, TOP_RIGHT
);
104 AddAnchor(IDC_STATUS_STATIC
, BOTTOM_LEFT
,BOTTOM_RIGHT
);
105 AddAnchor(IDC_REBASE_CONTINUE
,BOTTOM_RIGHT
);
106 AddAnchor(IDC_REBASE_ABORT
, BOTTOM_RIGHT
);
107 AddAnchor(IDC_REBASE_PROGRESS
,BOTTOM_LEFT
, BOTTOM_RIGHT
);
108 AddAnchor(IDC_PICK_ALL
,TOP_LEFT
);
109 AddAnchor(IDC_SQUASH_ALL
,TOP_LEFT
);
110 AddAnchor(IDC_EDIT_ALL
,TOP_LEFT
);
111 AddAnchor(IDC_BUTTON_UP2
,TOP_LEFT
);
112 AddAnchor(IDC_BUTTON_DOWN2
,TOP_LEFT
);
113 AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM
,TOP_LEFT
);
114 AddAnchor(IDC_REBASE_COMBOXEX_BRANCH
,TOP_LEFT
);
115 AddAnchor(IDC_REBASE_STATIC_UPSTREAM
,TOP_LEFT
);
116 AddAnchor(IDC_REBASE_STATIC_BRANCH
,TOP_LEFT
);
117 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
118 AddAnchor(IDC_REBASE_CHECK_FORCE
,TOP_RIGHT
);
119 AddAnchor(IDC_CHECK_CHERRYPICKED_FROM
, TOP_RIGHT
);
120 AddAnchor(IDC_REBASE_POST_BUTTON
,BOTTOM_LEFT
);
122 this->AddOthersToAnchor();
125 BOOL
CRebaseDlg::OnInitDialog()
127 CResizableStandAloneDialog::OnInitDialog();
128 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
130 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
131 // do this, Explorer would be unable to send that message to our window if we
132 // were running elevated. It's OK to make the call all the time, since if we're
133 // not elevated, this is a no-op.
134 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
135 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
136 CAutoLibrary hUser
= ::LoadLibrary(_T("user32.dll"));
139 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
140 if (pfnChangeWindowMessageFilterEx
)
142 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
145 m_pTaskbarList
.Release();
146 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
149 //IDC_REBASE_DUMY_TAB
151 GetClientRect(m_DlgOrigRect
);
152 m_CommitList
.GetClientRect(m_CommitListOrigRect
);
154 CWnd
*pwnd
=this->GetDlgItem(IDC_REBASE_DUMY_TAB
);
155 pwnd
->GetWindowRect(&rectDummy
);
156 this->ScreenToClient(rectDummy
);
158 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_REBASE_TAB
))
160 TRACE0("Failed to create output tab window\n");
161 return FALSE
; // fail to create
163 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
164 // Create output panes:
165 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
166 DWORD dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
168 if (! this->m_FileListCtrl
.Create(dwStyle
,rectDummy
,&this->m_ctrlTabCtrl
,0) )
170 TRACE0("Failed to create output windows\n");
171 return FALSE
; // fail to create
174 if( ! this->m_LogMessageCtrl
.Create(_T("Scintilla"),_T("source"),0,rectDummy
,&m_ctrlTabCtrl
,0,0) )
176 TRACE0("Failed to create log message control");
179 m_LogMessageCtrl
.Init(0);
180 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);
182 dwStyle
= LBS_NOINTEGRALHEIGHT
| WS_CHILD
| WS_VISIBLE
| WS_HSCROLL
| WS_VSCROLL
;
184 if (!m_wndOutputRebase
.Create(_T("Scintilla"),_T("source"),0,rectDummy
, &m_ctrlTabCtrl
, 0,0) )
186 TRACE0("Failed to create output windows\n");
187 return -1; // fail to create
189 m_wndOutputRebase
.Init(0);
190 m_wndOutputRebase
.Call(SCI_SETREADONLY
, TRUE
);
192 m_tooltips
.Create(this);
194 m_tooltips
.AddTool(IDC_REBASE_CHECK_FORCE
,IDS_REBASE_FORCE_TT
);
195 m_tooltips
.AddTool(IDC_REBASE_ABORT
,IDS_REBASE_ABORT_TT
);
199 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
);
201 m_ctrlTabCtrl
.AddTab(&m_FileListCtrl
, CString(MAKEINTRESOURCE(IDS_PROC_REVISIONFILES
)));
202 m_ctrlTabCtrl
.AddTab(&m_LogMessageCtrl
, CString(MAKEINTRESOURCE(IDS_PROC_COMMITMESSAGE
)), 1);
205 AdjustControlSize(IDC_PICK_ALL
);
206 AdjustControlSize(IDC_SQUASH_ALL
);
207 AdjustControlSize(IDC_EDIT_ALL
);
208 AdjustControlSize(IDC_CHECK_CHERRYPICKED_FROM
);
210 CString sWindowTitle
;
211 GetWindowText(sWindowTitle
);
212 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
214 EnableSaveRestore(_T("RebaseDlg"));
216 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
217 RECT rcDlg
, rcLogMsg
, rcFileList
;
218 GetClientRect(&rcDlg
);
219 m_CommitList
.GetWindowRect(&rcLogMsg
);
220 ScreenToClient(&rcLogMsg
);
221 this->m_ctrlTabCtrl
.GetWindowRect(&rcFileList
);
222 ScreenToClient(&rcFileList
);
226 m_wndSplitter
.GetWindowRect(&rectSplitter
);
227 ScreenToClient(&rectSplitter
);
228 int delta
= yPos
- rectSplitter
.top
;
229 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
231 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
236 if( this->m_RebaseStage
== CHOOSE_BRANCH
)
238 this->LoadBranchInfo();
243 this->m_BranchCtrl
.EnableWindow(FALSE
);
244 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
247 m_CommitList
.m_ColumnRegKey
= _T("Rebase");
248 m_CommitList
.m_IsIDReplaceAction
= TRUE
;
249 // m_CommitList.m_IsOldFirst = TRUE;
250 m_CommitList
.m_IsRebaseReplaceGraph
= TRUE
;
251 m_CommitList
.m_bNoHightlightHead
= TRUE
;
253 m_CommitList
.InsertGitColumn();
255 this->SetControlEnable();
257 if(!this->m_PreCmd
.IsEmpty())
259 CProgressDlg progress
;
260 progress
.m_GitCmd
=m_PreCmd
;
261 progress
.m_bAutoCloseOnSuccess
=true;
267 this->m_BranchCtrl
.SetCurSel(-1);
268 this->m_BranchCtrl
.EnableWindow(FALSE
);
269 GetDlgItem(IDC_REBASE_CHECK_FORCE
)->ShowWindow(SW_HIDE
);
270 GetDlgItem(IDC_BUTTON_BROWSE
)->EnableWindow(FALSE
);
271 this->m_UpstreamCtrl
.AddString(_T("HEAD"));
272 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
273 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CHERRYPICK
)));
274 this->m_CommitList
.StartFilter();
278 GetDlgItem(IDC_CHECK_CHERRYPICKED_FROM
)->ShowWindow(SW_HIDE
);
279 SetContinueButtonText();
280 m_CommitList
.DeleteAllItems();
284 m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_CHERRY_PICK
)|
285 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_SWITCHTOREV
)|
286 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_RESET
)|
287 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTREV
)|
288 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_TO_VERSION
)|
289 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV
)|
290 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_COMBINE_COMMIT
));
292 if(m_CommitList
.m_IsOldFirst
)
293 this->m_CurrentRebaseIndex
= -1;
295 this->m_CurrentRebaseIndex
= (int)m_CommitList
.m_logEntries
.size();
298 if(this->CheckRebaseCondition())
300 /* Disable Start Rebase */
301 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
306 // CRebaseDlg message handlers
308 void CRebaseDlg::OnBnClickedPickAll()
312 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
314 this->m_bEditAll
=FALSE
;
315 this->m_bSquashAll
=FALSE
;
316 this->UpdateData(FALSE
);
319 void CRebaseDlg::OnBnClickedSquashAll()
322 if(this->m_bSquashAll
)
323 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
325 this->m_bEditAll
=FALSE
;
326 this->m_bPickAll
=FALSE
;
327 this->UpdateData(FALSE
);
330 void CRebaseDlg::OnBnClickedEditAll()
333 if( this->m_bEditAll
)
334 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
336 this->m_bPickAll
=FALSE
;
337 this->m_bSquashAll
=FALSE
;
338 this->UpdateData(FALSE
);
341 void CRebaseDlg::SetAllRebaseAction(int action
)
343 for(int i
=0;i
<this->m_CommitList
.m_logEntries
.size();i
++)
345 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
)=action
;
347 m_CommitList
.Invalidate();
350 void CRebaseDlg::OnBnClickedRebaseSplit()
355 LRESULT
CRebaseDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
359 if (wParam
== IDC_REBASE_SPLIT
)
361 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
367 return __super::DefWindowProc(message
, wParam
, lParam
);
370 void CRebaseDlg::DoSize(int delta
)
372 this->RemoveAllAnchors();
374 CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST
), delta
, CW_TOPALIGN
);
375 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
376 CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB
), -delta
, CW_BOTTOMALIGN
);
377 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
378 CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL
),0,delta
);
379 CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL
),0,delta
);
380 CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL
),0,delta
);
381 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_UP2
),0,delta
);
382 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_DOWN2
),0,delta
);
383 CSplitterControl::ChangePos(GetDlgItem(IDC_REBASE_CHECK_FORCE
),0,delta
);
385 this->AddRebaseAnchor();
386 // adjust the minimum size of the dialog to prevent the resizing from
387 // moving the list control too far down.
389 m_CommitList
.GetClientRect(rcLogMsg
);
390 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_CommitListOrigRect
.Height()+rcLogMsg
.Height()));
393 // m_CommitList.Invalidate();
395 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
397 this->m_ctrlTabCtrl
.Invalidate();
398 this->m_CommitList
.Invalidate();
399 this->m_FileListCtrl
.Invalidate();
400 this->m_LogMessageCtrl
.Invalidate();
404 void CRebaseDlg::SetSplitterRange()
406 if ((m_CommitList
)&&(m_ctrlTabCtrl
))
409 m_CommitList
.GetWindowRect(rcTop
);
410 ScreenToClient(rcTop
);
412 m_ctrlTabCtrl
.GetWindowRect(rcMiddle
);
413 ScreenToClient(rcMiddle
);
414 if (rcMiddle
.Height() && rcMiddle
.Width())
415 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
419 void CRebaseDlg::OnSize(UINT nType
,int cx
, int cy
)
421 // first, let the resizing take place
422 __super::OnSize(nType
, cx
, cy
);
428 void CRebaseDlg::SaveSplitterPos()
432 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
434 m_wndSplitter
.GetWindowRect(&rectSplitter
);
435 ScreenToClient(&rectSplitter
);
436 regPos
= rectSplitter
.top
;
440 void CRebaseDlg::LoadBranchInfo()
442 m_BranchCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
443 m_UpstreamCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
448 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_ALL
);
449 m_BranchCtrl
.AddString(list
);
450 m_BranchCtrl
.SetCurSel(current
);
452 g_Git
.GetBranchList(list
, NULL
, CGit::BRANCH_ALL_F
);
453 m_UpstreamCtrl
.AddString(list
);
455 AddBranchToolTips(&m_BranchCtrl
);
456 AddBranchToolTips(&m_UpstreamCtrl
);
458 if(!m_Upstream
.IsEmpty())
460 m_UpstreamCtrl
.AddString(m_Upstream
);
461 m_UpstreamCtrl
.SetCurSel(m_UpstreamCtrl
.GetCount()-1);
465 //Select pull-remote from current branch
466 CString currentBranch
= g_Git
.GetSymbolicRef();
468 configName
.Format(L
"branch.%s.remote", currentBranch
);
469 CString pullRemote
= g_Git
.GetConfigValue(configName
);
471 //Select pull-branch from current branch
472 configName
.Format(L
"branch.%s.merge", currentBranch
);
473 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
475 CString defaultUpstream
;
476 defaultUpstream
.Format(L
"remotes/%s/%s", pullRemote
, pullBranch
);
477 int found
= m_UpstreamCtrl
.FindStringExact(0, defaultUpstream
);
479 m_UpstreamCtrl
.SetCurSel(found
);
481 m_UpstreamCtrl
.SetCurSel(-1);
485 void CRebaseDlg::OnCbnSelchangeBranch()
490 void CRebaseDlg::OnCbnSelchangeUpstream()
495 void CRebaseDlg::FetchLogList()
498 m_IsFastForward
=FALSE
;
500 hash
=g_Git
.GetHash(m_BranchCtrl
.GetString());
502 if(hash
== g_Git
.GetHash(this->m_UpstreamCtrl
.GetString()))
504 m_CommitList
.Clear();
506 fmt
.LoadString(IDS_REBASE_EQUAL_FMT
);
507 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
509 m_CommitList
.ShowText(text
);
510 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
514 if (g_Git
.IsFastForward(m_BranchCtrl
.GetString(), m_UpstreamCtrl
.GetString(), &base
))
517 this->m_IsFastForward
=TRUE
;
519 m_CommitList
.Clear();
521 fmt
.LoadString(IDS_REBASE_FASTFORWARD_FMT
);
522 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString(),
523 m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
525 m_CommitList
.ShowText(text
);
526 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(true);
527 SetContinueButtonText();
536 hash
=g_Git
.GetHash(m_UpstreamCtrl
.GetString());
540 m_CommitList
.Clear();
542 fmt
.LoadString(IDS_REBASE_UPTODATE_FMT
);
543 text
.Format(fmt
,m_BranchCtrl
.GetString());
544 m_CommitList
.ShowText(text
);
545 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
546 SetContinueButtonText();
551 m_CommitList
.Clear();
553 from
= m_UpstreamCtrl
.GetString();
554 to
= m_BranchCtrl
.GetString();
555 this->m_CommitList
.FillGitLog(NULL
,0,&from
,&to
);
557 if( m_CommitList
.GetItemCount() == 0 )
558 m_CommitList
.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_NOTHINGTOREBASE
)));
560 hash
=g_Git
.GetHash(m_UpstreamCtrl
.GetString());
563 if(m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
.size() >=0 )
565 if(hash
== m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
[0])
567 m_CommitList
.Clear();
568 m_CommitList
.ShowText(_T("Nothing Rebase"));
574 AddBranchToolTips(&this->m_BranchCtrl
);
575 AddBranchToolTips(&this->m_UpstreamCtrl
);
577 for(int i
=0;i
<m_CommitList
.m_logEntries
.size();i
++)
579 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
) = CTGitPath::LOGACTIONS_REBASE_PICK
;
582 m_CommitList
.Invalidate();
584 if(m_CommitList
.m_IsOldFirst
)
585 this->m_CurrentRebaseIndex
= -1;
587 this->m_CurrentRebaseIndex
= (int)m_CommitList
.m_logEntries
.size();
589 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
590 SetContinueButtonText();
593 void CRebaseDlg::AddBranchToolTips(CHistoryCombo
*pBranch
)
597 CString text
=pBranch
->GetString();
603 tooltip
.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"),
604 CString(MAKEINTRESOURCE(IDS_LOG_REVISION
)),
605 rev
.m_CommitHash
.ToString(),
606 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
)),
608 rev
.GetAuthorEmail(),
609 CString(MAKEINTRESOURCE(IDS_LOG_DATE
)),
610 CLoglistUtils::FormatDateAndTime(rev
.GetAuthorDate(), DATE_LONGDATE
),
611 CString(MAKEINTRESOURCE(IDS_LOG_MESSAGE
)),
615 pBranch
->DisableTooltip();
616 this->m_tooltips
.AddTool(pBranch
->GetComboBoxCtrl(),tooltip
);
620 BOOL
CRebaseDlg::PreTranslateMessage(MSG
*pMsg
)
622 if (pMsg
->message
== WM_KEYDOWN
)
624 switch (pMsg
->wParam
)
627 if(LogListHasFocus(pMsg
->hwnd
))
629 m_CommitList
.ShiftSelectedAction();
634 if(LogListHasFocus(pMsg
->hwnd
))
636 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
641 if(LogListHasFocus(pMsg
->hwnd
))
643 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP
);
648 if(LogListHasFocus(pMsg
->hwnd
))
650 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
655 if(LogListHasFocus(pMsg
->hwnd
))
657 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
662 if(LogListHasFocus(pMsg
->hwnd
) && GetAsyncKeyState(VK_CONTROL
) & 0x8000)
664 // select all entries
665 for (int i
= 0; i
< m_CommitList
.GetItemCount(); ++i
)
667 m_CommitList
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
680 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
682 if (GetDlgItem(IDC_REBASE_CONTINUE
)->IsWindowEnabled())
683 GetDlgItem(IDC_REBASE_CONTINUE
)->SetFocus();
684 else if (GetDlgItem(IDC_REBASE_ABORT
)->IsWindowEnabled())
685 GetDlgItem(IDC_REBASE_ABORT
)->SetFocus();
687 GetDlgItem(IDHELP
)->SetFocus();
692 /* Avoid TAB control destroy but dialog exist*/
697 ::GetClassName(pMsg
->hwnd
,buff
,128);
700 if(_tcsnicmp(buff
,_T("RichEdit20W"),128)==0 ||
701 _tcsnicmp(buff
,_T("Scintilla"),128)==0 ||
702 _tcsnicmp(buff
,_T("SysListView32"),128)==0||
703 ::GetParent(pMsg
->hwnd
) == this->m_ctrlTabCtrl
.m_hWnd
)
705 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
711 else if (pMsg
->message
== WM_NEXTDLGCTL
)
713 if (GetFocus()->GetSafeHwnd() == m_LogMessageCtrl
.GetSafeHwnd())
715 if (GetDlgItem(IDC_REBASE_CONTINUE
)->IsWindowEnabled())
716 GetDlgItem(IDC_REBASE_CONTINUE
)->SetFocus();
717 else if (GetDlgItem(IDC_REBASE_ABORT
)->IsWindowEnabled())
718 GetDlgItem(IDC_REBASE_ABORT
)->SetFocus();
720 GetDlgItem(IDHELP
)->SetFocus();
724 m_tooltips
.RelayEvent(pMsg
);
725 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
728 bool CRebaseDlg::LogListHasFocus(HWND hwnd
)
731 ::GetClassName(hwnd
, buff
, 128);
733 if(_tcsnicmp(buff
, _T("SysListView32"), 128) == 0)
738 int CRebaseDlg::CheckRebaseCondition()
740 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
742 if( !g_Git
.CheckCleanWorkTree() )
744 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
747 cmd
=_T("git.exe stash");
748 this->AddLogString(cmd
);
749 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
751 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
759 //Todo Check $REBASE_ROOT
762 while (g_Git
.GetUserName().IsEmpty() || g_Git
.GetUserEmail().IsEmpty())
764 if (CMessageBox::Show(NULL
, IDS_PROC_NOUSERDATA
, IDS_APPNAME
, MB_YESNO
| MB_ICONERROR
) == IDYES
)
766 CTGitPath
path(g_Git
.m_CurrentDir
);
767 CSettings
dlg(IDS_PROC_SETTINGS_TITLE
, &path
);
768 dlg
.SetTreeViewMode(TRUE
, TRUE
, TRUE
);
769 dlg
.SetTreeWidth(220);
770 dlg
.m_DefaultPage
= _T("gitconfig");
778 //Todo call pre_rebase_hook
781 int CRebaseDlg::StartRebase()
784 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
785 if(!this->m_IsCherryPick
)
787 //Todo call comment_for_reflog
788 cmd
.Format(_T("git.exe checkout %s"),this->m_BranchCtrl
.GetString());
789 this->AddLogString(cmd
);
791 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
793 this->AddLogString(out
);
797 this->AddLogString(out
);
800 cmd
=_T("git.exe rev-parse --verify HEAD");
801 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
803 AddLogString(CString(MAKEINTRESOURCE(IDS_PROC_NOHEAD
)));
807 //git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
808 // echo "detached HEAD" > "$DOTEST"/head-name
810 cmd
.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));
811 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
813 AddLogString(_T("update ORIG_HEAD Fail"));
817 m_OrigUpstreamHash
.Empty();
818 m_OrigUpstreamHash
= g_Git
.GetHash(this->m_UpstreamCtrl
.GetString());
819 if(m_OrigUpstreamHash
.IsEmpty())
821 this->AddLogString(m_OrigUpstreamHash
);
825 if( !this->m_IsCherryPick
)
827 cmd
.Format(_T("git.exe checkout -f %s"), m_OrigUpstreamHash
.ToString());
828 this->AddLogString(cmd
);
831 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
833 this->AddLogString(out
);
839 if( !this->m_IsCherryPick
)
841 m_OrigBranchHash
= g_Git
.GetHash(this->m_BranchCtrl
.GetString());
842 if(m_OrigBranchHash
.IsEmpty())
844 this->AddLogString(m_OrigBranchHash
.ToString());
847 log
.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTREBASE
)));
850 log
.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTCHERRYPICK
)));
852 this->AddLogString(log
);
855 int CRebaseDlg::VerifyNoConflict()
858 if(g_Git
.ListConflictFile(list
))
860 AddLogString(_T("Get conflict files fail"));
863 if( list
.GetCount() != 0 )
865 CMessageBox::Show(NULL
, IDS_PROGRS_CONFLICTSOCCURED
, IDS_APPNAME
, MB_OK
);
871 int CRebaseDlg::FinishRebase()
873 if(this->m_IsCherryPick
) //cherry pick mode no "branch", working at upstream branch
876 git_revnum_t head
= g_Git
.GetHash(_T("HEAD"));
880 cmd
.Format(_T("git.exe checkout -f %s"),this->m_BranchCtrl
.GetString());
882 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
890 cmd
.Format(_T("git.exe reset --hard %s"),head
);
892 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
899 m_ctrlTabCtrl
.RemoveTab(0);
900 m_ctrlTabCtrl
.RemoveTab(0);
901 m_LogMessageCtrl
.ShowWindow(SW_HIDE
);
902 m_CtrlStatusText
.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_REBASEFINISHED
)));
906 void CRebaseDlg::OnBnClickedContinue()
908 if( m_RebaseStage
== REBASE_DONE
)
914 if( this->m_IsFastForward
)
917 CString oldbranch
= g_Git
.GetCurrentBranch();
918 if( oldbranch
!= m_BranchCtrl
.GetString() )
920 cmd
.Format(_T("git.exe checkout %s"),m_BranchCtrl
.GetString());
922 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
924 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
931 m_OrigBranchHash
= g_Git
.GetHash(m_BranchCtrl
.GetString());
932 m_OrigUpstreamHash
= g_Git
.GetHash(this->m_UpstreamCtrl
.GetString());
934 if(!g_Git
.IsFastForward(this->m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString()))
936 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
937 AddLogString(_T("No fast forward possible.\r\nMaybe repository changed"));
941 cmd
.Format(_T("git.exe reset --hard %s"),g_Git
.FixBranchName(this->m_UpstreamCtrl
.GetString()));
943 log
.Format(IDS_PROC_REBASE_FFTO
, m_UpstreamCtrl
.GetString());
944 this->AddLogString(log
);
947 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
948 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
950 AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL
)));
955 AddLogString(CString(MAKEINTRESOURCE(IDS_DONE
)));
956 m_RebaseStage
= REBASE_DONE
;
957 UpdateCurrentStatus();
961 if( m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
963 if(CheckRebaseCondition())
965 m_RebaseStage
= REBASE_START
;
966 m_FileListCtrl
.Clear();
967 m_FileListCtrl
.m_CurrentVersion
= L
"";
968 m_ctrlTabCtrl
.SetTabLabel(REBASE_TAB_CONFLICT
, CString(MAKEINTRESOURCE(IDS_PROC_CONFLICTFILES
)));
969 m_ctrlTabCtrl
.AddTab(&m_wndOutputRebase
, CString(MAKEINTRESOURCE(IDS_LOG
)), 2);
972 if( m_RebaseStage
== REBASE_FINISH
)
980 if( m_RebaseStage
== REBASE_SQUASH_CONFLICT
)
982 if(VerifyNoConflict())
984 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
985 if(this->CheckNextCommitIsSquash())
986 {//next commit is not squash;
987 m_RebaseStage
= REBASE_SQUASH_EDIT
;
988 this->OnRebaseUpdateUI(0,0);
989 this->UpdateCurrentStatus();
993 m_RebaseStage
=REBASE_CONTINUE
;
994 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
995 this->UpdateCurrentStatus();
999 if( m_RebaseStage
== REBASE_CONFLICT
)
1001 if(VerifyNoConflict())
1004 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1006 CString out
=_T("");
1008 cmd
.Format(_T("git.exe commit -a -C %s"), curRev
->m_CommitHash
.ToString());
1012 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1015 if(!g_Git
.CheckCleanWorkTree())
1017 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1023 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1024 if( curRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_EDIT
)
1026 m_RebaseStage
=REBASE_EDIT
;
1027 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1028 this->UpdateCurrentStatus();
1033 m_RebaseStage
=REBASE_CONTINUE
;
1034 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
1035 this->UpdateCurrentStatus();
1039 if( m_RebaseStage
== REBASE_EDIT
|| m_RebaseStage
== REBASE_SQUASH_EDIT
)
1042 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1044 str
=this->m_LogMessageCtrl
.GetText();
1045 if(str
.Trim().IsEmpty())
1047 CMessageBox::Show(NULL
, IDS_PROC_COMMITMESSAGE_EMPTY
,IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1051 CString tempfile
=::GetTempFile();
1052 CAppUtils::SaveCommitUnicodeFile(tempfile
, str
);
1056 if( m_RebaseStage
== REBASE_SQUASH_EDIT
)
1057 cmd
.Format(_T("git.exe commit -F \"%s\""), tempfile
);
1059 cmd
.Format(_T("git.exe commit --amend -F \"%s\""), tempfile
);
1061 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1063 if(!g_Git
.CheckCleanWorkTree())
1065 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1070 CFile::Remove(tempfile
);
1072 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1073 m_RebaseStage
=REBASE_CONTINUE
;
1074 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
1075 this->UpdateCurrentStatus();
1079 InterlockedExchange(&m_bThreadRunning
, TRUE
);
1082 if (AfxBeginThread(RebaseThreadEntry
, this)==NULL
)
1084 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1085 CMessageBox::Show(NULL
, _T("Create Rebase Thread Fail"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1089 int CRebaseDlg::CheckNextCommitIsSquash()
1092 if(m_CommitList
.m_IsOldFirst
)
1093 index
=m_CurrentRebaseIndex
+1;
1095 index
=m_CurrentRebaseIndex
-1;
1102 if(index
>= m_CommitList
.GetItemCount())
1105 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[index
];
1107 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1109 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
)
1111 if(m_CommitList
.m_IsOldFirst
)
1119 }while(curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
);
1124 int CRebaseDlg::GoNext()
1126 if(m_CommitList
.m_IsOldFirst
)
1127 m_CurrentRebaseIndex
++;
1129 m_CurrentRebaseIndex
--;
1133 int CRebaseDlg::StateAction()
1135 switch(this->m_RebaseStage
)
1138 case CHOOSE_COMMIT_PICK_MODE
:
1141 m_RebaseStage
= REBASE_START
;
1148 void CRebaseDlg::SetContinueButtonText()
1151 switch(this->m_RebaseStage
)
1154 case CHOOSE_COMMIT_PICK_MODE
:
1155 if(this->m_IsFastForward
)
1156 Text
.LoadString(IDS_PROC_STARTREBASEFFBUTTON
);
1158 Text
.LoadString(IDS_PROC_STARTREBASEBUTTON
);
1162 case REBASE_CONTINUE
:
1163 case REBASE_SQUASH_CONFLICT
:
1164 Text
.LoadString(IDS_CONTINUEBUTTON
);
1167 case REBASE_CONFLICT
:
1168 Text
.LoadString(IDS_COMMITBUTTON
);
1171 Text
.LoadString(IDS_AMENDBUTTON
);
1174 case REBASE_SQUASH_EDIT
:
1175 Text
.LoadString(IDS_COMMITBUTTON
);
1180 Text
.LoadString(IDS_FINISHBUTTON
);
1184 Text
.LoadString(IDS_DONE
);
1187 this->GetDlgItem(IDC_REBASE_CONTINUE
)->SetWindowText(Text
);
1190 void CRebaseDlg::SetControlEnable()
1192 switch(this->m_RebaseStage
)
1195 case CHOOSE_COMMIT_PICK_MODE
:
1197 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(TRUE
);
1198 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(TRUE
);
1199 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(TRUE
);
1200 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(TRUE
);
1201 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(TRUE
);
1205 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(TRUE
);
1206 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(TRUE
);
1207 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(TRUE
);
1209 //this->m_CommitList.m_IsEnableRebaseMenu=TRUE;
1210 this->m_CommitList
.m_ContextMenuMask
|= m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1211 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1212 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1213 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
);
1217 case REBASE_CONTINUE
:
1220 case REBASE_CONFLICT
:
1222 case REBASE_SQUASH_CONFLICT
:
1224 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(FALSE
);
1225 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(FALSE
);
1226 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(FALSE
);
1227 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(FALSE
);
1228 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(FALSE
);
1229 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(FALSE
);
1230 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(FALSE
);
1231 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(FALSE
);
1232 //this->m_CommitList.m_IsEnableRebaseMenu=FALSE;
1233 this->m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1234 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1235 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1236 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
));
1238 if( m_RebaseStage
== REBASE_DONE
&& (this->m_PostButtonTexts
.GetCount() != 0) )
1240 this->GetDlgItem(IDC_STATUS_STATIC
)->ShowWindow(SW_HIDE
);
1241 this->GetDlgItem(IDC_REBASE_POST_BUTTON
)->ShowWindow(SW_SHOWNORMAL
);
1242 this->m_PostButton
.RemoveAll();
1243 this->m_PostButton
.AddEntries(m_PostButtonTexts
);
1244 //this->GetDlgItem(IDC_REBASE_POST_BUTTON)->SetWindowText(this->m_PostButtonText);
1249 if(m_bThreadRunning
)
1251 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1256 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(TRUE
);
1260 void CRebaseDlg::UpdateProgress()
1265 if(m_CommitList
.m_IsOldFirst
)
1266 index
= m_CurrentRebaseIndex
+1;
1268 index
= m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1270 m_ProgressBar
.SetRange32(1, m_CommitList
.GetItemCount());
1271 m_ProgressBar
.SetPos(index
);
1274 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1275 m_pTaskbarList
->SetProgressValue(m_hWnd
, index
, m_CommitList
.GetItemCount());
1278 if(m_CurrentRebaseIndex
>=0 && m_CurrentRebaseIndex
< m_CommitList
.GetItemCount())
1281 text
.Format(IDS_PROC_REBASING_PROGRESS
, index
, m_CommitList
.GetItemCount());
1282 m_CtrlStatusText
.SetWindowText(text
);
1286 GitRev
*prevRev
=NULL
, *curRev
=NULL
;
1288 if( m_CurrentRebaseIndex
>= 0 && m_CurrentRebaseIndex
< m_CommitList
.m_arShownList
.GetSize())
1290 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1293 for(int i
=0;i
<m_CommitList
.m_arShownList
.GetSize();i
++)
1295 prevRev
=(GitRev
*)m_CommitList
.m_arShownList
[i
];
1296 if(prevRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1298 prevRev
->GetAction(&m_CommitList
) &= ~ CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1299 m_CommitList
.GetItemRect(i
,&rect
,LVIR_BOUNDS
);
1300 m_CommitList
.InvalidateRect(rect
);
1306 curRev
->GetAction(&m_CommitList
) |= CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1307 m_CommitList
.GetItemRect(m_CurrentRebaseIndex
,&rect
,LVIR_BOUNDS
);
1308 m_CommitList
.InvalidateRect(rect
);
1310 m_CommitList
.EnsureVisible(m_CurrentRebaseIndex
,FALSE
);
1313 void CRebaseDlg::UpdateCurrentStatus()
1315 SetContinueButtonText();
1320 void CRebaseDlg::AddLogString(CString str
)
1322 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, FALSE
);
1323 CStringA sTextA
= m_wndOutputRebase
.StringForControl(str
);//CUnicodeUtils::GetUTF8(str);
1324 this->m_wndOutputRebase
.SendMessage(SCI_DOCUMENTEND
);
1325 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)sTextA
);
1326 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n");
1327 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, TRUE
);
1330 int CRebaseDlg::GetCurrentCommitID()
1332 if(m_CommitList
.m_IsOldFirst
)
1334 return this->m_CurrentRebaseIndex
+1;
1339 return m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1343 int CRebaseDlg::DoRebase()
1346 if(m_CurrentRebaseIndex
<0)
1348 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1351 GitRev
*pRev
= (GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1352 int mode
=pRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1355 if( mode
== CTGitPath::LOGACTIONS_REBASE_SKIP
)
1357 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1361 if (!CheckNextCommitIsSquash() || mode
!= CTGitPath::LOGACTIONS_REBASE_PICK
)
1362 { // next commit is squash or not pick
1363 if (!this->m_SquashMessage
.IsEmpty())
1364 this->m_SquashMessage
+= _T("\n\n");
1365 this->m_SquashMessage
+= pRev
->GetSubject();
1366 this->m_SquashMessage
+= _T("\n");
1367 this->m_SquashMessage
+= pRev
->GetBody().TrimRight();
1370 this->m_SquashMessage
.Empty();
1372 if (!CheckNextCommitIsSquash() || mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1373 { // next or this commit is squash
1374 nocommit
=_T(" --no-commit ");
1378 log
.Format(_T("%s %d: %s"),CTGitPath::GetActionName(mode
),this->GetCurrentCommitID(),pRev
->m_CommitHash
.ToString());
1380 AddLogString(pRev
->GetSubject());
1381 if (pRev
->GetSubject().IsEmpty())
1383 CMessageBox::Show(m_hWnd
, IDS_PROC_REBASE_EMPTYCOMMITMSG
, IDS_APPNAME
, MB_OK
| MB_ICONEXCLAMATION
);
1384 mode
= CTGitPath::LOGACTIONS_REBASE_EDIT
;
1387 CString cherryPickedFrom
;
1388 if (m_bAddCherryPickedFrom
)
1389 cherryPickedFrom
= _T("-x ");
1391 cmd
.Format(_T("git.exe cherry-pick %s%s %s"), cherryPickedFrom
, nocommit
, pRev
->m_CommitHash
.ToString());
1393 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1397 if(g_Git
.ListConflictFile(list
))
1399 AddLogString(_T("Get conflict files fail"));
1402 if(list
.GetCount() == 0 )
1404 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1406 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1409 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1411 this->m_RebaseStage
= REBASE_EDIT
;
1412 return -1; // Edit return -1 to stop rebase.
1415 if(CheckNextCommitIsSquash())
1417 // let user edit last commmit message
1418 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1422 if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1423 m_RebaseStage
= REBASE_SQUASH_CONFLICT
;
1425 m_RebaseStage
= REBASE_CONFLICT
;
1432 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1434 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1437 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1439 this->m_RebaseStage
= REBASE_EDIT
;
1440 return -1; // Edit return -1 to stop rebase.
1444 if(CheckNextCommitIsSquash())
1446 // let user edit last commmit message
1447 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1450 else if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1451 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1457 BOOL
CRebaseDlg::IsEnd()
1459 if(m_CommitList
.m_IsOldFirst
)
1460 return m_CurrentRebaseIndex
>= this->m_CommitList
.GetItemCount();
1462 return m_CurrentRebaseIndex
<0;
1465 int CRebaseDlg::RebaseThread()
1467 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
1472 if( m_RebaseStage
== REBASE_START
)
1474 if( this->StartRebase() )
1476 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1478 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1481 m_RebaseStage
= REBASE_CONTINUE
;
1484 else if( m_RebaseStage
== REBASE_CONTINUE
)
1487 UpdateCurrentStatus();
1491 m_RebaseStage
= REBASE_FINISH
;
1505 else if( m_RebaseStage
== REBASE_FINISH
)
1508 m_RebaseStage
= REBASE_DONE
;
1510 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1518 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1519 //this->UpdateCurrentStatus();
1522 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1523 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1527 void CRebaseDlg::ListConflictFile()
1529 this->m_FileListCtrl
.Clear();
1534 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
1536 this->m_FileListCtrl
.GetStatus(&list
,true);
1537 this->m_FileListCtrl
.Show(CTGitPath::LOGACTIONS_UNMERGED
|CTGitPath::LOGACTIONS_MODIFIED
|CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_DELETED
,
1538 CTGitPath::LOGACTIONS_UNMERGED
);
1541 LRESULT
CRebaseDlg::OnRebaseUpdateUI(WPARAM
,LPARAM
)
1543 UpdateCurrentStatus();
1544 if(m_CurrentRebaseIndex
<0)
1546 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1548 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1550 switch(m_RebaseStage
)
1552 case REBASE_CONFLICT
:
1553 case REBASE_SQUASH_CONFLICT
:
1555 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_CONFLICT
);
1557 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
1558 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1559 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1562 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1564 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1565 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1566 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1568 case REBASE_SQUASH_EDIT
:
1569 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1570 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1571 this->m_LogMessageCtrl
.SetText(this->m_SquashMessage
);
1573 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1576 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1580 void CRebaseDlg::OnCancel()
1584 void CRebaseDlg::OnBnClickedAbort()
1587 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1590 CString pron
= m_OrigUpstreamHash
.ToString();
1591 if(m_OrigUpstreamHash
.IsEmpty())
1593 __super::OnCancel();
1596 if(m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
1601 if(CMessageBox::Show(NULL
, IDS_PROC_REBASE_ABORT
, IDS_APPNAME
, MB_YESNO
) != IDYES
)
1604 if(this->m_IsFastForward
)
1606 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1607 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1610 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1612 __super::OnCancel();
1615 cmd
.Format(_T("git.exe checkout -f %s"),g_Git
.FixBranchName(this->m_UpstreamCtrl
.GetString()));
1616 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1619 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1620 __super::OnCancel();
1624 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigUpstreamHash
.ToString());
1625 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1628 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1629 __super::OnCancel();
1633 if(this->m_IsCherryPick
) //there are not "branch" at cherry pick mode
1635 __super::OnCancel();
1639 cmd
.Format(_T("git checkout -f %s"),this->m_BranchCtrl
.GetString());
1640 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1643 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1644 __super::OnCancel();
1648 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1649 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1652 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1654 __super::OnCancel();
1657 void CRebaseDlg::OnBnClickedButtonBrowse()
1659 if(CBrowseRefsDlg::PickRefForCombo(&m_UpstreamCtrl
, gPickRef_NoTag
))
1660 OnCbnSelchangeUpstream();
1663 void CRebaseDlg::OnBnClickedRebaseCheckForce()
1666 this->FetchLogList();
1667 if(this->CheckRebaseCondition())
1669 /* Disable Start Rebase */
1670 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1674 void CRebaseDlg::OnBnClickedRebasePostButton()
1676 this->m_Upstream
=this->m_UpstreamCtrl
.GetString();
1677 this->m_Branch
=this->m_BranchCtrl
.GetString();
1679 this->EndDialog((int)(IDC_REBASE_POST_BUTTON
+this->m_PostButton
.GetCurrentEntry()));
1682 void CRebaseDlg::Refresh()
1684 if (m_RebaseStage
== REBASE_CONFLICT
|| m_RebaseStage
== REBASE_SQUASH_CONFLICT
)
1690 if(this->m_IsCherryPick
)
1693 if(this->m_RebaseStage
== CHOOSE_BRANCH
)
1696 this->FetchLogList();
1697 if(this->CheckRebaseCondition())
1699 /* Disable Start Rebase */
1700 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1705 void CRebaseDlg::OnBnClickedButtonUp2()
1708 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1710 // do nothing if the first selected item is the first item in the list
1711 if (m_CommitList
.GetNextSelectedItem(pos
) == 0)
1714 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1716 bool changed
= false;
1719 int index
=m_CommitList
.GetNextSelectedItem(pos
);
1722 CGitHash old
= m_CommitList
.m_logEntries
[index
-1];
1723 m_CommitList
.m_logEntries
[index
-1] = m_CommitList
.m_logEntries
[index
];
1724 m_CommitList
.m_logEntries
[index
] = old
;
1725 m_CommitList
.SetItemState(index
-1, LVIS_SELECTED
, LVIS_SELECTED
);
1726 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1732 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1733 m_CommitList
.Invalidate();
1734 m_CommitList
.SetFocus();
1738 void CRebaseDlg::OnBnClickedButtonDown2()
1740 if (m_CommitList
.GetSelectedCount() == 0)
1744 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1745 bool changed
= false;
1746 // use an array to store all selected item indexes; the user won't select too much items
1747 int* indexes
= NULL
;
1748 indexes
= new int[m_CommitList
.GetSelectedCount()];
1752 indexes
[i
++] = m_CommitList
.GetNextSelectedItem(pos
);
1754 // don't move any item if the last selected item is the last item in the m_CommitList
1755 // (that would change the order of the selected items)
1756 if(indexes
[m_CommitList
.GetSelectedCount() - 1] < m_CommitList
.GetItemCount() - 1)
1758 // iterate over the indexes backwards in order to correctly move multiselected items
1759 for (i
= m_CommitList
.GetSelectedCount() - 1; i
>= 0; i
--)
1761 int index
= indexes
[i
];
1762 CGitHash old
= m_CommitList
.m_logEntries
[index
+1];
1763 m_CommitList
.m_logEntries
[index
+1] = m_CommitList
.m_logEntries
[index
];
1764 m_CommitList
.m_logEntries
[index
] = old
;
1765 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1766 m_CommitList
.SetItemState(index
+1, LVIS_SELECTED
, LVIS_SELECTED
);
1774 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1775 m_CommitList
.Invalidate();
1776 m_CommitList
.SetFocus();
1780 LRESULT
CRebaseDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1782 m_pTaskbarList
.Release();
1783 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
1787 void CRebaseDlg::OnLvnItemchangedLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1789 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1791 if(m_CommitList
.m_bNoDispUpdates
)
1793 if (pNMLV
->iItem
>= 0)
1795 this->m_CommitList
.m_nSearchIndex
= pNMLV
->iItem
;
1796 if (pNMLV
->iSubItem
!= 0)
1798 if ((pNMLV
->iItem
== m_CommitList
.m_arShownList
.GetCount()))
1800 // remove the selected state
1801 if (pNMLV
->uChanged
& LVIF_STATE
)
1803 m_CommitList
.SetItemState(pNMLV
->iItem
, 0, LVIS_SELECTED
);
1804 FillLogMessageCtrl();
1808 if (pNMLV
->uChanged
& LVIF_STATE
)
1810 FillLogMessageCtrl();
1815 FillLogMessageCtrl();
1819 void CRebaseDlg::FillLogMessageCtrl()
1821 int selCount
= m_CommitList
.GetSelectedCount();
1822 if (selCount
== 1 && (m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
))
1824 POSITION pos
= m_CommitList
.GetFirstSelectedItemPosition();
1825 int selIndex
= m_CommitList
.GetNextSelectedItem(pos
);
1826 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_CommitList
.m_arShownList
.SafeGetAt(selIndex
));
1827 m_FileListCtrl
.UpdateWithGitPathList(pLogEntry
->GetFiles(&m_CommitList
));
1828 m_FileListCtrl
.m_CurrentVersion
= pLogEntry
->m_CommitHash
;
1829 m_FileListCtrl
.Show(GITSLC_SHOWVERSIONED
);
1830 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1831 m_LogMessageCtrl
.SetText(pLogEntry
->GetSubject() + _T("\n") + pLogEntry
->GetBody());
1832 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);
1835 void CRebaseDlg::OnBnClickedCheckCherryPickedFrom()