X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=src%2FTortoiseProc%2FRebaseDlg.cpp;h=7af7210066e473ae02d063dc171d7b1335f727c5;hb=51fadc7b392bf8191610c4b32ca677457ec94a25;hp=6ae53491854387dc00dc851410a2270698d03f48;hpb=4a593efce534597f4657ae209ed07a399c510ff2;p=tortoisegit%2FTortoiseGitJp.git diff --git a/src/TortoiseProc/RebaseDlg.cpp b/src/TortoiseProc/RebaseDlg.cpp index 6ae5349..7af7210 100644 --- a/src/TortoiseProc/RebaseDlg.cpp +++ b/src/TortoiseProc/RebaseDlg.cpp @@ -7,6 +7,8 @@ #include "AppUtils.h" #include "MessageBox.h" #include "UnicodeUtils.h" +#include "BrowseRefsDlg.h" +#include "ProgressDlg.h" // CRebaseDlg dialog IMPLEMENT_DYNAMIC(CRebaseDlg, CResizableStandAloneDialog) @@ -21,6 +23,8 @@ CRebaseDlg::CRebaseDlg(CWnd* pParent /*=NULL*/) m_CurrentRebaseIndex=-1; m_bThreadRunning =FALSE; this->m_IsCherryPick = FALSE; + m_bForce=FALSE; + m_IsFastForward=FALSE; } CRebaseDlg::~CRebaseDlg() @@ -39,6 +43,7 @@ void CRebaseDlg::DoDataExchange(CDataExchange* pDX) DDX_Control(pDX,IDC_COMMIT_LIST,m_CommitList); DDX_Control(pDX,IDC_REBASE_COMBOXEX_BRANCH, this->m_BranchCtrl); DDX_Control(pDX,IDC_REBASE_COMBOXEX_UPSTREAM, this->m_UpstreamCtrl); + DDX_Check(pDX, IDC_REBASE_CHECK_FORCE,m_bForce); } @@ -54,6 +59,10 @@ BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog) ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH, &CRebaseDlg::OnCbnSelchangeBranch) ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM, &CRebaseDlg::OnCbnSelchangeUpstream) ON_MESSAGE(MSG_REBASE_UPDATE_UI, OnRebaseUpdateUI) + ON_BN_CLICKED(IDC_BUTTON_BROWSE, &CRebaseDlg::OnBnClickedButtonBrowse) + ON_BN_CLICKED(IDC_REBASE_CHECK_FORCE, &CRebaseDlg::OnBnClickedRebaseCheckForce) + ON_STN_CLICKED(IDC_STATUS_STATIC, &CRebaseDlg::OnStnClickedStatusStatic) + ON_BN_CLICKED(IDC_REBASE_POST_BUTTON, &CRebaseDlg::OnBnClickedRebasePostButton) END_MESSAGE_MAP() void CRebaseDlg::AddRebaseAnchor() @@ -72,6 +81,10 @@ void CRebaseDlg::AddRebaseAnchor() AddAnchor(IDC_REBASE_COMBOXEX_BRANCH,TOP_LEFT); AddAnchor(IDC_REBASE_STATIC_UPSTREAM,TOP_LEFT); AddAnchor(IDC_REBASE_STATIC_BRANCH,TOP_LEFT); + AddAnchor(IDHELP, BOTTOM_RIGHT); + AddAnchor(IDC_REBASE_CHECK_FORCE,TOP_RIGHT); + AddAnchor(IDC_REBASE_POST_BUTTON,BOTTOM_LEFT); + this->AddOthersToAnchor(); } @@ -123,8 +136,13 @@ BOOL CRebaseDlg::OnInitDialog() m_wndOutputRebase.Call(SCI_SETREADONLY, TRUE); m_tooltips.Create(this); + + m_tooltips.AddTool(IDC_REBASE_CHECK_FORCE,IDS_REBASE_FORCE_TT); + m_tooltips.AddTool(IDC_REBASE_ABORT,IDS_REBASE_ABORT_TT); + + - m_FileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |IDS_STATUSLIST_COLADD|IDS_STATUSLIST_COLDEL , _T("RebaseDlg"),(SVNSLC_POPALL ^ SVNSLC_POPCOMMIT),false); + m_FileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("RebaseDlg"),(SVNSLC_POPALL ^ SVNSLC_POPCOMMIT),false); m_ctrlTabCtrl.AddTab(&m_FileListCtrl,_T("Conflict File")); m_ctrlTabCtrl.AddTab(&m_LogMessageCtrl,_T("Commit Message"),1); @@ -172,6 +190,14 @@ BOOL CRebaseDlg::OnInitDialog() this->SetControlEnable(); + if(!this->m_PreCmd.IsEmpty()) + { + CProgressDlg progress; + progress.m_GitCmd=m_PreCmd; + progress.m_bAutoCloseOnSuccess=true; + progress.DoModal(); + } + if(m_IsCherryPick) { this->m_BranchCtrl.SetCurSel(-1); @@ -286,6 +312,7 @@ void CRebaseDlg::DoSize(int delta) CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL),0,delta); CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL),0,delta); CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL),0,delta); + CSplitterControl::ChangePos(GetDlgItem(IDC_REBASE_CHECK_FORCE),0,delta); this->AddRebaseAnchor(); // adjust the minimum size of the dialog to prevent the resizing from @@ -364,6 +391,24 @@ void CRebaseDlg::LoadBranchInfo() m_UpstreamCtrl.AddString(m_Upstream); m_UpstreamCtrl.SetCurSel(m_UpstreamCtrl.GetCount()-1); } + else + { + //Select pull-remote from current branch + CString currentBranch = g_Git.GetSymbolicRef(); + CString configName; + configName.Format(L"branch.%s.remote", currentBranch); + CString pullRemote = g_Git.GetConfigValue(configName); + + //Select pull-branch from current branch + configName.Format(L"branch.%s.merge", currentBranch); + CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName)); + + CString defaultUpstream; + defaultUpstream.Format(L"remotes/%s/%s", pullRemote, pullBranch); + int found = m_UpstreamCtrl.FindStringExact(0, defaultUpstream); + if(found >= 0) + m_UpstreamCtrl.SetCurSel(found); + } } void CRebaseDlg::OnCbnSelchangeBranch() @@ -378,12 +423,82 @@ void CRebaseDlg::OnCbnSelchangeUpstream() void CRebaseDlg::FetchLogList() { + CString base,hash; + CString cmd; + m_IsFastForward=FALSE; + cmd.Format(_T("git.exe merge-base %s %s"), m_UpstreamCtrl.GetString(),m_BranchCtrl.GetString()); + if(g_Git.Run(cmd,&base,CP_ACP)) + { + CMessageBox::Show(NULL,base,_T("TortoiseGit"),MB_OK|MB_ICONERROR); + return; + } + base=base.Left(40); + + hash=g_Git.GetHash(m_BranchCtrl.GetString()); + + if(hash == g_Git.GetHash(this->m_UpstreamCtrl.GetString())) + { + m_CommitList.Clear(); + CString text,fmt; + fmt.LoadString(IDS_REBASE_EQUAL_FMT); + text.Format(fmt,m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString()); + + m_CommitList.ShowText(text); + this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(false); + return; + } + + hash=hash.Left(40); + + if(hash == base ) + { + //fast forword + this->m_IsFastForward=TRUE; + + m_CommitList.Clear(); + CString text,fmt; + fmt.LoadString(IDS_REBASE_FASTFORWARD_FMT); + text.Format(fmt,m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString(), + m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString()); + + m_CommitList.ShowText(text); + this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(true); + SetContinueButtonText(); + + return ; + } + + hash.Empty(); + + if(!this->m_bForce) + { + cmd.Format(_T("git.exe rev-parse %s"), m_UpstreamCtrl.GetString()); + if( g_Git.Run(cmd,&hash,CP_ACP)) + { + CMessageBox::Show(NULL,base,_T("TortoiseGit"),MB_OK|MB_ICONERROR); + return; + } + hash=hash.Left(40); + + if( base == hash ) + { + m_CommitList.Clear(); + CString text,fmt; + fmt.LoadString(IDS_REBASE_UPTODATE_FMT); + text.Format(fmt,m_BranchCtrl.GetString()); + m_CommitList.ShowText(text); + this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(m_CommitList.GetItemCount()); + SetContinueButtonText(); + return; + } + } + m_CommitList.Clear(); this->m_CommitList.FillGitLog(NULL,0,&m_UpstreamCtrl.GetString(),&m_BranchCtrl.GetString()); if( m_CommitList.GetItemCount() == 0 ) - m_CommitList.ShowText(_T("Nothing Rebase")); + m_CommitList.ShowText(_T("Nothing to Rebase")); - CString hash=g_Git.GetHash(m_UpstreamCtrl.GetString()); + hash=g_Git.GetHash(m_UpstreamCtrl.GetString()); #if 0 if(m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash.size() >=0 ) @@ -404,7 +519,7 @@ void CRebaseDlg::FetchLogList() { m_CommitList.m_logEntries[i].m_Action = CTGitPath::LOGACTIONS_REBASE_PICK; } - + m_CommitList.Invalidate(); if(m_CommitList.m_IsOldFirst) @@ -412,6 +527,8 @@ void CRebaseDlg::FetchLogList() else this->m_CurrentRebaseIndex = m_CommitList.m_logEntries.size(); + this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(m_CommitList.GetItemCount()); + SetContinueButtonText(); } void CRebaseDlg::AddBranchToolTips(CHistoryCombo *pBranch) @@ -464,7 +581,7 @@ int CRebaseDlg::CheckRebaseCondition() int CRebaseDlg::StartRebase() { CString cmd,out; - + m_FileListCtrl.m_bIsRevertTheirMy = !m_IsCherryPick; if(!this->m_IsCherryPick) { //Todo call comment_for_reflog @@ -575,6 +692,57 @@ int CRebaseDlg::FinishRebase() } void CRebaseDlg::OnBnClickedContinue() { + if( m_RebaseStage == REBASE_DONE) + { + OnOK(); + return; + } + + if( this->m_IsFastForward ) + { + CString cmd,out; + CString oldbranch = g_Git.GetCurrentBranch(); + if( oldbranch != m_BranchCtrl.GetString() ) + { + cmd.Format(_T("git.exe checkout %s"),m_BranchCtrl.GetString()); + AddLogString(cmd); + if( g_Git.Run(cmd,&out,CP_ACP) ) + { + this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG); + AddLogString(out); + return; + } + } + AddLogString(out); + out.Empty(); + m_OrigBranchHash = g_Git.GetHash(m_BranchCtrl.GetString()); + m_OrigUpstreamHash = g_Git.GetHash(this->m_UpstreamCtrl.GetString()); + + if(!g_Git.IsFastForward(this->m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString())) + { + this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG); + AddLogString(_T("No fast forward\r\nMaybe repository changed")); + return; + } + + cmd.Format(_T("git.exe reset --hard %s"),this->m_UpstreamCtrl.GetString()); + this->AddLogString(CString(_T("Fast forward to "))+m_UpstreamCtrl.GetString()); + + AddLogString(cmd); + this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG); + if(g_Git.Run(cmd,&out,CP_ACP)) + { + AddLogString(_T("Fail")); + AddLogString(out); + return; + } + AddLogString(out); + AddLogString(_T("Done")); + m_RebaseStage = REBASE_DONE; + UpdateCurrentStatus(); + return; + + } if( m_RebaseStage == CHOOSE_BRANCH|| m_RebaseStage == CHOOSE_COMMIT_PICK_MODE ) { if(CheckRebaseCondition()) @@ -582,10 +750,6 @@ void CRebaseDlg::OnBnClickedContinue() m_RebaseStage = REBASE_START; } - if( m_RebaseStage == REBASE_DONE) - { - OnOK(); - } if( m_RebaseStage == REBASE_FINISH ) { @@ -771,7 +935,10 @@ void CRebaseDlg::SetContinueButtonText() { case CHOOSE_BRANCH: case CHOOSE_COMMIT_PICK_MODE: - Text = _T("Start"); + if(this->m_IsFastForward) + Text = _T("Start(FastFwd)"); + else + Text = _T("Start"); break; case REBASE_START: @@ -843,6 +1010,13 @@ void CRebaseDlg::SetControlEnable() m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH)| m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT)| m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP)); + + if( m_RebaseStage == REBASE_DONE && (!this->m_PostButtonText.IsEmpty()) ) + { + this->GetDlgItem(IDC_STATUS_STATIC)->ShowWindow(SW_HIDE); + this->GetDlgItem(IDC_REBASE_POST_BUTTON)->ShowWindow(SW_SHOWNORMAL); + this->GetDlgItem(IDC_REBASE_POST_BUTTON)->SetWindowText(this->m_PostButtonText); + } break; } @@ -1115,6 +1289,8 @@ void CRebaseDlg::ListConflictFile() CTGitPath path; list.AddPath(path); + m_FileListCtrl.m_bIsRevertTheirMy = !m_IsCherryPick; + this->m_FileListCtrl.GetStatus(&list,true); this->m_FileListCtrl.Show(CTGitPath::LOGACTIONS_UNMERGED|CTGitPath::LOGACTIONS_MODIFIED|CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_DELETED, CTGitPath::LOGACTIONS_UNMERGED); @@ -1171,9 +1347,20 @@ void CRebaseDlg::OnBnClickedAbort() return; } - if(CMessageBox::Show(NULL,_T("Are you sure abort rebase"),_T("TortoiseGit"),MB_YESNO) != IDYES) + if(CMessageBox::Show(NULL,_T("Are you sure you want to abort the rebase process?"),_T("TortoiseGit"),MB_YESNO) != IDYES) return; + if(this->m_IsFastForward) + { + cmd.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash.Left(40)); + if(g_Git.Run(cmd,&out,CP_UTF8)) + { + AddLogString(out); + return ; + } + __super::OnCancel(); + return; + } cmd.Format(_T("git.exe checkout -f %s"),this->m_UpstreamCtrl.GetString()); if(g_Git.Run(cmd,&out,CP_UTF8)) { @@ -1206,3 +1393,30 @@ void CRebaseDlg::OnBnClickedAbort() } __super::OnCancel(); } + +void CRebaseDlg::OnBnClickedButtonBrowse() +{ + if(CBrowseRefsDlg::PickRefForCombo(&m_UpstreamCtrl, gPickRef_NoTag)) + OnCbnSelchangeUpstream(); +} + +void CRebaseDlg::OnBnClickedRebaseCheckForce() +{ + // TODO: Add your control notification handler code here + this->UpdateData(); + this->FetchLogList(); +} + +void CRebaseDlg::OnStnClickedStatusStatic() +{ + // TODO: Add your control notification handler code here +} + +void CRebaseDlg::OnBnClickedRebasePostButton() +{ + // TODO: Add your control notification handler code here + this->m_Upstream=this->m_UpstreamCtrl.GetString(); + this->m_Branch=this->m_BranchCtrl.GetString(); + + this->EndDialog(IDC_REBASE_POST_BUTTON); +}