1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2011-2013 - Sven Strickroth <email@cs-ware.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // RebaseDlg.cpp : implementation file
25 #include "TortoiseProc.h"
26 #include "RebaseDlg.h"
28 #include "LoglistUtils.h"
29 #include "MessageBox.h"
30 #include "UnicodeUtils.h"
31 #include "BrowseRefsDlg.h"
32 #include "ProgressDlg.h"
33 #include "SmartHandle.h"
34 #include "../TGitCache/CacheInterface.h"
35 #include "Settings\Settings.h"
39 IMPLEMENT_DYNAMIC(CRebaseDlg
, CResizableStandAloneDialog
)
41 CRebaseDlg::CRebaseDlg(CWnd
* pParent
/*=NULL*/)
42 : CResizableStandAloneDialog(CRebaseDlg::IDD
, pParent
)
46 , m_bAddCherryPickedFrom(FALSE
)
48 m_RebaseStage
=CHOOSE_BRANCH
;
49 m_CurrentRebaseIndex
=-1;
50 m_bThreadRunning
=FALSE
;
51 this->m_IsCherryPick
= FALSE
;
53 m_IsFastForward
=FALSE
;
56 CRebaseDlg::~CRebaseDlg()
60 void CRebaseDlg::DoDataExchange(CDataExchange
* pDX
)
62 CDialog::DoDataExchange(pDX
);
63 DDX_Control(pDX
, IDC_REBASE_PROGRESS
, m_ProgressBar
);
64 DDX_Control(pDX
, IDC_STATUS_STATIC
, m_CtrlStatusText
);
65 DDX_Check(pDX
, IDC_PICK_ALL
, m_bPickAll
);
66 DDX_Check(pDX
, IDC_SQUASH_ALL
, m_bSquashAll
);
67 DDX_Check(pDX
, IDC_EDIT_ALL
, m_bEditAll
);
68 DDX_Control(pDX
, IDC_REBASE_SPLIT
, m_wndSplitter
);
69 DDX_Control(pDX
,IDC_COMMIT_LIST
,m_CommitList
);
70 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_BRANCH
, this->m_BranchCtrl
);
71 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_UPSTREAM
, this->m_UpstreamCtrl
);
72 DDX_Check(pDX
, IDC_REBASE_CHECK_FORCE
,m_bForce
);
73 DDX_Check(pDX
, IDC_CHECK_CHERRYPICKED_FROM
, m_bAddCherryPickedFrom
);
74 DDX_Control(pDX
,IDC_REBASE_POST_BUTTON
,m_PostButton
);
78 BEGIN_MESSAGE_MAP(CRebaseDlg
, CResizableStandAloneDialog
)
79 ON_BN_CLICKED(IDC_PICK_ALL
, &CRebaseDlg::OnBnClickedPickAll
)
80 ON_BN_CLICKED(IDC_SQUASH_ALL
, &CRebaseDlg::OnBnClickedSquashAll
)
81 ON_BN_CLICKED(IDC_EDIT_ALL
, &CRebaseDlg::OnBnClickedEditAll
)
82 ON_BN_CLICKED(IDC_REBASE_SPLIT
, &CRebaseDlg::OnBnClickedRebaseSplit
)
83 ON_BN_CLICKED(IDC_REBASE_CONTINUE
,OnBnClickedContinue
)
84 ON_BN_CLICKED(IDC_REBASE_ABORT
, OnBnClickedAbort
)
86 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH
, &CRebaseDlg::OnCbnSelchangeBranch
)
87 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM
, &CRebaseDlg::OnCbnSelchangeUpstream
)
88 ON_MESSAGE(MSG_REBASE_UPDATE_UI
, OnRebaseUpdateUI
)
89 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
90 ON_BN_CLICKED(IDC_BUTTON_BROWSE
, &CRebaseDlg::OnBnClickedButtonBrowse
)
91 ON_BN_CLICKED(IDC_REBASE_CHECK_FORCE
, &CRebaseDlg::OnBnClickedRebaseCheckForce
)
92 ON_BN_CLICKED(IDC_CHECK_CHERRYPICKED_FROM
, &CRebaseDlg::OnBnClickedCheckCherryPickedFrom
)
93 ON_BN_CLICKED(IDC_REBASE_POST_BUTTON
, &CRebaseDlg::OnBnClickedRebasePostButton
)
94 ON_BN_CLICKED(IDC_BUTTON_UP2
, &CRebaseDlg::OnBnClickedButtonUp2
)
95 ON_BN_CLICKED(IDC_BUTTON_DOWN2
, &CRebaseDlg::OnBnClickedButtonDown2
)
96 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
97 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_COMMIT_LIST
, OnLvnItemchangedLoglist
)
100 void CRebaseDlg::AddRebaseAnchor()
102 AddAnchor(IDC_REBASE_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
103 AddAnchor(IDC_COMMIT_LIST
,TOP_LEFT
, TOP_RIGHT
);
104 AddAnchor(IDC_REBASE_SPLIT
,TOP_LEFT
, TOP_RIGHT
);
105 AddAnchor(IDC_STATUS_STATIC
, BOTTOM_LEFT
,BOTTOM_RIGHT
);
106 AddAnchor(IDC_REBASE_CONTINUE
,BOTTOM_RIGHT
);
107 AddAnchor(IDC_REBASE_ABORT
, BOTTOM_RIGHT
);
108 AddAnchor(IDC_REBASE_PROGRESS
,BOTTOM_LEFT
, BOTTOM_RIGHT
);
109 AddAnchor(IDC_PICK_ALL
,TOP_LEFT
);
110 AddAnchor(IDC_SQUASH_ALL
,TOP_LEFT
);
111 AddAnchor(IDC_EDIT_ALL
,TOP_LEFT
);
112 AddAnchor(IDC_BUTTON_UP2
,TOP_LEFT
);
113 AddAnchor(IDC_BUTTON_DOWN2
,TOP_LEFT
);
114 AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM
,TOP_LEFT
);
115 AddAnchor(IDC_REBASE_COMBOXEX_BRANCH
,TOP_LEFT
);
116 AddAnchor(IDC_REBASE_STATIC_UPSTREAM
,TOP_LEFT
);
117 AddAnchor(IDC_REBASE_STATIC_BRANCH
,TOP_LEFT
);
118 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
119 AddAnchor(IDC_REBASE_CHECK_FORCE
,TOP_RIGHT
);
120 AddAnchor(IDC_CHECK_CHERRYPICKED_FROM
, TOP_RIGHT
);
121 AddAnchor(IDC_REBASE_POST_BUTTON
,BOTTOM_LEFT
);
123 this->AddOthersToAnchor();
126 BOOL
CRebaseDlg::OnInitDialog()
128 CResizableStandAloneDialog::OnInitDialog();
129 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
131 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
132 // do this, Explorer would be unable to send that message to our window if we
133 // were running elevated. It's OK to make the call all the time, since if we're
134 // not elevated, this is a no-op.
135 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
136 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
137 CAutoLibrary hUser
= AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
140 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
141 if (pfnChangeWindowMessageFilterEx
)
143 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
146 m_pTaskbarList
.Release();
147 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
150 //IDC_REBASE_DUMY_TAB
152 GetClientRect(m_DlgOrigRect
);
153 m_CommitList
.GetClientRect(m_CommitListOrigRect
);
155 CWnd
*pwnd
=this->GetDlgItem(IDC_REBASE_DUMY_TAB
);
156 pwnd
->GetWindowRect(&rectDummy
);
157 this->ScreenToClient(rectDummy
);
159 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_REBASE_TAB
))
161 TRACE0("Failed to create output tab window\n");
162 return FALSE
; // fail to create
164 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
165 // Create output panes:
166 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
167 DWORD dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
169 if (! this->m_FileListCtrl
.Create(dwStyle
,rectDummy
,&this->m_ctrlTabCtrl
,0) )
171 TRACE0("Failed to create output windows\n");
172 return FALSE
; // fail to create
174 m_FileListCtrl
.m_hwndLogicalParent
= this;
176 if( ! this->m_LogMessageCtrl
.Create(_T("Scintilla"),_T("source"),0,rectDummy
,&m_ctrlTabCtrl
,0,0) )
178 TRACE0("Failed to create log message control");
181 m_LogMessageCtrl
.Init(0);
182 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);
184 dwStyle
= LBS_NOINTEGRALHEIGHT
| WS_CHILD
| WS_VISIBLE
| WS_HSCROLL
| WS_VSCROLL
;
186 if (!m_wndOutputRebase
.Create(_T("Scintilla"),_T("source"),0,rectDummy
, &m_ctrlTabCtrl
, 0,0) )
188 TRACE0("Failed to create output windows\n");
189 return -1; // fail to create
191 m_wndOutputRebase
.Init(0);
192 m_wndOutputRebase
.Call(SCI_SETREADONLY
, TRUE
);
194 m_tooltips
.Create(this);
196 m_tooltips
.AddTool(IDC_REBASE_CHECK_FORCE
,IDS_REBASE_FORCE_TT
);
197 m_tooltips
.AddTool(IDC_REBASE_ABORT
,IDS_REBASE_ABORT_TT
);
201 m_FileListCtrl
.Init(GITSLC_COLEXT
| GITSLC_COLSTATUS
|GITSLC_COLADD
|GITSLC_COLDEL
, _T("RebaseDlg"),(GITSLC_POPALL
^ (GITSLC_POPCOMMIT
|GITSLC_POPRESTORE
)), false, true, GITSLC_COLEXT
| GITSLC_COLSTATUS
| GITSLC_COLADD
| GITSLC_COLDEL
);
203 m_ctrlTabCtrl
.AddTab(&m_FileListCtrl
, CString(MAKEINTRESOURCE(IDS_PROC_REVISIONFILES
)));
204 m_ctrlTabCtrl
.AddTab(&m_LogMessageCtrl
, CString(MAKEINTRESOURCE(IDS_PROC_COMMITMESSAGE
)), 1);
207 AdjustControlSize(IDC_PICK_ALL
);
208 AdjustControlSize(IDC_SQUASH_ALL
);
209 AdjustControlSize(IDC_EDIT_ALL
);
210 AdjustControlSize(IDC_CHECK_CHERRYPICKED_FROM
);
212 CString sWindowTitle
;
213 GetWindowText(sWindowTitle
);
214 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
216 EnableSaveRestore(_T("RebaseDlg"));
218 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
219 RECT rcDlg
, rcLogMsg
, rcFileList
;
220 GetClientRect(&rcDlg
);
221 m_CommitList
.GetWindowRect(&rcLogMsg
);
222 ScreenToClient(&rcLogMsg
);
223 this->m_ctrlTabCtrl
.GetWindowRect(&rcFileList
);
224 ScreenToClient(&rcFileList
);
228 m_wndSplitter
.GetWindowRect(&rectSplitter
);
229 ScreenToClient(&rectSplitter
);
230 int delta
= yPos
- rectSplitter
.top
;
231 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
233 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
238 if( this->m_RebaseStage
== CHOOSE_BRANCH
)
240 this->LoadBranchInfo();
245 this->m_BranchCtrl
.EnableWindow(FALSE
);
246 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
249 m_CommitList
.m_ColumnRegKey
= _T("Rebase");
250 m_CommitList
.m_IsIDReplaceAction
= TRUE
;
251 // m_CommitList.m_IsOldFirst = TRUE;
252 m_CommitList
.m_IsRebaseReplaceGraph
= TRUE
;
253 m_CommitList
.m_bNoHightlightHead
= TRUE
;
255 m_CommitList
.InsertGitColumn();
257 this->SetControlEnable();
259 if(!this->m_PreCmd
.IsEmpty())
261 CProgressDlg progress
;
262 progress
.m_GitCmd
=m_PreCmd
;
263 progress
.m_bAutoCloseOnSuccess
=true;
269 this->m_BranchCtrl
.SetCurSel(-1);
270 this->m_BranchCtrl
.EnableWindow(FALSE
);
271 GetDlgItem(IDC_REBASE_CHECK_FORCE
)->ShowWindow(SW_HIDE
);
272 GetDlgItem(IDC_BUTTON_BROWSE
)->EnableWindow(FALSE
);
273 this->m_UpstreamCtrl
.AddString(_T("HEAD"));
274 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
275 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CHERRYPICK
)));
276 this->m_CommitList
.StartFilter();
280 GetDlgItem(IDC_CHECK_CHERRYPICKED_FROM
)->ShowWindow(SW_HIDE
);
281 SetContinueButtonText();
282 m_CommitList
.DeleteAllItems();
286 m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_CHERRY_PICK
)|
287 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_SWITCHTOREV
)|
288 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_RESET
)|
289 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTREV
)|
290 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_TO_VERSION
)|
291 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV
)|
292 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_COMBINE_COMMIT
));
294 if(m_CommitList
.m_IsOldFirst
)
295 this->m_CurrentRebaseIndex
= -1;
297 this->m_CurrentRebaseIndex
= (int)m_CommitList
.m_logEntries
.size();
300 if(this->CheckRebaseCondition())
302 /* Disable Start Rebase */
303 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
308 // CRebaseDlg message handlers
310 void CRebaseDlg::OnBnClickedPickAll()
314 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
316 this->m_bEditAll
=FALSE
;
317 this->m_bSquashAll
=FALSE
;
318 this->UpdateData(FALSE
);
321 void CRebaseDlg::OnBnClickedSquashAll()
324 if(this->m_bSquashAll
)
325 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
327 this->m_bEditAll
=FALSE
;
328 this->m_bPickAll
=FALSE
;
329 this->UpdateData(FALSE
);
332 void CRebaseDlg::OnBnClickedEditAll()
335 if( this->m_bEditAll
)
336 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
338 this->m_bPickAll
=FALSE
;
339 this->m_bSquashAll
=FALSE
;
340 this->UpdateData(FALSE
);
343 void CRebaseDlg::SetAllRebaseAction(int action
)
345 for(int i
=0;i
<this->m_CommitList
.m_logEntries
.size();i
++)
347 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
)=action
;
349 m_CommitList
.Invalidate();
352 void CRebaseDlg::OnBnClickedRebaseSplit()
357 LRESULT
CRebaseDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
361 if (wParam
== IDC_REBASE_SPLIT
)
363 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
369 return __super::DefWindowProc(message
, wParam
, lParam
);
372 void CRebaseDlg::DoSize(int delta
)
374 this->RemoveAllAnchors();
376 CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST
), delta
, CW_TOPALIGN
);
377 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
378 CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB
), -delta
, CW_BOTTOMALIGN
);
379 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
380 CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL
),0,delta
);
381 CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL
),0,delta
);
382 CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL
),0,delta
);
383 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_UP2
),0,delta
);
384 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_DOWN2
),0,delta
);
385 CSplitterControl::ChangePos(GetDlgItem(IDC_REBASE_CHECK_FORCE
),0,delta
);
387 this->AddRebaseAnchor();
388 // adjust the minimum size of the dialog to prevent the resizing from
389 // moving the list control too far down.
391 m_CommitList
.GetClientRect(rcLogMsg
);
392 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_CommitListOrigRect
.Height()+rcLogMsg
.Height()));
395 // m_CommitList.Invalidate();
397 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
399 this->m_ctrlTabCtrl
.Invalidate();
400 this->m_CommitList
.Invalidate();
401 this->m_FileListCtrl
.Invalidate();
402 this->m_LogMessageCtrl
.Invalidate();
406 void CRebaseDlg::SetSplitterRange()
408 if ((m_CommitList
)&&(m_ctrlTabCtrl
))
411 m_CommitList
.GetWindowRect(rcTop
);
412 ScreenToClient(rcTop
);
414 m_ctrlTabCtrl
.GetWindowRect(rcMiddle
);
415 ScreenToClient(rcMiddle
);
416 if (rcMiddle
.Height() && rcMiddle
.Width())
417 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
421 void CRebaseDlg::OnSize(UINT nType
,int cx
, int cy
)
423 // first, let the resizing take place
424 __super::OnSize(nType
, cx
, cy
);
430 void CRebaseDlg::SaveSplitterPos()
434 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
436 m_wndSplitter
.GetWindowRect(&rectSplitter
);
437 ScreenToClient(&rectSplitter
);
438 regPos
= rectSplitter
.top
;
442 void CRebaseDlg::LoadBranchInfo()
444 m_BranchCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
445 m_UpstreamCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
450 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_ALL
);
451 m_BranchCtrl
.AddString(list
);
452 m_BranchCtrl
.SetCurSel(current
);
454 g_Git
.GetBranchList(list
, NULL
, CGit::BRANCH_ALL_F
);
455 m_UpstreamCtrl
.AddString(list
);
457 AddBranchToolTips(&m_BranchCtrl
);
458 AddBranchToolTips(&m_UpstreamCtrl
);
460 if(!m_Upstream
.IsEmpty())
462 m_UpstreamCtrl
.AddString(m_Upstream
);
463 m_UpstreamCtrl
.SetCurSel(m_UpstreamCtrl
.GetCount()-1);
467 //Select pull-remote from current branch
468 CString currentBranch
= g_Git
.GetSymbolicRef();
470 configName
.Format(L
"branch.%s.remote", currentBranch
);
471 CString pullRemote
= g_Git
.GetConfigValue(configName
);
473 //Select pull-branch from current branch
474 configName
.Format(L
"branch.%s.merge", currentBranch
);
475 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
477 CString defaultUpstream
;
478 defaultUpstream
.Format(L
"remotes/%s/%s", pullRemote
, pullBranch
);
479 int found
= m_UpstreamCtrl
.FindStringExact(0, defaultUpstream
);
481 m_UpstreamCtrl
.SetCurSel(found
);
483 m_UpstreamCtrl
.SetCurSel(-1);
487 void CRebaseDlg::OnCbnSelchangeBranch()
492 void CRebaseDlg::OnCbnSelchangeUpstream()
497 void CRebaseDlg::FetchLogList()
499 CGitHash base
,hash
,upstream
;
500 m_IsFastForward
=FALSE
;
502 if (g_Git
.GetHash(hash
, m_BranchCtrl
.GetString()))
504 m_CommitList
.ShowText(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl
.GetString() + _T("\".")));
505 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
508 if (g_Git
.GetHash(upstream
, m_UpstreamCtrl
.GetString()))
510 m_CommitList
.ShowText(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl
.GetString() + _T("\".")));
511 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
515 if (hash
== upstream
)
517 m_CommitList
.Clear();
519 fmt
.LoadString(IDS_REBASE_EQUAL_FMT
);
520 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
522 m_CommitList
.ShowText(text
);
523 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
527 if (g_Git
.IsFastForward(m_BranchCtrl
.GetString(), m_UpstreamCtrl
.GetString(), &base
))
530 this->m_IsFastForward
=TRUE
;
532 m_CommitList
.Clear();
534 fmt
.LoadString(IDS_REBASE_FASTFORWARD_FMT
);
535 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString(),
536 m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
538 m_CommitList
.ShowText(text
);
539 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(true);
540 SetContinueButtonText();
547 if (base
== upstream
)
549 m_CommitList
.Clear();
551 fmt
.LoadString(IDS_REBASE_UPTODATE_FMT
);
552 text
.Format(fmt
,m_BranchCtrl
.GetString());
553 m_CommitList
.ShowText(text
);
554 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
555 SetContinueButtonText();
560 m_CommitList
.Clear();
562 from
= m_UpstreamCtrl
.GetString();
563 to
= m_BranchCtrl
.GetString();
564 this->m_CommitList
.FillGitLog(NULL
,0,&from
,&to
);
566 if( m_CommitList
.GetItemCount() == 0 )
567 m_CommitList
.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_NOTHINGTOREBASE
)));
570 if(m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
.size() >=0 )
572 if(upstream
== m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
[0])
574 m_CommitList
.Clear();
575 m_CommitList
.ShowText(_T("Nothing Rebase"));
581 AddBranchToolTips(&this->m_BranchCtrl
);
582 AddBranchToolTips(&this->m_UpstreamCtrl
);
584 for(int i
=0;i
<m_CommitList
.m_logEntries
.size();i
++)
586 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
) = CTGitPath::LOGACTIONS_REBASE_PICK
;
589 m_CommitList
.Invalidate();
591 if(m_CommitList
.m_IsOldFirst
)
592 this->m_CurrentRebaseIndex
= -1;
594 this->m_CurrentRebaseIndex
= (int)m_CommitList
.m_logEntries
.size();
596 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
597 SetContinueButtonText();
600 void CRebaseDlg::AddBranchToolTips(CHistoryCombo
*pBranch
)
604 CString text
=pBranch
->GetString();
610 tooltip
.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"),
611 CString(MAKEINTRESOURCE(IDS_LOG_REVISION
)),
612 rev
.m_CommitHash
.ToString(),
613 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
)),
615 rev
.GetAuthorEmail(),
616 CString(MAKEINTRESOURCE(IDS_LOG_DATE
)),
617 CLoglistUtils::FormatDateAndTime(rev
.GetAuthorDate(), DATE_LONGDATE
),
618 CString(MAKEINTRESOURCE(IDS_LOG_MESSAGE
)),
622 pBranch
->DisableTooltip();
623 this->m_tooltips
.AddTool(pBranch
->GetComboBoxCtrl(),tooltip
);
627 BOOL
CRebaseDlg::PreTranslateMessage(MSG
*pMsg
)
629 if (pMsg
->message
== WM_KEYDOWN
)
631 switch (pMsg
->wParam
)
634 if(LogListHasFocus(pMsg
->hwnd
))
636 m_CommitList
.ShiftSelectedAction();
641 if(LogListHasFocus(pMsg
->hwnd
))
643 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
648 if(LogListHasFocus(pMsg
->hwnd
))
650 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP
);
655 if(LogListHasFocus(pMsg
->hwnd
))
657 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
662 if(LogListHasFocus(pMsg
->hwnd
))
664 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
669 if(LogListHasFocus(pMsg
->hwnd
) && GetAsyncKeyState(VK_CONTROL
) & 0x8000)
671 // select all entries
672 for (int i
= 0; i
< m_CommitList
.GetItemCount(); ++i
)
674 m_CommitList
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
687 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
689 if (GetDlgItem(IDC_REBASE_CONTINUE
)->IsWindowEnabled())
690 GetDlgItem(IDC_REBASE_CONTINUE
)->SetFocus();
691 else if (GetDlgItem(IDC_REBASE_ABORT
)->IsWindowEnabled())
692 GetDlgItem(IDC_REBASE_ABORT
)->SetFocus();
694 GetDlgItem(IDHELP
)->SetFocus();
699 /* Avoid TAB control destroy but dialog exist*/
704 ::GetClassName(pMsg
->hwnd
,buff
,128);
707 if(_tcsnicmp(buff
,_T("RichEdit20W"),128)==0 ||
708 _tcsnicmp(buff
,_T("Scintilla"),128)==0 ||
709 _tcsnicmp(buff
,_T("SysListView32"),128)==0||
710 ::GetParent(pMsg
->hwnd
) == this->m_ctrlTabCtrl
.m_hWnd
)
712 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
718 else if (pMsg
->message
== WM_NEXTDLGCTL
)
720 if (GetFocus()->GetSafeHwnd() == m_LogMessageCtrl
.GetSafeHwnd())
722 if (GetDlgItem(IDC_REBASE_CONTINUE
)->IsWindowEnabled())
723 GetDlgItem(IDC_REBASE_CONTINUE
)->SetFocus();
724 else if (GetDlgItem(IDC_REBASE_ABORT
)->IsWindowEnabled())
725 GetDlgItem(IDC_REBASE_ABORT
)->SetFocus();
727 GetDlgItem(IDHELP
)->SetFocus();
731 m_tooltips
.RelayEvent(pMsg
);
732 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
735 bool CRebaseDlg::LogListHasFocus(HWND hwnd
)
738 ::GetClassName(hwnd
, buff
, 128);
740 if(_tcsnicmp(buff
, _T("SysListView32"), 128) == 0)
745 int CRebaseDlg::CheckRebaseCondition()
747 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
749 if( !g_Git
.CheckCleanWorkTree() )
751 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
754 cmd
=_T("git.exe stash");
755 this->AddLogString(cmd
);
756 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
758 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
766 //Todo Check $REBASE_ROOT
769 if (!CAppUtils::CheckUserData())
772 //Todo call pre_rebase_hook
775 int CRebaseDlg::StartRebase()
778 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
779 if(!this->m_IsCherryPick
)
781 //Todo call comment_for_reflog
782 cmd
.Format(_T("git.exe checkout %s"),this->m_BranchCtrl
.GetString());
783 this->AddLogString(cmd
);
787 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
789 this->AddLogString(out
);
790 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
797 this->AddLogString(out
);
800 cmd
=_T("git.exe rev-parse --verify HEAD");
801 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
803 AddLogString(CString(MAKEINTRESOURCE(IDS_PROC_NOHEAD
)));
807 //git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
808 // echo "detached HEAD" > "$DOTEST"/head-name
810 cmd
.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));
811 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
813 AddLogString(_T("update ORIG_HEAD Fail"));
817 m_OrigUpstreamHash
.Empty();
818 if (g_Git
.GetHash(m_OrigUpstreamHash
, m_UpstreamCtrl
.GetString()))
820 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
824 if( !this->m_IsCherryPick
)
826 cmd
.Format(_T("git.exe checkout -f %s"), m_OrigUpstreamHash
.ToString());
827 this->AddLogString(cmd
);
831 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
833 this->AddLogString(out
);
834 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
843 if( !this->m_IsCherryPick
)
845 if (g_Git
.GetHash(m_OrigBranchHash
, m_BranchCtrl
.GetString()))
847 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
850 log
.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTREBASE
)));
853 log
.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTCHERRYPICK
)));
855 this->AddLogString(log
);
858 int CRebaseDlg::VerifyNoConflict()
861 if(g_Git
.ListConflictFile(list
))
863 AddLogString(_T("Get conflict files fail"));
866 if( list
.GetCount() != 0 )
868 CMessageBox::Show(NULL
, IDS_PROGRS_CONFLICTSOCCURED
, IDS_APPNAME
, MB_OK
);
874 int CRebaseDlg::FinishRebase()
876 if(this->m_IsCherryPick
) //cherry pick mode no "branch", working at upstream branch
880 if (g_Git
.GetHash(head
, _T("HEAD")))
882 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
887 cmd
.Format(_T("git.exe checkout -f %s"),this->m_BranchCtrl
.GetString());
892 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
895 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
903 cmd
.Format(_T("git.exe reset --hard %s"), head
.ToString());
908 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
911 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
919 m_ctrlTabCtrl
.RemoveTab(0);
920 m_ctrlTabCtrl
.RemoveTab(0);
921 m_LogMessageCtrl
.ShowWindow(SW_HIDE
);
922 m_CtrlStatusText
.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_REBASEFINISHED
)));
926 void CRebaseDlg::OnBnClickedContinue()
928 if( m_RebaseStage
== REBASE_DONE
)
934 if( this->m_IsFastForward
)
937 CString oldbranch
= g_Git
.GetCurrentBranch();
938 if( oldbranch
!= m_BranchCtrl
.GetString() )
940 cmd
.Format(_T("git.exe checkout %s"),m_BranchCtrl
.GetString());
945 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
947 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
949 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
958 if (g_Git
.GetHash(m_OrigBranchHash
, m_BranchCtrl
.GetString()))
960 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
963 if (g_Git
.GetHash(m_OrigUpstreamHash
, m_UpstreamCtrl
.GetString()))
965 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
969 if(!g_Git
.IsFastForward(this->m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString()))
971 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
972 AddLogString(_T("No fast forward possible.\r\nMaybe repository changed"));
976 cmd
.Format(_T("git.exe reset --hard %s"),g_Git
.FixBranchName(this->m_UpstreamCtrl
.GetString()));
978 log
.Format(IDS_PROC_REBASE_FFTO
, m_UpstreamCtrl
.GetString());
979 this->AddLogString(log
);
982 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
986 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
988 AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL
)));
990 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
997 AddLogString(CString(MAKEINTRESOURCE(IDS_DONE
)));
998 m_RebaseStage
= REBASE_DONE
;
999 UpdateCurrentStatus();
1003 if( m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
1005 if(CheckRebaseCondition())
1007 m_RebaseStage
= REBASE_START
;
1008 m_FileListCtrl
.Clear();
1009 m_FileListCtrl
.m_CurrentVersion
= L
"";
1010 m_ctrlTabCtrl
.SetTabLabel(REBASE_TAB_CONFLICT
, CString(MAKEINTRESOURCE(IDS_PROC_CONFLICTFILES
)));
1011 m_ctrlTabCtrl
.AddTab(&m_wndOutputRebase
, CString(MAKEINTRESOURCE(IDS_LOG
)), 2);
1014 if( m_RebaseStage
== REBASE_FINISH
)
1022 if( m_RebaseStage
== REBASE_SQUASH_CONFLICT
)
1024 if(VerifyNoConflict())
1026 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1027 if(this->CheckNextCommitIsSquash())
1028 {//next commit is not squash;
1029 m_RebaseStage
= REBASE_SQUASH_EDIT
;
1030 this->OnRebaseUpdateUI(0,0);
1031 this->UpdateCurrentStatus();
1035 m_RebaseStage
=REBASE_CONTINUE
;
1036 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
1037 this->UpdateCurrentStatus();
1041 if( m_RebaseStage
== REBASE_CONFLICT
)
1043 if(VerifyNoConflict())
1046 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1048 CString out
=_T("");
1050 cmd
.Format(_T("git.exe commit -a -C %s"), curRev
->m_CommitHash
.ToString());
1054 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1057 if(!g_Git
.CheckCleanWorkTree())
1059 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1065 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1066 if( curRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_EDIT
)
1068 m_RebaseStage
=REBASE_EDIT
;
1069 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1070 this->UpdateCurrentStatus();
1075 m_RebaseStage
=REBASE_CONTINUE
;
1076 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
1077 this->UpdateCurrentStatus();
1081 if( m_RebaseStage
== REBASE_EDIT
|| m_RebaseStage
== REBASE_SQUASH_EDIT
)
1084 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1086 str
=this->m_LogMessageCtrl
.GetText();
1087 if(str
.Trim().IsEmpty())
1089 CMessageBox::Show(NULL
, IDS_PROC_COMMITMESSAGE_EMPTY
,IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1093 CString tempfile
=::GetTempFile();
1094 CAppUtils::SaveCommitUnicodeFile(tempfile
, str
);
1098 if( m_RebaseStage
== REBASE_SQUASH_EDIT
)
1099 cmd
.Format(_T("git.exe commit -F \"%s\""), tempfile
);
1101 cmd
.Format(_T("git.exe commit --amend -F \"%s\""), tempfile
);
1103 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1105 if(!g_Git
.CheckCleanWorkTree())
1107 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1112 CFile::Remove(tempfile
);
1114 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1115 m_RebaseStage
=REBASE_CONTINUE
;
1116 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
1117 this->UpdateCurrentStatus();
1121 InterlockedExchange(&m_bThreadRunning
, TRUE
);
1124 if (AfxBeginThread(RebaseThreadEntry
, this)==NULL
)
1126 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1127 CMessageBox::Show(NULL
, _T("Create Rebase Thread Fail"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1131 int CRebaseDlg::CheckNextCommitIsSquash()
1134 if(m_CommitList
.m_IsOldFirst
)
1135 index
=m_CurrentRebaseIndex
+1;
1137 index
=m_CurrentRebaseIndex
-1;
1144 if(index
>= m_CommitList
.GetItemCount())
1147 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[index
];
1149 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1151 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
)
1153 if(m_CommitList
.m_IsOldFirst
)
1161 }while(curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
);
1166 int CRebaseDlg::GoNext()
1168 if(m_CommitList
.m_IsOldFirst
)
1169 m_CurrentRebaseIndex
++;
1171 m_CurrentRebaseIndex
--;
1175 int CRebaseDlg::StateAction()
1177 switch(this->m_RebaseStage
)
1180 case CHOOSE_COMMIT_PICK_MODE
:
1183 m_RebaseStage
= REBASE_START
;
1190 void CRebaseDlg::SetContinueButtonText()
1193 switch(this->m_RebaseStage
)
1196 case CHOOSE_COMMIT_PICK_MODE
:
1197 if(this->m_IsFastForward
)
1198 Text
.LoadString(IDS_PROC_STARTREBASEFFBUTTON
);
1200 Text
.LoadString(IDS_PROC_STARTREBASEBUTTON
);
1204 case REBASE_CONTINUE
:
1205 case REBASE_SQUASH_CONFLICT
:
1206 Text
.LoadString(IDS_CONTINUEBUTTON
);
1209 case REBASE_CONFLICT
:
1210 Text
.LoadString(IDS_COMMITBUTTON
);
1213 Text
.LoadString(IDS_AMENDBUTTON
);
1216 case REBASE_SQUASH_EDIT
:
1217 Text
.LoadString(IDS_COMMITBUTTON
);
1222 Text
.LoadString(IDS_FINISHBUTTON
);
1226 Text
.LoadString(IDS_DONE
);
1229 this->GetDlgItem(IDC_REBASE_CONTINUE
)->SetWindowText(Text
);
1232 void CRebaseDlg::SetControlEnable()
1234 switch(this->m_RebaseStage
)
1237 case CHOOSE_COMMIT_PICK_MODE
:
1239 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(TRUE
);
1240 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(TRUE
);
1241 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(TRUE
);
1242 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(TRUE
);
1243 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(TRUE
);
1247 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(TRUE
);
1248 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(TRUE
);
1249 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(TRUE
);
1251 //this->m_CommitList.m_IsEnableRebaseMenu=TRUE;
1252 this->m_CommitList
.m_ContextMenuMask
|= m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1253 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1254 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1255 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
);
1259 case REBASE_CONTINUE
:
1262 case REBASE_CONFLICT
:
1264 case REBASE_SQUASH_CONFLICT
:
1266 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(FALSE
);
1267 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(FALSE
);
1268 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(FALSE
);
1269 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(FALSE
);
1270 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(FALSE
);
1271 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(FALSE
);
1272 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(FALSE
);
1273 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(FALSE
);
1274 //this->m_CommitList.m_IsEnableRebaseMenu=FALSE;
1275 this->m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1276 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1277 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1278 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
));
1280 if( m_RebaseStage
== REBASE_DONE
&& (this->m_PostButtonTexts
.GetCount() != 0) )
1282 this->GetDlgItem(IDC_STATUS_STATIC
)->ShowWindow(SW_HIDE
);
1283 this->GetDlgItem(IDC_REBASE_POST_BUTTON
)->ShowWindow(SW_SHOWNORMAL
);
1284 this->m_PostButton
.RemoveAll();
1285 this->m_PostButton
.AddEntries(m_PostButtonTexts
);
1286 //this->GetDlgItem(IDC_REBASE_POST_BUTTON)->SetWindowText(this->m_PostButtonText);
1291 if(m_bThreadRunning
)
1293 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1298 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(TRUE
);
1302 void CRebaseDlg::UpdateProgress()
1307 if(m_CommitList
.m_IsOldFirst
)
1308 index
= m_CurrentRebaseIndex
+1;
1310 index
= m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1312 m_ProgressBar
.SetRange32(1, m_CommitList
.GetItemCount());
1313 m_ProgressBar
.SetPos(index
);
1316 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1317 m_pTaskbarList
->SetProgressValue(m_hWnd
, index
, m_CommitList
.GetItemCount());
1320 if(m_CurrentRebaseIndex
>=0 && m_CurrentRebaseIndex
< m_CommitList
.GetItemCount())
1323 text
.Format(IDS_PROC_REBASING_PROGRESS
, index
, m_CommitList
.GetItemCount());
1324 m_CtrlStatusText
.SetWindowText(text
);
1328 GitRev
*prevRev
=NULL
, *curRev
=NULL
;
1330 if( m_CurrentRebaseIndex
>= 0 && m_CurrentRebaseIndex
< m_CommitList
.m_arShownList
.GetSize())
1332 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1335 for(int i
=0;i
<m_CommitList
.m_arShownList
.GetSize();i
++)
1337 prevRev
=(GitRev
*)m_CommitList
.m_arShownList
[i
];
1338 if(prevRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1340 prevRev
->GetAction(&m_CommitList
) &= ~ CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1341 m_CommitList
.GetItemRect(i
,&rect
,LVIR_BOUNDS
);
1342 m_CommitList
.InvalidateRect(rect
);
1348 curRev
->GetAction(&m_CommitList
) |= CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1349 m_CommitList
.GetItemRect(m_CurrentRebaseIndex
,&rect
,LVIR_BOUNDS
);
1350 m_CommitList
.InvalidateRect(rect
);
1352 m_CommitList
.EnsureVisible(m_CurrentRebaseIndex
,FALSE
);
1355 void CRebaseDlg::UpdateCurrentStatus()
1357 SetContinueButtonText();
1362 void CRebaseDlg::AddLogString(CString str
)
1364 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, FALSE
);
1365 CStringA sTextA
= m_wndOutputRebase
.StringForControl(str
);//CUnicodeUtils::GetUTF8(str);
1366 this->m_wndOutputRebase
.SendMessage(SCI_DOCUMENTEND
);
1367 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)sTextA
);
1368 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n");
1369 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, TRUE
);
1372 int CRebaseDlg::GetCurrentCommitID()
1374 if(m_CommitList
.m_IsOldFirst
)
1376 return this->m_CurrentRebaseIndex
+1;
1381 return m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1385 int CRebaseDlg::DoRebase()
1388 if(m_CurrentRebaseIndex
<0)
1390 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1393 GitRev
*pRev
= (GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1394 int mode
=pRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1397 if( mode
== CTGitPath::LOGACTIONS_REBASE_SKIP
)
1399 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1403 if (!CheckNextCommitIsSquash() || mode
!= CTGitPath::LOGACTIONS_REBASE_PICK
)
1404 { // next commit is squash or not pick
1405 if (!this->m_SquashMessage
.IsEmpty())
1406 this->m_SquashMessage
+= _T("\n\n");
1407 this->m_SquashMessage
+= pRev
->GetSubject();
1408 this->m_SquashMessage
+= _T("\n");
1409 this->m_SquashMessage
+= pRev
->GetBody().TrimRight();
1412 this->m_SquashMessage
.Empty();
1414 if (!CheckNextCommitIsSquash() || mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1415 { // next or this commit is squash
1416 nocommit
=_T(" --no-commit ");
1420 log
.Format(_T("%s %d: %s"),CTGitPath::GetActionName(mode
),this->GetCurrentCommitID(),pRev
->m_CommitHash
.ToString());
1422 AddLogString(pRev
->GetSubject());
1423 if (pRev
->GetSubject().IsEmpty())
1425 CMessageBox::Show(m_hWnd
, IDS_PROC_REBASE_EMPTYCOMMITMSG
, IDS_APPNAME
, MB_OK
| MB_ICONEXCLAMATION
);
1426 mode
= CTGitPath::LOGACTIONS_REBASE_EDIT
;
1429 CString cherryPickedFrom
;
1430 if (m_bAddCherryPickedFrom
)
1431 cherryPickedFrom
= _T("-x ");
1433 cmd
.Format(_T("git.exe cherry-pick %s%s %s"), cherryPickedFrom
, nocommit
, pRev
->m_CommitHash
.ToString());
1435 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1439 if(g_Git
.ListConflictFile(list
))
1441 AddLogString(_T("Get conflict files fail"));
1444 if(list
.GetCount() == 0 )
1446 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1448 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1451 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1453 this->m_RebaseStage
= REBASE_EDIT
;
1454 return -1; // Edit return -1 to stop rebase.
1457 if(CheckNextCommitIsSquash())
1459 // let user edit last commmit message
1460 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1464 if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1465 m_RebaseStage
= REBASE_SQUASH_CONFLICT
;
1467 m_RebaseStage
= REBASE_CONFLICT
;
1474 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1476 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1479 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1481 this->m_RebaseStage
= REBASE_EDIT
;
1482 return -1; // Edit return -1 to stop rebase.
1486 if(CheckNextCommitIsSquash())
1488 // let user edit last commmit message
1489 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1492 else if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1493 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1499 BOOL
CRebaseDlg::IsEnd()
1501 if(m_CommitList
.m_IsOldFirst
)
1502 return m_CurrentRebaseIndex
>= this->m_CommitList
.GetItemCount();
1504 return m_CurrentRebaseIndex
<0;
1507 int CRebaseDlg::RebaseThread()
1509 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
1514 if( m_RebaseStage
== REBASE_START
)
1516 if( this->StartRebase() )
1518 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1520 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1523 m_RebaseStage
= REBASE_CONTINUE
;
1526 else if( m_RebaseStage
== REBASE_CONTINUE
)
1529 UpdateCurrentStatus();
1533 m_RebaseStage
= REBASE_FINISH
;
1547 else if( m_RebaseStage
== REBASE_FINISH
)
1550 m_RebaseStage
= REBASE_DONE
;
1552 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1560 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1561 //this->UpdateCurrentStatus();
1564 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1565 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1569 void CRebaseDlg::ListConflictFile()
1571 this->m_FileListCtrl
.Clear();
1576 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
1578 this->m_FileListCtrl
.GetStatus(&list
,true);
1579 this->m_FileListCtrl
.Show(CTGitPath::LOGACTIONS_UNMERGED
|CTGitPath::LOGACTIONS_MODIFIED
|CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_DELETED
,
1580 CTGitPath::LOGACTIONS_UNMERGED
);
1583 LRESULT
CRebaseDlg::OnRebaseUpdateUI(WPARAM
,LPARAM
)
1585 UpdateCurrentStatus();
1586 if(m_CurrentRebaseIndex
<0)
1588 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1590 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1592 switch(m_RebaseStage
)
1594 case REBASE_CONFLICT
:
1595 case REBASE_SQUASH_CONFLICT
:
1597 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_CONFLICT
);
1599 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
1600 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1601 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1604 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1606 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1607 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1608 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1610 case REBASE_SQUASH_EDIT
:
1611 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1612 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1613 this->m_LogMessageCtrl
.SetText(this->m_SquashMessage
);
1615 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1618 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1622 void CRebaseDlg::OnCancel()
1626 void CRebaseDlg::OnBnClickedAbort()
1629 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1632 CString pron
= m_OrigUpstreamHash
.ToString();
1633 if(m_OrigUpstreamHash
.IsEmpty())
1635 __super::OnCancel();
1638 if(m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
1643 if(CMessageBox::Show(NULL
, IDS_PROC_REBASE_ABORT
, IDS_APPNAME
, MB_YESNO
) != IDYES
)
1646 if(this->m_IsFastForward
)
1648 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1652 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1655 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1661 __super::OnCancel();
1664 cmd
.Format(_T("git.exe checkout -f %s"),g_Git
.FixBranchName(this->m_UpstreamCtrl
.GetString()));
1668 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1671 if (CMessageBox::Show(this->m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1673 __super::OnCancel();
1681 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigUpstreamHash
.ToString());
1685 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1688 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1690 __super::OnCancel();
1698 if(this->m_IsCherryPick
) //there are not "branch" at cherry pick mode
1700 __super::OnCancel();
1704 cmd
.Format(_T("git checkout -f %s"),this->m_BranchCtrl
.GetString());
1705 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1708 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1709 __super::OnCancel();
1713 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1717 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1720 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1726 __super::OnCancel();
1729 void CRebaseDlg::OnBnClickedButtonBrowse()
1731 if(CBrowseRefsDlg::PickRefForCombo(&m_UpstreamCtrl
, gPickRef_NoTag
))
1732 OnCbnSelchangeUpstream();
1735 void CRebaseDlg::OnBnClickedRebaseCheckForce()
1738 this->FetchLogList();
1739 if(this->CheckRebaseCondition())
1741 /* Disable Start Rebase */
1742 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1746 void CRebaseDlg::OnBnClickedRebasePostButton()
1748 this->m_Upstream
=this->m_UpstreamCtrl
.GetString();
1749 this->m_Branch
=this->m_BranchCtrl
.GetString();
1751 this->EndDialog((int)(IDC_REBASE_POST_BUTTON
+this->m_PostButton
.GetCurrentEntry()));
1754 LRESULT
CRebaseDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1760 void CRebaseDlg::Refresh()
1762 if (m_RebaseStage
== REBASE_CONFLICT
|| m_RebaseStage
== REBASE_SQUASH_CONFLICT
)
1768 if(this->m_IsCherryPick
)
1771 if(this->m_RebaseStage
== CHOOSE_BRANCH
)
1774 this->FetchLogList();
1775 if(this->CheckRebaseCondition())
1777 /* Disable Start Rebase */
1778 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1783 void CRebaseDlg::OnBnClickedButtonUp2()
1786 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1788 // do nothing if the first selected item is the first item in the list
1789 if (m_CommitList
.GetNextSelectedItem(pos
) == 0)
1792 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1794 bool changed
= false;
1797 int index
=m_CommitList
.GetNextSelectedItem(pos
);
1800 CGitHash old
= m_CommitList
.m_logEntries
[index
-1];
1801 m_CommitList
.m_logEntries
[index
-1] = m_CommitList
.m_logEntries
[index
];
1802 m_CommitList
.m_logEntries
[index
] = old
;
1803 m_CommitList
.SetItemState(index
-1, LVIS_SELECTED
, LVIS_SELECTED
);
1804 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1810 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1811 m_CommitList
.Invalidate();
1812 m_CommitList
.SetFocus();
1816 void CRebaseDlg::OnBnClickedButtonDown2()
1818 if (m_CommitList
.GetSelectedCount() == 0)
1822 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1823 bool changed
= false;
1824 // use an array to store all selected item indexes; the user won't select too much items
1825 int* indexes
= NULL
;
1826 indexes
= new int[m_CommitList
.GetSelectedCount()];
1830 indexes
[i
++] = m_CommitList
.GetNextSelectedItem(pos
);
1832 // don't move any item if the last selected item is the last item in the m_CommitList
1833 // (that would change the order of the selected items)
1834 if(indexes
[m_CommitList
.GetSelectedCount() - 1] < m_CommitList
.GetItemCount() - 1)
1836 // iterate over the indexes backwards in order to correctly move multiselected items
1837 for (i
= m_CommitList
.GetSelectedCount() - 1; i
>= 0; i
--)
1839 int index
= indexes
[i
];
1840 CGitHash old
= m_CommitList
.m_logEntries
[index
+1];
1841 m_CommitList
.m_logEntries
[index
+1] = m_CommitList
.m_logEntries
[index
];
1842 m_CommitList
.m_logEntries
[index
] = old
;
1843 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1844 m_CommitList
.SetItemState(index
+1, LVIS_SELECTED
, LVIS_SELECTED
);
1852 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1853 m_CommitList
.Invalidate();
1854 m_CommitList
.SetFocus();
1858 LRESULT
CRebaseDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1860 m_pTaskbarList
.Release();
1861 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
1865 void CRebaseDlg::OnLvnItemchangedLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1867 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1869 if(m_CommitList
.m_bNoDispUpdates
)
1871 if (pNMLV
->iItem
>= 0)
1873 this->m_CommitList
.m_nSearchIndex
= pNMLV
->iItem
;
1874 if (pNMLV
->iSubItem
!= 0)
1876 if ((pNMLV
->iItem
== m_CommitList
.m_arShownList
.GetCount()))
1878 // remove the selected state
1879 if (pNMLV
->uChanged
& LVIF_STATE
)
1881 m_CommitList
.SetItemState(pNMLV
->iItem
, 0, LVIS_SELECTED
);
1882 FillLogMessageCtrl();
1886 if (pNMLV
->uChanged
& LVIF_STATE
)
1888 FillLogMessageCtrl();
1893 FillLogMessageCtrl();
1897 void CRebaseDlg::FillLogMessageCtrl()
1899 int selCount
= m_CommitList
.GetSelectedCount();
1900 if (selCount
== 1 && (m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
))
1902 POSITION pos
= m_CommitList
.GetFirstSelectedItemPosition();
1903 int selIndex
= m_CommitList
.GetNextSelectedItem(pos
);
1904 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_CommitList
.m_arShownList
.SafeGetAt(selIndex
));
1905 m_FileListCtrl
.UpdateWithGitPathList(pLogEntry
->GetFiles(&m_CommitList
));
1906 m_FileListCtrl
.m_CurrentVersion
= pLogEntry
->m_CommitHash
;
1907 m_FileListCtrl
.Show(GITSLC_SHOWVERSIONED
);
1908 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1909 m_LogMessageCtrl
.SetText(pLogEntry
->GetSubject() + _T("\n") + pLogEntry
->GetBody());
1910 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);
1913 void CRebaseDlg::OnBnClickedCheckCherryPickedFrom()