Skip to content

Commit

Permalink
update branch if branch is a ref
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Oct 24, 2015
1 parent 883ab98 commit d532f14
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions get_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (g *GitGetter) Get(dst string, u *url.URL) error {
return err
}
if err == nil {
err = g.update(dst, u)
err = g.update(dst, ref)
} else {
err = g.clone(dst, u)
}
Expand Down Expand Up @@ -97,13 +97,22 @@ func (g *GitGetter) clone(dst string, u *url.URL) error {
return getRunCommand(cmd)
}

func (g *GitGetter) update(dst string, u *url.URL) error {
func (g *GitGetter) update(dst string, ref string) error {
// Determine if we're a branch. If we're NOT a branch, then we just
// switch to master prior to checking out
cmd := exec.Command("git", "show-ref", "-q", "--verify", "refs/heads/"+ref)
cmd.Dir = dst
if getRunCommand(cmd) != nil {
// Not a branch, switch to master
ref = "master"
}

// We have to be on a branch to pull
if err := g.checkout(dst, "master"); err != nil {
if err := g.checkout(dst, ref); err != nil {
return err
}

cmd := exec.Command("git", "pull", "--ff-only")
cmd = exec.Command("git", "pull", "--ff-only")
cmd.Dir = dst
return getRunCommand(cmd)
}

0 comments on commit d532f14

Please sign in to comment.