OSDN Git Service

Fixed issue #187: Allow start new rebase after finish rebase
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RebaseDlg.cpp
index cab8be1..0e6d8eb 100644 (file)
@@ -7,6 +7,8 @@
 #include "AppUtils.h"\r
 #include "MessageBox.h"\r
 #include "UnicodeUtils.h"\r
+#include "BrowseRefsDlg.h"\r
+#include "ProgressDlg.h"\r
 // CRebaseDlg dialog\r
 \r
 IMPLEMENT_DYNAMIC(CRebaseDlg, CResizableStandAloneDialog)\r
@@ -20,6 +22,9 @@ CRebaseDlg::CRebaseDlg(CWnd* pParent /*=NULL*/)
        m_RebaseStage=CHOOSE_BRANCH;\r
        m_CurrentRebaseIndex=-1;\r
        m_bThreadRunning =FALSE;\r
+       this->m_IsCherryPick = FALSE;\r
+       m_bForce=FALSE;\r
+       m_IsFastForward=FALSE;\r
 }\r
 \r
 CRebaseDlg::~CRebaseDlg()\r
@@ -38,7 +43,8 @@ void CRebaseDlg::DoDataExchange(CDataExchange* pDX)
        DDX_Control(pDX,IDC_COMMIT_LIST,m_CommitList);\r
        DDX_Control(pDX,IDC_REBASE_COMBOXEX_BRANCH, this->m_BranchCtrl);\r
        DDX_Control(pDX,IDC_REBASE_COMBOXEX_UPSTREAM,   this->m_UpstreamCtrl);\r
-\r
+       DDX_Check(pDX, IDC_REBASE_CHECK_FORCE,m_bForce);\r
+       DDX_Control(pDX,IDC_REBASE_POST_BUTTON,m_PostButton);\r
 }\r
 \r
 \r
@@ -53,6 +59,10 @@ BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog)
        ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH,   &CRebaseDlg::OnCbnSelchangeBranch)\r
        ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM, &CRebaseDlg::OnCbnSelchangeUpstream)\r
        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
@@ -71,7 +81,11 @@ void CRebaseDlg::AddRebaseAnchor()
        AddAnchor(IDC_REBASE_COMBOXEX_BRANCH,TOP_LEFT);\r
        AddAnchor(IDC_REBASE_STATIC_UPSTREAM,TOP_LEFT);\r
        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
 BOOL CRebaseDlg::OnInitDialog()\r
@@ -86,13 +100,8 @@ BOOL CRebaseDlg::OnInitDialog()
 \r
        CWnd *pwnd=this->GetDlgItem(IDC_REBASE_DUMY_TAB);\r
        pwnd->GetWindowRect(&rectDummy);\r
+       this->ScreenToClient(rectDummy);\r
 \r
-       rectDummy.top-=20;\r
-       rectDummy.bottom-=20;\r
-\r
-       rectDummy.left-=5;\r
-       rectDummy.right-=5;\r
-       \r
        if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_REBASE_TAB))\r
        {\r
                TRACE0("Failed to create output tab window\n");\r
@@ -127,8 +136,13 @@ BOOL CRebaseDlg::OnInitDialog()
        m_wndOutputRebase.Call(SCI_SETREADONLY, TRUE);\r
        \r
        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 |IDS_STATUSLIST_COLADD|IDS_STATUSLIST_COLDEL , _T("RebaseDlg"),(SVNSLC_POPALL ^ SVNSLC_POPCOMMIT),false);\r
+       m_FileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("RebaseDlg"),(SVNSLC_POPALL ^ SVNSLC_POPCOMMIT),false);\r
 \r
        m_ctrlTabCtrl.AddTab(&m_FileListCtrl,_T("Conflict File"));\r
        m_ctrlTabCtrl.AddTab(&m_LogMessageCtrl,_T("Commit Message"),1);\r
@@ -172,18 +186,46 @@ BOOL CRebaseDlg::OnInitDialog()
 //     m_CommitList.m_IsOldFirst = TRUE;\r
        m_CommitList.m_IsRebaseReplaceGraph = TRUE;\r
 \r
-       m_CommitList.DeleteAllItems();\r
        m_CommitList.InsertGitColumn();\r
 \r
-       FetchLogList();\r
-       SetContinueButtonText();\r
        this->SetControlEnable();\r
 \r
+       if(!this->m_PreCmd.IsEmpty())\r
+       {\r
+               CProgressDlg progress;\r
+               progress.m_GitCmd=m_PreCmd;\r
+               progress.m_bAutoCloseOnSuccess=true;\r
+               progress.DoModal();\r
+       }\r
+\r
+       if(m_IsCherryPick)\r
+       {\r
+               this->m_BranchCtrl.SetCurSel(-1);\r
+               this->m_BranchCtrl.EnableWindow(FALSE);\r
+               this->m_UpstreamCtrl.EnableWindow(FALSE);\r
+               this->SetWindowText(_T("Cherry Pick"));\r
+               this->m_CommitList.StartFilter();\r
+\r
+       }else\r
+       {\r
+               SetContinueButtonText();\r
+               m_CommitList.DeleteAllItems();\r
+               FetchLogList();\r
+       }\r
+\r
        m_CommitList.m_ContextMenuMask &= ~(m_CommitList.GetContextMenuBit(CGitLogListBase::ID_CHERRY_PICK)|\r
                                                                                m_CommitList.GetContextMenuBit(CGitLogListBase::ID_SWITCHTOREV)|\r
                                                                                m_CommitList.GetContextMenuBit(CGitLogListBase::ID_RESET)|\r
                                                                                m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REVERTREV)|\r
-                                                                               m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV));\r
+                                                                               m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_TO_VERSION)|\r
+                                                                               m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV)|\r
+                                                                               m_CommitList.GetContextMenuBit(CGitLogListBase::ID_COMBINE_COMMIT));\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
 \r
        return TRUE;\r
 }\r
@@ -270,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
@@ -343,6 +386,29 @@ void CRebaseDlg::LoadBranchInfo()
        AddBranchToolTips(&m_BranchCtrl);\r
        AddBranchToolTips(&m_UpstreamCtrl);\r
 \r
+       if(!m_Upstream.IsEmpty())\r
+       {\r
+               m_UpstreamCtrl.AddString(m_Upstream);\r
+               m_UpstreamCtrl.SetCurSel(m_UpstreamCtrl.GetCount()-1);\r
+       }\r
+       else\r
+       {\r
+               //Select pull-remote from current branch\r
+               CString currentBranch = g_Git.GetSymbolicRef();\r
+               CString configName;\r
+               configName.Format(L"branch.%s.remote", currentBranch);\r
+               CString pullRemote = g_Git.GetConfigValue(configName);\r
+\r
+               //Select pull-branch from current branch\r
+               configName.Format(L"branch.%s.merge", currentBranch);\r
+               CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));\r
+\r
+               CString defaultUpstream;\r
+               defaultUpstream.Format(L"remotes/%s/%s", pullRemote, pullBranch);\r
+               int found = m_UpstreamCtrl.FindStringExact(0, defaultUpstream);\r
+               if(found >= 0)\r
+                       m_UpstreamCtrl.SetCurSel(found);\r
+       }\r
 }\r
 \r
 void CRebaseDlg::OnCbnSelchangeBranch()\r
@@ -357,12 +423,82 @@ void CRebaseDlg::OnCbnSelchangeUpstream()
 \r
 void CRebaseDlg::FetchLogList()\r
 {\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
+               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
+                       CMessageBox::Show(NULL,base,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
+                       return;\r
+               }\r
+               hash=hash.Left(40);\r
+               \r
+               if( base == hash )\r
+               {\r
+                       m_CommitList.Clear();\r
+                       CString text,fmt;\r
+                       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
+\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 Rebase"));\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
@@ -383,7 +519,7 @@ void CRebaseDlg::FetchLogList()
        {\r
                m_CommitList.m_logEntries[i].m_Action = CTGitPath::LOGACTIONS_REBASE_PICK;\r
        }\r
-       \r
+\r
        m_CommitList.Invalidate();\r
 \r
        if(m_CommitList.m_IsOldFirst)\r
@@ -391,6 +527,8 @@ void CRebaseDlg::FetchLogList()
        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
@@ -438,18 +576,23 @@ int CRebaseDlg::CheckRebaseCondition()
                return -1;\r
 \r
        //Todo call pre_rebase_hook\r
+       return 0;\r
 }\r
 int CRebaseDlg::StartRebase()\r
 {\r
        CString cmd,out;\r
-       //Todo call comment_for_reflog\r
-       cmd.Format(_T("git.exe checkout %s"),this->m_BranchCtrl.GetString());\r
-       this->AddLogString(cmd);\r
+       m_FileListCtrl.m_bIsRevertTheirMy = !m_IsCherryPick;\r
+       if(!this->m_IsCherryPick)\r
+       {\r
+               //Todo call comment_for_reflog\r
+               cmd.Format(_T("git.exe checkout %s"),this->m_BranchCtrl.GetString());\r
+               this->AddLogString(cmd);\r
 \r
-       if(g_Git.Run(cmd,&out,CP_UTF8))\r
-               return -1;\r
+               if(g_Git.Run(cmd,&out,CP_UTF8))\r
+                       return -1;\r
 \r
-       this->AddLogString(out);\r
+               this->AddLogString(out);\r
+       }\r
 \r
        cmd=_T("git.exe rev-parse --verify HEAD");\r
        if(g_Git.Run(cmd,&out,CP_UTF8))\r
@@ -468,32 +611,39 @@ int CRebaseDlg::StartRebase()
                return -1;\r
        }\r
        \r
-       cmd.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));\r
-\r
-       cmd.Format(_T("git.exe checkout %s"),this->m_UpstreamCtrl.GetString());\r
-       this->AddLogString(cmd);\r
-\r
-       out.Empty();\r
-       if(g_Git.Run(cmd,&out,CP_UTF8))\r
+       if( !this->m_IsCherryPick )\r
        {\r
-               return -1;\r
+               cmd.Format(_T("git.exe checkout %s"),this->m_UpstreamCtrl.GetString());\r
+               this->AddLogString(cmd);\r
+\r
+               out.Empty();\r
+               if(g_Git.Run(cmd,&out,CP_UTF8))\r
+               {\r
+                       return -1;\r
+               }\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
+       m_OrigUpstreamHash.Empty();\r
+       m_OrigUpstreamHash= g_Git.GetHash(this->m_UpstreamCtrl.GetString());\r
+       if(m_OrigUpstreamHash.IsEmpty())\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
+       if( !this->m_IsCherryPick )\r
        {\r
-               this->AddLogString(m_OrigBranchHash);\r
-               return -1;\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
+               this->AddLogString(_T("Start Rebase\r\n"));\r
 \r
-       this->AddLogString(_T("Start Rebase\r\n"));\r
+       }else\r
+               this->AddLogString(_T("Start Cherry-pick\r\n"));\r
+       \r
        return 0;\r
 }\r
 int  CRebaseDlg::VerifyNoConflict()\r
@@ -512,30 +662,100 @@ int  CRebaseDlg::VerifyNoConflict()
        return 0;\r
 \r
 }\r
+int CRebaseDlg::FinishRebase()\r
+{\r
+       if(this->m_IsCherryPick) //cherry pick mode no "branch", working at upstream branch\r
+               return 0;\r
+\r
+       CString cmd,out;\r
+       cmd.Format(_T("git.exe branch -f %s"),this->m_BranchCtrl.GetString());\r
+       if(g_Git.Run(cmd,&out,CP_UTF8))\r
+       {\r
+               AddLogString(out);\r
+               return -1;\r
+       }\r
+       out.Empty();\r
+       cmd.Format(_T("git.exe reset --hard %s"),this->m_OrigUpstreamHash);\r
+       if(g_Git.Run(cmd,&out,CP_UTF8))\r
+       {\r
+               AddLogString(out);\r
+               return -1;\r
+       }\r
+       out.Empty();\r
+       cmd.Format(_T("git.exe checkout -f %s"),this->m_BranchCtrl.GetString());\r
+       if(g_Git.Run(cmd,&out,CP_UTF8))\r
+       {\r
+               AddLogString(out);\r
+               return -1;\r
+       }\r
+       return 0;\r
+}\r
 void CRebaseDlg::OnBnClickedContinue()\r
 {\r
-       if( m_RebaseStage == CHOOSE_BRANCH|| m_RebaseStage == CHOOSE_COMMIT_PICK_MODE )\r
+       if( m_RebaseStage == REBASE_DONE)\r
        {\r
-               if(CheckRebaseCondition())\r
-                       return ;\r
-               m_RebaseStage = REBASE_START;\r
+               OnOK();\r
+               return;\r
        }\r
 \r
-       if( m_RebaseStage == REBASE_FINISH )\r
+       if( this->m_IsFastForward )\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
+               CString oldbranch = g_Git.GetCurrentBranch();\r
+               if( oldbranch != m_BranchCtrl.GetString() )\r
                {\r
-                       AddLogString(out);\r
-                       return ;\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
-               cmd.Format(_T("git reset --hard %s"),this->m_OrigUpstreamHash);\r
-               if(g_Git.Run(cmd,&out,CP_UTF8))\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
+                       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
+                       return ;\r
+               m_RebaseStage = REBASE_START;\r
+       }\r
+\r
+\r
+       if( m_RebaseStage == REBASE_FINISH )\r
+       {\r
+               if(FinishRebase())\r
+                       return ;\r
+\r
                OnOK();\r
        }\r
 \r
@@ -661,6 +881,11 @@ int CRebaseDlg::CheckNextCommitIsSquash()
        GitRev *curRev;\r
        do\r
        {\r
+               if(index<0)\r
+                       return -1;\r
+               if(index>= m_CommitList.GetItemCount())\r
+                       return -1;\r
+\r
                curRev=(GitRev*)m_CommitList.m_arShownList[index];\r
                \r
                if( curRev->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH )\r
@@ -672,12 +897,7 @@ int CRebaseDlg::CheckNextCommitIsSquash()
                        else\r
                                index--;\r
                }else\r
-                       return -1;\r
-\r
-               if(index<0)\r
-                       return -1;\r
-               if(index>= m_CommitList.GetItemCount())\r
-                       return -1;\r
+                       return -1;              \r
 \r
        }while(curRev->m_Action&CTGitPath::LOGACTIONS_REBASE_SKIP);\r
        \r
@@ -715,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
@@ -739,6 +962,10 @@ void CRebaseDlg::SetContinueButtonText()
        case REBASE_FINISH:\r
                Text = _T("Finish");\r
                break;\r
+\r
+       case REBASE_DONE:\r
+               Text = _T("Done");\r
+               break;\r
        }\r
        this->GetDlgItem(IDC_REBASE_CONTINUE)->SetWindowText(Text);\r
 }\r
@@ -753,8 +980,13 @@ 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
-               this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH)->EnableWindow(TRUE);\r
-               this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM)->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
                                                                                                m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH)|\r
@@ -769,16 +1001,27 @@ void CRebaseDlg::SetControlEnable()
        case REBASE_CONFLICT:\r
        case REBASE_EDIT:\r
        case REBASE_SQUASH_CONFLICT:\r
+       case REBASE_DONE:\r
                this->GetDlgItem(IDC_PICK_ALL)->EnableWindow(FALSE);\r
                this->GetDlgItem(IDC_EDIT_ALL)->EnableWindow(FALSE);\r
                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
@@ -807,7 +1050,7 @@ void CRebaseDlg::UpdateProgress()
        m_ProgressBar.SetRange(1,m_CommitList.GetItemCount());\r
        m_ProgressBar.SetPos(index);\r
 \r
-       if(m_CurrentRebaseIndex>0 && m_CurrentRebaseIndex< m_CommitList.GetItemCount())\r
+       if(m_CurrentRebaseIndex>=0 && m_CurrentRebaseIndex< m_CommitList.GetItemCount())\r
        {\r
                CString text;\r
                text.Format(_T("Rebasing...(%d/%d)"),index,m_CommitList.GetItemCount());\r
@@ -845,7 +1088,7 @@ void CRebaseDlg::UpdateProgress()
 \r
 void CRebaseDlg::UpdateCurrentStatus()\r
 {\r
-       if( m_CurrentRebaseIndex < 0)\r
+       if( m_CurrentRebaseIndex < 0 && m_RebaseStage!= REBASE_DONE)\r
        {\r
                if(m_CommitList.m_IsOldFirst)\r
                        m_RebaseStage = CRebaseDlg::REBASE_START;\r
@@ -853,12 +1096,12 @@ void CRebaseDlg::UpdateCurrentStatus()
                        m_RebaseStage = CRebaseDlg::REBASE_FINISH;\r
        }\r
 \r
-       if( m_CurrentRebaseIndex == m_CommitList.m_arShownList.GetSize())\r
+       if( m_CurrentRebaseIndex == m_CommitList.m_arShownList.GetSize() && m_RebaseStage!= REBASE_DONE)\r
        {\r
                if(m_CommitList.m_IsOldFirst)\r
-                       m_RebaseStage = CRebaseDlg::REBASE_FINISH;\r
+                       m_RebaseStage = CRebaseDlg::REBASE_DONE;\r
                else\r
-                       m_RebaseStage = CRebaseDlg::REBASE_START;\r
+                       m_RebaseStage = CRebaseDlg::REBASE_FINISH;\r
        }\r
 \r
        SetContinueButtonText();\r
@@ -940,8 +1183,10 @@ int CRebaseDlg::DoRebase()
                                return 0;\r
                        }\r
                        if(mode == CTGitPath::LOGACTIONS_REBASE_EDIT)\r
+                       {\r
+                               this->m_RebaseStage = REBASE_EDIT ;\r
                                return -1; // Edit return -1 to stop rebase. \r
-                       \r
+                       }\r
                        // Squash Case\r
                        if(CheckNextCommitIsSquash())\r
                        {   // no squash\r
@@ -965,7 +1210,10 @@ int CRebaseDlg::DoRebase()
                        return 0;\r
                }\r
                if(mode == CTGitPath::LOGACTIONS_REBASE_EDIT)\r
+               {\r
+                       this->m_RebaseStage = REBASE_EDIT ;\r
                        return -1; // Edit return -1 to stop rebase. \r
+               }\r
 \r
                // Squash Case\r
                if(CheckNextCommitIsSquash())\r
@@ -1009,18 +1257,27 @@ int CRebaseDlg::RebaseThread()
                        {\r
                                ret = 0;\r
                                m_RebaseStage = REBASE_FINISH;\r
-                               break;\r
-                       }\r
-\r
-                       ret = DoRebase();\r
+                               \r
+                       }else\r
+                       {\r
+                               ret = DoRebase();\r
 \r
-                       if( ret )\r
-                       {       \r
-                               break;\r
+                               if( ret )\r
+                               {       \r
+                                       break;\r
+                               }\r
                        }\r
 \r
+               }else if( m_RebaseStage == REBASE_FINISH )\r
+               {                       \r
+                       FinishRebase();\r
+                       m_RebaseStage = REBASE_DONE;\r
+                       break;\r
+                       \r
                }else\r
+               {\r
                        break;\r
+               }\r
                this->PostMessage(MSG_REBASE_UPDATE_UI);\r
                //this->UpdateCurrentStatus();\r
        }\r
@@ -1037,8 +1294,11 @@ void CRebaseDlg::ListConflictFile()
        CTGitPath path;\r
        list.AddPath(path);\r
 \r
-       this->m_FileListCtrl.GetStatus(list,true);\r
-       this->m_FileListCtrl.Show(CTGitPath::LOGACTIONS_UNMERGED|CTGitPath::LOGACTIONS_MODIFIED,CTGitPath::LOGACTIONS_UNMERGED);\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
        if( this->m_FileListCtrl.GetItemCount() == 0 )\r
        {\r
                \r
@@ -1084,11 +1344,35 @@ void CRebaseDlg::OnBnClickedAbort()
        CString cmd,out;\r
        if(m_OrigUpstreamHash.IsEmpty())\r
        {\r
-               this->OnCancel();\r
+               __super::OnCancel();\r
        }\r
-       if(CMessageBox::Show(NULL,_T("Are you sure abort rebase"),_T("TortoiseGit"),MB_YESNO) != IDYES)\r
+       \r
+       if(m_RebaseStage == CHOOSE_BRANCH || m_RebaseStage== CHOOSE_COMMIT_PICK_MODE)\r
+       {\r
+               return;\r
+       }\r
+\r
+       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
+               AddLogString(out);\r
+               return ;\r
+       }\r
+\r
        cmd.Format(_T("git.exe reset --hard  %s"),this->m_OrigUpstreamHash.Left(40));\r
        if(g_Git.Run(cmd,&out,CP_UTF8))\r
        {\r
@@ -1096,6 +1380,9 @@ void CRebaseDlg::OnBnClickedAbort()
                return ;\r
        }\r
        \r
+       if(this->m_IsCherryPick) //there are not "branch" at cherry pick mode\r
+               return;\r
+\r
        cmd.Format(_T("git checkout -f %s"),this->m_BranchCtrl.GetString());\r
        if(g_Git.Run(cmd,&out,CP_UTF8))\r
        {\r
@@ -1103,5 +1390,38 @@ void CRebaseDlg::OnBnClickedAbort()
                return ;\r
        }\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
 }\r
+\r
+void CRebaseDlg::OnBnClickedButtonBrowse()\r
+{\r
+       if(CBrowseRefsDlg::PickRefForCombo(&m_UpstreamCtrl, gPickRef_NoTag))\r
+               OnCbnSelchangeUpstream();\r
+}\r
+\r
+void CRebaseDlg::OnBnClickedRebaseCheckForce()\r
+{\r
+       // TODO: Add your control notification handler code here\r
+       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