return refName;\r
}\r
\r
+CString CGit::GetFullRefName(CString shortRefName)\r
+{\r
+ CString refName;\r
+ CString cmd;\r
+ cmd.Format(L"git rev-parse --symbolic-full-name %s", shortRefName);\r
+ if(Run(cmd, &refName, CP_UTF8) != 0)\r
+ return CString();//Error\r
+ int iStart = 0;\r
+ return refName.Tokenize(L"\n", iStart);\r
+}\r
+\r
CString CGit::StripRefName(CString refName)\r
{\r
if(wcsncmp(refName, L"refs/heads/", 11) == 0)\r
int GetRefList(STRING_VECTOR &list);\r
\r
\r
- //Removes 'refs/heads/' or just 'refs'\r
+ //Example: master -> refs/heads/master\r
+ CString GetFullRefName(CString shortRefName);\r
+ //Removes 'refs/heads/' or just 'refs'. Example: refs/heads/master -> master\r
static CString StripRefName(CString refName);\r
\r
};\r
return FALSE;\r
}\r
\r
-bool CAppUtils::Switch(CString *CommitHash)\r
+bool CAppUtils::Switch(CString *CommitHash, CString initialRefName)\r
{\r
CGitSwitchDlg dlg;\r
if(CommitHash)\r
dlg.m_Base=*CommitHash;\r
+ if(!initialRefName.IsEmpty())\r
+ dlg.m_initialRefName = initialRefName;\r
\r
if (dlg.DoModal() == IDOK)\r
{\r
CString cmd;\r
CString track;\r
- CString base;\r
+// CString base;\r
CString force;\r
CString branch;\r
\r
\r
static bool Export(CString *BashHash=NULL);\r
static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL);\r
- static bool Switch(CString *CommitHash);\r
+ static bool Switch(CString *CommitHash, CString initialRefName = CString());\r
\r
// static bool IgnoreFile(CTGitPath &file, bool IsMask);\r
static bool IgnoreFile(CTGitPathList &filelist,bool IsMask);\r
bool bShowDeleteTagOption = false;\r
bool bShowDeleteRemoteBranchOption = false;\r
bool bShowFetchOption = false;\r
+ bool bShowSwitchOption = false;\r
\r
CString fetchFromCmd;\r
\r
{\r
bShowReflogOption = true;\r
bShowDeleteBranchOption = true;\r
+ bShowSwitchOption = true;\r
}\r
else if(selectedLeafs[0]->IsFrom(L"refs/remotes"))\r
{\r
popupMenu.AppendMenuIcon(eCmd_ViewLog, L"Show Log", IDI_LOG);\r
if(bShowReflogOption) popupMenu.AppendMenuIcon(eCmd_ShowReflog, L"Show Reflog", IDI_LOG);\r
if(bShowFetchOption) popupMenu.AppendMenuIcon(eCmd_Fetch, fetchFromCmd, IDI_PULL);\r
+ if(bShowSwitchOption) popupMenu.AppendMenuIcon(eCmd_Switch, L"Switch to this Ref", IDI_SWITCH);\r
if(bShowDeleteTagOption) popupMenu.AppendMenuIcon(eCmd_DeleteTag, L"Delete Tag", IDI_DELETE);\r
if(bShowDeleteBranchOption) popupMenu.AppendMenuIcon(eCmd_DeleteBranch, L"Delete Branch", IDI_DELETE);\r
if(bShowDeleteRemoteBranchOption) popupMenu.AppendMenuIcon(eCmd_DeleteRemoteBranch, L"Delete Remote Branch", IDI_DELETE);\r
Refresh();\r
}\r
break;\r
+ case eCmd_Switch:\r
+ {\r
+ CAppUtils::Switch(NULL, selectedLeafs[0]->GetRefName());\r
+ }\r
+ break;\r
case eCmd_AddRemote:\r
{\r
CAddRemoteDlg(this).DoModal();\r
eCmd_DeleteTag,\r
eCmd_ShowReflog,\r
eCmd_Diff,\r
- eCmd_Fetch\r
+ eCmd_Fetch,\r
+ eCmd_Switch\r
};\r
\r
enum eCol\r
class CChooseVersion\r
{\r
public:\r
+ CString m_initialRefName;\r
\r
private:\r
CWnd * m_pWin;\r
CString resultRef = CBrowseRefsDlg::PickRef(false, m_VersionName, gPickRef_All);\r
if(resultRef.IsEmpty())\r
return;\r
- if(wcsncmp(resultRef,L"refs/",5)==0)\r
- resultRef = resultRef.Mid(5);\r
- if(wcsncmp(resultRef,L"heads/",6)==0)\r
+ SelectRef(resultRef, false);\r
+ }\r
+\r
+ void SelectRef(CString refName, bool bRefNameIsPossiblyNotFullName = true)\r
+ {\r
+ if(bRefNameIsPossiblyNotFullName)\r
+ {\r
+ //Make sure refName is a full ref name first\r
+ CString fullRefName = g_Git.GetFullRefName(refName);\r
+ if(!fullRefName.IsEmpty())\r
+ refName = fullRefName;\r
+ }\r
+\r
+ if(wcsncmp(refName,L"refs/",5)==0)\r
+ refName = refName.Mid(5);\r
+ if(wcsncmp(refName,L"heads/",6)==0)\r
{\r
- resultRef = resultRef.Mid(6);\r
+ refName = refName.Mid(6);\r
SetDefaultChoose(IDC_RADIO_BRANCH);\r
m_ChooseVersioinBranch.SetCurSel(\r
- m_ChooseVersioinBranch.FindStringExact(-1, resultRef));\r
+ m_ChooseVersioinBranch.FindStringExact(-1, refName));\r
}\r
- else if(wcsncmp(resultRef,L"remotes/",8)==0)\r
+ else if(wcsncmp(refName,L"remotes/",8)==0)\r
{\r
SetDefaultChoose(IDC_RADIO_BRANCH);\r
m_ChooseVersioinBranch.SetCurSel(\r
- m_ChooseVersioinBranch.FindStringExact(-1, resultRef));\r
+ m_ChooseVersioinBranch.FindStringExact(-1, refName));\r
}\r
- else if(wcsncmp(resultRef,L"tags/",5)==0)\r
+ else if(wcsncmp(refName,L"tags/",5)==0)\r
{\r
- resultRef = resultRef.Mid(5);\r
+ refName = refName.Mid(5);\r
SetDefaultChoose(IDC_RADIO_TAGS);\r
m_ChooseVersioinTags.SetCurSel(\r
- m_ChooseVersioinTags.FindStringExact(-1, resultRef));\r
+ m_ChooseVersioinTags.FindStringExact(-1, refName));\r
}\r
OnVersionChanged();\r
}\r
m_ChooseVersioinBranch.SetCurSel(current);\r
\r
\r
- OnVersionChanged();\r
+ if(m_initialRefName.IsEmpty())\r
+ OnVersionChanged();\r
+ else\r
+ SelectRef(m_initialRefName);\r
}\r
public: \r
CString m_VersionName;\r