diff --git a/get_git.go b/get_git.go index 8b9a3829..f38e0d29 100644 --- a/get_git.go +++ b/get_git.go @@ -251,6 +251,14 @@ func (g *GitGetter) update(ctx context.Context, dst, sshKeyFile string, u *url.U return err } + // Fetch the remote ref + cmd = exec.CommandContext(ctx, "git", "fetch", "--tags") + cmd.Dir = dst + err = getRunCommand(cmd) + if err != nil { + return err + } + // Fetch the remote ref cmd = exec.CommandContext(ctx, "git", "fetch", "origin", "--", ref) cmd.Dir = dst @@ -273,10 +281,11 @@ func (g *GitGetter) update(ctx context.Context, dst, sshKeyFile string, u *url.U return err } + // Pull the latest changes from the ref branch if depth > 0 { - cmd = exec.CommandContext(ctx, "git", "pull", "--depth", strconv.Itoa(depth), "--ff-only") + cmd = exec.CommandContext(ctx, "git", "pull", "origin", "--depth", strconv.Itoa(depth), "--ff-only", "--", ref) } else { - cmd = exec.CommandContext(ctx, "git", "pull", "--ff-only") + cmd = exec.CommandContext(ctx, "git", "pull", "origin", "--ff-only", "--", ref) } cmd.Dir = dst diff --git a/get_git_test.go b/get_git_test.go index 8e53ce95..64279b76 100644 --- a/get_git_test.go +++ b/get_git_test.go @@ -169,8 +169,9 @@ func TestGitGetter_remoteWithoutMaster(t *testing.T) { t.Fatalf("err: %s", err) } + dst2 := tempDir(t) // Get again should work - if err := g.Get(dst, repo.url); err != nil { + if err := g.Get(dst2, repo.url); err != nil { t.Fatalf("err: %s", err) }