diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-12-16 16:18:06 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-12-16 16:18:06 +0100 |
| commit | ce6744512e81ac2e291fea247d55fb0bf8e703e2 (patch) | |
| tree | 7670f0ced49db9f4e05b96812b322eb608314c77 /pkg/vcs/git.go | |
| parent | c7e64e2b4f3a9d7734a92aebc53f285cd6afd94b (diff) | |
pkg/vcs: fix fetching of commits on non master branch
Fixes #728
Diffstat (limited to 'pkg/vcs/git.go')
| -rw-r--r-- | pkg/vcs/git.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go index bc0e05373..f73c47c58 100644 --- a/pkg/vcs/git.go +++ b/pkg/vcs/git.go @@ -16,6 +16,7 @@ import ( "strings" "time" + "github.com/google/syzkaller/pkg/hash" "github.com/google/syzkaller/pkg/osutil" ) @@ -87,13 +88,20 @@ func (git *git) CheckoutCommit(repo, commit string) (*Commit, error) { return nil, err } } - _, err := runSandboxed(dir, "git", "fetch", repo) - if err != nil { + if err := git.fetchRemote(repo); err != nil { return nil, err } return git.SwitchCommit(commit) } +func (git *git) fetchRemote(repo string) error { + repoHash := hash.String([]byte(repo)) + // Ignore error as we can double add the same remote and that will fail. + runSandboxed(git.dir, "git", "remote", "add", repoHash, repo) + _, err := runSandboxed(git.dir, "git", "fetch", repoHash) + return err +} + func (git *git) SwitchCommit(commit string) (*Commit, error) { dir := git.dir if _, err := runSandboxed(dir, "git", "checkout", commit); err != nil { |
