From ce6744512e81ac2e291fea247d55fb0bf8e703e2 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 16 Dec 2018 16:18:06 +0100 Subject: pkg/vcs: fix fetching of commits on non master branch Fixes #728 --- pkg/vcs/git.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'pkg/vcs/git.go') 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 { -- cgit mrf-deployment