Skip to content

Commit

Permalink
fetch tags on update and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dduzgun-security committed Jun 20, 2024
1 parent 9906874 commit 5b7ec5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions get_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion get_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 5b7ec5f

Please sign in to comment.