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"
38 IMPLEMENT_DYNAMIC(CRebaseDlg
, CResizableStandAloneDialog
)
40 CRebaseDlg::CRebaseDlg(CWnd
* pParent
/*=NULL*/)
41 : CResizableStandAloneDialog(CRebaseDlg::IDD
, pParent
)
45 , m_bAddCherryPickedFrom(FALSE
)
47 m_RebaseStage
=CHOOSE_BRANCH
;
48 m_CurrentRebaseIndex
=-1;
49 m_bThreadRunning
=FALSE
;
50 this->m_IsCherryPick
= FALSE
;
52 m_IsFastForward
=FALSE
;
55 CRebaseDlg::~CRebaseDlg()
59 void CRebaseDlg::DoDataExchange(CDataExchange
* pDX
)
61 CDialog::DoDataExchange(pDX
);
62 DDX_Control(pDX
, IDC_REBASE_PROGRESS
, m_ProgressBar
);
63 DDX_Control(pDX
, IDC_STATUS_STATIC
, m_CtrlStatusText
);
64 DDX_Check(pDX
, IDC_PICK_ALL
, m_bPickAll
);
65 DDX_Check(pDX
, IDC_SQUASH_ALL
, m_bSquashAll
);
66 DDX_Check(pDX
, IDC_EDIT_ALL
, m_bEditAll
);
67 DDX_Control(pDX
, IDC_REBASE_SPLIT
, m_wndSplitter
);
68 DDX_Control(pDX
,IDC_COMMIT_LIST
,m_CommitList
);
69 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_BRANCH
, this->m_BranchCtrl
);
70 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_UPSTREAM
, this->m_UpstreamCtrl
);
71 DDX_Check(pDX
, IDC_REBASE_CHECK_FORCE
,m_bForce
);
72 DDX_Check(pDX
, IDC_CHECK_CHERRYPICKED_FROM
, m_bAddCherryPickedFrom
);
73 DDX_Control(pDX
,IDC_REBASE_POST_BUTTON
,m_PostButton
);
77 BEGIN_MESSAGE_MAP(CRebaseDlg
, CResizableStandAloneDialog
)
78 ON_BN_CLICKED(IDC_PICK_ALL
, &CRebaseDlg::OnBnClickedPickAll
)
79 ON_BN_CLICKED(IDC_SQUASH_ALL
, &CRebaseDlg::OnBnClickedSquashAll
)
80 ON_BN_CLICKED(IDC_EDIT_ALL
, &CRebaseDlg::OnBnClickedEditAll
)
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_BN_CLICKED(IDC_BUTTON_BROWSE
, &CRebaseDlg::OnBnClickedButtonBrowse
)
89 ON_BN_CLICKED(IDC_REBASE_CHECK_FORCE
, &CRebaseDlg::OnBnClickedRebaseCheckForce
)
90 ON_BN_CLICKED(IDC_CHECK_CHERRYPICKED_FROM
, &CRebaseDlg::OnBnClickedCheckCherryPickedFrom
)
91 ON_BN_CLICKED(IDC_REBASE_POST_BUTTON
, &CRebaseDlg::OnBnClickedRebasePostButton
)
92 ON_BN_CLICKED(IDC_BUTTON_UP2
, &CRebaseDlg::OnBnClickedButtonUp2
)
93 ON_BN_CLICKED(IDC_BUTTON_DOWN2
, &CRebaseDlg::OnBnClickedButtonDown2
)
94 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
95 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_COMMIT_LIST
, OnLvnItemchangedLoglist
)
98 void CRebaseDlg::AddRebaseAnchor()
100 AddAnchor(IDC_REBASE_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
101 AddAnchor(IDC_COMMIT_LIST
,TOP_LEFT
, TOP_RIGHT
);
102 AddAnchor(IDC_REBASE_SPLIT
,TOP_LEFT
, TOP_RIGHT
);
103 AddAnchor(IDC_STATUS_STATIC
, BOTTOM_LEFT
,BOTTOM_RIGHT
);
104 AddAnchor(IDC_REBASE_CONTINUE
,BOTTOM_RIGHT
);
105 AddAnchor(IDC_REBASE_ABORT
, BOTTOM_RIGHT
);
106 AddAnchor(IDC_REBASE_PROGRESS
,BOTTOM_LEFT
, BOTTOM_RIGHT
);
107 AddAnchor(IDC_PICK_ALL
,TOP_LEFT
);
108 AddAnchor(IDC_SQUASH_ALL
,TOP_LEFT
);
109 AddAnchor(IDC_EDIT_ALL
,TOP_LEFT
);
110 AddAnchor(IDC_BUTTON_UP2
,TOP_LEFT
);
111 AddAnchor(IDC_BUTTON_DOWN2
,TOP_LEFT
);
112 AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM
,TOP_LEFT
);
113 AddAnchor(IDC_REBASE_COMBOXEX_BRANCH
,TOP_LEFT
);
114 AddAnchor(IDC_REBASE_STATIC_UPSTREAM
,TOP_LEFT
);
115 AddAnchor(IDC_REBASE_STATIC_BRANCH
,TOP_LEFT
);
116 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
117 AddAnchor(IDC_REBASE_CHECK_FORCE
,TOP_RIGHT
);
118 AddAnchor(IDC_CHECK_CHERRYPICKED_FROM
, TOP_RIGHT
);
119 AddAnchor(IDC_REBASE_POST_BUTTON
,BOTTOM_LEFT
);
121 this->AddOthersToAnchor();
124 BOOL
CRebaseDlg::OnInitDialog()
126 CResizableStandAloneDialog::OnInitDialog();
127 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
129 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
130 // do this, Explorer would be unable to send that message to our window if we
131 // were running elevated. It's OK to make the call all the time, since if we're
132 // not elevated, this is a no-op.
133 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
134 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
135 CAutoLibrary hUser
= ::LoadLibrary(_T("user32.dll"));
138 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
139 if (pfnChangeWindowMessageFilterEx
)
141 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
144 m_pTaskbarList
.Release();
145 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
148 //IDC_REBASE_DUMY_TAB
150 GetClientRect(m_DlgOrigRect
);
151 m_CommitList
.GetClientRect(m_CommitListOrigRect
);
153 CWnd
*pwnd
=this->GetDlgItem(IDC_REBASE_DUMY_TAB
);
154 pwnd
->GetWindowRect(&rectDummy
);
155 this->ScreenToClient(rectDummy
);
157 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_REBASE_TAB
))
159 TRACE0("Failed to create output tab window\n");
160 return FALSE
; // fail to create
162 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
163 // Create output panes:
164 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
165 DWORD dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
167 if (! this->m_FileListCtrl
.Create(dwStyle
,rectDummy
,&this->m_ctrlTabCtrl
,0) )
169 TRACE0("Failed to create output windows\n");
170 return FALSE
; // fail to create
173 if( ! this->m_LogMessageCtrl
.Create(_T("Scintilla"),_T("source"),0,rectDummy
,&m_ctrlTabCtrl
,0,0) )
175 TRACE0("Failed to create log message control");
178 m_LogMessageCtrl
.Init(0);
179 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);
181 dwStyle
= LBS_NOINTEGRALHEIGHT
| WS_CHILD
| WS_VISIBLE
| WS_HSCROLL
| WS_VSCROLL
;
183 if (!m_wndOutputRebase
.Create(_T("Scintilla"),_T("source"),0,rectDummy
, &m_ctrlTabCtrl
, 0,0) )
185 TRACE0("Failed to create output windows\n");
186 return -1; // fail to create
188 m_wndOutputRebase
.Init(0);
189 m_wndOutputRebase
.Call(SCI_SETREADONLY
, TRUE
);
191 m_tooltips
.Create(this);
193 m_tooltips
.AddTool(IDC_REBASE_CHECK_FORCE
,IDS_REBASE_FORCE_TT
);
194 m_tooltips
.AddTool(IDC_REBASE_ABORT
,IDS_REBASE_ABORT_TT
);
198 m_FileListCtrl
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("RebaseDlg"),(GITSLC_POPALL
^ (GITSLC_POPCOMMIT
|GITSLC_POPRESTORE
)),false);
200 m_ctrlTabCtrl
.AddTab(&m_FileListCtrl
, CString(MAKEINTRESOURCE(IDS_PROC_REVISIONFILES
)));
201 m_ctrlTabCtrl
.AddTab(&m_LogMessageCtrl
, CString(MAKEINTRESOURCE(IDS_PROC_COMMITMESSAGE
)), 1);
204 CString sWindowTitle
;
205 GetWindowText(sWindowTitle
);
206 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
208 EnableSaveRestore(_T("RebaseDlg"));
210 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
211 RECT rcDlg
, rcLogMsg
, rcFileList
;
212 GetClientRect(&rcDlg
);
213 m_CommitList
.GetWindowRect(&rcLogMsg
);
214 ScreenToClient(&rcLogMsg
);
215 this->m_ctrlTabCtrl
.GetWindowRect(&rcFileList
);
216 ScreenToClient(&rcFileList
);
220 m_wndSplitter
.GetWindowRect(&rectSplitter
);
221 ScreenToClient(&rectSplitter
);
222 int delta
= yPos
- rectSplitter
.top
;
223 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
225 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
230 if( this->m_RebaseStage
== CHOOSE_BRANCH
)
232 this->LoadBranchInfo();
237 this->m_BranchCtrl
.EnableWindow(FALSE
);
238 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
241 m_CommitList
.m_ColumnRegKey
= _T("Rebase");
242 m_CommitList
.m_IsIDReplaceAction
= TRUE
;
243 // m_CommitList.m_IsOldFirst = TRUE;
244 m_CommitList
.m_IsRebaseReplaceGraph
= TRUE
;
246 m_CommitList
.InsertGitColumn();
248 this->SetControlEnable();
250 if(!this->m_PreCmd
.IsEmpty())
252 CProgressDlg progress
;
253 progress
.m_GitCmd
=m_PreCmd
;
254 progress
.m_bAutoCloseOnSuccess
=true;
260 this->m_BranchCtrl
.SetCurSel(-1);
261 this->m_BranchCtrl
.EnableWindow(FALSE
);
262 GetDlgItem(IDC_REBASE_CHECK_FORCE
)->ShowWindow(SW_HIDE
);
263 GetDlgItem(IDC_BUTTON_BROWSE
)->EnableWindow(FALSE
);
264 this->m_UpstreamCtrl
.AddString(_T("HEAD"));
265 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
266 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CHERRYPICK
)));
267 this->m_CommitList
.StartFilter();
271 GetDlgItem(IDC_CHECK_CHERRYPICKED_FROM
)->ShowWindow(SW_HIDE
);
272 SetContinueButtonText();
273 m_CommitList
.DeleteAllItems();
277 m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_CHERRY_PICK
)|
278 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_SWITCHTOREV
)|
279 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_RESET
)|
280 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTREV
)|
281 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_TO_VERSION
)|
282 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV
)|
283 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_COMBINE_COMMIT
));
285 if(m_CommitList
.m_IsOldFirst
)
286 this->m_CurrentRebaseIndex
= -1;
288 this->m_CurrentRebaseIndex
= m_CommitList
.m_logEntries
.size();
291 if(this->CheckRebaseCondition())
293 /* Disable Start Rebase */
294 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
299 // CRebaseDlg message handlers
301 void CRebaseDlg::OnBnClickedPickAll()
305 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
307 this->m_bEditAll
=FALSE
;
308 this->m_bSquashAll
=FALSE
;
309 this->UpdateData(FALSE
);
312 void CRebaseDlg::OnBnClickedSquashAll()
315 if(this->m_bSquashAll
)
316 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
318 this->m_bEditAll
=FALSE
;
319 this->m_bPickAll
=FALSE
;
320 this->UpdateData(FALSE
);
323 void CRebaseDlg::OnBnClickedEditAll()
326 if( this->m_bEditAll
)
327 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
329 this->m_bPickAll
=FALSE
;
330 this->m_bSquashAll
=FALSE
;
331 this->UpdateData(FALSE
);
334 void CRebaseDlg::SetAllRebaseAction(int action
)
336 for(int i
=0;i
<this->m_CommitList
.m_logEntries
.size();i
++)
338 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
)=action
;
340 m_CommitList
.Invalidate();
343 void CRebaseDlg::OnBnClickedRebaseSplit()
348 LRESULT
CRebaseDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
352 if (wParam
== IDC_REBASE_SPLIT
)
354 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
360 return __super::DefWindowProc(message
, wParam
, lParam
);
363 void CRebaseDlg::DoSize(int delta
)
365 this->RemoveAllAnchors();
367 CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST
), delta
, CW_TOPALIGN
);
368 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
369 CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB
), -delta
, CW_BOTTOMALIGN
);
370 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
371 CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL
),0,delta
);
372 CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL
),0,delta
);
373 CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL
),0,delta
);
374 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_UP2
),0,delta
);
375 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_DOWN2
),0,delta
);
376 CSplitterControl::ChangePos(GetDlgItem(IDC_REBASE_CHECK_FORCE
),0,delta
);
378 this->AddRebaseAnchor();
379 // adjust the minimum size of the dialog to prevent the resizing from
380 // moving the list control too far down.
382 m_CommitList
.GetClientRect(rcLogMsg
);
383 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_CommitListOrigRect
.Height()+rcLogMsg
.Height()));
386 // m_CommitList.Invalidate();
388 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
390 this->m_ctrlTabCtrl
.Invalidate();
391 this->m_CommitList
.Invalidate();
392 this->m_FileListCtrl
.Invalidate();
393 this->m_LogMessageCtrl
.Invalidate();
397 void CRebaseDlg::SetSplitterRange()
399 if ((m_CommitList
)&&(m_ctrlTabCtrl
))
402 m_CommitList
.GetWindowRect(rcTop
);
403 ScreenToClient(rcTop
);
405 m_ctrlTabCtrl
.GetWindowRect(rcMiddle
);
406 ScreenToClient(rcMiddle
);
407 if (rcMiddle
.Height() && rcMiddle
.Width())
408 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
412 void CRebaseDlg::OnSize(UINT nType
,int cx
, int cy
)
414 // first, let the resizing take place
415 __super::OnSize(nType
, cx
, cy
);
421 void CRebaseDlg::SaveSplitterPos()
425 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
427 m_wndSplitter
.GetWindowRect(&rectSplitter
);
428 ScreenToClient(&rectSplitter
);
429 regPos
= rectSplitter
.top
;
433 void CRebaseDlg::LoadBranchInfo()
435 m_BranchCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
436 m_UpstreamCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
441 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_ALL
);
442 m_BranchCtrl
.AddString(list
);
444 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_ALL_F
);
445 m_UpstreamCtrl
.AddString(list
);
447 m_BranchCtrl
.SetCurSel(current
);
449 AddBranchToolTips(&m_BranchCtrl
);
450 AddBranchToolTips(&m_UpstreamCtrl
);
452 if(!m_Upstream
.IsEmpty())
454 m_UpstreamCtrl
.AddString(m_Upstream
);
455 m_UpstreamCtrl
.SetCurSel(m_UpstreamCtrl
.GetCount()-1);
459 //Select pull-remote from current branch
460 CString currentBranch
= g_Git
.GetSymbolicRef();
462 configName
.Format(L
"branch.%s.remote", currentBranch
);
463 CString pullRemote
= g_Git
.GetConfigValue(configName
);
465 //Select pull-branch from current branch
466 configName
.Format(L
"branch.%s.merge", currentBranch
);
467 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
469 CString defaultUpstream
;
470 defaultUpstream
.Format(L
"remotes/%s/%s", pullRemote
, pullBranch
);
471 int found
= m_UpstreamCtrl
.FindStringExact(0, defaultUpstream
);
473 m_UpstreamCtrl
.SetCurSel(found
);
477 void CRebaseDlg::OnCbnSelchangeBranch()
482 void CRebaseDlg::OnCbnSelchangeUpstream()
487 void CRebaseDlg::FetchLogList()
490 CString basestr
, err
;
492 m_IsFastForward
=FALSE
;
493 cmd
.Format(_T("git.exe merge-base %s %s"), g_Git
.FixBranchName(m_UpstreamCtrl
.GetString()),
494 g_Git
.FixBranchName(m_BranchCtrl
.GetString()));
495 g_Git
.Run(cmd
, &basestr
, &err
, CP_UTF8
);
499 hash
=g_Git
.GetHash(m_BranchCtrl
.GetString());
501 if(hash
== g_Git
.GetHash(this->m_UpstreamCtrl
.GetString()))
503 m_CommitList
.Clear();
505 fmt
.LoadString(IDS_REBASE_EQUAL_FMT
);
506 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
508 m_CommitList
.ShowText(text
);
509 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
516 this->m_IsFastForward
=TRUE
;
518 m_CommitList
.Clear();
520 fmt
.LoadString(IDS_REBASE_FASTFORWARD_FMT
);
521 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString(),
522 m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
524 m_CommitList
.ShowText(text
);
525 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(true);
526 SetContinueButtonText();
535 hash
=g_Git
.GetHash(m_UpstreamCtrl
.GetString());
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();
552 from
= m_UpstreamCtrl
.GetString();
553 to
= m_BranchCtrl
.GetString();
554 this->m_CommitList
.FillGitLog(NULL
,0,&from
,&to
);
556 if( m_CommitList
.GetItemCount() == 0 )
557 m_CommitList
.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_NOTHINGTOREBASE
)));
559 hash
=g_Git
.GetHash(m_UpstreamCtrl
.GetString());
562 if(m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
.size() >=0 )
564 if(hash
== m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
[0])
566 m_CommitList
.Clear();
567 m_CommitList
.ShowText(_T("Nothing Rebase"));
573 AddBranchToolTips(&this->m_BranchCtrl
);
574 AddBranchToolTips(&this->m_UpstreamCtrl
);
576 for(int i
=0;i
<m_CommitList
.m_logEntries
.size();i
++)
578 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
) = CTGitPath::LOGACTIONS_REBASE_PICK
;
581 m_CommitList
.Invalidate();
583 if(m_CommitList
.m_IsOldFirst
)
584 this->m_CurrentRebaseIndex
= -1;
586 this->m_CurrentRebaseIndex
= m_CommitList
.m_logEntries
.size();
588 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
589 SetContinueButtonText();
592 void CRebaseDlg::AddBranchToolTips(CHistoryCombo
*pBranch
)
596 CString text
=pBranch
->GetString();
602 tooltip
.Format(_T("%s: %s\n%s: %s\n%s: %s\n%s:\n<b>%s</b>\n%s"),
603 CString(MAKEINTRESOURCE(IDS_LOG_REVISION
)),
604 rev
.m_CommitHash
.ToString(),
605 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
)),
607 CString(MAKEINTRESOURCE(IDS_LOG_DATE
)),
608 CLoglistUtils::FormatDateAndTime(rev
.GetAuthorDate(), DATE_LONGDATE
),
609 CString(MAKEINTRESOURCE(IDS_LOG_MESSAGE
)),
613 pBranch
->DisableTooltip();
614 this->m_tooltips
.AddTool(pBranch
->GetComboBoxCtrl(),tooltip
);
618 BOOL
CRebaseDlg::PreTranslateMessage(MSG
*pMsg
)
620 if (pMsg
->message
== WM_KEYDOWN
)
622 switch (pMsg
->wParam
)
625 if(LogListHasFocus(pMsg
->hwnd
))
627 m_CommitList
.ShiftSelectedAction();
632 if(LogListHasFocus(pMsg
->hwnd
))
634 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
639 if(LogListHasFocus(pMsg
->hwnd
))
641 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP
);
646 if(LogListHasFocus(pMsg
->hwnd
))
648 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
653 if(LogListHasFocus(pMsg
->hwnd
))
655 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
660 if(LogListHasFocus(pMsg
->hwnd
) && GetAsyncKeyState(VK_CONTROL
) & 0x8000)
662 // select all entries
663 for (int i
= 0; i
< m_CommitList
.GetItemCount(); ++i
)
665 m_CommitList
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
676 /* Avoid TAB control destroy but dialog exist*/
681 ::GetClassName(pMsg
->hwnd
,buff
,128);
684 if(_tcsnicmp(buff
,_T("RichEdit20W"),128)==0 ||
685 _tcsnicmp(buff
,_T("Scintilla"),128)==0 ||
686 _tcsnicmp(buff
,_T("SysListView32"),128)==0||
687 ::GetParent(pMsg
->hwnd
) == this->m_ctrlTabCtrl
.m_hWnd
)
689 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
695 m_tooltips
.RelayEvent(pMsg
);
696 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
699 bool CRebaseDlg::LogListHasFocus(HWND hwnd
)
702 ::GetClassName(hwnd
, buff
, 128);
704 if(_tcsnicmp(buff
, _T("SysListView32"), 128) == 0)
709 int CRebaseDlg::CheckRebaseCondition()
711 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
713 if( !g_Git
.CheckCleanWorkTree() )
715 if(CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
718 cmd
=_T("git.exe stash");
719 this->AddLogString(cmd
);
720 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
722 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
730 //Todo Check $REBASE_ROOT
734 cmd
=_T("git.exe var GIT_COMMITTER_IDENT");
735 if(g_Git
.Run(cmd
,NULL
,CP_UTF8
))
738 //Todo call pre_rebase_hook
741 int CRebaseDlg::StartRebase()
744 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
745 if(!this->m_IsCherryPick
)
747 //Todo call comment_for_reflog
748 cmd
.Format(_T("git.exe checkout %s"),this->m_BranchCtrl
.GetString());
749 this->AddLogString(cmd
);
751 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
753 this->AddLogString(out
);
757 this->AddLogString(out
);
760 cmd
=_T("git.exe rev-parse --verify HEAD");
761 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
763 AddLogString(CString(MAKEINTRESOURCE(IDS_PROC_NOHEAD
)));
767 //git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
768 // echo "detached HEAD" > "$DOTEST"/head-name
770 cmd
.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));
771 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
773 AddLogString(_T("update ORIG_HEAD Fail"));
777 m_OrigUpstreamHash
.Empty();
778 m_OrigUpstreamHash
= g_Git
.GetHash(this->m_UpstreamCtrl
.GetString());
779 if(m_OrigUpstreamHash
.IsEmpty())
781 this->AddLogString(m_OrigUpstreamHash
);
785 if( !this->m_IsCherryPick
)
787 cmd
.Format(_T("git.exe checkout -f %s"), m_OrigUpstreamHash
.ToString());
788 this->AddLogString(cmd
);
791 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
793 this->AddLogString(out
);
799 if( !this->m_IsCherryPick
)
801 m_OrigBranchHash
= g_Git
.GetHash(this->m_BranchCtrl
.GetString());
802 if(m_OrigBranchHash
.IsEmpty())
804 this->AddLogString(m_OrigBranchHash
.ToString());
807 log
.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTREBASE
)));
810 log
.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTCHERRYPICK
)));
812 this->AddLogString(log
);
815 int CRebaseDlg::VerifyNoConflict()
818 if(g_Git
.ListConflictFile(list
))
820 AddLogString(_T("Get conflict files fail"));
823 if( list
.GetCount() != 0 )
825 CMessageBox::Show(NULL
, IDS_PROGRS_CONFLICTSOCCURED
, IDS_APPNAME
, MB_OK
);
831 int CRebaseDlg::FinishRebase()
833 if(this->m_IsCherryPick
) //cherry pick mode no "branch", working at upstream branch
836 git_revnum_t head
= g_Git
.GetHash(_T("HEAD"));
840 cmd
.Format(_T("git.exe checkout -f %s"),this->m_BranchCtrl
.GetString());
842 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
850 cmd
.Format(_T("git.exe reset --hard %s"),head
);
852 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
859 m_ctrlTabCtrl
.RemoveTab(0);
860 m_ctrlTabCtrl
.RemoveTab(0);
861 m_CtrlStatusText
.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_REBASEFINISHED
)));
865 void CRebaseDlg::OnBnClickedContinue()
867 if( m_RebaseStage
== REBASE_DONE
)
873 if( this->m_IsFastForward
)
876 CString oldbranch
= g_Git
.GetCurrentBranch();
877 if( oldbranch
!= m_BranchCtrl
.GetString() )
879 cmd
.Format(_T("git.exe checkout %s"),m_BranchCtrl
.GetString());
881 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
883 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
890 m_OrigBranchHash
= g_Git
.GetHash(m_BranchCtrl
.GetString());
891 m_OrigUpstreamHash
= g_Git
.GetHash(this->m_UpstreamCtrl
.GetString());
893 if(!g_Git
.IsFastForward(this->m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString()))
895 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
896 AddLogString(_T("No fast forward possible.\r\nMaybe repository changed"));
900 cmd
.Format(_T("git.exe reset --hard %s"),g_Git
.FixBranchName(this->m_UpstreamCtrl
.GetString()));
902 log
.Format(IDS_PROC_REBASE_FFTO
, m_UpstreamCtrl
.GetString());
903 this->AddLogString(log
);
906 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
907 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
909 AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL
)));
914 AddLogString(CString(MAKEINTRESOURCE(IDS_DONE
)));
915 m_RebaseStage
= REBASE_DONE
;
916 UpdateCurrentStatus();
920 if( m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
922 if(CheckRebaseCondition())
924 m_RebaseStage
= REBASE_START
;
925 m_FileListCtrl
.Clear();
926 m_FileListCtrl
.m_CurrentVersion
= L
"";
927 m_ctrlTabCtrl
.SetTabLabel(REBASE_TAB_CONFLICT
, CString(MAKEINTRESOURCE(IDS_PROC_CONFLICTFILES
)));
928 m_ctrlTabCtrl
.AddTab(&m_wndOutputRebase
, CString(MAKEINTRESOURCE(IDS_LOG
)), 2);
931 if( m_RebaseStage
== REBASE_FINISH
)
939 if( m_RebaseStage
== REBASE_SQUASH_CONFLICT
)
941 if(VerifyNoConflict())
943 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
944 if(this->CheckNextCommitIsSquash())
945 {//next commit is not squash;
946 m_RebaseStage
= REBASE_SQUASH_EDIT
;
947 this->OnRebaseUpdateUI(0,0);
948 this->UpdateCurrentStatus();
952 m_RebaseStage
=REBASE_CONTINUE
;
953 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
954 this->UpdateCurrentStatus();
958 if( m_RebaseStage
== REBASE_CONFLICT
)
960 if(VerifyNoConflict())
963 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
967 cmd
.Format(_T("git.exe commit -a -C %s"), curRev
->m_CommitHash
.ToString());
971 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
974 if(!g_Git
.CheckCleanWorkTree())
976 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
982 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
983 if( curRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_EDIT
)
985 m_RebaseStage
=REBASE_EDIT
;
986 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
987 this->UpdateCurrentStatus();
992 m_RebaseStage
=REBASE_CONTINUE
;
993 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
994 this->UpdateCurrentStatus();
998 if( m_RebaseStage
== REBASE_EDIT
|| m_RebaseStage
== REBASE_SQUASH_EDIT
)
1001 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1003 str
=this->m_LogMessageCtrl
.GetText();
1004 if(str
.Trim().IsEmpty())
1006 CMessageBox::Show(NULL
, IDS_PROC_COMMITMESSAGE_EMPTY
,IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1010 CString tempfile
=::GetTempFile();
1011 CAppUtils::SaveCommitUnicodeFile(tempfile
, str
);
1015 if( m_RebaseStage
== REBASE_SQUASH_EDIT
)
1016 cmd
.Format(_T("git.exe commit -F \"%s\""), tempfile
);
1018 cmd
.Format(_T("git.exe commit --amend -F \"%s\""), tempfile
);
1020 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1022 if(!g_Git
.CheckCleanWorkTree())
1024 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1029 CFile::Remove(tempfile
);
1031 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1032 m_RebaseStage
=REBASE_CONTINUE
;
1033 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
1034 this->UpdateCurrentStatus();
1038 InterlockedExchange(&m_bThreadRunning
, TRUE
);
1041 if (AfxBeginThread(RebaseThreadEntry
, this)==NULL
)
1043 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1044 CMessageBox::Show(NULL
, _T("Create Rebase Thread Fail"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1048 int CRebaseDlg::CheckNextCommitIsSquash()
1051 if(m_CommitList
.m_IsOldFirst
)
1052 index
=m_CurrentRebaseIndex
+1;
1054 index
=m_CurrentRebaseIndex
-1;
1061 if(index
>= m_CommitList
.GetItemCount())
1064 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[index
];
1066 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1068 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
)
1070 if(m_CommitList
.m_IsOldFirst
)
1078 }while(curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
);
1083 int CRebaseDlg::GoNext()
1085 if(m_CommitList
.m_IsOldFirst
)
1086 m_CurrentRebaseIndex
++;
1088 m_CurrentRebaseIndex
--;
1092 int CRebaseDlg::StateAction()
1094 switch(this->m_RebaseStage
)
1097 case CHOOSE_COMMIT_PICK_MODE
:
1100 m_RebaseStage
= REBASE_START
;
1107 void CRebaseDlg::SetContinueButtonText()
1110 switch(this->m_RebaseStage
)
1113 case CHOOSE_COMMIT_PICK_MODE
:
1114 if(this->m_IsFastForward
)
1115 Text
.LoadString(IDS_PROC_STARTREBASEFFBUTTON
);
1117 Text
.LoadString(IDS_PROC_STARTREBASEBUTTON
);
1121 case REBASE_CONTINUE
:
1122 case REBASE_SQUASH_CONFLICT
:
1123 Text
.LoadString(IDS_CONTINUEBUTTON
);
1126 case REBASE_CONFLICT
:
1127 Text
.LoadString(IDS_COMMITBUTTON
);
1130 Text
.LoadString(IDS_AMENDBUTTON
);
1133 case REBASE_SQUASH_EDIT
:
1134 Text
.LoadString(IDS_COMMITBUTTON
);
1139 Text
.LoadString(IDS_FINISHBUTTON
);
1143 Text
.LoadString(IDS_DONE
);
1146 this->GetDlgItem(IDC_REBASE_CONTINUE
)->SetWindowText(Text
);
1149 void CRebaseDlg::SetControlEnable()
1151 switch(this->m_RebaseStage
)
1154 case CHOOSE_COMMIT_PICK_MODE
:
1156 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(TRUE
);
1157 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(TRUE
);
1158 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(TRUE
);
1159 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(TRUE
);
1160 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(TRUE
);
1164 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(TRUE
);
1165 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(TRUE
);
1166 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(TRUE
);
1168 //this->m_CommitList.m_IsEnableRebaseMenu=TRUE;
1169 this->m_CommitList
.m_ContextMenuMask
|= m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1170 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1171 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1172 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
);
1176 case REBASE_CONTINUE
:
1179 case REBASE_CONFLICT
:
1181 case REBASE_SQUASH_CONFLICT
:
1183 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(FALSE
);
1184 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(FALSE
);
1185 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(FALSE
);
1186 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(FALSE
);
1187 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(FALSE
);
1188 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(FALSE
);
1189 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(FALSE
);
1190 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(FALSE
);
1191 //this->m_CommitList.m_IsEnableRebaseMenu=FALSE;
1192 this->m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1193 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1194 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1195 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
));
1197 if( m_RebaseStage
== REBASE_DONE
&& (this->m_PostButtonTexts
.GetCount() != 0) )
1199 this->GetDlgItem(IDC_STATUS_STATIC
)->ShowWindow(SW_HIDE
);
1200 this->GetDlgItem(IDC_REBASE_POST_BUTTON
)->ShowWindow(SW_SHOWNORMAL
);
1201 this->m_PostButton
.RemoveAll();
1202 this->m_PostButton
.AddEntries(m_PostButtonTexts
);
1203 //this->GetDlgItem(IDC_REBASE_POST_BUTTON)->SetWindowText(this->m_PostButtonText);
1208 if(m_bThreadRunning
)
1210 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1215 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(TRUE
);
1219 void CRebaseDlg::UpdateProgress()
1224 if(m_CommitList
.m_IsOldFirst
)
1225 index
= m_CurrentRebaseIndex
+1;
1227 index
= m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1229 m_ProgressBar
.SetRange(1,m_CommitList
.GetItemCount());
1230 m_ProgressBar
.SetPos(index
);
1233 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1234 m_pTaskbarList
->SetProgressValue(m_hWnd
, index
, m_CommitList
.GetItemCount());
1237 if(m_CurrentRebaseIndex
>=0 && m_CurrentRebaseIndex
< m_CommitList
.GetItemCount())
1240 text
.Format(IDS_PROC_REBASING_PROGRESS
, index
, m_CommitList
.GetItemCount());
1241 m_CtrlStatusText
.SetWindowText(text
);
1245 GitRev
*prevRev
=NULL
, *curRev
=NULL
;
1247 if( m_CurrentRebaseIndex
>= 0 && m_CurrentRebaseIndex
< m_CommitList
.m_arShownList
.GetSize())
1249 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1252 for(int i
=0;i
<m_CommitList
.m_arShownList
.GetSize();i
++)
1254 prevRev
=(GitRev
*)m_CommitList
.m_arShownList
[i
];
1255 if(prevRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1257 prevRev
->GetAction(&m_CommitList
) &= ~ CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1258 m_CommitList
.GetItemRect(i
,&rect
,LVIR_BOUNDS
);
1259 m_CommitList
.InvalidateRect(rect
);
1265 curRev
->GetAction(&m_CommitList
) |= CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1266 m_CommitList
.GetItemRect(m_CurrentRebaseIndex
,&rect
,LVIR_BOUNDS
);
1267 m_CommitList
.InvalidateRect(rect
);
1269 m_CommitList
.EnsureVisible(m_CurrentRebaseIndex
,FALSE
);
1272 void CRebaseDlg::UpdateCurrentStatus()
1274 SetContinueButtonText();
1279 void CRebaseDlg::AddLogString(CString str
)
1281 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, FALSE
);
1282 CStringA sTextA
= m_wndOutputRebase
.StringForControl(str
);//CUnicodeUtils::GetUTF8(str);
1283 this->m_wndOutputRebase
.SendMessage(SCI_DOCUMENTEND
);
1284 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)sTextA
);
1285 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n");
1286 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, TRUE
);
1289 int CRebaseDlg::GetCurrentCommitID()
1291 if(m_CommitList
.m_IsOldFirst
)
1293 return this->m_CurrentRebaseIndex
+1;
1298 return m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1302 int CRebaseDlg::DoRebase()
1305 if(m_CurrentRebaseIndex
<0)
1307 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1310 GitRev
*pRev
= (GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1311 int mode
=pRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1314 if( mode
== CTGitPath::LOGACTIONS_REBASE_SKIP
)
1316 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1320 if( mode
!= CTGitPath::LOGACTIONS_REBASE_PICK
)
1322 this->m_SquashMessage
+= pRev
->GetSubject();
1323 this->m_SquashMessage
+= _T("\n");
1324 this->m_SquashMessage
+= pRev
->GetBody();
1327 this->m_SquashMessage
.Empty();
1329 if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1330 nocommit
=_T(" --no-commit ");
1333 log
.Format(_T("%s %d: %s"),CTGitPath::GetActionName(mode
),this->GetCurrentCommitID(),pRev
->m_CommitHash
.ToString());
1335 AddLogString(pRev
->GetSubject());
1336 if (pRev
->GetSubject().IsEmpty())
1338 CMessageBox::Show(m_hWnd
, IDS_PROC_REBASE_EMPTYCOMMITMSG
, IDS_APPNAME
, MB_OK
| MB_ICONEXCLAMATION
);
1339 mode
= CTGitPath::LOGACTIONS_REBASE_EDIT
;
1342 CString cherryPickedFrom
;
1343 if (m_bAddCherryPickedFrom
)
1344 cherryPickedFrom
= _T("-x ");
1346 cmd
.Format(_T("git.exe cherry-pick %s%s %s"), cherryPickedFrom
, nocommit
, pRev
->m_CommitHash
.ToString());
1348 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1352 if(g_Git
.ListConflictFile(list
))
1354 AddLogString(_T("Get conflict files fail"));
1357 if(list
.GetCount() == 0 )
1359 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1361 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1364 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1366 this->m_RebaseStage
= REBASE_EDIT
;
1367 return -1; // Edit return -1 to stop rebase.
1370 if(CheckNextCommitIsSquash())
1372 // let user edit last commmit message
1373 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1377 if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1378 m_RebaseStage
= REBASE_SQUASH_CONFLICT
;
1380 m_RebaseStage
= REBASE_CONFLICT
;
1387 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1389 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1392 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1394 this->m_RebaseStage
= REBASE_EDIT
;
1395 return -1; // Edit return -1 to stop rebase.
1399 if(CheckNextCommitIsSquash())
1401 // let user edit last commmit message
1402 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1405 else if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1406 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1412 BOOL
CRebaseDlg::IsEnd()
1414 if(m_CommitList
.m_IsOldFirst
)
1415 return m_CurrentRebaseIndex
>= this->m_CommitList
.GetItemCount();
1417 return m_CurrentRebaseIndex
<0;
1420 int CRebaseDlg::RebaseThread()
1422 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
1427 if( m_RebaseStage
== REBASE_START
)
1429 if( this->StartRebase() )
1431 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1433 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1436 m_RebaseStage
= REBASE_CONTINUE
;
1439 else if( m_RebaseStage
== REBASE_CONTINUE
)
1442 UpdateCurrentStatus();
1446 m_RebaseStage
= REBASE_FINISH
;
1460 else if( m_RebaseStage
== REBASE_FINISH
)
1463 m_RebaseStage
= REBASE_DONE
;
1465 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1473 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1474 //this->UpdateCurrentStatus();
1477 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1478 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1482 void CRebaseDlg::ListConflictFile()
1484 this->m_FileListCtrl
.Clear();
1489 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
1491 this->m_FileListCtrl
.GetStatus(&list
,true);
1492 this->m_FileListCtrl
.Show(CTGitPath::LOGACTIONS_UNMERGED
|CTGitPath::LOGACTIONS_MODIFIED
|CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_DELETED
,
1493 CTGitPath::LOGACTIONS_UNMERGED
);
1496 LRESULT
CRebaseDlg::OnRebaseUpdateUI(WPARAM
,LPARAM
)
1498 UpdateCurrentStatus();
1499 if(m_CurrentRebaseIndex
<0)
1501 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1503 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1505 switch(m_RebaseStage
)
1507 case REBASE_CONFLICT
:
1508 case REBASE_SQUASH_CONFLICT
:
1510 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_CONFLICT
);
1512 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
1513 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1514 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1517 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1519 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1520 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1521 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1523 case REBASE_SQUASH_EDIT
:
1524 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1525 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1526 this->m_LogMessageCtrl
.SetText(this->m_SquashMessage
);
1528 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1531 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1535 void CRebaseDlg::OnCancel()
1539 void CRebaseDlg::OnBnClickedAbort()
1542 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1545 CString pron
= m_OrigUpstreamHash
.ToString();
1546 if(m_OrigUpstreamHash
.IsEmpty())
1548 __super::OnCancel();
1551 if(m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
1556 if(CMessageBox::Show(NULL
, IDS_PROC_REBASE_ABORT
, IDS_APPNAME
, MB_YESNO
) != IDYES
)
1559 if(this->m_IsFastForward
)
1561 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1562 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1565 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1567 __super::OnCancel();
1570 cmd
.Format(_T("git.exe checkout -f %s"),g_Git
.FixBranchName(this->m_UpstreamCtrl
.GetString()));
1571 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1574 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1575 __super::OnCancel();
1579 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigUpstreamHash
.ToString());
1580 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1583 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1584 __super::OnCancel();
1588 if(this->m_IsCherryPick
) //there are not "branch" at cherry pick mode
1590 __super::OnCancel();
1594 cmd
.Format(_T("git checkout -f %s"),this->m_BranchCtrl
.GetString());
1595 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1598 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1599 __super::OnCancel();
1603 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1604 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1607 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1609 __super::OnCancel();
1612 void CRebaseDlg::OnBnClickedButtonBrowse()
1614 if(CBrowseRefsDlg::PickRefForCombo(&m_UpstreamCtrl
, gPickRef_NoTag
))
1615 OnCbnSelchangeUpstream();
1618 void CRebaseDlg::OnBnClickedRebaseCheckForce()
1621 this->FetchLogList();
1622 if(this->CheckRebaseCondition())
1624 /* Disable Start Rebase */
1625 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1629 void CRebaseDlg::OnBnClickedRebasePostButton()
1631 this->m_Upstream
=this->m_UpstreamCtrl
.GetString();
1632 this->m_Branch
=this->m_BranchCtrl
.GetString();
1634 this->EndDialog(IDC_REBASE_POST_BUTTON
+this->m_PostButton
.GetCurrentEntry());
1637 void CRebaseDlg::Refresh()
1639 if(this->m_IsCherryPick
)
1642 if(this->m_RebaseStage
== CHOOSE_BRANCH
)
1645 this->FetchLogList();
1646 if(this->CheckRebaseCondition())
1648 /* Disable Start Rebase */
1649 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1654 void CRebaseDlg::OnBnClickedButtonUp2()
1657 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1659 // do nothing if the first selected item is the first item in the list
1660 if (m_CommitList
.GetNextSelectedItem(pos
) == 0)
1663 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1665 bool changed
= false;
1668 int index
=m_CommitList
.GetNextSelectedItem(pos
);
1671 CGitHash old
= m_CommitList
.m_logEntries
[index
-1];
1672 m_CommitList
.m_logEntries
[index
-1] = m_CommitList
.m_logEntries
[index
];
1673 m_CommitList
.m_logEntries
[index
] = old
;
1674 m_CommitList
.SetItemState(index
-1, LVIS_SELECTED
, LVIS_SELECTED
);
1675 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1681 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1682 m_CommitList
.Invalidate();
1683 m_CommitList
.SetFocus();
1687 void CRebaseDlg::OnBnClickedButtonDown2()
1689 if (m_CommitList
.GetSelectedCount() == 0)
1693 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1694 bool changed
= false;
1695 // use an array to store all selected item indexes; the user won't select too much items
1696 int* indexes
= NULL
;
1697 indexes
= new int[m_CommitList
.GetSelectedCount()];
1701 indexes
[i
++] = m_CommitList
.GetNextSelectedItem(pos
);
1703 // don't move any item if the last selected item is the last item in the m_CommitList
1704 // (that would change the order of the selected items)
1705 if(indexes
[m_CommitList
.GetSelectedCount() - 1] < m_CommitList
.GetItemCount() - 1)
1707 // iterate over the indexes backwards in order to correctly move multiselected items
1708 for (i
= m_CommitList
.GetSelectedCount() - 1; i
>= 0; i
--)
1710 int index
= indexes
[i
];
1711 CGitHash old
= m_CommitList
.m_logEntries
[index
+1];
1712 m_CommitList
.m_logEntries
[index
+1] = m_CommitList
.m_logEntries
[index
];
1713 m_CommitList
.m_logEntries
[index
] = old
;
1714 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1715 m_CommitList
.SetItemState(index
+1, LVIS_SELECTED
, LVIS_SELECTED
);
1723 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1724 m_CommitList
.Invalidate();
1725 m_CommitList
.SetFocus();
1729 LRESULT
CRebaseDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1731 m_pTaskbarList
.Release();
1732 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
1736 void CRebaseDlg::OnLvnItemchangedLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1738 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1740 if(m_CommitList
.m_bNoDispUpdates
)
1742 if (pNMLV
->iItem
>= 0)
1744 this->m_CommitList
.m_nSearchIndex
= pNMLV
->iItem
;
1745 if (pNMLV
->iSubItem
!= 0)
1747 if ((pNMLV
->iItem
== m_CommitList
.m_arShownList
.GetCount()))
1749 // remove the selected state
1750 if (pNMLV
->uChanged
& LVIF_STATE
)
1752 m_CommitList
.SetItemState(pNMLV
->iItem
, 0, LVIS_SELECTED
);
1753 FillLogMessageCtrl();
1757 if (pNMLV
->uChanged
& LVIF_STATE
)
1759 FillLogMessageCtrl();
1764 FillLogMessageCtrl();
1768 void CRebaseDlg::FillLogMessageCtrl()
1770 int selCount
= m_CommitList
.GetSelectedCount();
1771 if (selCount
== 1 && (m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
))
1773 POSITION pos
= m_CommitList
.GetFirstSelectedItemPosition();
1774 int selIndex
= m_CommitList
.GetNextSelectedItem(pos
);
1775 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_CommitList
.m_arShownList
.SafeGetAt(selIndex
));
1776 m_FileListCtrl
.UpdateWithGitPathList(pLogEntry
->GetFiles(&m_CommitList
));
1777 m_FileListCtrl
.m_CurrentVersion
= pLogEntry
->m_CommitHash
;
1778 m_FileListCtrl
.Show(GITSLC_SHOWVERSIONED
);
1779 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1780 m_LogMessageCtrl
.SetText(pLogEntry
->GetSubject() + _T("\n") + pLogEntry
->GetBody());
1781 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);
1784 void CRebaseDlg::OnBnClickedCheckCherryPickedFrom()