RebaseDlg: Correctly remember commits for rewriting on Squash after (Edit|Squash...
[TortoiseGit.git] / src / TortoiseProc / MergeDlg.cpp
blob808f786e13d65d104124e85f40780acabc08c937
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017, 2019-2020, 2023-2024 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // MergeDlg.cpp : implementation file
23 #include "stdafx.h"
25 #include "Git.h"
26 #include "TortoiseProc.h"
27 #include "MergeDlg.h"
28 #include "AppUtils.h"
29 #include "HistoryDlg.h"
31 // CMergeDlg dialog
33 IMPLEMENT_DYNAMIC(CMergeDlg, CResizableStandAloneDialog)
35 CMergeDlg::CMergeDlg(CWnd* pParent /*=nullptr*/)
36 : CResizableStandAloneDialog(CMergeDlg::IDD, pParent)
37 , CChooseVersion(this)
38 , m_pDefaultText(MAKEINTRESOURCE(IDS_PROC_AUTOGENERATEDBYGIT))
39 , m_bSquash(BST_UNCHECKED)
40 , m_bNoCommit(BST_UNCHECKED)
41 , m_bLog(BST_UNCHECKED)
42 , m_bNoFF(BST_UNCHECKED)
43 , m_bFFonly(BST_UNCHECKED)
45 CString mergeLog = g_Git.GetConfigValue(L"merge.log");
46 int nLog = _wtoi(mergeLog);
47 m_nLog = nLog > 0 ? nLog : 20;
48 m_bSkipCurrentBranch = true;
51 CMergeDlg::~CMergeDlg()
55 void CMergeDlg::DoDataExchange(CDataExchange* pDX)
57 CDialog::DoDataExchange(pDX);
59 CHOOSE_VERSION_DDX;
61 DDX_Check(pDX,IDC_CHECK_NOFF,this->m_bNoFF);
62 DDX_Check(pDX,IDC_CHECK_SQUASH,this->m_bSquash);
63 DDX_Check(pDX,IDC_CHECK_NOCOMMIT,this->m_bNoCommit);
64 DDX_Check(pDX, IDC_CHECK_MERGE_LOG, m_bLog);
65 DDX_Text(pDX, IDC_EDIT_MERGE_LOGNUM, m_nLog);
66 DDX_Text(pDX, IDC_COMBO_MERGESTRATEGY, m_MergeStrategy);
67 DDX_Text(pDX, IDC_COMBO_STRATEGYOPTION, m_StrategyOption);
68 DDX_Text(pDX, IDC_EDIT_STRATEGYPARAM, m_StrategyParam);
69 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
70 DDX_Check(pDX, IDC_CHECK_FFONLY, m_bFFonly);
74 BEGIN_MESSAGE_MAP(CMergeDlg, CResizableStandAloneDialog)
75 CHOOSE_VERSION_EVENT
76 ON_BN_CLICKED(IDOK, &CMergeDlg::OnBnClickedOk)
77 ON_WM_DESTROY()
78 ON_BN_CLICKED(IDC_CHECK_SQUASH, &CMergeDlg::OnBnClickedCheckSquash)
79 ON_BN_CLICKED(IDC_CHECK_MERGE_LOG, &CMergeDlg::OnBnClickedCheckMergeLog)
80 ON_CBN_SELCHANGE(IDC_COMBO_MERGESTRATEGY, &CMergeDlg::OnCbnSelchangeComboMergestrategy)
81 ON_CBN_SELCHANGE(IDC_COMBO_STRATEGYOPTION, &CMergeDlg::OnCbnSelchangeComboStrategyoption)
82 ON_BN_CLICKED(IDC_CHECK_FFONLY, OnBnClickedCheckFFonlyOrNoFF)
83 ON_BN_CLICKED(IDC_CHECK_NOFF, OnBnClickedCheckFFonlyOrNoFF)
84 END_MESSAGE_MAP()
86 void CMergeDlg::ReloadHistoryEntries()
88 m_History.Load(L"Software\\TortoiseGit\\History\\merge", L"logmsgs");
91 BOOL CMergeDlg::OnInitDialog()
93 CResizableStandAloneDialog::OnInitDialog();
94 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
96 AdjustControlSize(IDC_RADIO_BRANCH);
97 AdjustControlSize(IDC_RADIO_TAGS);
98 AdjustControlSize(IDC_RADIO_VERSION);
99 AdjustControlSize(IDC_CHECK_SQUASH);
100 AdjustControlSize(IDC_CHECK_NOFF);
101 AdjustControlSize(IDC_CHECK_NOCOMMIT);
102 AdjustControlSize(IDC_CHECK_MERGE_LOG);
104 CHOOSE_VERSION_ADDANCHOR;
106 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
107 AddAnchor(IDC_STATIC_MERGE_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
108 AddAnchor(IDC_LOGMESSAGE,TOP_LEFT,BOTTOM_RIGHT);
110 AddAnchor(IDOK,BOTTOM_RIGHT);
111 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
112 AddAnchor(IDHELP, BOTTOM_RIGHT);
114 this->AddOthersToAnchor();
116 CheckRadioButton(IDC_RADIO_BRANCH,IDC_RADIO_VERSION,IDC_RADIO_BRANCH);
117 this->SetDefaultChoose(IDC_RADIO_BRANCH);
119 CAppUtils::SetWindowTitle(*this, g_Git.m_CurrentDir);
121 m_ProjectProperties.ReadProps();
123 m_cLogMessage.Init(m_ProjectProperties);
124 m_cLogMessage.SetFont(CAppUtils::GetLogFontName(), CAppUtils::GetLogFontSize());
125 m_cLogMessage.RegisterContextMenuHandler(this);
127 m_cLogMessage.SetText(m_pDefaultText);
128 m_cLogMessage.Call(SCI_EMPTYUNDOBUFFER);
129 m_cLogMessage.EnableWindow(!m_bSquash);
131 m_History.SetMaxHistoryItems(CRegDWORD(L"Software\\TortoiseGit\\MaxHistoryItems", 25));
132 ReloadHistoryEntries();
134 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(L"resolve");
135 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(L"recursive");
136 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(L"ours");
137 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_MERGESTRATEGY))->AddString(L"subtree");
138 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"ours");
139 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"theirs");
140 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"patience");
141 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"ignore-space-change");
142 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"ignore-all-space");
143 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"ignore-space-at-eol");
144 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"renormalize");
145 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"no-renormalize");
146 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"rename-threshold");
147 static_cast<CComboBox*>(GetDlgItem(IDC_COMBO_STRATEGYOPTION))->AddString(L"subtree");
149 EnableSaveRestore(L"MergeDlg");
150 GetDlgItem(IDOK)->SetFocus();
152 if (m_initialRefName.IsEmpty())
154 CString currentBranch;
155 if (g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir, currentBranch))
156 currentBranch.Empty();
158 CString pr, pb;
159 g_Git.GetRemotePushBranch(currentBranch, pr, pb);
160 if (!pr.IsEmpty() && !pb.IsEmpty())
161 m_initialRefName = L"remotes/" + pr + L'/' + pb;
164 InitChooseVersion(true);
166 SetTheme(CTheme::Instance().IsDarkTheme());
168 return FALSE;
171 // CMergeDlg message handlers
174 void CMergeDlg::OnBnClickedOk()
176 this->UpdateData(TRUE);
178 this->UpdateRevsionName();
180 if (GetCheckedRadioButton(IDC_RADIO_HEAD, IDC_RADIO_VERSION) == IDC_RADIO_BRANCH && m_ChooseVersioinBranch.GetCurSel() == -1)
182 CMessageBox::Show(GetSafeHwnd(), IDS_B_T_NOTEMPTY, IDS_APPNAME, MB_ICONEXCLAMATION);
183 return;
186 this->m_strLogMesage = m_cLogMessage.GetText() ;
187 if( m_strLogMesage == CString(this->m_pDefaultText) )
189 m_strLogMesage.Empty();
192 if (!m_strLogMesage.IsEmpty() && !m_bNoCommit)
194 ReloadHistoryEntries();
195 m_History.AddEntry(m_strLogMesage);
196 m_History.Save();
199 if (m_MergeStrategy != L"recursive")
200 m_StrategyOption.Empty();
201 if (m_StrategyOption != L"rename-threshold" && m_StrategyOption != L"subtree")
202 m_StrategyParam.Empty();
204 OnOK();
207 void CMergeDlg::OnCancel()
209 UpdateData(TRUE);
210 m_strLogMesage = m_cLogMessage.GetText();
211 if (m_strLogMesage != CString(this->m_pDefaultText) && !m_strLogMesage.IsEmpty() && !m_bNoCommit)
213 ReloadHistoryEntries();
214 m_History.AddEntry(m_strLogMesage);
215 m_History.Save();
217 CResizableStandAloneDialog::OnCancel();
220 void CMergeDlg::OnDestroy()
222 WaitForFinishLoading();
223 __super::OnDestroy();
226 // CSciEditContextMenuInterface
227 void CMergeDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
229 ReloadHistoryEntries();
230 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
231 if (m_History.GetCount() > 0)
233 CString sMenuItemText;
234 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
235 m_nPopupPasteLastMessage = nCmd++;
236 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
238 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
239 m_nPopupRecentMessage = nCmd++;
240 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
244 bool CMergeDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
246 if (m_History.IsEmpty())
247 return false;
249 if (cmd == m_nPopupPasteLastMessage)
251 if (pSciEdit->GetText() == CString(m_pDefaultText))
252 pSciEdit->SetText(L"");
253 CString logmsg (m_History.GetEntry(0));
254 pSciEdit->InsertText(logmsg);
255 return true;
258 if (cmd == m_nPopupRecentMessage)
260 CHistoryDlg historyDlg;
261 historyDlg.SetHistory(m_History);
262 if (historyDlg.DoModal() != IDOK)
263 return false;
265 if (pSciEdit->GetText() == CString(m_pDefaultText))
266 pSciEdit->SetText(L"");
267 m_cLogMessage.InsertText(historyDlg.GetSelectedText(), !m_cLogMessage.GetText().IsEmpty());
268 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
269 return true;
271 return false;
274 void CMergeDlg::OnBnClickedCheckSquash()
276 UpdateData(TRUE);
277 m_cLogMessage.EnableWindow(!m_bSquash);
278 GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(!m_bSquash);
281 void CMergeDlg::OnBnClickedCheckMergeLog()
283 UpdateData(TRUE);
284 GetDlgItem(IDC_EDIT_MERGE_LOGNUM)->EnableWindow(m_bLog);
287 void CMergeDlg::OnCbnSelchangeComboMergestrategy()
289 UpdateData(TRUE);
290 GetDlgItem(IDC_COMBO_STRATEGYOPTION)->EnableWindow(m_MergeStrategy == L"recursive");
291 GetDlgItem(IDC_EDIT_STRATEGYPARAM)->EnableWindow(m_MergeStrategy == L"recursive" ? m_StrategyOption == L"rename-threshold" || m_StrategyOption == L"subtree" : FALSE);
294 void CMergeDlg::OnCbnSelchangeComboStrategyoption()
296 UpdateData(TRUE);
297 GetDlgItem(IDC_EDIT_STRATEGYPARAM)->EnableWindow(m_StrategyOption == L"rename-threshold" || m_StrategyOption == L"subtree");
300 void CMergeDlg::OnBnClickedCheckFFonlyOrNoFF()
302 UpdateData();
304 GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(!m_bNoFF);
305 GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(!m_bFFonly);
306 GetDlgItem(IDC_CHECK_SQUASH)->EnableWindow(!m_bNoFF);