diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-01-15 17:07:26 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-01-17 09:28:36 +0000 |
| commit | f3c9957806e53e07de6c36da01736aa5bbbca2bf (patch) | |
| tree | e0e47ce0cb3ac17bc6df398bd7261984d1162f83 /pkg/vcs/git.go | |
| parent | 974181fc9058dafde8c999ec3d450f684c375c34 (diff) | |
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.
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) && |
