aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/git
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-06-22 16:27:37 +0200
committerGitHub <noreply@github.com>2017-06-22 16:27:37 +0200
commit0b4cf413ea0e3004ac0e61437bf3dda6ae8862c0 (patch)
tree3256aed29d7510e35e609da75e0c21503538b915 /pkg/git
parent5509235822dd7e89f6019bb328b276ca36cf184f (diff)
parent6573032fffc201ee69dfe22d0d678eda8f915436 (diff)
Merge pull request #241 from dvyukov/dvyukov-ci
syz-ci: add continuous integration system
Diffstat (limited to 'pkg/git')
-rw-r--r--pkg/git/git.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/pkg/git/git.go b/pkg/git/git.go
index fdea886cf..5c91c6040 100644
--- a/pkg/git/git.go
+++ b/pkg/git/git.go
@@ -22,16 +22,27 @@ func Poll(dir, repo, branch string) (string, error) {
osutil.RunCmd(timeout, dir, "git", "reset", "--hard")
origin, err := osutil.RunCmd(timeout, dir, "git", "remote", "get-url", "origin")
if err != nil || strings.TrimSpace(string(origin)) != repo {
+ // The repo is here, but it has wrong origin (e.g. repo in config has changed), re-clone.
+ if err := clone(dir, repo, branch); err != nil {
+ return "", err
+ }
+ }
+ // Use origin/branch for the case the branch was force-pushed,
+ // in such case branch is not the same is origin/branch and we will
+ // stuck with the local version forever (git checkout won't fail).
+ if _, err := osutil.RunCmd(timeout, dir, "git", "checkout", "origin/"+branch); err != nil {
+ // No such branch (e.g. branch in config has changed), re-clone.
if err := clone(dir, repo, branch); err != nil {
return "", err
}
}
if _, err := osutil.RunCmd(timeout, dir, "git", "fetch", "--no-tags", "--depth", "1"); err != nil {
+ // Something else is wrong, re-clone.
if err := clone(dir, repo, branch); err != nil {
return "", err
}
}
- if _, err := osutil.RunCmd(timeout, dir, "git", "checkout", branch); err != nil {
+ if _, err := osutil.RunCmd(timeout, dir, "git", "checkout", "origin/"+branch); err != nil {
return "", err
}
return HeadCommit(dir)