OSDN Git Service

RebaseDlg Add Abort function
authorFrank Li <lznuaa@gmail.com>
Tue, 17 Feb 2009 15:16:10 +0000 (23:16 +0800)
committerFrank Li <lznuaa@gmail.com>
Tue, 17 Feb 2009 15:16:10 +0000 (23:16 +0800)
src/TortoiseProc/RebaseDlg.cpp
src/TortoiseProc/RebaseDlg.h

index a259a97..105d412 100644 (file)
@@ -48,6 +48,7 @@ BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog)
     ON_BN_CLICKED(IDC_EDIT_ALL, &CRebaseDlg::OnBnClickedEditAll)\r
     ON_BN_CLICKED(IDC_REBASE_SPLIT, &CRebaseDlg::OnBnClickedRebaseSplit)\r
        ON_BN_CLICKED(IDC_REBASE_CONTINUE,OnBnClickedContinue)\r
+       ON_BN_CLICKED(IDC_REBASE_ABORT,  OnBnClickedAbort)\r
        ON_WM_SIZE()\r
        ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH,   &CRebaseDlg::OnCbnSelchangeBranch)\r
        ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM, &CRebaseDlg::OnCbnSelchangeUpstream)\r
@@ -469,6 +470,20 @@ int CRebaseDlg::StartRebase()
        {\r
                return -1;\r
        }\r
+       \r
+       cmd.Format(_T("git.exe rev-parse %s"),this->m_UpstreamCtrl.GetString());\r
+       if(g_Git.Run(cmd,&this->m_OrigUpstreamHash,CP_UTF8))\r
+       {\r
+               this->AddLogString(m_OrigUpstreamHash);\r
+               return -1;\r
+       }\r
+\r
+       cmd.Format(_T("git.exe rev-parse %s"),this->m_BranchCtrl.GetString());\r
+       if(g_Git.Run(cmd,&this->m_OrigBranchHash,CP_UTF8))\r
+       {\r
+               this->AddLogString(m_OrigBranchHash);\r
+               return -1;\r
+       }\r
 \r
        this->AddLogString(_T("Start Rebase\r\n"));\r
        return 0;\r
@@ -482,6 +497,24 @@ void CRebaseDlg::OnBnClickedContinue()
                m_RebaseStage = REBASE_START;\r
        }\r
 \r
+       if( m_RebaseStage == REBASE_FINISH )\r
+       {\r
+               CString cmd,out;\r
+               cmd.Format(_T("git branch -f %s"),this->m_BranchCtrl.GetString());\r
+               if(g_Git.Run(cmd,&out,CP_UTF8))\r
+               {\r
+                       AddLogString(out);\r
+                       return ;\r
+               }\r
+               cmd.Format(_T("git reset --hard %s"),this->m_OrigUpstreamHash);\r
+               if(g_Git.Run(cmd,&out,CP_UTF8))\r
+               {\r
+                       AddLogString(out);\r
+                       return ;\r
+               }\r
+               OnOK();\r
+       }\r
+\r
        if( m_RebaseStage == REBASE_CONFLICT )\r
        {\r
                CTGitPathList list;\r
@@ -835,4 +868,27 @@ LRESULT CRebaseDlg::OnRebaseUpdateUI(WPARAM,LPARAM)
                this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
        }       \r
        return 0;\r
+}\r
+\r
+void CRebaseDlg::OnBnClickedAbort()\r
+{\r
+       CString cmd,out;\r
+       if(m_OrigUpstreamHash.IsEmpty())\r
+       {\r
+               this->OnCancel();\r
+       }\r
+       cmd.Format(_T("git reset --hard %s"),this->m_OrigUpstreamHash);\r
+       if(g_Git.Run(cmd,&out,CP_UTF8))\r
+       {\r
+               AddLogString(out);\r
+               return ;\r
+       }\r
+       \r
+       cmd.Format(_T("git checkout -f %s"),this->m_BranchCtrl.GetString());\r
+       if(g_Git.Run(cmd,&out,CP_UTF8))\r
+       {\r
+               AddLogString(out);\r
+               return ;\r
+       }\r
+       this->OnCancel();\r
 }
\ No newline at end of file
index 735a743..af18158 100644 (file)
@@ -72,6 +72,9 @@ protected:
        static UINT RebaseThreadEntry(LPVOID pVoid){return ((CRebaseDlg *)pVoid)->RebaseThread();};\r
        BOOL IsEnd();\r
 \r
+       CString m_OrigBranchHash;\r
+       CString m_OrigUpstreamHash;\r
+\r
 public:\r
    \r
     afx_msg void OnBnClickedPickAll();\r
@@ -82,6 +85,7 @@ public:
        afx_msg void OnCbnSelchangeBranch();\r
        afx_msg void OnCbnSelchangeUpstream();\r
        afx_msg void OnBnClickedContinue();\r
+       afx_msg void OnBnClickedAbort();\r
 \r
     CProgressCtrl m_ProgressBar;\r
     CStatic m_CtrlStatusText;\r