Skip to content

Commit 5b7ec5f

Browse files
fetch tags on update and fix tests
1 parent 9906874 commit 5b7ec5f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

get_git.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ func (g *GitGetter) update(ctx context.Context, dst, sshKeyFile string, u *url.U
251251
return err
252252
}
253253

254+
// Fetch the remote ref
255+
cmd = exec.CommandContext(ctx, "git", "fetch", "--tags")
256+
cmd.Dir = dst
257+
err = getRunCommand(cmd)
258+
if err != nil {
259+
return err
260+
}
261+
254262
// Fetch the remote ref
255263
cmd = exec.CommandContext(ctx, "git", "fetch", "origin", "--", ref)
256264
cmd.Dir = dst
@@ -273,10 +281,11 @@ func (g *GitGetter) update(ctx context.Context, dst, sshKeyFile string, u *url.U
273281
return err
274282
}
275283

284+
// Pull the latest changes from the ref branch
276285
if depth > 0 {
277-
cmd = exec.CommandContext(ctx, "git", "pull", "--depth", strconv.Itoa(depth), "--ff-only")
286+
cmd = exec.CommandContext(ctx, "git", "pull", "origin", "--depth", strconv.Itoa(depth), "--ff-only", "--", ref)
278287
} else {
279-
cmd = exec.CommandContext(ctx, "git", "pull", "--ff-only")
288+
cmd = exec.CommandContext(ctx, "git", "pull", "origin", "--ff-only", "--", ref)
280289
}
281290

282291
cmd.Dir = dst

get_git_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ func TestGitGetter_remoteWithoutMaster(t *testing.T) {
169169
t.Fatalf("err: %s", err)
170170
}
171171

172+
dst2 := tempDir(t)
172173
// Get again should work
173-
if err := g.Get(dst, repo.url); err != nil {
174+
if err := g.Get(dst2, repo.url); err != nil {
174175
t.Fatalf("err: %s", err)
175176
}
176177

0 commit comments

Comments
 (0)