From 3a1fa4e53e5700cc276195802225533bd647ad3b Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sun, 9 Nov 2014 12:36:59 +0100 Subject: [PATCH] RebaseDlg: Allow to split commits Signed-off-by: Sven Strickroth --- Languages/Tortoise.pot | 10 +++++- src/Resources/TortoiseProcENG.rc | 3 +- src/TortoiseProc/CommitDlg.cpp | 4 ++- src/TortoiseProc/RebaseDlg.cpp | 75 +++++++++++++++++++++++++--------------- src/TortoiseProc/RebaseDlg.h | 3 ++ src/TortoiseProc/resource.h | 3 +- 6 files changed, 67 insertions(+), 31 deletions(-) diff --git a/Languages/Tortoise.pot b/Languages/Tortoise.pot index 868a6e1ad..d52c0868b 100644 --- a/Languages/Tortoise.pot +++ b/Languages/Tortoise.pot @@ -5162,6 +5162,10 @@ msgstr "" msgid "ID:32870:V C +L" msgstr "" +#. Accelerator Entry for Menu ID:32873; '' +msgid "ID:32873:V C +E" +msgstr "" + #. Accelerator Entry for Menu ID:32881; '' msgid "ID:32881:V C +P" msgstr "" @@ -8638,6 +8642,10 @@ msgstr "" msgid "Spin1" msgstr "" +#. Resource IDs: (1827) +msgid "Split commit" +msgstr "" + #. Resource IDs: (1253) msgid "Split lines" msgstr "" @@ -9212,7 +9220,7 @@ msgid "The two selected URL's are not created from the same root.\nIt's not poss msgstr "" #. Resource IDs: (96) -msgid "The working tree is not clean and contains unstaged changes. This can cause conflicts while rebasing/cherry picking." +msgid "The working tree is not clean and contains unstaged changes.\nReview and commit the changes?" msgstr "" #. Resource IDs: (65535) diff --git a/src/Resources/TortoiseProcENG.rc b/src/Resources/TortoiseProcENG.rc index cff0e11cf..56bd9a7c5 100644 --- a/src/Resources/TortoiseProcENG.rc +++ b/src/Resources/TortoiseProcENG.rc @@ -1461,6 +1461,7 @@ BEGIN PUSHBUTTON "Dumy Group For locat TabCtr",IDC_REBASE_DUMY_TAB,7,137,402,64,NOT WS_VISIBLE CONTROL "",IDC_REBASE_PROGRESS,"msctls_progress32",WS_BORDER,7,204,402,7 LTEXT "",IDC_STATUS_STATIC,7,215,201,8 + CONTROL "Split commit",IDC_REBASE_SPLIT_COMMIT,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,122,219,91,10 DEFPUSHBUTTON "Continue",IDC_REBASE_CONTINUE,213,217,63,14 PUSHBUTTON "Abort",IDC_REBASE_ABORT,285,217,57,14 PUSHBUTTON "Help",IDHELP,351,217,58,14 @@ -4595,7 +4596,7 @@ BEGIN IDS_FORCE_WITH_LEASE_TT "Force push only if the remote reference points to the same commit as the remote tracking branch.\nThis can cause the remote repository to lose commits; use it with care.\nThis option corresponds to the --force-with-lease git option." IDS_FORCE_TT "Force push to the selected remote reference and override it without any safety checks.\nThis can cause the remote repository to lose unseen commits; use it with care.\nThis option corresponds to the --force git option." IDS_PROC_REBASE_CONTINUE_NOTCLEAN - "The working tree is not clean and contains unstaged changes. This can cause conflicts while rebasing/cherry picking." + "The working tree is not clean and contains unstaged changes.\nReview and commit the changes?" IDS_PROC_COMMIT_SUPERPROJECT "Commit super project" IDS_LOG_NOT_VISIBLE "Commit %s is NOT visible right now." IDS_PROC_SELECTION_HISTORY "Selection History" diff --git a/src/TortoiseProc/CommitDlg.cpp b/src/TortoiseProc/CommitDlg.cpp index eb4309419..ed22b4154 100644 --- a/src/TortoiseProc/CommitDlg.cpp +++ b/src/TortoiseProc/CommitDlg.cpp @@ -428,6 +428,9 @@ BOOL CCommitDlg::OnInitDialog() SetSplitterRange(); + if (m_bForceCommitAmend || m_bCommitAmend) + GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW); + // add all directories to the watcher /* for (int i=0; iShowWindow(SW_SHOW); m_bCommitAmend = TRUE; SendMessage(WM_UPDATEDATAFALSE); } diff --git a/src/TortoiseProc/RebaseDlg.cpp b/src/TortoiseProc/RebaseDlg.cpp index d5ff58a4c..2565c3bee 100644 --- a/src/TortoiseProc/RebaseDlg.cpp +++ b/src/TortoiseProc/RebaseDlg.cpp @@ -46,6 +46,7 @@ CRebaseDlg::CRebaseDlg(CWnd* pParent /*=NULL*/) , m_bAutoSkipFailedCommit(FALSE) , m_bFinishedRebase(false) , m_bStashed(false) + , m_bSplitCommit(FALSE) { m_RebaseStage=CHOOSE_BRANCH; m_CurrentRebaseIndex=-1; @@ -72,6 +73,7 @@ void CRebaseDlg::DoDataExchange(CDataExchange* pDX) DDX_Check(pDX, IDC_CHECK_CHERRYPICKED_FROM, m_bAddCherryPickedFrom); DDX_Control(pDX,IDC_REBASE_POST_BUTTON,m_PostButton); DDX_Control(pDX, IDC_SPLITALLOPTIONS, m_SplitAllOptions); + DDX_Check(pDX, IDC_REBASE_SPLIT_COMMIT, m_bSplitCommit); } @@ -96,6 +98,7 @@ BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog) ON_REGISTERED_MESSAGE(CGitLogListBase::m_RebaseActionMessage, OnRebaseActionMessage) ON_WM_CTLCOLOR() ON_BN_CLICKED(IDC_SPLITALLOPTIONS, &CRebaseDlg::OnBnClickedSplitAllOptions) + ON_BN_CLICKED(IDC_REBASE_SPLIT_COMMIT, &CRebaseDlg::OnBnClickedRebaseSplitCommit) END_MESSAGE_MAP() void CRebaseDlg::AddRebaseAnchor() @@ -117,6 +120,7 @@ void CRebaseDlg::AddRebaseAnchor() AddAnchor(IDHELP, BOTTOM_RIGHT); AddAnchor(IDC_REBASE_CHECK_FORCE,TOP_RIGHT); AddAnchor(IDC_CHECK_CHERRYPICKED_FROM, TOP_RIGHT); + AddAnchor(IDC_REBASE_SPLIT_COMMIT, BOTTOM_RIGHT); AddAnchor(IDC_REBASE_POST_BUTTON,BOTTOM_LEFT); this->AddOthersToAnchor(); @@ -213,6 +217,7 @@ BOOL CRebaseDlg::OnInitDialog() AddRebaseAnchor(); AdjustControlSize(IDC_CHECK_CHERRYPICKED_FROM); + AdjustControlSize(IDC_REBASE_SPLIT_COMMIT); CString sWindowTitle; GetWindowText(sWindowTitle); @@ -1236,35 +1241,44 @@ void CRebaseDlg::OnBnClickedContinue() } } - if ((m_RebaseStage == REBASE_EDIT || m_RebaseStage == REBASE_CONTINUE) && CheckNextCommitIsSquash() && !g_Git.CheckCleanWorkTree(true)) + if ((m_RebaseStage == REBASE_EDIT || m_RebaseStage == REBASE_CONTINUE || m_bSplitCommit) && CheckNextCommitIsSquash() && (m_bSplitCommit || !g_Git.CheckCleanWorkTree(true))) { - CCommitDlg dlg; - dlg.m_sLogMessage = m_LogMessageCtrl.GetText(); - dlg.m_bWholeProject = true; - dlg.m_bSelectFilesForCommit = true; - dlg.m_bForceCommitAmend = true; - CTGitPathList gpl; - gpl.AddPath(CTGitPath(g_Git.m_CurrentDir)); - dlg.m_pathList = gpl; - dlg.m_bAmendDiffToLastCommit = TRUE; - dlg.m_bNoPostActions = true; - dlg.m_AmendStr = dlg.m_sLogMessage; - dlg.m_bWarnDetachedHead = false; - - if (dlg.DoModal() == IDOK) - { - if (CheckNextCommitIsSquash() == 0) // remember commit msg after edit if next commit if squash - ResetParentForSquash(dlg.m_sLogMessage); - else - m_SquashMessage.Empty(); - this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG); - m_RebaseStage = REBASE_CONTINUE; - GitRev* curRev = (GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex]; - curRev->GetRebaseAction() |= CGitLogListBase::LOGACTIONS_REBASE_DONE; - this->UpdateCurrentStatus(); - } - else + if (!m_bSplitCommit && CMessageBox::Show(nullptr, IDS_PROC_REBASE_CONTINUE_NOTCLEAN, IDS_APPNAME, 1, IDI_ERROR, IDS_MSGBOX_OK, IDS_ABORTBUTTON) == 2) return; + BOOL isFirst = TRUE; + do + { + CCommitDlg dlg; + if (isFirst) + dlg.m_sLogMessage = m_LogMessageCtrl.GetText(); + dlg.m_bWholeProject = true; + dlg.m_bSelectFilesForCommit = true; + dlg.m_bCommitAmend = isFirst && (m_RebaseStage != REBASE_SQUASH_EDIT); // do not amend on squash_edit stage, we need a normal commit there + CTGitPathList gpl; + gpl.AddPath(CTGitPath(g_Git.m_CurrentDir)); + dlg.m_pathList = gpl; + dlg.m_bAmendDiffToLastCommit = !m_bSplitCommit; + dlg.m_bNoPostActions = true; + if (dlg.m_bCommitAmend) + dlg.m_AmendStr = dlg.m_sLogMessage; + dlg.m_bWarnDetachedHead = false; + + if (dlg.DoModal() != IDOK) + return; + + isFirst = !m_bSplitCommit; // only select amend on second+ runs if not in split commit mode + + m_SquashMessage.Empty(); + } while (!g_Git.CheckCleanWorkTree() || (m_bSplitCommit && MessageBox(_T("Add another commit?"), _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)); + + m_bSplitCommit = FALSE; + UpdateData(FALSE); + + this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG); + m_RebaseStage = REBASE_CONTINUE; + GitRev* curRev = (GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex]; + curRev->GetRebaseAction() |= CGitLogListBase::LOGACTIONS_REBASE_DONE; + this->UpdateCurrentStatus(); } if( m_RebaseStage == REBASE_EDIT || m_RebaseStage == REBASE_SQUASH_EDIT ) @@ -1502,6 +1516,8 @@ void CRebaseDlg::SetControlEnable() break; } + GetDlgItem(IDC_REBASE_SPLIT_COMMIT)->ShowWindow((m_RebaseStage == REBASE_EDIT || m_RebaseStage == REBASE_SQUASH_EDIT) ? SW_SHOW : SW_HIDE); + if(m_bThreadRunning) { this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(FALSE); @@ -2336,3 +2352,8 @@ void CRebaseDlg::OnBnClickedSplitAllOptions() ATLASSERT(false); } } + +void CRebaseDlg::OnBnClickedRebaseSplitCommit() +{ + UpdateData(); +} diff --git a/src/TortoiseProc/RebaseDlg.h b/src/TortoiseProc/RebaseDlg.h index 9d8086764..edf069928 100644 --- a/src/TortoiseProc/RebaseDlg.h +++ b/src/TortoiseProc/RebaseDlg.h @@ -166,6 +166,8 @@ protected: CMenuButton m_SplitAllOptions; + BOOL m_bSplitCommit; + REBASE_STAGE m_RebaseStage; bool m_bFinishedRebase; bool m_bStashed; @@ -192,4 +194,5 @@ protected: CComPtr m_pTaskbarList; afx_msg LRESULT OnRebaseActionMessage(WPARAM wParam, LPARAM lParam); + afx_msg void OnBnClickedRebaseSplitCommit(); }; diff --git a/src/TortoiseProc/resource.h b/src/TortoiseProc/resource.h index e5cbed1a4..48fd427f9 100644 --- a/src/TortoiseProc/resource.h +++ b/src/TortoiseProc/resource.h @@ -1531,6 +1531,7 @@ #define IDC_MINESUBJECT 1824 #define IDC_BUTTON_UPDATE2 1825 #define IDC_BUTTON_UPDATE3 1826 +#define IDC_REBASE_SPLIT_COMMIT 1827 #define IDS_LOG_FILTER_BY 1850 #define IDS_LOG_FILTER_PATHS 1851 #define IDS_LOG_FILTER_AUTHORS 1852 @@ -1988,7 +1989,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 358 #define _APS_NEXT_COMMAND_VALUE 32874 -#define _APS_NEXT_CONTROL_VALUE 1827 +#define _APS_NEXT_CONTROL_VALUE 1828 #define _APS_NEXT_SYMED_VALUE 201 #endif #endif -- 2.11.4.GIT