1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2011 - 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 "MessageBox.h"
29 #include "UnicodeUtils.h"
30 #include "BrowseRefsDlg.h"
31 #include "ProgressDlg.h"
34 IMPLEMENT_DYNAMIC(CRebaseDlg
, CResizableStandAloneDialog
)
36 CRebaseDlg::CRebaseDlg(CWnd
* pParent
/*=NULL*/)
37 : CResizableStandAloneDialog(CRebaseDlg::IDD
, pParent
)
42 m_RebaseStage
=CHOOSE_BRANCH
;
43 m_CurrentRebaseIndex
=-1;
44 m_bThreadRunning
=FALSE
;
45 this->m_IsCherryPick
= FALSE
;
47 m_IsFastForward
=FALSE
;
50 CRebaseDlg::~CRebaseDlg()
54 void CRebaseDlg::DoDataExchange(CDataExchange
* pDX
)
56 CDialog::DoDataExchange(pDX
);
57 DDX_Control(pDX
, IDC_REBASE_PROGRESS
, m_ProgressBar
);
58 DDX_Control(pDX
, IDC_STATUS_STATIC
, m_CtrlStatusText
);
59 DDX_Check(pDX
, IDC_PICK_ALL
, m_bPickAll
);
60 DDX_Check(pDX
, IDC_SQUASH_ALL
, m_bSquashAll
);
61 DDX_Check(pDX
, IDC_EDIT_ALL
, m_bEditAll
);
62 DDX_Control(pDX
, IDC_REBASE_SPLIT
, m_wndSplitter
);
63 DDX_Control(pDX
,IDC_COMMIT_LIST
,m_CommitList
);
64 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_BRANCH
, this->m_BranchCtrl
);
65 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_UPSTREAM
, this->m_UpstreamCtrl
);
66 DDX_Check(pDX
, IDC_REBASE_CHECK_FORCE
,m_bForce
);
67 DDX_Control(pDX
,IDC_REBASE_POST_BUTTON
,m_PostButton
);
71 BEGIN_MESSAGE_MAP(CRebaseDlg
, CResizableStandAloneDialog
)
72 ON_BN_CLICKED(IDC_PICK_ALL
, &CRebaseDlg::OnBnClickedPickAll
)
73 ON_BN_CLICKED(IDC_SQUASH_ALL
, &CRebaseDlg::OnBnClickedSquashAll
)
74 ON_BN_CLICKED(IDC_EDIT_ALL
, &CRebaseDlg::OnBnClickedEditAll
)
75 ON_BN_CLICKED(IDC_REBASE_SPLIT
, &CRebaseDlg::OnBnClickedRebaseSplit
)
76 ON_BN_CLICKED(IDC_REBASE_CONTINUE
,OnBnClickedContinue
)
77 ON_BN_CLICKED(IDC_REBASE_ABORT
, OnBnClickedAbort
)
79 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH
, &CRebaseDlg::OnCbnSelchangeBranch
)
80 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM
, &CRebaseDlg::OnCbnSelchangeUpstream
)
81 ON_MESSAGE(MSG_REBASE_UPDATE_UI
, OnRebaseUpdateUI
)
82 ON_BN_CLICKED(IDC_BUTTON_BROWSE
, &CRebaseDlg::OnBnClickedButtonBrowse
)
83 ON_BN_CLICKED(IDC_REBASE_CHECK_FORCE
, &CRebaseDlg::OnBnClickedRebaseCheckForce
)
84 ON_BN_CLICKED(IDC_REBASE_POST_BUTTON
, &CRebaseDlg::OnBnClickedRebasePostButton
)
85 ON_BN_CLICKED(IDC_BUTTON_UP2
, &CRebaseDlg::OnBnClickedButtonUp2
)
86 ON_BN_CLICKED(IDC_BUTTON_DOWN2
, &CRebaseDlg::OnBnClickedButtonDown2
)
87 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
88 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_COMMIT_LIST
, OnLvnItemchangedLoglist
)
91 void CRebaseDlg::AddRebaseAnchor()
93 AddAnchor(IDC_REBASE_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
94 AddAnchor(IDC_COMMIT_LIST
,TOP_LEFT
, TOP_RIGHT
);
95 AddAnchor(IDC_REBASE_SPLIT
,TOP_LEFT
, TOP_RIGHT
);
96 AddAnchor(IDC_STATUS_STATIC
, BOTTOM_LEFT
,BOTTOM_RIGHT
);
97 AddAnchor(IDC_REBASE_CONTINUE
,BOTTOM_RIGHT
);
98 AddAnchor(IDC_REBASE_ABORT
, BOTTOM_RIGHT
);
99 AddAnchor(IDC_REBASE_PROGRESS
,BOTTOM_LEFT
, BOTTOM_RIGHT
);
100 AddAnchor(IDC_PICK_ALL
,TOP_LEFT
);
101 AddAnchor(IDC_SQUASH_ALL
,TOP_LEFT
);
102 AddAnchor(IDC_EDIT_ALL
,TOP_LEFT
);
103 AddAnchor(IDC_BUTTON_UP2
,TOP_LEFT
);
104 AddAnchor(IDC_BUTTON_DOWN2
,TOP_LEFT
);
105 AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM
,TOP_LEFT
);
106 AddAnchor(IDC_REBASE_COMBOXEX_BRANCH
,TOP_LEFT
);
107 AddAnchor(IDC_REBASE_STATIC_UPSTREAM
,TOP_LEFT
);
108 AddAnchor(IDC_REBASE_STATIC_BRANCH
,TOP_LEFT
);
109 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
110 AddAnchor(IDC_REBASE_CHECK_FORCE
,TOP_RIGHT
);
111 AddAnchor(IDC_REBASE_POST_BUTTON
,BOTTOM_LEFT
);
113 this->AddOthersToAnchor();
116 BOOL
CRebaseDlg::OnInitDialog()
118 CResizableStandAloneDialog::OnInitDialog();
119 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
121 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
122 // do this, Explorer would be unable to send that message to our window if we
123 // were running elevated. It's OK to make the call all the time, since if we're
124 // not elevated, this is a no-op.
125 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
126 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
127 HMODULE hUser
= ::LoadLibrary(_T("user32.dll"));
130 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
131 if (pfnChangeWindowMessageFilterEx
)
133 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
137 m_pTaskbarList
.Release();
138 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
141 //IDC_REBASE_DUMY_TAB
143 GetClientRect(m_DlgOrigRect
);
144 m_CommitList
.GetClientRect(m_CommitListOrigRect
);
146 CWnd
*pwnd
=this->GetDlgItem(IDC_REBASE_DUMY_TAB
);
147 pwnd
->GetWindowRect(&rectDummy
);
148 this->ScreenToClient(rectDummy
);
150 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_REBASE_TAB
))
152 TRACE0("Failed to create output tab window\n");
153 return FALSE
; // fail to create
155 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
156 // Create output panes:
157 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
158 DWORD dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
160 if (! this->m_FileListCtrl
.Create(dwStyle
,rectDummy
,&this->m_ctrlTabCtrl
,0) )
162 TRACE0("Failed to create output windows\n");
163 return FALSE
; // fail to create
166 if( ! this->m_LogMessageCtrl
.Create(_T("Scintilla"),_T("source"),0,rectDummy
,&m_ctrlTabCtrl
,0,0) )
168 TRACE0("Failed to create log message control");
171 m_LogMessageCtrl
.Init(0);
172 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);
174 dwStyle
= LBS_NOINTEGRALHEIGHT
| WS_CHILD
| WS_VISIBLE
| WS_HSCROLL
| WS_VSCROLL
;
176 if (!m_wndOutputRebase
.Create(_T("Scintilla"),_T("source"),0,rectDummy
, &m_ctrlTabCtrl
, 0,0) )
178 TRACE0("Failed to create output windows\n");
179 return -1; // fail to create
181 m_wndOutputRebase
.Init(0);
182 m_wndOutputRebase
.Call(SCI_SETREADONLY
, TRUE
);
184 m_tooltips
.Create(this);
186 m_tooltips
.AddTool(IDC_REBASE_CHECK_FORCE
,IDS_REBASE_FORCE_TT
);
187 m_tooltips
.AddTool(IDC_REBASE_ABORT
,IDS_REBASE_ABORT_TT
);
191 m_FileListCtrl
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
|SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("RebaseDlg"),(SVNSLC_POPALL
^ SVNSLC_POPCOMMIT
),false);
193 m_ctrlTabCtrl
.AddTab(&m_FileListCtrl
,_T("Revision Files"));
194 m_ctrlTabCtrl
.AddTab(&m_LogMessageCtrl
,_T("Commit Message"),1);
197 CString sWindowTitle
;
198 GetWindowText(sWindowTitle
);
199 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
201 EnableSaveRestore(_T("RebaseDlg"));
203 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
204 RECT rcDlg
, rcLogMsg
, rcFileList
;
205 GetClientRect(&rcDlg
);
206 m_CommitList
.GetWindowRect(&rcLogMsg
);
207 ScreenToClient(&rcLogMsg
);
208 this->m_ctrlTabCtrl
.GetWindowRect(&rcFileList
);
209 ScreenToClient(&rcFileList
);
213 m_wndSplitter
.GetWindowRect(&rectSplitter
);
214 ScreenToClient(&rectSplitter
);
215 int delta
= yPos
- rectSplitter
.top
;
216 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
218 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
223 if( this->m_RebaseStage
== CHOOSE_BRANCH
)
225 this->LoadBranchInfo();
229 this->m_BranchCtrl
.EnableWindow(FALSE
);
230 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
233 m_CommitList
.m_ColumnRegKey
= _T("Rebase");
234 m_CommitList
.m_IsIDReplaceAction
= TRUE
;
235 // m_CommitList.m_IsOldFirst = TRUE;
236 m_CommitList
.m_IsRebaseReplaceGraph
= TRUE
;
238 m_CommitList
.InsertGitColumn();
240 this->SetControlEnable();
242 if(!this->m_PreCmd
.IsEmpty())
244 CProgressDlg progress
;
245 progress
.m_GitCmd
=m_PreCmd
;
246 progress
.m_bAutoCloseOnSuccess
=true;
252 this->m_BranchCtrl
.SetCurSel(-1);
253 this->m_BranchCtrl
.EnableWindow(FALSE
);
254 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
255 this->SetWindowText(_T("Cherry Pick"));
256 this->m_CommitList
.StartFilter();
260 SetContinueButtonText();
261 m_CommitList
.DeleteAllItems();
265 m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_CHERRY_PICK
)|
266 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_SWITCHTOREV
)|
267 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_RESET
)|
268 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTREV
)|
269 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_TO_VERSION
)|
270 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV
)|
271 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_COMBINE_COMMIT
));
273 if(m_CommitList
.m_IsOldFirst
)
274 this->m_CurrentRebaseIndex
= -1;
276 this->m_CurrentRebaseIndex
= m_CommitList
.m_logEntries
.size();
279 if(this->CheckRebaseCondition())
281 /* Disable Start Rebase */
282 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
287 // CRebaseDlg message handlers
289 void CRebaseDlg::OnBnClickedPickAll()
293 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
295 this->m_bEditAll
=FALSE
;
296 this->m_bSquashAll
=FALSE
;
297 this->UpdateData(FALSE
);
300 void CRebaseDlg::OnBnClickedSquashAll()
303 if(this->m_bSquashAll
)
304 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
306 this->m_bEditAll
=FALSE
;
307 this->m_bPickAll
=FALSE
;
308 this->UpdateData(FALSE
);
311 void CRebaseDlg::OnBnClickedEditAll()
314 if( this->m_bEditAll
)
315 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
317 this->m_bPickAll
=FALSE
;
318 this->m_bSquashAll
=FALSE
;
319 this->UpdateData(FALSE
);
322 void CRebaseDlg::SetAllRebaseAction(int action
)
324 for(int i
=0;i
<this->m_CommitList
.m_logEntries
.size();i
++)
326 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
)=action
;
328 m_CommitList
.Invalidate();
331 void CRebaseDlg::OnBnClickedRebaseSplit()
336 LRESULT
CRebaseDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
340 if (wParam
== IDC_REBASE_SPLIT
)
342 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
348 return __super::DefWindowProc(message
, wParam
, lParam
);
351 void CRebaseDlg::DoSize(int delta
)
353 this->RemoveAllAnchors();
355 CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST
), delta
, CW_TOPALIGN
);
356 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
357 CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB
), -delta
, CW_BOTTOMALIGN
);
358 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
359 CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL
),0,delta
);
360 CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL
),0,delta
);
361 CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL
),0,delta
);
362 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_UP2
),0,delta
);
363 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_DOWN2
),0,delta
);
364 CSplitterControl::ChangePos(GetDlgItem(IDC_REBASE_CHECK_FORCE
),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
.AddString(list
);
432 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_ALL_F
);
433 m_UpstreamCtrl
.AddString(list
);
435 m_BranchCtrl
.SetCurSel(current
);
437 AddBranchToolTips(&m_BranchCtrl
);
438 AddBranchToolTips(&m_UpstreamCtrl
);
440 if(!m_Upstream
.IsEmpty())
442 m_UpstreamCtrl
.AddString(m_Upstream
);
443 m_UpstreamCtrl
.SetCurSel(m_UpstreamCtrl
.GetCount()-1);
447 //Select pull-remote from current branch
448 CString currentBranch
= g_Git
.GetSymbolicRef();
450 configName
.Format(L
"branch.%s.remote", currentBranch
);
451 CString pullRemote
= g_Git
.GetConfigValue(configName
);
453 //Select pull-branch from current branch
454 configName
.Format(L
"branch.%s.merge", currentBranch
);
455 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
457 CString defaultUpstream
;
458 defaultUpstream
.Format(L
"remotes/%s/%s", pullRemote
, pullBranch
);
459 int found
= m_UpstreamCtrl
.FindStringExact(0, defaultUpstream
);
461 m_UpstreamCtrl
.SetCurSel(found
);
465 void CRebaseDlg::OnCbnSelchangeBranch()
470 void CRebaseDlg::OnCbnSelchangeUpstream()
475 void CRebaseDlg::FetchLogList()
480 m_IsFastForward
=FALSE
;
481 cmd
.Format(_T("git.exe merge-base %s %s"), g_Git
.FixBranchName(m_UpstreamCtrl
.GetString()),
482 g_Git
.FixBranchName(m_BranchCtrl
.GetString()));
483 if(g_Git
.Run(cmd
,&basestr
,CP_ACP
))
485 CMessageBox::Show(NULL
,basestr
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
490 hash
=g_Git
.GetHash(m_BranchCtrl
.GetString());
492 if(hash
== g_Git
.GetHash(this->m_UpstreamCtrl
.GetString()))
494 m_CommitList
.Clear();
496 fmt
.LoadString(IDS_REBASE_EQUAL_FMT
);
497 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
499 m_CommitList
.ShowText(text
);
500 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
507 this->m_IsFastForward
=TRUE
;
509 m_CommitList
.Clear();
511 fmt
.LoadString(IDS_REBASE_FASTFORWARD_FMT
);
512 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString(),
513 m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
515 m_CommitList
.ShowText(text
);
516 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(true);
517 SetContinueButtonText();
526 hash
=g_Git
.GetHash(m_UpstreamCtrl
.GetString());
530 m_CommitList
.Clear();
532 fmt
.LoadString(IDS_REBASE_UPTODATE_FMT
);
533 text
.Format(fmt
,m_BranchCtrl
.GetString());
534 m_CommitList
.ShowText(text
);
535 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
536 SetContinueButtonText();
541 m_CommitList
.Clear();
543 from
= m_UpstreamCtrl
.GetString();
544 to
= m_BranchCtrl
.GetString();
545 this->m_CommitList
.FillGitLog(NULL
,0,&from
,&to
);
547 if( m_CommitList
.GetItemCount() == 0 )
548 m_CommitList
.ShowText(_T("Nothing to Rebase"));
550 hash
=g_Git
.GetHash(m_UpstreamCtrl
.GetString());
553 if(m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
.size() >=0 )
555 if(hash
== m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
[0])
557 m_CommitList
.Clear();
558 m_CommitList
.ShowText(_T("Nothing Rebase"));
564 AddBranchToolTips(&this->m_BranchCtrl
);
565 AddBranchToolTips(&this->m_UpstreamCtrl
);
567 for(int i
=0;i
<m_CommitList
.m_logEntries
.size();i
++)
569 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
) = CTGitPath::LOGACTIONS_REBASE_PICK
;
572 m_CommitList
.Invalidate();
574 if(m_CommitList
.m_IsOldFirst
)
575 this->m_CurrentRebaseIndex
= -1;
577 this->m_CurrentRebaseIndex
= m_CommitList
.m_logEntries
.size();
579 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
580 SetContinueButtonText();
583 void CRebaseDlg::AddBranchToolTips(CHistoryCombo
*pBranch
)
587 CString text
=pBranch
->GetString();
593 tooltip
.Format(_T("CommitHash:%s\nCommit by: %s %s\n <b>%s</b> \n %s"),
594 rev
.m_CommitHash
.ToString(),
596 CAppUtils::FormatDateAndTime(rev
.GetAuthorDate(),DATE_LONGDATE
),
600 pBranch
->DisableTooltip();
601 this->m_tooltips
.AddTool(pBranch
->GetComboBoxCtrl(),tooltip
);
605 BOOL
CRebaseDlg::PreTranslateMessage(MSG
*pMsg
)
607 if (pMsg
->message
== WM_KEYDOWN
)
609 switch (pMsg
->wParam
)
612 if(LogListHasFocus(pMsg
->hwnd
))
614 m_CommitList
.ShiftSelectedAction();
619 if(LogListHasFocus(pMsg
->hwnd
))
621 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
626 if(LogListHasFocus(pMsg
->hwnd
))
628 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP
);
633 if(LogListHasFocus(pMsg
->hwnd
))
635 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
640 if(LogListHasFocus(pMsg
->hwnd
))
642 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
647 if(LogListHasFocus(pMsg
->hwnd
) && GetAsyncKeyState(VK_CONTROL
) & 0x8000)
649 // select all entries
650 for (int i
= 0; i
< m_CommitList
.GetItemCount(); ++i
)
652 m_CommitList
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
663 /* Avoid TAB control destroy but dialog exist*/
668 ::GetClassName(pMsg
->hwnd
,buff
,128);
671 if(_tcsnicmp(buff
,_T("RichEdit20W"),128)==0 ||
672 _tcsnicmp(buff
,_T("Scintilla"),128)==0 ||
673 _tcsnicmp(buff
,_T("SysListView32"),128)==0||
674 ::GetParent(pMsg
->hwnd
) == this->m_ctrlTabCtrl
.m_hWnd
)
676 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
682 m_tooltips
.RelayEvent(pMsg
);
683 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
686 bool CRebaseDlg::LogListHasFocus(HWND hwnd
)
689 ::GetClassName(hwnd
, buff
, 128);
691 if(_tcsnicmp(buff
, _T("SysListView32"), 128) == 0)
696 int CRebaseDlg::CheckRebaseCondition()
698 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
700 if( !g_Git
.CheckCleanWorkTree() )
702 if(CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
705 cmd
=_T("git.exe stash");
706 this->AddLogString(cmd
);
707 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
709 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
716 //Todo Check $REBASE_ROOT
720 cmd
=_T("git.exe var GIT_COMMITTER_IDENT");
721 if(g_Git
.Run(cmd
,NULL
,CP_UTF8
))
724 //Todo call pre_rebase_hook
727 int CRebaseDlg::StartRebase()
730 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
731 if(!this->m_IsCherryPick
)
733 //Todo call comment_for_reflog
734 cmd
.Format(_T("git.exe checkout %s"),this->m_BranchCtrl
.GetString());
735 this->AddLogString(cmd
);
737 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
740 this->AddLogString(out
);
743 cmd
=_T("git.exe rev-parse --verify HEAD");
744 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
746 AddLogString(_T("No Head"));
750 //git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
751 // echo "detached HEAD" > "$DOTEST"/head-name
753 cmd
.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));
754 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
756 AddLogString(_T("update ORIG_HEAD Fail"));
760 m_OrigUpstreamHash
.Empty();
761 m_OrigUpstreamHash
= g_Git
.GetHash(this->m_UpstreamCtrl
.GetString());
762 if(m_OrigUpstreamHash
.IsEmpty())
764 this->AddLogString(m_OrigUpstreamHash
);
768 if( !this->m_IsCherryPick
)
770 cmd
.Format(_T("git.exe checkout -f %s"), m_OrigUpstreamHash
.ToString());
771 this->AddLogString(cmd
);
774 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
776 this->AddLogString(out
);
781 if( !this->m_IsCherryPick
)
783 m_OrigBranchHash
= g_Git
.GetHash(this->m_BranchCtrl
.GetString());
784 if(m_OrigBranchHash
.IsEmpty())
786 this->AddLogString(m_OrigBranchHash
.ToString());
789 this->AddLogString(_T("Start Rebase\r\n"));
792 this->AddLogString(_T("Start Cherry-pick\r\n"));
796 int CRebaseDlg::VerifyNoConflict()
799 if(g_Git
.ListConflictFile(list
))
801 AddLogString(_T("Get conflict files fail"));
804 if( list
.GetCount() != 0 )
806 CMessageBox::Show(NULL
,_T("There are conflict file, you should mark it resolve"),_T("TortoiseGit"),MB_OK
);
812 int CRebaseDlg::FinishRebase()
814 if(this->m_IsCherryPick
) //cherry pick mode no "branch", working at upstream branch
817 git_revnum_t head
= g_Git
.GetHash(_T("HEAD"));
821 cmd
.Format(_T("git.exe checkout -f %s"),this->m_BranchCtrl
.GetString());
823 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
831 cmd
.Format(_T("git.exe reset --hard %s"),head
);
833 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
840 m_ctrlTabCtrl
.RemoveTab(0);
841 m_ctrlTabCtrl
.RemoveTab(0);
842 m_CtrlStatusText
.SetWindowText(_T("Finished rebasing."));
846 void CRebaseDlg::OnBnClickedContinue()
848 if( m_RebaseStage
== REBASE_DONE
)
854 if( this->m_IsFastForward
)
857 CString oldbranch
= g_Git
.GetCurrentBranch();
858 if( oldbranch
!= m_BranchCtrl
.GetString() )
860 cmd
.Format(_T("git.exe checkout %s"),m_BranchCtrl
.GetString());
862 if( g_Git
.Run(cmd
,&out
,CP_ACP
) )
864 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
871 m_OrigBranchHash
= g_Git
.GetHash(m_BranchCtrl
.GetString());
872 m_OrigUpstreamHash
= g_Git
.GetHash(this->m_UpstreamCtrl
.GetString());
874 if(!g_Git
.IsFastForward(this->m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString()))
876 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
877 AddLogString(_T("No fast forward\r\nMaybe repository changed"));
881 cmd
.Format(_T("git.exe reset --hard %s"),g_Git
.FixBranchName(this->m_UpstreamCtrl
.GetString()));
882 this->AddLogString(CString(_T("Fast forward to "))+m_UpstreamCtrl
.GetString());
885 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
886 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
888 AddLogString(_T("Fail"));
893 AddLogString(_T("Done"));
894 m_RebaseStage
= REBASE_DONE
;
895 UpdateCurrentStatus();
899 if( m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
901 if(CheckRebaseCondition())
903 m_RebaseStage
= REBASE_START
;
904 m_FileListCtrl
.Clear();
905 m_FileListCtrl
.m_CurrentVersion
= L
"";
906 m_ctrlTabCtrl
.SetTabLabel(REBASE_TAB_CONFLICT
, _T("Conflict Files"));
907 m_ctrlTabCtrl
.AddTab(&m_wndOutputRebase
,_T("Log"),2);
910 if( m_RebaseStage
== REBASE_FINISH
)
918 if( m_RebaseStage
== REBASE_SQUASH_CONFLICT
)
920 if(VerifyNoConflict())
922 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
923 if(this->CheckNextCommitIsSquash())
924 {//next commit is not squash;
925 m_RebaseStage
= REBASE_SQUASH_EDIT
;
926 this->OnRebaseUpdateUI(0,0);
927 this->UpdateCurrentStatus();
931 m_RebaseStage
=REBASE_CONTINUE
;
932 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
933 this->UpdateCurrentStatus();
937 if( m_RebaseStage
== REBASE_CONFLICT
)
939 if(VerifyNoConflict())
942 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
946 cmd
.Format(_T("git.exe commit -a -C %s"), curRev
->m_CommitHash
.ToString());
950 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
953 if(!g_Git
.CheckCleanWorkTree())
955 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
961 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
962 if( curRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_EDIT
)
964 m_RebaseStage
=REBASE_EDIT
;
965 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
966 this->UpdateCurrentStatus();
971 m_RebaseStage
=REBASE_CONTINUE
;
972 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
973 this->UpdateCurrentStatus();
977 if( m_RebaseStage
== REBASE_EDIT
|| m_RebaseStage
== REBASE_SQUASH_EDIT
)
980 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
982 str
=this->m_LogMessageCtrl
.GetText();
983 if(str
.Trim().IsEmpty())
985 CMessageBox::Show(NULL
,_T("Commit Message Is Empty"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
989 CString tempfile
=::GetTempFile();
990 CFile
file(tempfile
,CFile::modeReadWrite
|CFile::modeCreate
);
991 CStringA log
=CUnicodeUtils::GetUTF8( str
);
992 file
.Write(log
,log
.GetLength());
993 //file.WriteString(m_sLogMessage);
998 if( m_RebaseStage
== REBASE_SQUASH_EDIT
)
999 cmd
.Format(_T("git.exe commit -F \"%s\""), tempfile
);
1001 cmd
.Format(_T("git.exe commit --amend -F \"%s\""), tempfile
);
1003 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1005 if(!g_Git
.CheckCleanWorkTree())
1007 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1012 CFile::Remove(tempfile
);
1014 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1015 m_RebaseStage
=REBASE_CONTINUE
;
1016 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
1017 this->UpdateCurrentStatus();
1021 InterlockedExchange(&m_bThreadRunning
, TRUE
);
1024 if (AfxBeginThread(RebaseThreadEntry
, this)==NULL
)
1026 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1027 CMessageBox::Show(NULL
, _T("Create Rebase Thread Fail"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1031 int CRebaseDlg::CheckNextCommitIsSquash()
1034 if(m_CommitList
.m_IsOldFirst
)
1035 index
=m_CurrentRebaseIndex
+1;
1037 index
=m_CurrentRebaseIndex
-1;
1044 if(index
>= m_CommitList
.GetItemCount())
1047 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[index
];
1049 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1051 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
)
1053 if(m_CommitList
.m_IsOldFirst
)
1060 }while(curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
);
1065 int CRebaseDlg::GoNext()
1067 if(m_CommitList
.m_IsOldFirst
)
1068 m_CurrentRebaseIndex
++;
1070 m_CurrentRebaseIndex
--;
1074 int CRebaseDlg::StateAction()
1076 switch(this->m_RebaseStage
)
1079 case CHOOSE_COMMIT_PICK_MODE
:
1082 m_RebaseStage
= REBASE_START
;
1089 void CRebaseDlg::SetContinueButtonText()
1092 switch(this->m_RebaseStage
)
1095 case CHOOSE_COMMIT_PICK_MODE
:
1096 if(this->m_IsFastForward
)
1097 Text
= _T("Start(FastFwd)");
1103 case REBASE_CONTINUE
:
1104 case REBASE_SQUASH_CONFLICT
:
1105 Text
= _T("Continue");
1108 case REBASE_CONFLICT
:
1109 Text
= _T("Commit");
1115 case REBASE_SQUASH_EDIT
:
1116 Text
= _T("Commit");
1121 Text
= _T("Finish");
1128 this->GetDlgItem(IDC_REBASE_CONTINUE
)->SetWindowText(Text
);
1131 void CRebaseDlg::SetControlEnable()
1133 switch(this->m_RebaseStage
)
1136 case CHOOSE_COMMIT_PICK_MODE
:
1138 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(TRUE
);
1139 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(TRUE
);
1140 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(TRUE
);
1141 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(TRUE
);
1142 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(TRUE
);
1146 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(TRUE
);
1147 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(TRUE
);
1148 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(TRUE
);
1150 //this->m_CommitList.m_IsEnableRebaseMenu=TRUE;
1151 this->m_CommitList
.m_ContextMenuMask
|= m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1152 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1153 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1154 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
);
1158 case REBASE_CONTINUE
:
1161 case REBASE_CONFLICT
:
1163 case REBASE_SQUASH_CONFLICT
:
1165 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(FALSE
);
1166 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(FALSE
);
1167 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(FALSE
);
1168 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(FALSE
);
1169 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(FALSE
);
1170 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(FALSE
);
1171 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(FALSE
);
1172 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(FALSE
);
1173 //this->m_CommitList.m_IsEnableRebaseMenu=FALSE;
1174 this->m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1175 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1176 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1177 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
));
1179 if( m_RebaseStage
== REBASE_DONE
&& (this->m_PostButtonTexts
.GetCount() != 0) )
1181 this->GetDlgItem(IDC_STATUS_STATIC
)->ShowWindow(SW_HIDE
);
1182 this->GetDlgItem(IDC_REBASE_POST_BUTTON
)->ShowWindow(SW_SHOWNORMAL
);
1183 this->m_PostButton
.RemoveAll();
1184 this->m_PostButton
.AddEntries(m_PostButtonTexts
);
1185 //this->GetDlgItem(IDC_REBASE_POST_BUTTON)->SetWindowText(this->m_PostButtonText);
1190 if(m_bThreadRunning
)
1192 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1196 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(TRUE
);
1200 void CRebaseDlg::UpdateProgress()
1205 if(m_CommitList
.m_IsOldFirst
)
1206 index
= m_CurrentRebaseIndex
+1;
1208 index
= m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1210 m_ProgressBar
.SetRange(1,m_CommitList
.GetItemCount());
1211 m_ProgressBar
.SetPos(index
);
1214 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1215 m_pTaskbarList
->SetProgressValue(m_hWnd
, index
, m_CommitList
.GetItemCount());
1218 if(m_CurrentRebaseIndex
>=0 && m_CurrentRebaseIndex
< m_CommitList
.GetItemCount())
1221 text
.Format(_T("Rebasing... (%d/%d)"),index
,m_CommitList
.GetItemCount());
1222 m_CtrlStatusText
.SetWindowText(text
);
1226 GitRev
*prevRev
=NULL
, *curRev
=NULL
;
1228 if( m_CurrentRebaseIndex
>= 0 && m_CurrentRebaseIndex
< m_CommitList
.m_arShownList
.GetSize())
1230 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1233 for(int i
=0;i
<m_CommitList
.m_arShownList
.GetSize();i
++)
1235 prevRev
=(GitRev
*)m_CommitList
.m_arShownList
[i
];
1236 if(prevRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1238 prevRev
->GetAction(&m_CommitList
) &= ~ CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1239 m_CommitList
.GetItemRect(i
,&rect
,LVIR_BOUNDS
);
1240 m_CommitList
.InvalidateRect(rect
);
1246 curRev
->GetAction(&m_CommitList
) |= CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1247 m_CommitList
.GetItemRect(m_CurrentRebaseIndex
,&rect
,LVIR_BOUNDS
);
1248 m_CommitList
.InvalidateRect(rect
);
1250 m_CommitList
.EnsureVisible(m_CurrentRebaseIndex
,FALSE
);
1253 void CRebaseDlg::UpdateCurrentStatus()
1255 SetContinueButtonText();
1260 void CRebaseDlg::AddLogString(CString str
)
1262 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, FALSE
);
1263 CStringA sTextA
= m_wndOutputRebase
.StringForControl(str
);//CUnicodeUtils::GetUTF8(str);
1264 this->m_wndOutputRebase
.SendMessage(SCI_DOCUMENTEND
);
1265 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)sTextA
);
1266 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n");
1267 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, TRUE
);
1270 int CRebaseDlg::GetCurrentCommitID()
1272 if(m_CommitList
.m_IsOldFirst
)
1274 return this->m_CurrentRebaseIndex
+1;
1278 return m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1282 int CRebaseDlg::DoRebase()
1285 if(m_CurrentRebaseIndex
<0)
1287 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1290 GitRev
*pRev
= (GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1291 int mode
=pRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1294 if( mode
== CTGitPath::LOGACTIONS_REBASE_SKIP
)
1296 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1300 if( mode
!= CTGitPath::LOGACTIONS_REBASE_PICK
)
1302 this->m_SquashMessage
+= pRev
->GetSubject();
1303 this->m_SquashMessage
+= _T("\n");
1304 this->m_SquashMessage
+= pRev
->GetBody();
1307 this->m_SquashMessage
.Empty();
1309 if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1310 nocommit
=_T(" --no-commit ");
1313 log
.Format(_T("%s %d: %s"),CTGitPath::GetActionName(mode
),this->GetCurrentCommitID(),pRev
->m_CommitHash
.ToString());
1315 AddLogString(pRev
->GetSubject());
1316 if (pRev
->GetSubject().IsEmpty())
1318 CMessageBox::Show(m_hWnd
, _T("Found an empty commit message. You have to enter one or rebase cannot proceed."), _T("TortoiseGit"), MB_OK
| MB_ICONEXCLAMATION
);
1319 mode
= CTGitPath::LOGACTIONS_REBASE_EDIT
;
1322 cmd
.Format(_T("git.exe cherry-pick %s %s"),nocommit
,pRev
->m_CommitHash
.ToString());
1324 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1328 if(g_Git
.ListConflictFile(list
))
1330 AddLogString(_T("Get conflict files fail"));
1333 if(list
.GetCount() == 0 )
1335 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1337 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1340 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1342 this->m_RebaseStage
= REBASE_EDIT
;
1343 return -1; // Edit return -1 to stop rebase.
1346 if(CheckNextCommitIsSquash())
1348 // let user edit last commmit message
1349 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1353 if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1354 m_RebaseStage
= REBASE_SQUASH_CONFLICT
;
1356 m_RebaseStage
= REBASE_CONFLICT
;
1362 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1364 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1367 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1369 this->m_RebaseStage
= REBASE_EDIT
;
1370 return -1; // Edit return -1 to stop rebase.
1374 if(CheckNextCommitIsSquash())
1376 // let user edit last commmit message
1377 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1380 else if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1381 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1387 BOOL
CRebaseDlg::IsEnd()
1389 if(m_CommitList
.m_IsOldFirst
)
1390 return m_CurrentRebaseIndex
>= this->m_CommitList
.GetItemCount();
1392 return m_CurrentRebaseIndex
<0;
1395 int CRebaseDlg::RebaseThread()
1400 if( m_RebaseStage
== REBASE_START
)
1402 if( this->StartRebase() )
1404 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1408 m_RebaseStage
= REBASE_CONTINUE
;
1410 }else if( m_RebaseStage
== REBASE_CONTINUE
)
1413 UpdateCurrentStatus();
1417 m_RebaseStage
= REBASE_FINISH
;
1429 }else if( m_RebaseStage
== REBASE_FINISH
)
1432 m_RebaseStage
= REBASE_DONE
;
1434 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1441 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1442 //this->UpdateCurrentStatus();
1445 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1446 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1450 void CRebaseDlg::ListConflictFile()
1452 this->m_FileListCtrl
.Clear();
1457 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
1459 this->m_FileListCtrl
.GetStatus(&list
,true);
1460 this->m_FileListCtrl
.Show(CTGitPath::LOGACTIONS_UNMERGED
|CTGitPath::LOGACTIONS_MODIFIED
|CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_DELETED
,
1461 CTGitPath::LOGACTIONS_UNMERGED
);
1464 LRESULT
CRebaseDlg::OnRebaseUpdateUI(WPARAM
,LPARAM
)
1466 UpdateCurrentStatus();
1467 if(m_CurrentRebaseIndex
<0)
1469 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1471 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1473 switch(m_RebaseStage
)
1475 case REBASE_CONFLICT
:
1476 case REBASE_SQUASH_CONFLICT
:
1478 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_CONFLICT
);
1480 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
1481 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1482 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1485 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1487 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1488 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1489 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1491 case REBASE_SQUASH_EDIT
:
1492 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1493 this->m_LogMessageCtrl
.SetText(this->m_SquashMessage
);
1494 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1496 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1499 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1503 void CRebaseDlg::OnCancel()
1507 void CRebaseDlg::OnBnClickedAbort()
1510 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1513 if(m_OrigUpstreamHash
.IsEmpty())
1515 __super::OnCancel();
1518 if(m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
1523 if(CMessageBox::Show(NULL
,_T("Are you sure you want to abort the rebase process?"),_T("TortoiseGit"),MB_YESNO
) != IDYES
)
1526 if(this->m_IsFastForward
)
1528 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1529 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1534 __super::OnCancel();
1537 cmd
.Format(_T("git.exe checkout -f %s"),g_Git
.FixBranchName(this->m_UpstreamCtrl
.GetString()));
1538 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1544 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigUpstreamHash
.ToString());
1545 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1551 if(this->m_IsCherryPick
) //there are not "branch" at cherry pick mode
1553 __super::OnCancel();
1557 cmd
.Format(_T("git checkout -f %s"),this->m_BranchCtrl
.GetString());
1558 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1564 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1565 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1570 __super::OnCancel();
1573 void CRebaseDlg::OnBnClickedButtonBrowse()
1575 if(CBrowseRefsDlg::PickRefForCombo(&m_UpstreamCtrl
, gPickRef_NoTag
))
1576 OnCbnSelchangeUpstream();
1579 void CRebaseDlg::OnBnClickedRebaseCheckForce()
1582 this->FetchLogList();
1583 if(this->CheckRebaseCondition())
1585 /* Disable Start Rebase */
1586 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1590 void CRebaseDlg::OnBnClickedRebasePostButton()
1592 this->m_Upstream
=this->m_UpstreamCtrl
.GetString();
1593 this->m_Branch
=this->m_BranchCtrl
.GetString();
1595 this->EndDialog(IDC_REBASE_POST_BUTTON
+this->m_PostButton
.GetCurrentEntry());
1598 void CRebaseDlg::Refresh()
1600 if(this->m_IsCherryPick
)
1603 if(this->m_RebaseStage
== CHOOSE_BRANCH
)
1606 this->FetchLogList();
1607 if(this->CheckRebaseCondition())
1609 /* Disable Start Rebase */
1610 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1615 void CRebaseDlg::OnBnClickedButtonUp2()
1618 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1620 // do nothing if the first selected item is the first item in the list
1621 if (m_CommitList
.GetNextSelectedItem(pos
) == 0)
1624 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1626 bool changed
= false;
1629 int index
=m_CommitList
.GetNextSelectedItem(pos
);
1632 CGitHash old
= m_CommitList
.m_logEntries
[index
-1];
1633 m_CommitList
.m_logEntries
[index
-1] = m_CommitList
.m_logEntries
[index
];
1634 m_CommitList
.m_logEntries
[index
] = old
;
1635 m_CommitList
.SetItemState(index
-1, LVIS_SELECTED
, LVIS_SELECTED
);
1636 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1642 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1643 m_CommitList
.Invalidate();
1644 m_CommitList
.SetFocus();
1648 void CRebaseDlg::OnBnClickedButtonDown2()
1650 if (m_CommitList
.GetSelectedCount() == 0)
1654 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1655 bool changed
= false;
1656 // use an array to store all selected item indexes; the user won't select too much items
1657 int* indexes
= NULL
;
1658 indexes
= new int[m_CommitList
.GetSelectedCount()];
1662 indexes
[i
++] = m_CommitList
.GetNextSelectedItem(pos
);
1664 // don't move any item if the last selected item is the last item in the m_CommitList
1665 // (that would change the order of the selected items)
1666 if(indexes
[m_CommitList
.GetSelectedCount() - 1] < m_CommitList
.GetItemCount() - 1)
1668 // iterate over the indexes backwards in order to correctly move multiselected items
1669 for (i
= m_CommitList
.GetSelectedCount() - 1; i
>= 0; i
--)
1671 int index
= indexes
[i
];
1672 CGitHash old
= m_CommitList
.m_logEntries
[index
+1];
1673 m_CommitList
.m_logEntries
[index
+1] = m_CommitList
.m_logEntries
[index
];
1674 m_CommitList
.m_logEntries
[index
] = old
;
1675 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1676 m_CommitList
.SetItemState(index
+1, LVIS_SELECTED
, LVIS_SELECTED
);
1684 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1685 m_CommitList
.Invalidate();
1686 m_CommitList
.SetFocus();
1690 LRESULT
CRebaseDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1692 m_pTaskbarList
.Release();
1693 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
1697 void CRebaseDlg::OnLvnItemchangedLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1699 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1701 if(m_CommitList
.m_bNoDispUpdates
)
1703 if (pNMLV
->iItem
>= 0)
1705 this->m_CommitList
.m_nSearchIndex
= pNMLV
->iItem
;
1706 if (pNMLV
->iSubItem
!= 0)
1708 if ((pNMLV
->iItem
== m_CommitList
.m_arShownList
.GetCount()))
1710 // remove the selected state
1711 if (pNMLV
->uChanged
& LVIF_STATE
)
1713 m_CommitList
.SetItemState(pNMLV
->iItem
, 0, LVIS_SELECTED
);
1714 FillLogMessageCtrl();
1718 if (pNMLV
->uChanged
& LVIF_STATE
)
1720 FillLogMessageCtrl();
1725 FillLogMessageCtrl();
1729 void CRebaseDlg::FillLogMessageCtrl()
1731 int selCount
= m_CommitList
.GetSelectedCount();
1732 if (selCount
== 1 && (m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
))
1734 POSITION pos
= m_CommitList
.GetFirstSelectedItemPosition();
1735 int selIndex
= m_CommitList
.GetNextSelectedItem(pos
);
1736 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_CommitList
.m_arShownList
.SafeGetAt(selIndex
));
1737 m_FileListCtrl
.UpdateWithGitPathList(pLogEntry
->GetFiles(&m_CommitList
));
1738 m_FileListCtrl
.m_CurrentVersion
= pLogEntry
->m_CommitHash
;
1739 m_FileListCtrl
.Show(SVNSLC_SHOWVERSIONED
);
1740 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1741 m_LogMessageCtrl
.SetText(pLogEntry
->GetSubject() + _T("\n") + pLogEntry
->GetBody());
1742 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);