OSDN Git Service

Fixed issue #187: Allow start new rebase after finish rebase
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RebaseDlg.cpp
index c39c386..0e6d8eb 100644 (file)
@@ -24,6 +24,7 @@ CRebaseDlg::CRebaseDlg(CWnd* pParent /*=NULL*/)
        m_bThreadRunning =FALSE;\r
        this->m_IsCherryPick = FALSE;\r
        m_bForce=FALSE;\r
+       m_IsFastForward=FALSE;\r
 }\r
 \r
 CRebaseDlg::~CRebaseDlg()\r
@@ -43,7 +44,7 @@ void CRebaseDlg::DoDataExchange(CDataExchange* pDX)
        DDX_Control(pDX,IDC_REBASE_COMBOXEX_BRANCH, this->m_BranchCtrl);\r
        DDX_Control(pDX,IDC_REBASE_COMBOXEX_UPSTREAM,   this->m_UpstreamCtrl);\r
        DDX_Check(pDX, IDC_REBASE_CHECK_FORCE,m_bForce);\r
-\r
+       DDX_Control(pDX,IDC_REBASE_POST_BUTTON,m_PostButton);\r
 }\r
 \r
 \r
@@ -60,6 +61,8 @@ BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog)
        ON_MESSAGE(MSG_REBASE_UPDATE_UI, OnRebaseUpdateUI)\r
        ON_BN_CLICKED(IDC_BUTTON_BROWSE, &CRebaseDlg::OnBnClickedButtonBrowse)\r
        ON_BN_CLICKED(IDC_REBASE_CHECK_FORCE, &CRebaseDlg::OnBnClickedRebaseCheckForce)\r
+       ON_STN_CLICKED(IDC_STATUS_STATIC, &CRebaseDlg::OnStnClickedStatusStatic)\r
+       ON_BN_CLICKED(IDC_REBASE_POST_BUTTON, &CRebaseDlg::OnBnClickedRebasePostButton)\r
 END_MESSAGE_MAP()\r
 \r
 void CRebaseDlg::AddRebaseAnchor()\r
@@ -80,6 +83,8 @@ void CRebaseDlg::AddRebaseAnchor()
        AddAnchor(IDC_REBASE_STATIC_BRANCH,TOP_LEFT);\r
        AddAnchor(IDHELP, BOTTOM_RIGHT);\r
        AddAnchor(IDC_REBASE_CHECK_FORCE,TOP_RIGHT);\r
+       AddAnchor(IDC_REBASE_POST_BUTTON,BOTTOM_LEFT);\r
+       \r
        this->AddOthersToAnchor();\r
 }\r
 \r
@@ -133,6 +138,9 @@ BOOL CRebaseDlg::OnInitDialog()
        m_tooltips.Create(this);\r
        \r
        m_tooltips.AddTool(IDC_REBASE_CHECK_FORCE,IDS_REBASE_FORCE_TT);\r
+       m_tooltips.AddTool(IDC_REBASE_ABORT,IDS_REBASE_ABORT_TT);\r
+       \r
+\r
 \r
        m_FileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("RebaseDlg"),(SVNSLC_POPALL ^ SVNSLC_POPCOMMIT),false);\r
 \r
@@ -304,6 +312,7 @@ void CRebaseDlg::DoSize(int delta)
        CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL),0,delta);\r
        CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL),0,delta);\r
        CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL),0,delta);\r
+       CSplitterControl::ChangePos(GetDlgItem(IDC_REBASE_CHECK_FORCE),0,delta);\r
        \r
        this->AddRebaseAnchor();\r
        // adjust the minimum size of the dialog to prevent the resizing from\r
@@ -414,18 +423,55 @@ void CRebaseDlg::OnCbnSelchangeUpstream()
 \r
 void CRebaseDlg::FetchLogList()\r
 {\r
-       if(!this->m_bForce)\r
+       CString base,hash;\r
+       CString cmd;\r
+       m_IsFastForward=FALSE;\r
+       cmd.Format(_T("git.exe merge-base %s %s"), m_UpstreamCtrl.GetString(),m_BranchCtrl.GetString());\r
+       if(g_Git.Run(cmd,&base,CP_ACP))\r
        {\r
-               CString base,hash;\r
-               CString cmd;\r
-               cmd.Format(_T("git.exe merge-base %s %s"), m_UpstreamCtrl.GetString(),m_BranchCtrl.GetString());\r
-               if(g_Git.Run(cmd,&base,CP_ACP))\r
-               {\r
-                       CMessageBox::Show(NULL,base,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
-                       return;\r
-               }\r
-               base=base.Left(40);\r
+               CMessageBox::Show(NULL,base,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
+               return;\r
+       }\r
+       base=base.Left(40);\r
+\r
+       hash=g_Git.GetHash(m_BranchCtrl.GetString());\r
+\r
+       if(hash == g_Git.GetHash(this->m_UpstreamCtrl.GetString()))\r
+       {\r
+               m_CommitList.Clear();\r
+               CString text,fmt;\r
+               fmt.LoadString(IDS_REBASE_EQUAL_FMT);\r
+               text.Format(fmt,m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString());\r
+\r
+               m_CommitList.ShowText(text);\r
+               this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(false);\r
+               return;\r
+       }\r
+\r
+       hash=hash.Left(40);\r
+       \r
+       if(hash == base )\r
+       {\r
+               //fast forword\r
+               this->m_IsFastForward=TRUE;\r
+\r
+               m_CommitList.Clear();\r
+               CString text,fmt;\r
+               fmt.LoadString(IDS_REBASE_FASTFORWARD_FMT);\r
+               text.Format(fmt,m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString(),\r
+                                               m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString());\r
+\r
+               m_CommitList.ShowText(text);\r
+               this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(true);\r
+               SetContinueButtonText();\r
+               \r
+               return ;\r
+       }\r
 \r
+       hash.Empty();\r
+\r
+       if(!this->m_bForce)\r
+       {\r
                cmd.Format(_T("git.exe rev-parse %s"), m_UpstreamCtrl.GetString());\r
                if( g_Git.Run(cmd,&hash,CP_ACP))\r
                {\r
@@ -441,47 +487,48 @@ void CRebaseDlg::FetchLogList()
                        fmt.LoadString(IDS_REBASE_UPTODATE_FMT);\r
                        text.Format(fmt,m_BranchCtrl.GetString());\r
                        m_CommitList.ShowText(text);\r
+                       this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(m_CommitList.GetItemCount());\r
+                       SetContinueButtonText();\r
+                       return;\r
                }\r
-               \r
-       }else\r
-       {\r
-               m_CommitList.Clear();\r
-               this->m_CommitList.FillGitLog(NULL,0,&m_UpstreamCtrl.GetString(),&m_BranchCtrl.GetString());\r
-               if( m_CommitList.GetItemCount() == 0 )\r
-                       m_CommitList.ShowText(_T("Nothing to Rebase"));\r
+       }\r
+\r
+       m_CommitList.Clear();\r
+       this->m_CommitList.FillGitLog(NULL,0,&m_UpstreamCtrl.GetString(),&m_BranchCtrl.GetString());\r
+       if( m_CommitList.GetItemCount() == 0 )\r
+               m_CommitList.ShowText(_T("Nothing to Rebase"));\r
 \r
-               CString hash=g_Git.GetHash(m_UpstreamCtrl.GetString());\r
+       hash=g_Git.GetHash(m_UpstreamCtrl.GetString());\r
        \r
 #if 0\r
-               if(m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash.size() >=0 )\r
+       if(m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash.size() >=0 )\r
+       {\r
+               if(hash ==  m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash[0])\r
                {\r
-                       if(hash ==  m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash[0])\r
-                       {\r
-                               m_CommitList.Clear();\r
-                               m_CommitList.ShowText(_T("Nothing Rebase"));\r
-                       }\r
+                       m_CommitList.Clear();\r
+                       m_CommitList.ShowText(_T("Nothing Rebase"));\r
                }\r
+       }\r
 #endif\r
 \r
-               m_tooltips.Pop();\r
-               AddBranchToolTips(&this->m_BranchCtrl);\r
-               AddBranchToolTips(&this->m_UpstreamCtrl);\r
-       \r
-               for(int i=0;i<m_CommitList.m_logEntries.size();i++)\r
-               {\r
-                       m_CommitList.m_logEntries[i].m_Action = CTGitPath::LOGACTIONS_REBASE_PICK;\r
-               }\r
-       \r
-               m_CommitList.Invalidate();\r
-\r
-               if(m_CommitList.m_IsOldFirst)\r
-                       this->m_CurrentRebaseIndex = -1;\r
-               else\r
-                       this->m_CurrentRebaseIndex = m_CommitList.m_logEntries.size();\r
+       m_tooltips.Pop();\r
+       AddBranchToolTips(&this->m_BranchCtrl);\r
+       AddBranchToolTips(&this->m_UpstreamCtrl);\r
        \r
+       for(int i=0;i<m_CommitList.m_logEntries.size();i++)\r
+       {\r
+               m_CommitList.m_logEntries[i].m_Action = CTGitPath::LOGACTIONS_REBASE_PICK;\r
        }\r
 \r
+       m_CommitList.Invalidate();\r
+\r
+       if(m_CommitList.m_IsOldFirst)\r
+               this->m_CurrentRebaseIndex = -1;\r
+       else\r
+               this->m_CurrentRebaseIndex = m_CommitList.m_logEntries.size();\r
+       \r
        this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(m_CommitList.GetItemCount());\r
+       SetContinueButtonText();\r
 }\r
 \r
 void CRebaseDlg::AddBranchToolTips(CHistoryCombo *pBranch)\r
@@ -534,7 +581,7 @@ int CRebaseDlg::CheckRebaseCondition()
 int CRebaseDlg::StartRebase()\r
 {\r
        CString cmd,out;\r
-\r
+       m_FileListCtrl.m_bIsRevertTheirMy = !m_IsCherryPick;\r
        if(!this->m_IsCherryPick)\r
        {\r
                //Todo call comment_for_reflog\r
@@ -645,6 +692,57 @@ int CRebaseDlg::FinishRebase()
 }\r
 void CRebaseDlg::OnBnClickedContinue()\r
 {\r
+       if( m_RebaseStage == REBASE_DONE)\r
+       {\r
+               OnOK();\r
+               return;\r
+       }\r
+\r
+       if( this->m_IsFastForward )\r
+       {\r
+               CString cmd,out;\r
+               CString oldbranch = g_Git.GetCurrentBranch();\r
+               if( oldbranch != m_BranchCtrl.GetString() )\r
+               {\r
+                       cmd.Format(_T("git.exe checkout %s"),m_BranchCtrl.GetString());\r
+                       AddLogString(cmd);\r
+                       if( g_Git.Run(cmd,&out,CP_ACP) )\r
+                       {\r
+                               this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
+                               AddLogString(out);\r
+                               return;\r
+                       }\r
+               }\r
+               AddLogString(out);\r
+               out.Empty();\r
+               m_OrigBranchHash = g_Git.GetHash(m_BranchCtrl.GetString());\r
+               m_OrigUpstreamHash = g_Git.GetHash(this->m_UpstreamCtrl.GetString());\r
+                       \r
+               if(!g_Git.IsFastForward(this->m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString()))\r
+               {\r
+                       this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
+                       AddLogString(_T("No fast forward\r\nMaybe repository changed"));\r
+                       return;\r
+               }\r
+               \r
+               cmd.Format(_T("git.exe reset --hard %s"),this->m_UpstreamCtrl.GetString());\r
+               this->AddLogString(CString(_T("Fast forward to "))+m_UpstreamCtrl.GetString());\r
+\r
+               AddLogString(cmd);\r
+               this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
+               if(g_Git.Run(cmd,&out,CP_ACP))\r
+               {\r
+                       AddLogString(_T("Fail"));\r
+                       AddLogString(out);\r
+                       return;\r
+               }\r
+               AddLogString(out);\r
+               AddLogString(_T("Done"));\r
+               m_RebaseStage = REBASE_DONE;\r
+               UpdateCurrentStatus();\r
+               return;\r
+\r
+       }\r
        if( m_RebaseStage == CHOOSE_BRANCH|| m_RebaseStage == CHOOSE_COMMIT_PICK_MODE )\r
        {\r
                if(CheckRebaseCondition())\r
@@ -652,10 +750,6 @@ void CRebaseDlg::OnBnClickedContinue()
                m_RebaseStage = REBASE_START;\r
        }\r
 \r
-       if( m_RebaseStage == REBASE_DONE)\r
-       {\r
-               OnOK();\r
-       }\r
 \r
        if( m_RebaseStage == REBASE_FINISH )\r
        {\r
@@ -841,7 +935,10 @@ void CRebaseDlg::SetContinueButtonText()
        {\r
        case CHOOSE_BRANCH:\r
        case CHOOSE_COMMIT_PICK_MODE:\r
-               Text = _T("Start");\r
+               if(this->m_IsFastForward)\r
+                       Text = _T("Start(FastFwd)");\r
+               else\r
+                       Text = _T("Start");\r
                break;\r
 \r
        case REBASE_START:\r
@@ -883,10 +980,12 @@ void CRebaseDlg::SetControlEnable()
                this->GetDlgItem(IDC_PICK_ALL)->EnableWindow(TRUE);\r
                this->GetDlgItem(IDC_EDIT_ALL)->EnableWindow(TRUE);\r
                this->GetDlgItem(IDC_SQUASH_ALL)->EnableWindow(TRUE);\r
+               \r
                if(!m_IsCherryPick)\r
                {\r
                        this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH)->EnableWindow(TRUE);\r
                        this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM)->EnableWindow(TRUE);\r
+                       this->GetDlgItem(IDC_REBASE_CHECK_FORCE)->EnableWindow(TRUE);                   \r
                }\r
                //this->m_CommitList.m_IsEnableRebaseMenu=TRUE;\r
                this->m_CommitList.m_ContextMenuMask |= m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK)|\r
@@ -908,11 +1007,21 @@ void CRebaseDlg::SetControlEnable()
                this->GetDlgItem(IDC_SQUASH_ALL)->EnableWindow(FALSE);\r
                this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH)->EnableWindow(FALSE);\r
                this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM)->EnableWindow(FALSE);\r
+               this->GetDlgItem(IDC_REBASE_CHECK_FORCE)->EnableWindow(FALSE);\r
                //this->m_CommitList.m_IsEnableRebaseMenu=FALSE;\r
                this->m_CommitList.m_ContextMenuMask &= ~(m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK)|\r
                                                                                                m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH)|\r
                                                                                                m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT)|\r
                                                                                                m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP));\r
+\r
+               if( m_RebaseStage == REBASE_DONE && (this->m_PostButtonTexts.GetCount() != 0) )\r
+               {\r
+                       this->GetDlgItem(IDC_STATUS_STATIC)->ShowWindow(SW_HIDE);\r
+                       this->GetDlgItem(IDC_REBASE_POST_BUTTON)->ShowWindow(SW_SHOWNORMAL);\r
+                       this->m_PostButton.RemoveAll();\r
+                       this->m_PostButton.AddEntries(m_PostButtonTexts);\r
+                       //this->GetDlgItem(IDC_REBASE_POST_BUTTON)->SetWindowText(this->m_PostButtonText);\r
+               }\r
                break;\r
        }\r
 \r
@@ -1185,6 +1294,8 @@ void CRebaseDlg::ListConflictFile()
        CTGitPath path;\r
        list.AddPath(path);\r
 \r
+       m_FileListCtrl.m_bIsRevertTheirMy = !m_IsCherryPick;\r
+\r
        this->m_FileListCtrl.GetStatus(&list,true);\r
        this->m_FileListCtrl.Show(CTGitPath::LOGACTIONS_UNMERGED|CTGitPath::LOGACTIONS_MODIFIED|CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_DELETED,\r
                                                           CTGitPath::LOGACTIONS_UNMERGED);\r
@@ -1244,6 +1355,17 @@ void CRebaseDlg::OnBnClickedAbort()
        if(CMessageBox::Show(NULL,_T("Are you sure you want to abort the rebase process?"),_T("TortoiseGit"),MB_YESNO) != IDYES)\r
                return;\r
 \r
+       if(this->m_IsFastForward)\r
+       {\r
+               cmd.Format(_T("git.exe reset --hard  %s"),this->m_OrigBranchHash.Left(40));\r
+               if(g_Git.Run(cmd,&out,CP_UTF8))\r
+               {\r
+                       AddLogString(out);\r
+                       return ;\r
+               }\r
+               __super::OnCancel();\r
+               return;\r
+       }\r
        cmd.Format(_T("git.exe checkout -f %s"),this->m_UpstreamCtrl.GetString());\r
        if(g_Git.Run(cmd,&out,CP_UTF8))\r
        {\r
@@ -1289,3 +1411,17 @@ void CRebaseDlg::OnBnClickedRebaseCheckForce()
        this->UpdateData();\r
        this->FetchLogList();\r
 }\r
+\r
+void CRebaseDlg::OnStnClickedStatusStatic()\r
+{\r
+       // TODO: Add your control notification handler code here\r
+}\r
+\r
+void CRebaseDlg::OnBnClickedRebasePostButton()\r
+{\r
+       // TODO: Add your control notification handler code here\r
+       this->m_Upstream=this->m_UpstreamCtrl.GetString();\r
+       this->m_Branch=this->m_BranchCtrl.GetString();\r
+\r
+       this->EndDialog(IDC_REBASE_POST_BUTTON);\r
+}\r