1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2023 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "StandAloneDlg.h"
22 #include "GitStatusListCtrl.h"
24 #include "SplitterControl.h"
25 #include "HistoryCombo.h"
26 #include "GitLogList.h"
27 #include "MenuButton.h"
28 #include "ProjectProperties.h"
32 #define IDC_REBASE_TAB 0x1000000
34 #define REBASE_TAB_CONFLICT 0
35 #define REBASE_TAB_MESSAGE 1
36 #define REBASE_TAB_LOG 2
38 #define MSG_REBASE_UPDATE_UI (WM_USER+151)
40 class CRebaseDlg
: public CResizableStandAloneDialog
42 DECLARE_DYNAMIC(CRebaseDlg
)
45 CRebaseDlg(CWnd
* pParent
= nullptr); // standard constructor
46 virtual ~CRebaseDlg();
49 enum { IDD
= IDD_REBASE
};
51 enum class RebaseStage
54 Choose_Commit_Pick_Mode
,
68 void DoDataExchange(CDataExchange
* pDX
) override
; // DDX/DDV support
69 BOOL
OnInitDialog() override
;
71 LRESULT
DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
) override
;
72 afx_msg HBRUSH
OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
);
73 afx_msg LRESULT
OnRebaseUpdateUI(WPARAM wParam
, LPARAM lParam
);
74 void SetTheme(bool bDark
) override
;
75 void DoSize(int delta
);
76 void AddRebaseAnchor();
78 void SetSplitterRange();
79 void SaveSplitterPos();
81 void LoadBranchInfo();
83 void SetAllRebaseAction(int action
);
84 void OnCancel() override
;
87 CRect m_CommitListOrigRect
;
88 CString m_sStatusText
;
89 bool m_bStatusWarning
= false;
90 BOOL
PreTranslateMessage(MSG
* pMsg
) override
;
91 bool LogListHasFocus(HWND hwnd
);
92 bool LogListHasMenuItem(int i
);
94 CSciEdit m_wndOutputRebase
;
95 void SetContinueButtonText();
96 void SetControlEnable();
97 void UpdateProgress();
98 void UpdateCurrentStatus();
99 void ListConflictFile(bool noStoreScrollPosition
);
100 int RunGitCmdRetryOrAbort(const CString
& cmd
);
102 afx_msg LRESULT
OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
);
104 volatile LONG m_bThreadRunning
= FALSE
;
105 volatile LONG m_bAbort
= FALSE
;
107 static UINT
RebaseThreadEntry(LPVOID pVoid
) { return static_cast<CRebaseDlg
*>(pVoid
)->RebaseThread(); };
110 int IsCommitEmpty(const CGitHash
& hash
);
112 bool m_IsFastForward
= false;
114 CGitHash m_OrigBranchHash
;
115 CGitHash m_OrigUpstreamHash
;
116 CString m_OrigHEADBranch
;
117 CGitHash m_OrigHEADHash
;
119 ProjectProperties m_ProjectProperties
;
121 int VerifyNoConflict();
123 CString m_SquashMessage
;
124 bool m_CurrentCommitEmpty
= false;
125 struct SquashFirstMetaData
132 SquashFirstMetaData() = default;
134 SquashFirstMetaData(GitRev
* rev
)
136 , name(rev
->GetAuthorName())
137 , email(rev
->GetAuthorEmail())
138 , time(rev
->GetAuthorDate())
142 void UpdateDate(GitRev
* rev
)
145 time
= rev
->GetAuthorDate();
156 CString
GetAuthor() const
161 temp
.Format(L
"%s <%s>", static_cast<LPCWSTR
>(name
), static_cast<LPCWSTR
>(email
));
165 CString
GetAsParam(bool now
) const
170 CString date
= time
.Format(L
"%Y-%m-%dT%H:%M:%S");
175 temp
.Format(L
"--date=%s --author=\"%s\" ", static_cast<LPCWSTR
>(date
), static_cast<LPCWSTR
>(GetAuthor()));
178 } m_SquashFirstMetaData
;
179 int m_iSquashdate
= 0;
181 int CheckNextCommitIsSquash();
182 int GetCurrentCommitID();
186 CMenuButton m_PostButton
;
188 afx_msg
void OnBnClickedRebaseSplit();
189 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
190 afx_msg
void OnCbnSelchangeBranch();
191 afx_msg
void OnCbnSelchangeUpstream();
192 afx_msg
void OnBnClickedContinue();
193 afx_msg
void OnBnClickedAbort();
194 afx_msg
void OnLvnItemchangedLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
);
195 void FillLogMessageCtrl();
197 CProgressCtrl m_ProgressBar
;
198 CStatic m_CtrlStatusText
;
200 BOOL m_bAddCherryPickedFrom
;
201 BOOL m_bAutoSkipFailedCommit
= FALSE
;
202 bool m_bRebaseAutoEnd
= false;
205 CStringArray m_PostButtonTexts
;
206 CGitLogList m_CommitList
;
212 bool m_IsCherryPick
= false;
213 bool m_bRebaseAutoStart
= false;
214 BOOL m_bPreserveMerges
;
217 CSplitterControl m_wndSplitter
;
218 CMFCTabCtrl m_ctrlTabCtrl
;
219 CGitStatusListCtrl m_FileListCtrl
;
220 CSciEdit m_LogMessageCtrl
;
222 CHistoryCombo m_BranchCtrl
;
223 CHistoryCombo m_UpstreamCtrl
;
225 CMenuButton m_SplitAllOptions
;
229 RebaseStage m_RebaseStage
= RebaseStage::Choose_Branch
;
230 bool m_bFinishedRebase
= false;
231 bool m_bStashed
= false;
233 std::unordered_map
<CGitHash
, CGitHash
> m_rewrittenCommitsMap
;
234 std::vector
<CGitHash
> m_forRewrite
;
235 std::unordered_map
<CGitHash
, GIT_REV_LIST
> m_droppedCommitsMap
;
236 std::vector
<CGitHash
> m_currentCommits
;
238 void AddBranchToolTips(CHistoryCombo
& pBranch
);
239 void AddLogString(const CString
& str
);
240 int WriteReflog(CGitHash hash
, const char* message
);
242 int CheckRebaseCondition();
243 void CheckRestoreStash();
244 int m_CurrentRebaseIndex
= -1;
246 void ResetParentForSquash(const CString
& commitMessage
);
247 void CleanUpRebaseActiveFolder();
248 afx_msg
void OnBnClickedButtonReverse();
249 afx_msg
void OnBnClickedButtonBrowse();
250 afx_msg
void OnBnClickedRebaseCheckForce();
251 afx_msg
void OnBnClickedCheckCherryPickedFrom();
252 afx_msg
void OnBnClickedRebasePostButton();
253 afx_msg
void OnBnClickedSplitAllOptions();
254 afx_msg
void OnBnClickedButtonUp();
255 afx_msg
void OnBnClickedButtonDown();
256 afx_msg
void OnHelp();
258 afx_msg LRESULT
OnTaskbarBtnCreated(WPARAM wParam
, LPARAM lParam
);
259 CComPtr
<ITaskbarList3
> m_pTaskbarList
;
261 afx_msg LRESULT
OnRebaseActionMessage(WPARAM wParam
, LPARAM lParam
);
262 afx_msg LRESULT
OnCommitsReordered(WPARAM wParam
, LPARAM lParam
);
263 afx_msg
void OnRefreshFilelist();
264 afx_msg
void OnBnClickedRebaseSplitCommit();
265 afx_msg
void OnBnClickedButtonOnto();
266 afx_msg
void OnBnClickedButtonAdd();