From f3c9957806e53e07de6c36da01736aa5bbbca2bf Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Mon, 15 Jan 2024 17:07:26 +0100 Subject: pkg/vcs: make git fetch calls more specific This should make syzkaller only fetch the commits relevant for further processing. Also, specifying the exact commit/branch name to fetch allows us to access commits from custom refs. Test the new behaviour and double-check that remote tags fetch was not broken. --- pkg/vcs/git.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'pkg/vcs/git.go') 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) && -- cgit mrf-deployment