diff options
Diffstat (limited to 'pkg/vcs/git.go')
| -rw-r--r-- | pkg/vcs/git.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go index 71fcac97a..0bd72d9a6 100644 --- a/pkg/vcs/git.go +++ b/pkg/vcs/git.go @@ -134,17 +134,21 @@ func (git *git) CheckoutCommit(repo, commit string) (*Commit, error) { if err := git.repair(); err != nil { return nil, err } - if err := git.fetchRemote(repo); err != nil { + if err := git.fetchRemote(repo, commit); err != nil { return nil, err } return git.SwitchCommit(commit) } -func (git *git) fetchRemote(repo string) error { +func (git *git) fetchRemote(repo, commit string) error { repoHash := hash.String([]byte(repo)) // Ignore error as we can double add the same remote and that will fail. git.git("remote", "add", repoHash, repo) - _, err := git.git("fetch", "--force", "--tags", repoHash) + fetchArgs := []string{"fetch", "--force", "--tags", repoHash} + if commit != "" { + fetchArgs = append(fetchArgs, commit) + } + _, err := git.git(fetchArgs...) if err != nil { var verbose *osutil.VerboseError if errors.As(err, &verbose) && |
