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"
36 #include "MassiveGitTask.h"
40 IMPLEMENT_DYNAMIC(CRebaseDlg
, CResizableStandAloneDialog
)
42 CRebaseDlg::CRebaseDlg(CWnd
* pParent
/*=NULL*/)
43 : CResizableStandAloneDialog(CRebaseDlg::IDD
, pParent
)
47 , m_bAddCherryPickedFrom(FALSE
)
48 , m_bStatusWarning(false)
50 m_RebaseStage
=CHOOSE_BRANCH
;
51 m_CurrentRebaseIndex
=-1;
52 m_bThreadRunning
=FALSE
;
53 this->m_IsCherryPick
= FALSE
;
55 m_IsFastForward
=FALSE
;
58 CRebaseDlg::~CRebaseDlg()
62 void CRebaseDlg::DoDataExchange(CDataExchange
* pDX
)
64 CDialog::DoDataExchange(pDX
);
65 DDX_Control(pDX
, IDC_REBASE_PROGRESS
, m_ProgressBar
);
66 DDX_Control(pDX
, IDC_STATUS_STATIC
, m_CtrlStatusText
);
67 DDX_Check(pDX
, IDC_PICK_ALL
, m_bPickAll
);
68 DDX_Check(pDX
, IDC_SQUASH_ALL
, m_bSquashAll
);
69 DDX_Check(pDX
, IDC_EDIT_ALL
, m_bEditAll
);
70 DDX_Control(pDX
, IDC_REBASE_SPLIT
, m_wndSplitter
);
71 DDX_Control(pDX
,IDC_COMMIT_LIST
,m_CommitList
);
72 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_BRANCH
, this->m_BranchCtrl
);
73 DDX_Control(pDX
,IDC_REBASE_COMBOXEX_UPSTREAM
, this->m_UpstreamCtrl
);
74 DDX_Check(pDX
, IDC_REBASE_CHECK_FORCE
,m_bForce
);
75 DDX_Check(pDX
, IDC_CHECK_CHERRYPICKED_FROM
, m_bAddCherryPickedFrom
);
76 DDX_Control(pDX
,IDC_REBASE_POST_BUTTON
,m_PostButton
);
80 BEGIN_MESSAGE_MAP(CRebaseDlg
, CResizableStandAloneDialog
)
81 ON_BN_CLICKED(IDC_PICK_ALL
, &CRebaseDlg::OnBnClickedPickAll
)
82 ON_BN_CLICKED(IDC_SQUASH_ALL
, &CRebaseDlg::OnBnClickedSquashAll
)
83 ON_BN_CLICKED(IDC_EDIT_ALL
, &CRebaseDlg::OnBnClickedEditAll
)
84 ON_BN_CLICKED(IDC_REBASE_SPLIT
, &CRebaseDlg::OnBnClickedRebaseSplit
)
85 ON_BN_CLICKED(IDC_REBASE_CONTINUE
,OnBnClickedContinue
)
86 ON_BN_CLICKED(IDC_REBASE_ABORT
, OnBnClickedAbort
)
88 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH
, &CRebaseDlg::OnCbnSelchangeBranch
)
89 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM
, &CRebaseDlg::OnCbnSelchangeUpstream
)
90 ON_MESSAGE(MSG_REBASE_UPDATE_UI
, OnRebaseUpdateUI
)
91 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH
, OnGitStatusListCtrlNeedsRefresh
)
92 ON_BN_CLICKED(IDC_BUTTON_BROWSE
, &CRebaseDlg::OnBnClickedButtonBrowse
)
93 ON_BN_CLICKED(IDC_REBASE_CHECK_FORCE
, &CRebaseDlg::OnBnClickedRebaseCheckForce
)
94 ON_BN_CLICKED(IDC_CHECK_CHERRYPICKED_FROM
, &CRebaseDlg::OnBnClickedCheckCherryPickedFrom
)
95 ON_BN_CLICKED(IDC_REBASE_POST_BUTTON
, &CRebaseDlg::OnBnClickedRebasePostButton
)
96 ON_BN_CLICKED(IDC_BUTTON_UP2
, &CRebaseDlg::OnBnClickedButtonUp2
)
97 ON_BN_CLICKED(IDC_BUTTON_DOWN2
, &CRebaseDlg::OnBnClickedButtonDown2
)
98 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
99 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_COMMIT_LIST
, OnLvnItemchangedLoglist
)
103 void CRebaseDlg::AddRebaseAnchor()
105 AddAnchor(IDC_REBASE_TAB
,TOP_LEFT
,BOTTOM_RIGHT
);
106 AddAnchor(IDC_COMMIT_LIST
,TOP_LEFT
, TOP_RIGHT
);
107 AddAnchor(IDC_REBASE_SPLIT
,TOP_LEFT
, TOP_RIGHT
);
108 AddAnchor(IDC_STATUS_STATIC
, BOTTOM_LEFT
,BOTTOM_RIGHT
);
109 AddAnchor(IDC_REBASE_CONTINUE
,BOTTOM_RIGHT
);
110 AddAnchor(IDC_REBASE_ABORT
, BOTTOM_RIGHT
);
111 AddAnchor(IDC_REBASE_PROGRESS
,BOTTOM_LEFT
, BOTTOM_RIGHT
);
112 AddAnchor(IDC_PICK_ALL
,TOP_LEFT
);
113 AddAnchor(IDC_SQUASH_ALL
,TOP_LEFT
);
114 AddAnchor(IDC_EDIT_ALL
,TOP_LEFT
);
115 AddAnchor(IDC_BUTTON_UP2
,TOP_LEFT
);
116 AddAnchor(IDC_BUTTON_DOWN2
,TOP_LEFT
);
117 AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM
,TOP_LEFT
);
118 AddAnchor(IDC_REBASE_COMBOXEX_BRANCH
,TOP_LEFT
);
119 AddAnchor(IDC_REBASE_STATIC_UPSTREAM
,TOP_LEFT
);
120 AddAnchor(IDC_REBASE_STATIC_BRANCH
,TOP_LEFT
);
121 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
122 AddAnchor(IDC_REBASE_CHECK_FORCE
,TOP_RIGHT
);
123 AddAnchor(IDC_CHECK_CHERRYPICKED_FROM
, TOP_RIGHT
);
124 AddAnchor(IDC_REBASE_POST_BUTTON
,BOTTOM_LEFT
);
126 this->AddOthersToAnchor();
129 BOOL
CRebaseDlg::OnInitDialog()
131 CResizableStandAloneDialog::OnInitDialog();
132 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
134 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
135 // do this, Explorer would be unable to send that message to our window if we
136 // were running elevated. It's OK to make the call all the time, since if we're
137 // not elevated, this is a no-op.
138 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
139 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
140 CAutoLibrary hUser
= AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
143 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
144 if (pfnChangeWindowMessageFilterEx
)
146 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
149 m_pTaskbarList
.Release();
150 if (FAILED(m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
)))
151 m_pTaskbarList
= nullptr;
154 //IDC_REBASE_DUMY_TAB
156 GetClientRect(m_DlgOrigRect
);
157 m_CommitList
.GetClientRect(m_CommitListOrigRect
);
159 CWnd
*pwnd
=this->GetDlgItem(IDC_REBASE_DUMY_TAB
);
160 pwnd
->GetWindowRect(&rectDummy
);
161 this->ScreenToClient(rectDummy
);
163 if (!m_ctrlTabCtrl
.Create(CMFCTabCtrl::STYLE_FLAT
, rectDummy
, this, IDC_REBASE_TAB
))
165 TRACE0("Failed to create output tab window\n");
166 return FALSE
; // fail to create
168 m_ctrlTabCtrl
.SetResizeMode(CMFCTabCtrl::RESIZE_NO
);
169 // Create output panes:
170 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
171 DWORD dwStyle
=LVS_REPORT
| LVS_SHOWSELALWAYS
| LVS_ALIGNLEFT
| WS_BORDER
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
173 if (! this->m_FileListCtrl
.Create(dwStyle
,rectDummy
,&this->m_ctrlTabCtrl
,0) )
175 TRACE0("Failed to create output windows\n");
176 return FALSE
; // fail to create
178 m_FileListCtrl
.m_hwndLogicalParent
= this;
180 if( ! this->m_LogMessageCtrl
.Create(_T("Scintilla"),_T("source"),0,rectDummy
,&m_ctrlTabCtrl
,0,0) )
182 TRACE0("Failed to create log message control");
185 m_LogMessageCtrl
.Init(0);
186 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);
188 dwStyle
= LBS_NOINTEGRALHEIGHT
| WS_CHILD
| WS_VISIBLE
| WS_HSCROLL
| WS_VSCROLL
;
190 if (!m_wndOutputRebase
.Create(_T("Scintilla"),_T("source"),0,rectDummy
, &m_ctrlTabCtrl
, 0,0) )
192 TRACE0("Failed to create output windows\n");
193 return -1; // fail to create
195 m_wndOutputRebase
.Init(0);
196 m_wndOutputRebase
.Call(SCI_SETREADONLY
, TRUE
);
198 m_tooltips
.Create(this);
200 m_tooltips
.AddTool(IDC_REBASE_CHECK_FORCE
,IDS_REBASE_FORCE_TT
);
201 m_tooltips
.AddTool(IDC_REBASE_ABORT
,IDS_REBASE_ABORT_TT
);
205 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
);
207 m_ctrlTabCtrl
.AddTab(&m_FileListCtrl
, CString(MAKEINTRESOURCE(IDS_PROC_REVISIONFILES
)));
208 m_ctrlTabCtrl
.AddTab(&m_LogMessageCtrl
, CString(MAKEINTRESOURCE(IDS_PROC_COMMITMESSAGE
)), 1);
211 AdjustControlSize(IDC_PICK_ALL
);
212 AdjustControlSize(IDC_SQUASH_ALL
);
213 AdjustControlSize(IDC_EDIT_ALL
);
214 AdjustControlSize(IDC_CHECK_CHERRYPICKED_FROM
);
216 CString sWindowTitle
;
217 GetWindowText(sWindowTitle
);
218 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
220 EnableSaveRestore(_T("RebaseDlg"));
222 DWORD yPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
223 RECT rcDlg
, rcLogMsg
, rcFileList
;
224 GetClientRect(&rcDlg
);
225 m_CommitList
.GetWindowRect(&rcLogMsg
);
226 ScreenToClient(&rcLogMsg
);
227 this->m_ctrlTabCtrl
.GetWindowRect(&rcFileList
);
228 ScreenToClient(&rcFileList
);
232 m_wndSplitter
.GetWindowRect(&rectSplitter
);
233 ScreenToClient(&rectSplitter
);
234 int delta
= yPos
- rectSplitter
.top
;
235 if ((rcLogMsg
.bottom
+ delta
> rcLogMsg
.top
)&&(rcLogMsg
.bottom
+ delta
< rcFileList
.bottom
- 30))
237 m_wndSplitter
.SetWindowPos(NULL
, 0, yPos
, 0, 0, SWP_NOSIZE
);
242 if( this->m_RebaseStage
== CHOOSE_BRANCH
)
244 this->LoadBranchInfo();
249 this->m_BranchCtrl
.EnableWindow(FALSE
);
250 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
253 m_CommitList
.m_ColumnRegKey
= _T("Rebase");
254 m_CommitList
.m_IsIDReplaceAction
= TRUE
;
255 // m_CommitList.m_IsOldFirst = TRUE;
256 m_CommitList
.m_IsRebaseReplaceGraph
= TRUE
;
257 m_CommitList
.m_bNoHightlightHead
= TRUE
;
259 m_CommitList
.InsertGitColumn();
261 this->SetControlEnable();
263 if(!this->m_PreCmd
.IsEmpty())
265 CProgressDlg progress
;
266 progress
.m_GitCmd
=m_PreCmd
;
267 progress
.m_bAutoCloseOnSuccess
=true;
273 this->m_BranchCtrl
.SetCurSel(-1);
274 this->m_BranchCtrl
.EnableWindow(FALSE
);
275 GetDlgItem(IDC_REBASE_CHECK_FORCE
)->ShowWindow(SW_HIDE
);
276 GetDlgItem(IDC_BUTTON_BROWSE
)->EnableWindow(FALSE
);
277 this->m_UpstreamCtrl
.AddString(_T("HEAD"));
278 this->m_UpstreamCtrl
.EnableWindow(FALSE
);
279 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CHERRYPICK
)));
280 this->m_CommitList
.StartFilter();
284 GetDlgItem(IDC_CHECK_CHERRYPICKED_FROM
)->ShowWindow(SW_HIDE
);
285 SetContinueButtonText();
286 m_CommitList
.DeleteAllItems();
290 m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_CHERRY_PICK
)|
291 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_SWITCHTOREV
)|
292 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_RESET
)|
293 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTREV
)|
294 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_TO_VERSION
)|
295 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV
)|
296 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_COMBINE_COMMIT
));
298 if(m_CommitList
.m_IsOldFirst
)
299 this->m_CurrentRebaseIndex
= -1;
301 this->m_CurrentRebaseIndex
= (int)m_CommitList
.m_logEntries
.size();
304 if(this->CheckRebaseCondition())
306 /* Disable Start Rebase */
307 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
312 // CRebaseDlg message handlers
314 HBRUSH
CRebaseDlg::OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
)
316 if (pWnd
->GetDlgCtrlID() == IDC_STATUS_STATIC
&& nCtlColor
== CTLCOLOR_STATIC
&& m_bStatusWarning
)
318 pDC
->SetBkColor(RGB(255, 0, 0));
319 pDC
->SetTextColor(RGB(255, 255, 255));
320 return CreateSolidBrush(RGB(255, 0, 0));
323 return CResizableStandAloneDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
326 void CRebaseDlg::OnBnClickedPickAll()
330 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
332 this->m_bEditAll
=FALSE
;
333 this->m_bSquashAll
=FALSE
;
334 this->UpdateData(FALSE
);
337 void CRebaseDlg::OnBnClickedSquashAll()
340 if(this->m_bSquashAll
)
341 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
343 this->m_bEditAll
=FALSE
;
344 this->m_bPickAll
=FALSE
;
345 this->UpdateData(FALSE
);
348 void CRebaseDlg::OnBnClickedEditAll()
351 if( this->m_bEditAll
)
352 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
354 this->m_bPickAll
=FALSE
;
355 this->m_bSquashAll
=FALSE
;
356 this->UpdateData(FALSE
);
359 void CRebaseDlg::SetAllRebaseAction(int action
)
361 for (int i
= 0; i
< this->m_CommitList
.m_logEntries
.size(); ++i
)
363 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
)=action
;
365 m_CommitList
.Invalidate();
368 void CRebaseDlg::OnBnClickedRebaseSplit()
373 LRESULT
CRebaseDlg::DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
)
377 if (wParam
== IDC_REBASE_SPLIT
)
379 SPC_NMHDR
* pHdr
= (SPC_NMHDR
*) lParam
;
385 return __super::DefWindowProc(message
, wParam
, lParam
);
388 void CRebaseDlg::DoSize(int delta
)
390 this->RemoveAllAnchors();
392 CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST
), delta
, CW_TOPALIGN
);
393 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
394 CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB
), -delta
, CW_BOTTOMALIGN
);
395 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
396 CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL
),0,delta
);
397 CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL
),0,delta
);
398 CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL
),0,delta
);
399 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_UP2
),0,delta
);
400 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_DOWN2
),0,delta
);
401 CSplitterControl::ChangePos(GetDlgItem(IDC_REBASE_CHECK_FORCE
),0,delta
);
402 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECK_CHERRYPICKED_FROM
), 0, delta
);
404 this->AddRebaseAnchor();
405 // adjust the minimum size of the dialog to prevent the resizing from
406 // moving the list control too far down.
408 m_CommitList
.GetClientRect(rcLogMsg
);
409 SetMinTrackSize(CSize(m_DlgOrigRect
.Width(), m_DlgOrigRect
.Height()-m_CommitListOrigRect
.Height()+rcLogMsg
.Height()));
412 // m_CommitList.Invalidate();
414 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
416 this->m_ctrlTabCtrl
.Invalidate();
417 this->m_CommitList
.Invalidate();
418 this->m_FileListCtrl
.Invalidate();
419 this->m_LogMessageCtrl
.Invalidate();
423 void CRebaseDlg::SetSplitterRange()
425 if ((m_CommitList
)&&(m_ctrlTabCtrl
))
428 m_CommitList
.GetWindowRect(rcTop
);
429 ScreenToClient(rcTop
);
431 m_ctrlTabCtrl
.GetWindowRect(rcMiddle
);
432 ScreenToClient(rcMiddle
);
433 if (rcMiddle
.Height() && rcMiddle
.Width())
434 m_wndSplitter
.SetRange(rcTop
.top
+60, rcMiddle
.bottom
-80);
438 void CRebaseDlg::OnSize(UINT nType
,int cx
, int cy
)
440 // first, let the resizing take place
441 __super::OnSize(nType
, cx
, cy
);
447 void CRebaseDlg::SaveSplitterPos()
451 CRegDWORD regPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
453 m_wndSplitter
.GetWindowRect(&rectSplitter
);
454 ScreenToClient(&rectSplitter
);
455 regPos
= rectSplitter
.top
;
459 void CRebaseDlg::LoadBranchInfo()
461 m_BranchCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
462 m_UpstreamCtrl
.SetMaxHistoryItems(0x7FFFFFFF);
467 g_Git
.GetBranchList(list
,¤t
,CGit::BRANCH_ALL
);
468 m_BranchCtrl
.AddString(list
);
469 m_BranchCtrl
.SetCurSel(current
);
471 g_Git
.GetBranchList(list
, NULL
, CGit::BRANCH_ALL_F
);
472 m_UpstreamCtrl
.AddString(list
);
474 AddBranchToolTips(&m_BranchCtrl
);
475 AddBranchToolTips(&m_UpstreamCtrl
);
477 if(!m_Upstream
.IsEmpty())
479 m_UpstreamCtrl
.AddString(m_Upstream
);
480 m_UpstreamCtrl
.SetCurSel(m_UpstreamCtrl
.GetCount()-1);
484 //Select pull-remote from current branch
485 CString currentBranch
= g_Git
.GetSymbolicRef();
487 configName
.Format(L
"branch.%s.remote", currentBranch
);
488 CString pullRemote
= g_Git
.GetConfigValue(configName
);
490 //Select pull-branch from current branch
491 configName
.Format(L
"branch.%s.merge", currentBranch
);
492 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
494 CString defaultUpstream
;
495 defaultUpstream
.Format(L
"remotes/%s/%s", pullRemote
, pullBranch
);
496 int found
= m_UpstreamCtrl
.FindStringExact(0, defaultUpstream
);
498 m_UpstreamCtrl
.SetCurSel(found
);
500 m_UpstreamCtrl
.SetCurSel(-1);
504 void CRebaseDlg::OnCbnSelchangeBranch()
509 void CRebaseDlg::OnCbnSelchangeUpstream()
514 void CRebaseDlg::FetchLogList()
516 CGitHash base
,hash
,upstream
;
517 m_IsFastForward
=FALSE
;
519 if (g_Git
.GetHash(hash
, m_BranchCtrl
.GetString()))
521 m_CommitList
.ShowText(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl
.GetString() + _T("\".")));
522 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
525 if (g_Git
.GetHash(upstream
, m_UpstreamCtrl
.GetString()))
527 m_CommitList
.ShowText(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl
.GetString() + _T("\".")));
528 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
532 if (hash
== upstream
)
534 m_CommitList
.Clear();
536 fmt
.LoadString(IDS_REBASE_EQUAL_FMT
);
537 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
539 m_CommitList
.ShowText(text
);
540 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(false);
544 if (g_Git
.IsFastForward(m_BranchCtrl
.GetString(), m_UpstreamCtrl
.GetString(), &base
))
547 this->m_IsFastForward
=TRUE
;
549 m_CommitList
.Clear();
551 fmt
.LoadString(IDS_REBASE_FASTFORWARD_FMT
);
552 text
.Format(fmt
,m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString(),
553 m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString());
555 m_CommitList
.ShowText(text
);
556 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(true);
557 SetContinueButtonText();
564 if (base
== upstream
)
566 m_CommitList
.Clear();
568 fmt
.LoadString(IDS_REBASE_UPTODATE_FMT
);
569 text
.Format(fmt
,m_BranchCtrl
.GetString());
570 m_CommitList
.ShowText(text
);
571 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
572 SetContinueButtonText();
577 m_CommitList
.Clear();
579 range
.Format(_T("%s..%s"), g_Git
.FixBranchName(m_UpstreamCtrl
.GetString()), g_Git
.FixBranchName(m_BranchCtrl
.GetString()));
580 this->m_CommitList
.FillGitLog(nullptr, &range
, 0);
582 if( m_CommitList
.GetItemCount() == 0 )
583 m_CommitList
.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_NOTHINGTOREBASE
)));
586 if(m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
.size() >=0 )
588 if(upstream
== m_CommitList
.m_logEntries
[m_CommitList
.m_logEntries
.size()-1].m_ParentHash
[0])
590 m_CommitList
.Clear();
591 m_CommitList
.ShowText(_T("Nothing Rebase"));
597 AddBranchToolTips(&this->m_BranchCtrl
);
598 AddBranchToolTips(&this->m_UpstreamCtrl
);
600 for (int i
= 0; i
< m_CommitList
.m_logEntries
.size(); ++i
)
602 m_CommitList
.m_logEntries
.GetGitRevAt(i
).GetAction(&m_CommitList
) = CTGitPath::LOGACTIONS_REBASE_PICK
;
605 m_CommitList
.Invalidate();
607 if(m_CommitList
.m_IsOldFirst
)
608 this->m_CurrentRebaseIndex
= -1;
610 this->m_CurrentRebaseIndex
= (int)m_CommitList
.m_logEntries
.size();
612 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(m_CommitList
.GetItemCount());
613 SetContinueButtonText();
616 void CRebaseDlg::AddBranchToolTips(CHistoryCombo
*pBranch
)
620 CString text
=pBranch
->GetString();
626 tooltip
.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"),
627 CString(MAKEINTRESOURCE(IDS_LOG_REVISION
)),
628 rev
.m_CommitHash
.ToString(),
629 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR
)),
631 rev
.GetAuthorEmail(),
632 CString(MAKEINTRESOURCE(IDS_LOG_DATE
)),
633 CLoglistUtils::FormatDateAndTime(rev
.GetAuthorDate(), DATE_LONGDATE
),
634 CString(MAKEINTRESOURCE(IDS_LOG_MESSAGE
)),
638 pBranch
->DisableTooltip();
639 this->m_tooltips
.AddTool(pBranch
->GetComboBoxCtrl(),tooltip
);
643 BOOL
CRebaseDlg::PreTranslateMessage(MSG
*pMsg
)
645 if (pMsg
->message
== WM_KEYDOWN
)
647 switch (pMsg
->wParam
)
650 if(LogListHasFocus(pMsg
->hwnd
))
652 m_CommitList
.ShiftSelectedAction();
657 if(LogListHasFocus(pMsg
->hwnd
))
659 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
664 if(LogListHasFocus(pMsg
->hwnd
))
666 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP
);
671 if(LogListHasFocus(pMsg
->hwnd
))
673 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
678 if(LogListHasFocus(pMsg
->hwnd
))
680 m_CommitList
.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
685 if(LogListHasFocus(pMsg
->hwnd
) && GetAsyncKeyState(VK_CONTROL
) & 0x8000)
687 // select all entries
688 for (int i
= 0; i
< m_CommitList
.GetItemCount(); ++i
)
690 m_CommitList
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
703 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
705 if (GetDlgItem(IDC_REBASE_CONTINUE
)->IsWindowEnabled())
706 GetDlgItem(IDC_REBASE_CONTINUE
)->SetFocus();
707 else if (GetDlgItem(IDC_REBASE_ABORT
)->IsWindowEnabled())
708 GetDlgItem(IDC_REBASE_ABORT
)->SetFocus();
710 GetDlgItem(IDHELP
)->SetFocus();
715 /* Avoid TAB control destroy but dialog exist*/
720 ::GetClassName(pMsg
->hwnd
,buff
,128);
723 if(_tcsnicmp(buff
,_T("RichEdit20W"),128)==0 ||
724 _tcsnicmp(buff
,_T("Scintilla"),128)==0 ||
725 _tcsnicmp(buff
,_T("SysListView32"),128)==0||
726 ::GetParent(pMsg
->hwnd
) == this->m_ctrlTabCtrl
.m_hWnd
)
728 this->PostMessage(WM_KEYDOWN
,VK_ESCAPE
,0);
734 else if (pMsg
->message
== WM_NEXTDLGCTL
)
736 if (GetFocus()->GetSafeHwnd() == m_LogMessageCtrl
.GetSafeHwnd())
738 if (GetDlgItem(IDC_REBASE_CONTINUE
)->IsWindowEnabled())
739 GetDlgItem(IDC_REBASE_CONTINUE
)->SetFocus();
740 else if (GetDlgItem(IDC_REBASE_ABORT
)->IsWindowEnabled())
741 GetDlgItem(IDC_REBASE_ABORT
)->SetFocus();
743 GetDlgItem(IDHELP
)->SetFocus();
747 m_tooltips
.RelayEvent(pMsg
);
748 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
751 bool CRebaseDlg::LogListHasFocus(HWND hwnd
)
754 ::GetClassName(hwnd
, buff
, 128);
756 if(_tcsnicmp(buff
, _T("SysListView32"), 128) == 0)
761 int CRebaseDlg::CheckRebaseCondition()
763 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
765 if( !g_Git
.CheckCleanWorkTree() )
767 if (CMessageBox::Show(NULL
, IDS_ERROR_NOCLEAN_STASH
, IDS_APPNAME
, 1, IDI_QUESTION
, IDS_STASHBUTTON
, IDS_ABORTBUTTON
) == 1)
770 cmd
=_T("git.exe stash");
771 this->AddLogString(cmd
);
772 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
774 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
782 //Todo Check $REBASE_ROOT
785 if (!CAppUtils::CheckUserData())
788 //Todo call pre_rebase_hook
791 int CRebaseDlg::StartRebase()
794 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
795 if(!this->m_IsCherryPick
)
797 //Todo call comment_for_reflog
798 cmd
.Format(_T("git.exe checkout %s"),this->m_BranchCtrl
.GetString());
799 this->AddLogString(cmd
);
803 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
805 this->AddLogString(out
);
806 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
813 this->AddLogString(out
);
816 cmd
=_T("git.exe rev-parse --verify HEAD");
817 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
819 AddLogString(CString(MAKEINTRESOURCE(IDS_PROC_NOHEAD
)));
823 //git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
824 // echo "detached HEAD" > "$DOTEST"/head-name
826 cmd
.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));
827 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
829 AddLogString(_T("update ORIG_HEAD Fail"));
833 m_OrigUpstreamHash
.Empty();
834 if (g_Git
.GetHash(m_OrigUpstreamHash
, m_UpstreamCtrl
.GetString()))
836 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
840 if( !this->m_IsCherryPick
)
842 cmd
.Format(_T("git.exe checkout -f %s"), m_OrigUpstreamHash
.ToString());
843 this->AddLogString(cmd
);
847 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
849 this->AddLogString(out
);
850 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
859 if( !this->m_IsCherryPick
)
861 if (g_Git
.GetHash(m_OrigBranchHash
, m_BranchCtrl
.GetString()))
863 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
866 log
.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTREBASE
)));
869 log
.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTCHERRYPICK
)));
871 this->AddLogString(log
);
874 int CRebaseDlg::VerifyNoConflict()
877 if(g_Git
.ListConflictFile(list
))
879 AddLogString(_T("Get conflict files fail"));
882 if( list
.GetCount() != 0 )
884 CMessageBox::Show(NULL
, IDS_PROGRS_CONFLICTSOCCURED
, IDS_APPNAME
, MB_OK
);
890 int CRebaseDlg::FinishRebase()
892 if(this->m_IsCherryPick
) //cherry pick mode no "branch", working at upstream branch
896 if (g_Git
.GetHash(head
, _T("HEAD")))
898 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR
);
903 cmd
.Format(_T("git.exe checkout -f %s"),this->m_BranchCtrl
.GetString());
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 cmd
.Format(_T("git.exe reset --hard %s"), head
.ToString());
924 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
927 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
935 while (m_ctrlTabCtrl
.GetTabsNum() > 1)
936 m_ctrlTabCtrl
.RemoveTab(0);
937 m_CtrlStatusText
.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_REBASEFINISHED
)));
938 m_sStatusText
= CString(MAKEINTRESOURCE(IDS_PROC_REBASEFINISHED
));
939 m_bStatusWarning
= false;
940 m_CtrlStatusText
.Invalidate();
944 void CRebaseDlg::OnBnClickedContinue()
946 if( m_RebaseStage
== REBASE_DONE
)
952 if( this->m_IsFastForward
)
955 CString oldbranch
= g_Git
.GetCurrentBranch();
956 if( oldbranch
!= m_BranchCtrl
.GetString() )
958 cmd
.Format(_T("git.exe checkout %s"),m_BranchCtrl
.GetString());
963 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
965 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
967 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
976 if (g_Git
.GetHash(m_OrigBranchHash
, m_BranchCtrl
.GetString()))
978 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
981 if (g_Git
.GetHash(m_OrigUpstreamHash
, m_UpstreamCtrl
.GetString()))
983 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl
.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR
);
987 if(!g_Git
.IsFastForward(this->m_BranchCtrl
.GetString(),this->m_UpstreamCtrl
.GetString()))
989 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
990 AddLogString(_T("No fast forward possible.\r\nMaybe repository changed"));
994 cmd
.Format(_T("git.exe reset --hard %s"),g_Git
.FixBranchName(this->m_UpstreamCtrl
.GetString()));
996 log
.Format(IDS_PROC_REBASE_FFTO
, m_UpstreamCtrl
.GetString());
997 this->AddLogString(log
);
1000 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1004 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1006 AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL
)));
1008 if (CMessageBox::Show(m_hWnd
, out
+ _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1015 AddLogString(CString(MAKEINTRESOURCE(IDS_DONE
)));
1016 m_RebaseStage
= REBASE_DONE
;
1017 UpdateCurrentStatus();
1021 if( m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
1023 if(CheckRebaseCondition())
1025 m_RebaseStage
= REBASE_START
;
1026 m_FileListCtrl
.Clear();
1027 m_FileListCtrl
.SetHasCheckboxes(false);
1028 m_FileListCtrl
.m_CurrentVersion
= L
"";
1029 m_ctrlTabCtrl
.SetTabLabel(REBASE_TAB_CONFLICT
, CString(MAKEINTRESOURCE(IDS_PROC_CONFLICTFILES
)));
1030 m_ctrlTabCtrl
.AddTab(&m_wndOutputRebase
, CString(MAKEINTRESOURCE(IDS_LOG
)), 2);
1033 if( m_RebaseStage
== REBASE_FINISH
)
1041 if( m_RebaseStage
== REBASE_SQUASH_CONFLICT
)
1043 if(VerifyNoConflict())
1045 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1046 if(this->CheckNextCommitIsSquash())
1047 {//next commit is not squash;
1048 m_RebaseStage
= REBASE_SQUASH_EDIT
;
1049 this->OnRebaseUpdateUI(0,0);
1050 this->UpdateCurrentStatus();
1054 m_RebaseStage
=REBASE_CONTINUE
;
1055 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
1056 this->UpdateCurrentStatus();
1060 if( m_RebaseStage
== REBASE_CONFLICT
)
1062 if(VerifyNoConflict())
1065 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1066 // ***************************************************
1067 // ATTENTION: Similar code in CommitDlg.cpp!!!
1068 // ***************************************************
1069 CMassiveGitTask
mgtReAddAfterCommit(_T("add --ignore-errors -f"));
1070 for (int i
= 0; i
< m_FileListCtrl
.GetItemCount(); i
++)
1073 CTGitPath
*entry
= (CTGitPath
*)m_FileListCtrl
.GetItemData(i
);
1074 if (entry
->m_Checked
)
1076 if (entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
)
1077 cmd
.Format(_T("git.exe add -f -- \"%s\""), entry
->GetGitPathString());
1078 else if (entry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
1079 cmd
.Format(_T("git.exe update-index --force-remove -- \"%s\""), entry
->GetGitPathString());
1081 cmd
.Format(_T("git.exe update-index -- \"%s\""), entry
->GetGitPathString());
1083 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1085 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1089 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
1090 cmd
.Format(_T("git.exe rm -- \"%s\""), entry
->GetGitOldPathString());
1092 g_Git
.Run(cmd
, &out
, CP_UTF8
);
1096 if (entry
->m_Action
& CTGitPath::LOGACTIONS_ADDED
|| entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
1098 cmd
.Format(_T("git.exe rm -f --cache -- \"%s\""), entry
->GetGitPathString());
1099 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1101 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1104 mgtReAddAfterCommit
.AddFile(*entry
);
1106 if (entry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
&& !entry
->GetGitOldPathString().IsEmpty())
1108 cmd
.Format(_T("git.exe reset -- \"%s\""), entry
->GetGitOldPathString());
1109 g_Git
.Run(cmd
, &out
, CP_UTF8
);
1112 else if(!(entry
->m_Action
& CTGitPath::LOGACTIONS_UNVER
))
1114 cmd
.Format(_T("git.exe reset -- \"%s\""), entry
->GetGitPathString());
1115 g_Git
.Run(cmd
, &out
, CP_UTF8
);
1120 CString out
=_T("");
1122 cmd
.Format(_T("git.exe commit -C %s"), curRev
->m_CommitHash
.ToString());
1126 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1129 if(!g_Git
.CheckCleanWorkTree())
1131 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1138 if (((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit"), TRUE
)) == TRUE
)
1140 BOOL cancel
= FALSE
;
1141 mgtReAddAfterCommit
.Execute(cancel
);
1144 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1145 if( curRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_EDIT
)
1147 m_RebaseStage
=REBASE_EDIT
;
1148 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1149 this->UpdateCurrentStatus();
1154 m_RebaseStage
=REBASE_CONTINUE
;
1155 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
1156 this->UpdateCurrentStatus();
1160 if( m_RebaseStage
== REBASE_EDIT
|| m_RebaseStage
== REBASE_SQUASH_EDIT
)
1163 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1165 str
=this->m_LogMessageCtrl
.GetText();
1166 if(str
.Trim().IsEmpty())
1168 CMessageBox::Show(NULL
, IDS_PROC_COMMITMESSAGE_EMPTY
,IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1172 CString tempfile
=::GetTempFile();
1173 CAppUtils::SaveCommitUnicodeFile(tempfile
, str
);
1177 if( m_RebaseStage
== REBASE_SQUASH_EDIT
)
1178 cmd
.Format(_T("git.exe commit -F \"%s\""), tempfile
);
1180 cmd
.Format(_T("git.exe commit --amend -F \"%s\""), tempfile
);
1182 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1184 if(!g_Git
.CheckCleanWorkTree())
1186 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
1191 CFile::Remove(tempfile
);
1193 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1194 m_RebaseStage
=REBASE_CONTINUE
;
1195 curRev
->GetAction(&m_CommitList
)|=CTGitPath::LOGACTIONS_REBASE_DONE
;
1196 this->UpdateCurrentStatus();
1200 InterlockedExchange(&m_bThreadRunning
, TRUE
);
1203 if (AfxBeginThread(RebaseThreadEntry
, this)==NULL
)
1205 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1206 CMessageBox::Show(NULL
, _T("Create Rebase Thread Fail"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
1210 int CRebaseDlg::CheckNextCommitIsSquash()
1213 if(m_CommitList
.m_IsOldFirst
)
1214 index
=m_CurrentRebaseIndex
+1;
1216 index
=m_CurrentRebaseIndex
-1;
1223 if(index
>= m_CommitList
.GetItemCount())
1226 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[index
];
1228 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1230 if( curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
)
1232 if(m_CommitList
.m_IsOldFirst
)
1240 }while(curRev
->GetAction(&m_CommitList
)&CTGitPath::LOGACTIONS_REBASE_SKIP
);
1245 int CRebaseDlg::GoNext()
1247 if(m_CommitList
.m_IsOldFirst
)
1248 ++m_CurrentRebaseIndex
;
1250 --m_CurrentRebaseIndex
;
1254 int CRebaseDlg::StateAction()
1256 switch(this->m_RebaseStage
)
1259 case CHOOSE_COMMIT_PICK_MODE
:
1262 m_RebaseStage
= REBASE_START
;
1269 void CRebaseDlg::SetContinueButtonText()
1272 switch(this->m_RebaseStage
)
1275 case CHOOSE_COMMIT_PICK_MODE
:
1276 if(this->m_IsFastForward
)
1277 Text
.LoadString(IDS_PROC_STARTREBASEFFBUTTON
);
1279 Text
.LoadString(IDS_PROC_STARTREBASEBUTTON
);
1284 case REBASE_CONTINUE
:
1285 case REBASE_SQUASH_CONFLICT
:
1286 Text
.LoadString(IDS_CONTINUEBUTTON
);
1289 case REBASE_CONFLICT
:
1290 Text
.LoadString(IDS_COMMITBUTTON
);
1293 Text
.LoadString(IDS_AMENDBUTTON
);
1296 case REBASE_SQUASH_EDIT
:
1297 Text
.LoadString(IDS_COMMITBUTTON
);
1302 Text
.LoadString(IDS_FINISHBUTTON
);
1306 Text
.LoadString(IDS_DONE
);
1309 this->GetDlgItem(IDC_REBASE_CONTINUE
)->SetWindowText(Text
);
1312 void CRebaseDlg::SetControlEnable()
1314 switch(this->m_RebaseStage
)
1317 case CHOOSE_COMMIT_PICK_MODE
:
1319 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(TRUE
);
1320 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(TRUE
);
1321 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(TRUE
);
1322 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(TRUE
);
1323 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(TRUE
);
1327 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(TRUE
);
1328 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(TRUE
);
1329 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(TRUE
);
1331 //this->m_CommitList.m_IsEnableRebaseMenu=TRUE;
1332 this->m_CommitList
.m_ContextMenuMask
|= m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1333 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1334 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1335 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
);
1339 case REBASE_CONTINUE
:
1343 case REBASE_CONFLICT
:
1345 case REBASE_SQUASH_CONFLICT
:
1347 this->GetDlgItem(IDC_PICK_ALL
)->EnableWindow(FALSE
);
1348 this->GetDlgItem(IDC_EDIT_ALL
)->EnableWindow(FALSE
);
1349 this->GetDlgItem(IDC_SQUASH_ALL
)->EnableWindow(FALSE
);
1350 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH
)->EnableWindow(FALSE
);
1351 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM
)->EnableWindow(FALSE
);
1352 this->GetDlgItem(IDC_REBASE_CHECK_FORCE
)->EnableWindow(FALSE
);
1353 this->GetDlgItem(IDC_BUTTON_UP2
)->EnableWindow(FALSE
);
1354 this->GetDlgItem(IDC_BUTTON_DOWN2
)->EnableWindow(FALSE
);
1355 //this->m_CommitList.m_IsEnableRebaseMenu=FALSE;
1356 this->m_CommitList
.m_ContextMenuMask
&= ~(m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK
)|
1357 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH
)|
1358 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT
)|
1359 m_CommitList
.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP
));
1361 if( m_RebaseStage
== REBASE_DONE
&& (this->m_PostButtonTexts
.GetCount() != 0) )
1363 this->GetDlgItem(IDC_STATUS_STATIC
)->ShowWindow(SW_HIDE
);
1364 this->GetDlgItem(IDC_REBASE_POST_BUTTON
)->ShowWindow(SW_SHOWNORMAL
);
1365 this->m_PostButton
.RemoveAll();
1366 this->m_PostButton
.AddEntries(m_PostButtonTexts
);
1367 //this->GetDlgItem(IDC_REBASE_POST_BUTTON)->SetWindowText(this->m_PostButtonText);
1372 if(m_bThreadRunning
)
1374 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1377 else if (m_RebaseStage
!= REBASE_ERROR
)
1379 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(TRUE
);
1383 void CRebaseDlg::UpdateProgress()
1388 if(m_CommitList
.m_IsOldFirst
)
1389 index
= m_CurrentRebaseIndex
+1;
1391 index
= m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1393 m_ProgressBar
.SetRange32(1, m_CommitList
.GetItemCount());
1394 m_ProgressBar
.SetPos(index
);
1397 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
1398 m_pTaskbarList
->SetProgressValue(m_hWnd
, index
, m_CommitList
.GetItemCount());
1401 if(m_CurrentRebaseIndex
>=0 && m_CurrentRebaseIndex
< m_CommitList
.GetItemCount())
1404 text
.Format(IDS_PROC_REBASING_PROGRESS
, index
, m_CommitList
.GetItemCount());
1405 m_sStatusText
= text
;
1406 m_CtrlStatusText
.SetWindowText(text
);
1407 m_bStatusWarning
= false;
1408 m_CtrlStatusText
.Invalidate();
1411 GitRev
*prevRev
=NULL
, *curRev
=NULL
;
1413 if( m_CurrentRebaseIndex
>= 0 && m_CurrentRebaseIndex
< m_CommitList
.m_arShownList
.GetSize())
1415 curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1418 for (int i
= 0; i
< m_CommitList
.m_arShownList
.GetSize(); ++i
)
1420 prevRev
=(GitRev
*)m_CommitList
.m_arShownList
[i
];
1421 if(prevRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1423 prevRev
->GetAction(&m_CommitList
) &= ~ CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1424 m_CommitList
.GetItemRect(i
,&rect
,LVIR_BOUNDS
);
1425 m_CommitList
.InvalidateRect(rect
);
1431 curRev
->GetAction(&m_CommitList
) |= CTGitPath::LOGACTIONS_REBASE_CURRENT
;
1432 m_CommitList
.GetItemRect(m_CurrentRebaseIndex
,&rect
,LVIR_BOUNDS
);
1433 m_CommitList
.InvalidateRect(rect
);
1435 m_CommitList
.EnsureVisible(m_CurrentRebaseIndex
,FALSE
);
1438 void CRebaseDlg::UpdateCurrentStatus()
1440 SetContinueButtonText();
1445 void CRebaseDlg::AddLogString(CString str
)
1447 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, FALSE
);
1448 CStringA sTextA
= m_wndOutputRebase
.StringForControl(str
);//CUnicodeUtils::GetUTF8(str);
1449 this->m_wndOutputRebase
.SendMessage(SCI_DOCUMENTEND
);
1450 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)sTextA
);
1451 this->m_wndOutputRebase
.SendMessage(SCI_REPLACESEL
, 0, (LPARAM
)(LPCSTR
)"\n");
1452 this->m_wndOutputRebase
.SendMessage(SCI_SETREADONLY
, TRUE
);
1455 int CRebaseDlg::GetCurrentCommitID()
1457 if(m_CommitList
.m_IsOldFirst
)
1459 return this->m_CurrentRebaseIndex
+1;
1464 return m_CommitList
.GetItemCount()-m_CurrentRebaseIndex
;
1468 int CRebaseDlg::DoRebase()
1471 if(m_CurrentRebaseIndex
<0)
1473 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1476 GitRev
*pRev
= (GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1477 int mode
=pRev
->GetAction(&m_CommitList
) & CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1480 if( mode
== CTGitPath::LOGACTIONS_REBASE_SKIP
)
1482 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1486 if (!CheckNextCommitIsSquash() || mode
!= CTGitPath::LOGACTIONS_REBASE_PICK
)
1487 { // next commit is squash or not pick
1488 if (!this->m_SquashMessage
.IsEmpty())
1489 this->m_SquashMessage
+= _T("\n\n");
1490 this->m_SquashMessage
+= pRev
->GetSubject();
1491 this->m_SquashMessage
+= _T("\n");
1492 this->m_SquashMessage
+= pRev
->GetBody().TrimRight();
1495 this->m_SquashMessage
.Empty();
1497 if (!CheckNextCommitIsSquash() || mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1498 { // next or this commit is squash
1499 nocommit
=_T(" --no-commit ");
1503 log
.Format(_T("%s %d: %s"),CTGitPath::GetActionName(mode
),this->GetCurrentCommitID(),pRev
->m_CommitHash
.ToString());
1505 AddLogString(pRev
->GetSubject());
1506 if (pRev
->GetSubject().IsEmpty())
1508 CMessageBox::Show(m_hWnd
, IDS_PROC_REBASE_EMPTYCOMMITMSG
, IDS_APPNAME
, MB_OK
| MB_ICONEXCLAMATION
);
1509 mode
= CTGitPath::LOGACTIONS_REBASE_EDIT
;
1512 CString cherryPickedFrom
;
1513 if (m_bAddCherryPickedFrom
)
1514 cherryPickedFrom
= _T("-x ");
1516 cmd
.Format(_T("git.exe cherry-pick %s%s %s"), cherryPickedFrom
, nocommit
, pRev
->m_CommitHash
.ToString());
1518 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1522 if(g_Git
.ListConflictFile(list
))
1524 AddLogString(_T("Get conflict files fail"));
1527 if(list
.GetCount() == 0 )
1529 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1531 m_RebaseStage
= REBASE_ERROR
;
1532 AddLogString(_T("An unrecoverable error occoured."));
1535 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1537 this->m_RebaseStage
= REBASE_EDIT
;
1538 return -1; // Edit return -1 to stop rebase.
1541 if(CheckNextCommitIsSquash())
1543 // let user edit last commmit message
1544 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1548 if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1549 m_RebaseStage
= REBASE_SQUASH_CONFLICT
;
1551 m_RebaseStage
= REBASE_CONFLICT
;
1558 if(mode
== CTGitPath::LOGACTIONS_REBASE_PICK
)
1560 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1563 if(mode
== CTGitPath::LOGACTIONS_REBASE_EDIT
)
1565 this->m_RebaseStage
= REBASE_EDIT
;
1566 return -1; // Edit return -1 to stop rebase.
1570 if(CheckNextCommitIsSquash())
1572 // let user edit last commmit message
1573 this->m_RebaseStage
= REBASE_SQUASH_EDIT
;
1576 else if(mode
== CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1577 pRev
->GetAction(&m_CommitList
)|= CTGitPath::LOGACTIONS_REBASE_DONE
;
1583 BOOL
CRebaseDlg::IsEnd()
1585 if(m_CommitList
.m_IsOldFirst
)
1586 return m_CurrentRebaseIndex
>= this->m_CommitList
.GetItemCount();
1588 return m_CurrentRebaseIndex
<0;
1591 int CRebaseDlg::RebaseThread()
1593 CBlockCacheForPath
cacheBlock(g_Git
.m_CurrentDir
);
1598 if( m_RebaseStage
== REBASE_START
)
1600 if( this->StartRebase() )
1605 m_RebaseStage
= REBASE_CONTINUE
;
1608 else if( m_RebaseStage
== REBASE_CONTINUE
)
1611 SendMessage(MSG_REBASE_UPDATE_UI
);
1615 m_RebaseStage
= REBASE_FINISH
;
1629 else if( m_RebaseStage
== REBASE_FINISH
)
1631 SendMessage(MSG_REBASE_UPDATE_UI
);
1632 m_RebaseStage
= REBASE_DONE
;
1640 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1643 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1644 this->PostMessage(MSG_REBASE_UPDATE_UI
);
1648 void CRebaseDlg::ListConflictFile()
1650 this->m_FileListCtrl
.Clear();
1651 m_FileListCtrl
.SetHasCheckboxes(true);
1656 m_FileListCtrl
.m_bIsRevertTheirMy
= !m_IsCherryPick
;
1658 this->m_FileListCtrl
.GetStatus(&list
,true);
1659 this->m_FileListCtrl
.Show(CTGitPath::LOGACTIONS_UNMERGED
|CTGitPath::LOGACTIONS_MODIFIED
|CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_DELETED
,
1660 CTGitPath::LOGACTIONS_UNMERGED
);
1662 m_FileListCtrl
.Check(GITSLC_SHOWFILES
);
1663 bool hasSubmoduleChange
= false;
1664 for (int i
= 0; i
< m_FileListCtrl
.GetItemCount(); i
++)
1666 CTGitPath
*entry
= (CTGitPath
*)m_FileListCtrl
.GetItemData(i
);
1667 if (entry
->IsDirectory())
1669 hasSubmoduleChange
= true;
1674 if (hasSubmoduleChange
)
1676 m_CtrlStatusText
.SetWindowText(m_sStatusText
+ _T(", ") + CString(MAKEINTRESOURCE(IDS_CARE_SUBMODULE_CHANGES
)));
1677 m_bStatusWarning
= true;
1678 m_CtrlStatusText
.Invalidate();
1682 m_CtrlStatusText
.SetWindowText(m_sStatusText
);
1683 m_bStatusWarning
= false;
1684 m_CtrlStatusText
.Invalidate();
1688 LRESULT
CRebaseDlg::OnRebaseUpdateUI(WPARAM
,LPARAM
)
1690 if (m_RebaseStage
== REBASE_FINISH
)
1694 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1697 UpdateCurrentStatus();
1698 if(m_CurrentRebaseIndex
<0)
1700 if(m_CurrentRebaseIndex
>= m_CommitList
.GetItemCount() )
1702 GitRev
*curRev
=(GitRev
*)m_CommitList
.m_arShownList
[m_CurrentRebaseIndex
];
1704 switch(m_RebaseStage
)
1706 case REBASE_CONFLICT
:
1707 case REBASE_SQUASH_CONFLICT
:
1709 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_CONFLICT
);
1711 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
1712 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1713 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1716 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1718 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1719 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1720 this->m_LogMessageCtrl
.SetText(curRev
->GetSubject()+_T("\n")+curRev
->GetBody());
1722 case REBASE_SQUASH_EDIT
:
1723 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_MESSAGE
);
1724 this->m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
1725 this->m_LogMessageCtrl
.SetText(this->m_SquashMessage
);
1727 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_PAUSED
);
1730 this->m_ctrlTabCtrl
.SetActiveTab(REBASE_TAB_LOG
);
1734 void CRebaseDlg::OnCancel()
1738 void CRebaseDlg::OnBnClickedAbort()
1741 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
1744 CString pron
= m_OrigUpstreamHash
.ToString();
1745 if(m_OrigUpstreamHash
.IsEmpty())
1747 __super::OnCancel();
1750 if(m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
)
1755 if(CMessageBox::Show(NULL
, IDS_PROC_REBASE_ABORT
, IDS_APPNAME
, MB_YESNO
) != IDYES
)
1758 if(this->m_IsFastForward
)
1760 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1764 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1767 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1773 __super::OnCancel();
1776 cmd
.Format(_T("git.exe checkout -f %s"),g_Git
.FixBranchName(this->m_UpstreamCtrl
.GetString()));
1780 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1783 if (CMessageBox::Show(this->m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1785 __super::OnCancel();
1793 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigUpstreamHash
.ToString());
1797 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1800 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1802 __super::OnCancel();
1810 if(this->m_IsCherryPick
) //there are not "branch" at cherry pick mode
1812 __super::OnCancel();
1816 cmd
.Format(_T("git checkout -f %s"),this->m_BranchCtrl
.GetString());
1817 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
1820 ::MessageBox(this->m_hWnd
, _T("Unrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_ICONERROR
);
1821 __super::OnCancel();
1825 cmd
.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash
.ToString());
1829 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
1832 if (CMessageBox::Show(m_hWnd
, _T("Retry?\nUnrecoverable error on cleanup:\n") + out
, _T("TortoiseGit"), MB_YESNO
| MB_ICONERROR
) != IDYES
)
1838 __super::OnCancel();
1841 void CRebaseDlg::OnBnClickedButtonBrowse()
1843 if(CBrowseRefsDlg::PickRefForCombo(&m_UpstreamCtrl
, gPickRef_NoTag
))
1844 OnCbnSelchangeUpstream();
1847 void CRebaseDlg::OnBnClickedRebaseCheckForce()
1850 this->FetchLogList();
1851 if(this->CheckRebaseCondition())
1853 /* Disable Start Rebase */
1854 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1858 void CRebaseDlg::OnBnClickedRebasePostButton()
1860 this->m_Upstream
=this->m_UpstreamCtrl
.GetString();
1861 this->m_Branch
=this->m_BranchCtrl
.GetString();
1863 this->EndDialog((int)(IDC_REBASE_POST_BUTTON
+this->m_PostButton
.GetCurrentEntry()));
1866 LRESULT
CRebaseDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
1872 void CRebaseDlg::Refresh()
1874 if (m_RebaseStage
== REBASE_CONFLICT
|| m_RebaseStage
== REBASE_SQUASH_CONFLICT
)
1880 if(this->m_IsCherryPick
)
1883 if(this->m_RebaseStage
== CHOOSE_BRANCH
)
1886 this->FetchLogList();
1887 if(this->CheckRebaseCondition())
1889 /* Disable Start Rebase */
1890 this->GetDlgItem(IDC_REBASE_CONTINUE
)->EnableWindow(FALSE
);
1895 void CRebaseDlg::OnBnClickedButtonUp2()
1898 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1900 // do nothing if the first selected item is the first item in the list
1901 if (m_CommitList
.GetNextSelectedItem(pos
) == 0)
1904 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1906 bool changed
= false;
1909 int index
=m_CommitList
.GetNextSelectedItem(pos
);
1912 CGitHash old
= m_CommitList
.m_logEntries
[index
-1];
1913 m_CommitList
.m_logEntries
[index
-1] = m_CommitList
.m_logEntries
[index
];
1914 m_CommitList
.m_logEntries
[index
] = old
;
1915 m_CommitList
.SetItemState(index
-1, LVIS_SELECTED
, LVIS_SELECTED
);
1916 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1922 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1923 m_CommitList
.Invalidate();
1924 m_CommitList
.SetFocus();
1928 void CRebaseDlg::OnBnClickedButtonDown2()
1930 if (m_CommitList
.GetSelectedCount() == 0)
1934 pos
= m_CommitList
.GetFirstSelectedItemPosition();
1935 bool changed
= false;
1936 // use an array to store all selected item indexes; the user won't select too much items
1937 int* indexes
= NULL
;
1938 indexes
= new int[m_CommitList
.GetSelectedCount()];
1942 indexes
[i
++] = m_CommitList
.GetNextSelectedItem(pos
);
1944 // don't move any item if the last selected item is the last item in the m_CommitList
1945 // (that would change the order of the selected items)
1946 if(indexes
[m_CommitList
.GetSelectedCount() - 1] < m_CommitList
.GetItemCount() - 1)
1948 // iterate over the indexes backwards in order to correctly move multiselected items
1949 for (i
= m_CommitList
.GetSelectedCount() - 1; i
>= 0; i
--)
1951 int index
= indexes
[i
];
1952 CGitHash old
= m_CommitList
.m_logEntries
[index
+1];
1953 m_CommitList
.m_logEntries
[index
+1] = m_CommitList
.m_logEntries
[index
];
1954 m_CommitList
.m_logEntries
[index
] = old
;
1955 m_CommitList
.SetItemState(index
, 0, LVIS_SELECTED
);
1956 m_CommitList
.SetItemState(index
+1, LVIS_SELECTED
, LVIS_SELECTED
);
1964 m_CommitList
.RecalculateShownList(&m_CommitList
.m_arShownList
);
1965 m_CommitList
.Invalidate();
1966 m_CommitList
.SetFocus();
1970 LRESULT
CRebaseDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
1972 m_pTaskbarList
.Release();
1973 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
1977 void CRebaseDlg::OnLvnItemchangedLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1979 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
1981 if(m_CommitList
.m_bNoDispUpdates
)
1983 if (pNMLV
->iItem
>= 0)
1985 this->m_CommitList
.m_nSearchIndex
= pNMLV
->iItem
;
1986 if (pNMLV
->iSubItem
!= 0)
1988 if ((pNMLV
->iItem
== m_CommitList
.m_arShownList
.GetCount()))
1990 // remove the selected state
1991 if (pNMLV
->uChanged
& LVIF_STATE
)
1993 m_CommitList
.SetItemState(pNMLV
->iItem
, 0, LVIS_SELECTED
);
1994 FillLogMessageCtrl();
1998 if (pNMLV
->uChanged
& LVIF_STATE
)
2000 FillLogMessageCtrl();
2005 FillLogMessageCtrl();
2009 void CRebaseDlg::FillLogMessageCtrl()
2011 int selCount
= m_CommitList
.GetSelectedCount();
2012 if (selCount
== 1 && (m_RebaseStage
== CHOOSE_BRANCH
|| m_RebaseStage
== CHOOSE_COMMIT_PICK_MODE
))
2014 POSITION pos
= m_CommitList
.GetFirstSelectedItemPosition();
2015 int selIndex
= m_CommitList
.GetNextSelectedItem(pos
);
2016 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_CommitList
.m_arShownList
.SafeGetAt(selIndex
));
2017 m_FileListCtrl
.UpdateWithGitPathList(pLogEntry
->GetFiles(&m_CommitList
));
2018 m_FileListCtrl
.m_CurrentVersion
= pLogEntry
->m_CommitHash
;
2019 m_FileListCtrl
.Show(GITSLC_SHOWVERSIONED
);
2020 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, FALSE
);
2021 m_LogMessageCtrl
.SetText(pLogEntry
->GetSubject() + _T("\n") + pLogEntry
->GetBody());
2022 m_LogMessageCtrl
.Call(SCI_SETREADONLY
, TRUE
);
2025 void CRebaseDlg::OnBnClickedCheckCherryPickedFrom()