1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // RebaseDlg.cpp : implementation file
24 #include "TortoiseProc.h"
25 #include "RebaseDlg.h"
27 #include "MessageBox.h"
28 #include "UnicodeUtils.h"
29 #include "BrowseRefsDlg.h"
30 #include "ProgressDlg.h"
33 IMPLEMENT_DYNAMIC(CRebaseDlg
, CResizableStandAloneDialog
)
35 CRebaseDlg::CRebaseDlg(CWnd
* pParent
/*=NULL*/)
36 : CResizableStandAloneDialog(CRebaseDlg::IDD
, pParent
)
41 m_RebaseStage
=CHOOSE_BRANCH
;
42 m_CurrentRebaseIndex
=-1;
43 m_bThreadRunning
=FALSE
;
44 this->m_IsCherryPick
= FALSE
;
46 m_IsFastForward
=FALSE
;
49 CRebaseDlg::~CRebaseDlg()
53 void CRebaseDlg::DoDataExchange(CDataExchange
* pDX
)
55 CDialog::DoDataExchange(pDX
);
56 DDX_Control(pDX
, IDC_REBASE_PROGRESS
, m_ProgressBar
);
57 DDX_Control(pDX
, IDC_STATUS_STATIC
, m_CtrlStatusText
);
58 DDX_Check(pDX
, IDC_PICK_ALL
, m_bPickAll
);
59 DDX_Check(pDX
, IDC_SQUASH_ALL
, m_bSquashAll
);
60 DDX_Check(pDX
, IDC_EDIT_ALL
, m_bEditAll
);
61 DDX_Control(pDX
, IDC_REBASE_SPLIT
, m_wndSplitter
);
62 DDX_Control(pDX
,IDC_COMMIT_LIST
,m_CommitList
);
63 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_BRANCH
, this->m_BranchCtrl
);
64 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_UPSTREAM
, this->m_UpstreamCtrl
);
65 DDX_Check(pDX
, IDC_REBASE_CHECK_FORCE
,m_bForce
);
66 DDX_Control(pDX
,IDC_REBASE_POST_BUTTON
,m_PostButton
);
70 BEGIN_MESSAGE_MAP(CRebaseDlg
, CResizableStandAloneDialog
)
71 ON_BN_CLICKED(IDC_PICK_ALL
, &CRebaseDlg::OnBnClickedPickAll
)
72 ON_BN_CLICKED(IDC_SQUASH_ALL
, &CRebaseDlg::OnBnClickedSquashAll
)
73 ON_BN_CLICKED(IDC_EDIT_ALL
, &CRebaseDlg::OnBnClickedEditAll
)
74 ON_BN_CLICKED(IDC_REBASE_SPLIT
, &CRebaseDlg::OnBnClickedRebaseSplit
)
75 ON_BN_CLICKED(IDC_REBASE_CONTINUE
,OnBnClickedContinue
)
76 ON_BN_CLICKED(IDC_REBASE_ABORT
, OnBnClickedAbort
)
78 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH
, &CRebaseDlg::OnCbnSelchangeBranch
)
79 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM
, &CRebaseDlg::OnCbnSelchangeUpstream
)
80 ON_MESSAGE(MSG_REBASE_UPDATE_UI
, OnRebaseUpdateUI
)
81 ON_BN_CLICKED(IDC_BUTTON_BROWSE
, &CRebaseDlg::OnBnClickedButtonBrowse
)
82 ON_BN_CLICKED(IDC_REBASE_CHECK_FORCE
, &CRebaseDlg::OnBnClickedRebaseCheckForce
)
83 ON_BN_CLICKED(IDC_REBASE_POST_BUTTON
, &CRebaseDlg::OnBnClickedRebasePostButton
)
84 ON_BN_CLICKED(IDC_BUTTON_UP2
, &CRebaseDlg::OnBnClickedButtonUp2
)
85 ON_BN_CLICKED(IDC_BUTTON_DOWN2
, &CRebaseDlg::OnBnClickedButtonDown2
)
88 void CRebaseDlg::AddRebaseAnchor()
90 AddAnchor(IDC_REBASE_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
91 AddAnchor(IDC_COMMIT_LIST
,TOP_LEFT
, TOP_RIGHT
);
92 AddAnchor(IDC_REBASE_SPLIT
,TOP_LEFT
, TOP_RIGHT
);
93 AddAnchor(IDC_STATUS_STATIC
, BOTTOM_LEFT
,BOTTOM_RIGHT
);
94 AddAnchor(IDC_REBASE_CONTINUE
,BOTTOM_RIGHT
);
95 AddAnchor(IDC_REBASE_ABORT
, BOTTOM_RIGHT
);
96 AddAnchor(IDC_REBASE_PROGRESS
,BOTTOM_LEFT
, BOTTOM_RIGHT
);
97 AddAnchor(IDC_PICK_ALL
,TOP_LEFT
);
98 AddAnchor(IDC_SQUASH_ALL
,TOP_LEFT
);
99 AddAnchor(IDC_EDIT_ALL
,TOP_LEFT
);
100 AddAnchor(IDC_BUTTON_UP2
,TOP_LEFT
);
101 AddAnchor(IDC_BUTTON_DOWN2
,TOP_LEFT
);
102 AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM
,TOP_LEFT
);
103 AddAnchor(IDC_REBASE_COMBOXEX_BRANCH
,TOP_LEFT
);
104 AddAnchor(IDC_REBASE_STATIC_UPSTREAM
,TOP_LEFT
);
105 AddAnchor(IDC_REBASE_STATIC_BRANCH
,TOP_LEFT
);
106 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
107 AddAnchor(IDC_REBASE_CHECK_FORCE
,TOP_RIGHT
);
108 AddAnchor(IDC_REBASE_POST_BUTTON
,BOTTOM_LEFT
);
110 this->AddOthersToAnchor();
113 BOOL
CRebaseDlg::OnInitDialog()
115 CResizableStandAloneDialog::OnInitDialog();
118 //IDC_REBASE_DUMY_TAB
120 GetClientRect(m_DlgOrigRect
);
121 m_CommitList
.GetClientRect(m_CommitListOrigRect
);
123 CWnd
*pwnd
=this->GetDlgItem(IDC_REBASE_DUMY_TAB
);
124 pwnd
->GetWindowRect(&rectDummy
);
125 this->ScreenToClient(rectDummy
);
127 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_REBASE_TAB
))
129 TRACE0("Failed to create output tab window\n");
130 return FALSE
; // fail to create
132 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
133 // Create output panes:
134 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
135 DWORD dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
|LVS_SINGLESEL
|WS_CHILD
| WS_VISIBLE
;
137 if (! this->m_FileListCtrl
.Create(dwStyle
,rectDummy
,&this->m_ctrlTabCtrl
,0) )
139 TRACE0("Failed to create output windows\n");
140 return FALSE
; // fail to create
143 if( ! this->m_LogMessageCtrl
.Create(_T("Scintilla"),_T("source"),0,rectDummy
,&m_ctrlTabCtrl
,0,0) )
145 TRACE0("Failed to create log message control");
148 m_LogMessageCtrl
.Init(0);
150 dwStyle
= LBS_NOINTEGRALHEIGHT
| WS_CHILD
| WS_VISIBLE
| WS_HSCROLL
| WS_VSCROLL
;
152 if (!m_wndOutputRebase
.Create(_T("Scintilla"),_T("source"),0,rectDummy
, &m_ctrlTabCtrl
, 0,0) )
154 TRACE0("Failed to create output windows\n");
155 return -1; // fail to create
157 m_wndOutputRebase
.Init(0);
158 m_wndOutputRebase
.Call(SCI_SETREADONLY
, TRUE
);
160 m_tooltips
.Create(this);
162 m_tooltips
.AddTool(IDC_REBASE_CHECK_FORCE
,IDS_REBASE_FORCE_TT
);
163 m_tooltips
.AddTool(IDC_REBASE_ABORT
,IDS_REBASE_ABORT_TT
);
167 m_FileListCtrl
.Init(SVNSLC_COLEXT
| SVNSLC_COLSTATUS
|SVNSLC_COLADD
|SVNSLC_COLDEL
, _T("RebaseDlg"),(SVNSLC_POPALL
^ SVNSLC_POPCOMMIT
),false);
169 m_ctrlTabCtrl
.AddTab(&m_FileListCtrl
,_T("Conflict File"));
170 m_ctrlTabCtrl
.AddTab(&m_LogMessageCtrl
,_T("Commit Message"),1);
171 m_ctrlTabCtrl
.AddTab(&m_wndOutputRebase
,_T("Log"),2);
175 EnableSaveRestore(_T("RebaseDlg"));
177 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
178 RECT rcDlg
, rcLogMsg
, rcFileList
;
179 GetClientRect(&rcDlg
);
180 m_CommitList
.GetWindowRect(&rcLogMsg
);
181 ScreenToClient(&rcLogMsg
);
182 this->m_ctrlTabCtrl
.GetWindowRect(&rcFileList
);
183 ScreenToClient(&rcFileList
);
187 m_wndSplitter
.GetWindowRect(&rectSplitter
);
188 ScreenToClient(&rectSplitter
);
189 int delta
= yPos
- rectSplitter
.top
;
190 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
192 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
197 if( this->m_RebaseStage
== CHOOSE_BRANCH
)
199 this->LoadBranchInfo();
203 this->m_BranchCtrl
.EnableWindow(FALSE
);
204 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
207 m_CommitList
.m_ColumnRegKey
= _T("Rebase");
208 m_CommitList
.m_IsIDReplaceAction
= TRUE
;
209 // m_CommitList.m_IsOldFirst = TRUE;
210 m_CommitList
.m_IsRebaseReplaceGraph
= TRUE
;
212 m_CommitList
.InsertGitColumn();
214 this->SetControlEnable();
216 if(!this->m_PreCmd
.IsEmpty())
218 CProgressDlg progress
;
219 progress
.m_GitCmd
=m_PreCmd
;
220 progress
.m_bAutoCloseOnSuccess
=true;
226 this->m_BranchCtrl
.SetCurSel(-1);
227 this->m_BranchCtrl
.EnableWindow(FALSE
);
228 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
229 this->SetWindowText(_T("Cherry Pick"));
230 this->m_CommitList
.StartFilter();
234 SetContinueButtonText();
235 m_CommitList
.DeleteAllItems();
239 m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_CHERRY_PICK
)|
240 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_SWITCHTOREV
)|
241 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_RESET
)|
242 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTREV
)|
243 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_TO_VERSION
)|
244 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV
)|
245 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_COMBINE_COMMIT
));
247 if(m_CommitList
.m_IsOldFirst
)
248 this->m_CurrentRebaseIndex
= -1;
250 this->m_CurrentRebaseIndex
= m_CommitList
.m_logEntries
.size();
253 if(this->CheckRebaseCondition())
255 /* Disable Start Rebase */
256 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
261 // CRebaseDlg message handlers
263 void CRebaseDlg::OnBnClickedPickAll()
267 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
269 this->m_bEditAll
=FALSE
;
270 this->m_bSquashAll
=FALSE
;
271 this->UpdateData(FALSE
);
274 void CRebaseDlg::OnBnClickedSquashAll()
277 if(this->m_bSquashAll
)
278 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
280 this->m_bEditAll
=FALSE
;
281 this->m_bPickAll
=FALSE
;
282 this->UpdateData(FALSE
);
285 void CRebaseDlg::OnBnClickedEditAll()
288 if( this->m_bEditAll
)
289 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
291 this->m_bPickAll
=FALSE
;
292 this->m_bSquashAll
=FALSE
;
293 this->UpdateData(FALSE
);
296 void CRebaseDlg::SetAllRebaseAction(int action
)
298 for(int i
=0;i
<this->m_CommitList
.m_logEntries
.size();i
++)
300 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
)=action
;
302 m_CommitList
.Invalidate();
305 void CRebaseDlg::OnBnClickedRebaseSplit()
310 LRESULT
CRebaseDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
314 if (wParam
== IDC_REBASE_SPLIT
)
316 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
322 return __super::DefWindowProc(message
, wParam
, lParam
);
325 void CRebaseDlg::DoSize(int delta
)
327 this->RemoveAllAnchors();
329 CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST
), delta
, CW_TOPALIGN
);
330 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
331 CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB
), -delta
, CW_BOTTOMALIGN
);
332 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
333 CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL
),0,delta
);
334 CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL
),0,delta
);
335 CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL
),0,delta
);
336 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_UP2
),0,delta
);
337 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_DOWN2
),0,delta
);
338 CSplitterControl::ChangePos(GetDlgItem(IDC_REBASE_CHECK_FORCE
),0,delta
);
340 this->AddRebaseAnchor();
341 // adjust the minimum size of the dialog to prevent the resizing from
342 // moving the list control too far down.
344 m_CommitList
.GetClientRect(rcLogMsg
);
345 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_CommitListOrigRect
.Height()+rcLogMsg
.Height()));
348 // m_CommitList.Invalidate();
350 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
352 this->m_ctrlTabCtrl
.Invalidate();
353 this->m_CommitList
.Invalidate();
354 this->m_FileListCtrl
.Invalidate();
355 this->m_LogMessageCtrl
.Invalidate();
359 void CRebaseDlg::SetSplitterRange()
361 if ((m_CommitList
)&&(m_ctrlTabCtrl
))
364 m_CommitList
.GetWindowRect(rcTop
);
365 ScreenToClient(rcTop
);
367 m_ctrlTabCtrl
.GetWindowRect(rcMiddle
);
368 ScreenToClient(rcMiddle
);
369 if (rcMiddle
.Height() && rcMiddle
.Width())
370 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
374 void CRebaseDlg::OnSize(UINT nType
,int cx
, int cy
)
376 // first, let the resizing take place
377 __super::OnSize(nType
, cx
, cy
);
383 void CRebaseDlg::SaveSplitterPos()
387 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
389 m_wndSplitter
.GetWindowRect(&rectSplitter
);
390 ScreenToClient(&rectSplitter
);
391 regPos
= rectSplitter
.top
;
395 void CRebaseDlg::LoadBranchInfo()
397 m_BranchCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
398 m_UpstreamCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
403 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_ALL
);
404 m_BranchCtrl
.AddString(list
);
405 m_UpstreamCtrl
.AddString(list
);
407 m_BranchCtrl
.SetCurSel(current
);
409 AddBranchToolTips(&m_BranchCtrl
);
410 AddBranchToolTips(&m_UpstreamCtrl
);
412 if(!m_Upstream
.IsEmpty())
414 m_UpstreamCtrl
.AddString(m_Upstream
);
415 m_UpstreamCtrl
.SetCurSel(m_UpstreamCtrl
.GetCount()-1);
419 //Select pull-remote from current branch
420 CString currentBranch
= g_Git
.GetSymbolicRef();
422 configName
.Format(L
"branch.%s.remote", currentBranch
);
423 CString pullRemote
= g_Git
.GetConfigValue(configName
);
425 //Select pull-branch from current branch
426 configName
.Format(L
"branch.%s.merge", currentBranch
);
427 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
429 CString defaultUpstream
;
430 defaultUpstream
.Format(L
"remotes/%s/%s", pullRemote
, pullBranch
);
431 int found
= m_UpstreamCtrl
.FindStringExact(0, defaultUpstream
);
433 m_UpstreamCtrl
.SetCurSel(found
);
437 void CRebaseDlg::OnCbnSelchangeBranch()
442 void CRebaseDlg::OnCbnSelchangeUpstream()
447 void CRebaseDlg::FetchLogList()
452 m_IsFastForward
=FALSE
;
453 cmd
.Format(_T("git.exe merge-base %s %s"), m_UpstreamCtrl
.GetString(),m_BranchCtrl
.GetString());
454 if(g_Git
.Run(cmd
,&basestr
,CP_ACP
))
456 CMessageBox::Show(NULL
,basestr
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
461 hash
=g_Git
.GetHash(m_BranchCtrl
.GetString());
463 if(hash
== g_Git
.GetHash(this->m_UpstreamCtrl
.GetString()))
465 m_CommitList
.Clear();
467 fmt
.LoadString(IDS_REBASE_EQUAL_FMT
);
468 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
470 m_CommitList
.ShowText(text
);
471 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
478 this->m_IsFastForward
=TRUE
;
480 m_CommitList
.Clear();
482 fmt
.LoadString(IDS_REBASE_FASTFORWARD_FMT
);
483 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString(),
484 m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
486 m_CommitList
.ShowText(text
);
487 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(true);
488 SetContinueButtonText();
497 hash
=g_Git
.GetHash(m_UpstreamCtrl
.GetString());
501 m_CommitList
.Clear();
503 fmt
.LoadString(IDS_REBASE_UPTODATE_FMT
);
504 text
.Format(fmt
,m_BranchCtrl
.GetString());
505 m_CommitList
.ShowText(text
);
506 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
507 SetContinueButtonText();
512 m_CommitList
.Clear();
514 from
= m_UpstreamCtrl
.GetString();
515 to
= m_BranchCtrl
.GetString();
516 this->m_CommitList
.FillGitLog(NULL
,0,&from
,&to
);
518 if( m_CommitList
.GetItemCount() == 0 )
519 m_CommitList
.ShowText(_T("Nothing to Rebase"));
521 hash
=g_Git
.GetHash(m_UpstreamCtrl
.GetString());
524 if(m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
.size() >=0 )
526 if(hash
== m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
[0])
528 m_CommitList
.Clear();
529 m_CommitList
.ShowText(_T("Nothing Rebase"));
535 AddBranchToolTips(&this->m_BranchCtrl
);
536 AddBranchToolTips(&this->m_UpstreamCtrl
);
538 for(int i
=0;i
<m_CommitList
.m_logEntries
.size();i
++)
540 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
) = CTGitPath::LOGACTIONS_REBASE_PICK
;
543 m_CommitList
.Invalidate();
545 if(m_CommitList
.m_IsOldFirst
)
546 this->m_CurrentRebaseIndex
= -1;
548 this->m_CurrentRebaseIndex
= m_CommitList
.m_logEntries
.size();
550 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
551 SetContinueButtonText();
554 void CRebaseDlg::AddBranchToolTips(CHistoryCombo
*pBranch
)
558 CString text
=pBranch
->GetString();
564 tooltip
.Format(_T("CommitHash:%s\nCommit by: %s %s\n <b>%s</b> \n %s"),
565 rev
.m_CommitHash
.ToString(),
567 CAppUtils::FormatDateAndTime(rev
.GetAuthorDate(),DATE_LONGDATE
),
571 pBranch
->DisableTooltip();
572 this->m_tooltips
.AddTool(pBranch
->GetComboBoxCtrl(),tooltip
);
576 BOOL
CRebaseDlg::PreTranslateMessage(MSG
*pMsg
)
578 if (pMsg
->message
== WM_KEYDOWN
)
580 switch (pMsg
->wParam
)
589 /* Avoid TAB control destroy but dialog exist*/
594 ::GetClassName(pMsg
->hwnd
,buff
,128);
597 if(_tcsnicmp(buff
,_T("RichEdit20W"),128)==0 ||
598 _tcsnicmp(buff
,_T("Scintilla"),128)==0 ||
599 _tcsnicmp(buff
,_T("SysListView32"),128)==0||
600 ::GetParent(pMsg
->hwnd
) == this->m_ctrlTabCtrl
.m_hWnd
)
602 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
608 m_tooltips
.RelayEvent(pMsg
);
609 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
611 int CRebaseDlg::CheckRebaseCondition()
613 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
615 if( !g_Git
.CheckCleanWorkTree() )
617 if(CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
,IDS_APPNAME
,MB_YESNO
|MB_ICONINFORMATION
)==IDYES
)
620 cmd
=_T("git.exe stash");
621 this->AddLogString(cmd
);
622 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
624 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
631 //Todo Check $REBASE_ROOT
635 cmd
=_T("git.exe var GIT_COMMITTER_IDENT");
636 if(g_Git
.Run(cmd
,NULL
,CP_UTF8
))
639 //Todo call pre_rebase_hook
642 int CRebaseDlg::StartRebase()
645 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
646 if(!this->m_IsCherryPick
)
648 //Todo call comment_for_reflog
649 cmd
.Format(_T("git.exe checkout %s"),this->m_BranchCtrl
.GetString());
650 this->AddLogString(cmd
);
652 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
655 this->AddLogString(out
);
658 cmd
=_T("git.exe rev-parse --verify HEAD");
659 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
661 AddLogString(_T("No Head"));
665 //git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
666 // echo "detached HEAD" > "$DOTEST"/head-name
668 cmd
.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));
669 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
671 AddLogString(_T("update ORIG_HEAD Fail"));
675 m_OrigUpstreamHash
.Empty();
676 m_OrigUpstreamHash
= g_Git
.GetHash(this->m_UpstreamCtrl
.GetString());
677 if(m_OrigUpstreamHash
.IsEmpty())
679 this->AddLogString(m_OrigUpstreamHash
);
683 if( !this->m_IsCherryPick
)
685 cmd
.Format(_T("git.exe checkout -f %s"), m_OrigUpstreamHash
.ToString());
686 this->AddLogString(cmd
);
689 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
691 this->AddLogString(out
);
696 if( !this->m_IsCherryPick
)
698 m_OrigBranchHash
= g_Git
.GetHash(this->m_BranchCtrl
.GetString());
699 if(m_OrigBranchHash
.IsEmpty())
701 this->AddLogString(m_OrigBranchHash
.ToString());
704 this->AddLogString(_T("Start Rebase\r\n"));
707 this->AddLogString(_T("Start Cherry-pick\r\n"));
711 int CRebaseDlg::VerifyNoConflict()
714 if(g_Git
.ListConflictFile(list
))
716 AddLogString(_T("Get conflict files fail"));
719 if( list
.GetCount() != 0 )
721 CMessageBox::Show(NULL
,_T("There are conflict file, you should mark it resolve"),_T("TortoiseGit"),MB_OK
);
727 int CRebaseDlg::FinishRebase()
729 if(this->m_IsCherryPick
) //cherry pick mode no "branch", working at upstream branch
732 git_revnum_t head
= g_Git
.GetHash(_T("HEAD"));
736 cmd
.Format(_T("git.exe checkout -f %s"),this->m_BranchCtrl
.GetString());
738 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
746 cmd
.Format(_T("git.exe reset --hard %s"),head
);
748 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
757 void CRebaseDlg::OnBnClickedContinue()
759 if( m_RebaseStage
== REBASE_DONE
)
765 if( this->m_IsFastForward
)
768 CString oldbranch
= g_Git
.GetCurrentBranch();
769 if( oldbranch
!= m_BranchCtrl
.GetString() )
771 cmd
.Format(_T("git.exe checkout %s"),m_BranchCtrl
.GetString());
773 if( g_Git
.Run(cmd
,&out
,CP_ACP
) )
775 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
782 m_OrigBranchHash
= g_Git
.GetHash(m_BranchCtrl
.GetString());
783 m_OrigUpstreamHash
= g_Git
.GetHash(this->m_UpstreamCtrl
.GetString());
785 if(!g_Git
.IsFastForward(this->m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString()))
787 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
788 AddLogString(_T("No fast forward\r\nMaybe repository changed"));
792 cmd
.Format(_T("git.exe reset --hard %s"),this->m_UpstreamCtrl
.GetString());
793 this->AddLogString(CString(_T("Fast forward to "))+m_UpstreamCtrl
.GetString());
796 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
797 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
799 AddLogString(_T("Fail"));
804 AddLogString(_T("Done"));
805 m_RebaseStage
= REBASE_DONE
;
806 UpdateCurrentStatus();
810 if( m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
812 if(CheckRebaseCondition())
814 m_RebaseStage
= REBASE_START
;
817 if( m_RebaseStage
== REBASE_FINISH
)
825 if( m_RebaseStage
== REBASE_SQUASH_CONFLICT
)
827 if(VerifyNoConflict())
829 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
830 if(this->CheckNextCommitIsSquash())
831 {//next commit is not squash;
832 m_RebaseStage
= REBASE_SQUASH_EDIT
;
833 this->OnRebaseUpdateUI(0,0);
834 this->UpdateCurrentStatus();
838 m_RebaseStage
=REBASE_CONTINUE
;
839 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
840 this->UpdateCurrentStatus();
844 if( m_RebaseStage
== REBASE_CONFLICT
)
846 if(VerifyNoConflict())
849 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
853 cmd
.Format(_T("git.exe commit -C %s"), curRev
->m_CommitHash
.ToString());
857 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
860 if(!g_Git
.CheckCleanWorkTree())
862 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
868 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
869 if( curRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_EDIT
)
871 m_RebaseStage
=REBASE_EDIT
;
872 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
873 this->UpdateCurrentStatus();
878 m_RebaseStage
=REBASE_CONTINUE
;
879 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
880 this->UpdateCurrentStatus();
884 if( m_RebaseStage
== REBASE_EDIT
|| m_RebaseStage
== REBASE_SQUASH_EDIT
)
887 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
889 str
=this->m_LogMessageCtrl
.GetText();
890 if(str
.Trim().IsEmpty())
892 CMessageBox::Show(NULL
,_T("Commit Message Is Empty"),_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
896 CString tempfile
=::GetTempFile();
897 CFile
file(tempfile
,CFile::modeReadWrite
|CFile::modeCreate
);
898 CStringA log
=CUnicodeUtils::GetUTF8( str
);
899 file
.Write(log
,log
.GetLength());
900 //file.WriteString(m_sLogMessage);
905 if( m_RebaseStage
== REBASE_SQUASH_EDIT
)
906 cmd
.Format(_T("git.exe commit -F \"%s\""), tempfile
);
908 cmd
.Format(_T("git.exe commit --amend -F \"%s\""), tempfile
);
910 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
912 if(!g_Git
.CheckCleanWorkTree())
914 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
919 CFile::Remove(tempfile
);
921 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
922 m_RebaseStage
=REBASE_CONTINUE
;
923 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
924 this->UpdateCurrentStatus();
928 InterlockedExchange(&m_bThreadRunning
, TRUE
);
931 if (AfxBeginThread(RebaseThreadEntry
, this)==NULL
)
933 InterlockedExchange(&m_bThreadRunning
, FALSE
);
934 CMessageBox::Show(NULL
, _T("Create Rebase Thread Fail"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
938 int CRebaseDlg::CheckNextCommitIsSquash()
941 if(m_CommitList
.m_IsOldFirst
)
942 index
=m_CurrentRebaseIndex
+1;
944 index
=m_CurrentRebaseIndex
-1;
951 if(index
>= m_CommitList
.GetItemCount())
954 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[index
];
956 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
958 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
)
960 if(m_CommitList
.m_IsOldFirst
)
967 }while(curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
);
972 int CRebaseDlg::GoNext()
974 if(m_CommitList
.m_IsOldFirst
)
975 m_CurrentRebaseIndex
++;
977 m_CurrentRebaseIndex
--;
981 int CRebaseDlg::StateAction()
983 switch(this->m_RebaseStage
)
986 case CHOOSE_COMMIT_PICK_MODE
:
989 m_RebaseStage
= REBASE_START
;
996 void CRebaseDlg::SetContinueButtonText()
999 switch(this->m_RebaseStage
)
1002 case CHOOSE_COMMIT_PICK_MODE
:
1003 if(this->m_IsFastForward
)
1004 Text
= _T("Start(FastFwd)");
1010 case REBASE_CONTINUE
:
1011 case REBASE_SQUASH_CONFLICT
:
1012 Text
= _T("Continue");
1015 case REBASE_CONFLICT
:
1016 Text
= _T("Commit");
1022 case REBASE_SQUASH_EDIT
:
1023 Text
= _T("Commit");
1028 Text
= _T("Finish");
1035 this->GetDlgItem(IDC_REBASE_CONTINUE
)->SetWindowText(Text
);
1038 void CRebaseDlg::SetControlEnable()
1040 switch(this->m_RebaseStage
)
1043 case CHOOSE_COMMIT_PICK_MODE
:
1045 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(TRUE
);
1046 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(TRUE
);
1047 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(TRUE
);
1048 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(TRUE
);
1049 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(TRUE
);
1053 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(TRUE
);
1054 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(TRUE
);
1055 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(TRUE
);
1057 //this->m_CommitList.m_IsEnableRebaseMenu=TRUE;
1058 this->m_CommitList
.m_ContextMenuMask
|= m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1059 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1060 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1061 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
);
1065 case REBASE_CONTINUE
:
1068 case REBASE_CONFLICT
:
1070 case REBASE_SQUASH_CONFLICT
:
1072 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(FALSE
);
1073 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(FALSE
);
1074 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(FALSE
);
1075 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(FALSE
);
1076 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(FALSE
);
1077 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(FALSE
);
1078 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(FALSE
);
1079 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(FALSE
);
1080 //this->m_CommitList.m_IsEnableRebaseMenu=FALSE;
1081 this->m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1082 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1083 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1084 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
));
1086 if( m_RebaseStage
== REBASE_DONE
&& (this->m_PostButtonTexts
.GetCount() != 0) )
1088 this->GetDlgItem(IDC_STATUS_STATIC
)->ShowWindow(SW_HIDE
);
1089 this->GetDlgItem(IDC_REBASE_POST_BUTTON
)->ShowWindow(SW_SHOWNORMAL
);
1090 this->m_PostButton
.RemoveAll();
1091 this->m_PostButton
.AddEntries(m_PostButtonTexts
);
1092 //this->GetDlgItem(IDC_REBASE_POST_BUTTON)->SetWindowText(this->m_PostButtonText);
1097 if(m_bThreadRunning
)
1099 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1100 this->GetDlgItem(IDC_REBASE_ABORT
)->EnableWindow(FALSE
);
1104 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(TRUE
);
1105 this->GetDlgItem(IDC_REBASE_ABORT
)->EnableWindow(TRUE
);
1109 void CRebaseDlg::UpdateProgress()
1114 if(m_CommitList
.m_IsOldFirst
)
1115 index
= m_CurrentRebaseIndex
+1;
1117 index
= m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1119 m_ProgressBar
.SetRange(1,m_CommitList
.GetItemCount());
1120 m_ProgressBar
.SetPos(index
);
1122 if(m_CurrentRebaseIndex
>=0 && m_CurrentRebaseIndex
< m_CommitList
.GetItemCount())
1125 text
.Format(_T("Rebasing...(%d/%d)"),index
,m_CommitList
.GetItemCount());
1126 m_CtrlStatusText
.SetWindowText(text
);
1130 GitRev
*prevRev
=NULL
, *curRev
=NULL
;
1132 if( m_CurrentRebaseIndex
>= 0 && m_CurrentRebaseIndex
< m_CommitList
.m_arShownList
.GetSize())
1134 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1137 for(int i
=0;i
<m_CommitList
.m_arShownList
.GetSize();i
++)
1139 prevRev
=(GitRev
*)m_CommitList
.m_arShownList
[i
];
1140 if(prevRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1142 prevRev
->GetAction(&m_CommitList
) &= ~ CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1143 m_CommitList
.GetItemRect(i
,&rect
,LVIR_BOUNDS
);
1144 m_CommitList
.InvalidateRect(rect
);
1150 curRev
->GetAction(&m_CommitList
) |= CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1151 m_CommitList
.GetItemRect(m_CurrentRebaseIndex
,&rect
,LVIR_BOUNDS
);
1152 m_CommitList
.InvalidateRect(rect
);
1154 m_CommitList
.EnsureVisible(m_CurrentRebaseIndex
,FALSE
);
1157 void CRebaseDlg::UpdateCurrentStatus()
1159 if( m_CurrentRebaseIndex
< 0 && m_RebaseStage
!= REBASE_DONE
)
1161 if(m_CommitList
.m_IsOldFirst
)
1162 m_RebaseStage
= CRebaseDlg::REBASE_START
;
1164 m_RebaseStage
= CRebaseDlg::REBASE_FINISH
;
1167 if( m_CurrentRebaseIndex
== m_CommitList
.m_arShownList
.GetSize() && m_RebaseStage
!= REBASE_DONE
)
1169 if(m_CommitList
.m_IsOldFirst
)
1170 m_RebaseStage
= CRebaseDlg::REBASE_DONE
;
1172 m_RebaseStage
= CRebaseDlg::REBASE_FINISH
;
1175 SetContinueButtonText();
1180 void CRebaseDlg::AddLogString(CString str
)
1182 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, FALSE
);
1183 CStringA sTextA
= m_wndOutputRebase
.StringForControl(str
);//CUnicodeUtils::GetUTF8(str);
1184 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)sTextA
);
1185 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n");
1186 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, TRUE
);
1189 int CRebaseDlg::GetCurrentCommitID()
1191 if(m_CommitList
.m_IsOldFirst
)
1193 return this->m_CurrentRebaseIndex
+1;
1197 return m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1201 int CRebaseDlg::DoRebase()
1204 if(m_CurrentRebaseIndex
<0)
1206 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1209 GitRev
*pRev
= (GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1210 int mode
=pRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1213 if( mode
== CTGitPath::LOGACTIONS_REBASE_SKIP
)
1215 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1219 if( mode
!= CTGitPath::LOGACTIONS_REBASE_PICK
)
1221 this->m_SquashMessage
+= pRev
->GetSubject();
1222 this->m_SquashMessage
+= _T("\n");
1223 this->m_SquashMessage
+= pRev
->GetBody();
1226 this->m_SquashMessage
.Empty();
1228 if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1229 nocommit
=_T(" --no-commit ");
1232 log
.Format(_T("%s %d:%s"),CTGitPath::GetActionName(mode
),this->GetCurrentCommitID(),pRev
->m_CommitHash
.ToString());
1234 AddLogString(pRev
->GetSubject());
1235 cmd
.Format(_T("git.exe cherry-pick %s %s"),nocommit
,pRev
->m_CommitHash
.ToString());
1237 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1241 if(g_Git
.ListConflictFile(list
))
1243 AddLogString(_T("Get conflict files fail"));
1246 if(list
.GetCount() == 0 )
1248 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1250 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1253 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1255 this->m_RebaseStage
= REBASE_EDIT
;
1256 return -1; // Edit return -1 to stop rebase.
1259 if(CheckNextCommitIsSquash())
1261 // let user edit last commmit message
1262 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1266 if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1267 m_RebaseStage
= REBASE_SQUASH_CONFLICT
;
1269 m_RebaseStage
= REBASE_CONFLICT
;
1275 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1277 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1280 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1282 this->m_RebaseStage
= REBASE_EDIT
;
1283 return -1; // Edit return -1 to stop rebase.
1287 if(CheckNextCommitIsSquash())
1289 // let user edit last commmit message
1290 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1298 BOOL
CRebaseDlg::IsEnd()
1300 if(m_CommitList
.m_IsOldFirst
)
1301 return m_CurrentRebaseIndex
>= this->m_CommitList
.GetItemCount();
1303 return m_CurrentRebaseIndex
<0;
1306 int CRebaseDlg::RebaseThread()
1311 if( m_RebaseStage
== REBASE_START
)
1313 if( this->StartRebase() )
1315 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1319 m_RebaseStage
= REBASE_CONTINUE
;
1321 }else if( m_RebaseStage
== REBASE_CONTINUE
)
1327 m_RebaseStage
= REBASE_FINISH
;
1339 }else if( m_RebaseStage
== REBASE_FINISH
)
1342 m_RebaseStage
= REBASE_DONE
;
1349 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1350 //this->UpdateCurrentStatus();
1353 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1354 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1358 void CRebaseDlg::ListConflictFile()
1360 this->m_FileListCtrl
.Clear();
1365 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
1367 this->m_FileListCtrl
.GetStatus(&list
,true);
1368 this->m_FileListCtrl
.Show(CTGitPath::LOGACTIONS_UNMERGED
|CTGitPath::LOGACTIONS_MODIFIED
|CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_DELETED
,
1369 CTGitPath::LOGACTIONS_UNMERGED
);
1372 LRESULT
CRebaseDlg::OnRebaseUpdateUI(WPARAM
,LPARAM
)
1374 UpdateCurrentStatus();
1375 if(m_CurrentRebaseIndex
<0)
1377 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1379 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1381 switch(m_RebaseStage
)
1383 case REBASE_CONFLICT
:
1384 case REBASE_SQUASH_CONFLICT
:
1386 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_CONFLICT
);
1387 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1390 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1391 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1393 case REBASE_SQUASH_EDIT
:
1394 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1395 this->m_LogMessageCtrl
.SetText(this->m_SquashMessage
);
1398 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1402 void CRebaseDlg::OnCancel()
1406 void CRebaseDlg::OnBnClickedAbort()
1409 if(m_OrigUpstreamHash
.IsEmpty())
1411 __super::OnCancel();
1414 if(m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
1419 if(CMessageBox::Show(NULL
,_T("Are you sure you want to abort the rebase process?"),_T("TortoiseGit"),MB_YESNO
) != IDYES
)
1422 if(this->m_IsFastForward
)
1424 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1425 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1430 __super::OnCancel();
1433 cmd
.Format(_T("git.exe checkout -f %s"),this->m_UpstreamCtrl
.GetString());
1434 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1440 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigUpstreamHash
.ToString());
1441 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1447 if(this->m_IsCherryPick
) //there are not "branch" at cherry pick mode
1449 __super::OnCancel();
1453 cmd
.Format(_T("git checkout -f %s"),this->m_BranchCtrl
.GetString());
1454 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1460 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1461 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1466 __super::OnCancel();
1469 void CRebaseDlg::OnBnClickedButtonBrowse()
1471 if(CBrowseRefsDlg::PickRefForCombo(&m_UpstreamCtrl
, gPickRef_NoTag
))
1472 OnCbnSelchangeUpstream();
1475 void CRebaseDlg::OnBnClickedRebaseCheckForce()
1478 this->FetchLogList();
1479 if(this->CheckRebaseCondition())
1481 /* Disable Start Rebase */
1482 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1486 void CRebaseDlg::OnBnClickedRebasePostButton()
1488 this->m_Upstream
=this->m_UpstreamCtrl
.GetString();
1489 this->m_Branch
=this->m_BranchCtrl
.GetString();
1491 this->EndDialog(IDC_REBASE_POST_BUTTON
+this->m_PostButton
.GetCurrentEntry());
1494 void CRebaseDlg::Refresh()
1496 if(this->m_IsCherryPick
)
1499 if(this->m_RebaseStage
== CHOOSE_BRANCH
)
1502 this->FetchLogList();
1503 if(this->CheckRebaseCondition())
1505 /* Disable Start Rebase */
1506 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1511 void CRebaseDlg::OnBnClickedButtonUp2()
1514 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1515 bool changed
= false;
1518 int index
=m_CommitList
.GetNextSelectedItem(pos
);
1521 CGitHash old
= m_CommitList
.m_logEntries
[index
-1];
1522 m_CommitList
.m_logEntries
[index
-1] = m_CommitList
.m_logEntries
[index
];
1523 m_CommitList
.m_logEntries
[index
] = old
;
1524 m_CommitList
.SetItemState(index
-1, LVIS_SELECTED
, LVIS_SELECTED
);
1525 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1531 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1532 m_CommitList
.Invalidate();
1533 m_CommitList
.SetFocus();
1537 void CRebaseDlg::OnBnClickedButtonDown2()
1540 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1541 bool changed
= false;
1544 int index
=m_CommitList
.GetNextSelectedItem(pos
);
1545 if(index
<m_CommitList
.GetItemCount()-1)
1547 CGitHash old
= m_CommitList
.m_logEntries
[index
+1];
1548 m_CommitList
.m_logEntries
[index
+1] = m_CommitList
.m_logEntries
[index
];
1549 m_CommitList
.m_logEntries
[index
] = old
;
1550 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1551 m_CommitList
.SetItemState(index
+1, LVIS_SELECTED
, LVIS_SELECTED
);
1557 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1558 m_CommitList
.Invalidate();
1559 m_CommitList
.SetFocus();