From 3410cd96addf2195269e1fd05964ddc428b3193d Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Tue, 3 Jan 2017 11:29:48 -0500 Subject: [PATCH] Fixed error updating HEAD when cloning a repo. GetHeadBranch() used to return a string of the Branch name, but now returns a type Branch (which is the Refspec, not the name.) The reset call wasn't updated, and was duplicating the refs/heads/ portion of the filename. Fixes #5 --- cmd/reset.go | 2 +- git/refspec.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/reset.go b/cmd/reset.go index f42c8f32..8178c730 100644 --- a/cmd/reset.go +++ b/cmd/reset.go @@ -56,7 +56,7 @@ func Reset(c *git.Client, args []string) { // git reset [mode] commit // First, update the head reference for all modes branchName := c.GetHeadBranch() - err := c.GitDir.WriteFile(git.File("refs/heads/"+branchName), + err := c.GitDir.WriteFile(git.File(branchName.String()), []byte(fmt.Sprintf("%s", commitId)), 0644, ) diff --git a/git/refspec.go b/git/refspec.go index 89110f18..1c749819 100644 --- a/git/refspec.go +++ b/git/refspec.go @@ -34,6 +34,10 @@ func (r RefSpec) Value(c *Client) (string, error) { // Use GetBranch to get a valid branch from a branchname, don't cast from string type Branch RefSpec +// Implements Stringer on Branch +func (b Branch) String() string { + return RefSpec(b).String() +} // Returns a valid Branch object for an existing branch. func GetBranch(c *Client, branchname string) (Branch, error) { b := Branch("refs/heads/" + branchname)