From 1660dd8d76b66ec293ed7d136c3c5f9054043f87 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Wed, 12 Oct 2011 01:59:09 +0200 Subject: [PATCH] refactored Signed-off-by: Sven Strickroth --- src/TortoiseProc/AppUtils.cpp | 65 ++++++++++++++++++++++++------------------- src/TortoiseProc/AppUtils.h | 1 + 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/TortoiseProc/AppUtils.cpp b/src/TortoiseProc/AppUtils.cpp index a360db82b..689795f3c 100644 --- a/src/TortoiseProc/AppUtils.cpp +++ b/src/TortoiseProc/AppUtils.cpp @@ -1188,40 +1188,49 @@ bool CAppUtils::Switch(CString *CommitHash, CString initialRefName, bool autoclo if (dlg.DoModal() == IDOK) { - CString cmd; - CString track; -// CString base; - CString force; CString branch; + if (dlg.m_bBranch) + branch = dlg.m_NewBranch; - if(dlg.m_bBranch){ - if (dlg.m_bBranchOverride) - { - branch.Format(_T("-B %s"),dlg.m_NewBranch); - } - else - { - branch.Format(_T("-b %s"),dlg.m_NewBranch); - } + return PerformSwitch(dlg.m_VersionName, dlg.m_bForce == TRUE , branch, dlg.m_bBranchOverride == TRUE, dlg.m_bTrack == TRUE, autoclose); + } + return FALSE; +} + +bool CAppUtils::PerformSwitch(CString ref, bool bForce /* false */, CString sNewBranch /* CString() */, bool bBranchOverride /* false */, bool bTrack /* false */, bool autoClose /* false */) +{ + CString cmd; + CString track; + CString force; + CString branch; + + if(!sNewBranch.IsEmpty()){ + if (bBranchOverride) + { + branch.Format(_T("-B %s"), sNewBranch); } - if(dlg.m_bForce) - force=_T("-f"); - if(dlg.m_bTrack) - track=_T("--track"); + else + { + branch.Format(_T("-b %s"), sNewBranch); + } + } + if (bTrack) + track = _T("--track"); + if (bForce) + force = _T("-f"); - cmd.Format(_T("git.exe checkout %s %s %s %s"), - force, - track, - branch, - g_Git.FixBranchName(dlg.m_VersionName)); + cmd.Format(_T("git.exe checkout %s %s %s %s"), + force, + track, + branch, + g_Git.FixBranchName(ref)); - CProgressDlg progress; - progress.m_bAutoCloseOnSuccess = autoclose; - progress.m_GitCmd=cmd; - if(progress.DoModal()==IDOK) - return TRUE; + CProgressDlg progress; + progress.m_bAutoCloseOnSuccess = autoClose; + progress.m_GitCmd = cmd; + if(progress.DoModal()==IDOK) + return TRUE; - } return FALSE; } diff --git a/src/TortoiseProc/AppUtils.h b/src/TortoiseProc/AppUtils.h index 5570132d9..360581f45 100644 --- a/src/TortoiseProc/AppUtils.h +++ b/src/TortoiseProc/AppUtils.h @@ -163,6 +163,7 @@ public: static bool Export(CString *BashHash=NULL); static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL, bool switch_new_brach=false); static bool Switch(CString *CommitHash, CString initialRefName = CString(), bool autoClose = false); + static bool PerformSwitch(CString ref, bool bForce = false, CString sNewBranch = CString(), bool bBranchOverride = false, bool bTrack = false, bool autoClose = false); // static bool IgnoreFile(CTGitPath &file, bool IsMask); static bool IgnoreFile(CTGitPathList &filelist,bool IsMask); -- 2.11.4.GIT