aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/git/git.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-06-19 16:37:31 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-06-19 16:37:31 +0200
commit98bf8f451c41f09aa473ae66b3d955df8fbdce38 (patch)
tree32afb224b315fb56f2d4b84d355839305730b0c2 /pkg/git/git.go
parent7e63cfac7fbdb4b8f819d5ac870f2a6fce69d53a (diff)
pkg/git: check origin repo in Poll
Diffstat (limited to 'pkg/git/git.go')
-rw-r--r--pkg/git/git.go42
1 files changed, 27 insertions, 15 deletions
diff --git a/pkg/git/git.go b/pkg/git/git.go
index 8e492177a..fdea886cf 100644
--- a/pkg/git/git.go
+++ b/pkg/git/git.go
@@ -7,6 +7,7 @@ package git
import (
"fmt"
"os"
+ "strings"
"time"
"github.com/google/syzkaller/pkg/osutil"
@@ -19,22 +20,14 @@ const timeout = time.Hour // timeout for all git invocations
// Returns hash of the HEAD commit in the specified branch.
func Poll(dir, repo, branch string) (string, error) {
osutil.RunCmd(timeout, dir, "git", "reset", "--hard")
- if _, err := osutil.RunCmd(timeout, dir, "git", "fetch", "--no-tags", "--depth", "1"); err != nil {
- if err := os.RemoveAll(dir); err != nil {
- return "", fmt.Errorf("failed to remove repo dir: %v", err)
- }
- if err := os.MkdirAll(dir, 0700); err != nil {
- return "", fmt.Errorf("failed to create repo dir: %v", err)
- }
- args := []string{
- "clone",
- repo,
- "--depth", "1",
- "--single-branch",
- "--branch", branch,
- dir,
+ origin, err := osutil.RunCmd(timeout, dir, "git", "remote", "get-url", "origin")
+ if err != nil || strings.TrimSpace(string(origin)) != repo {
+ if err := clone(dir, repo, branch); err != nil {
+ return "", err
}
- if _, err := osutil.RunCmd(timeout, "", "git", args...); err != nil {
+ }
+ if _, err := osutil.RunCmd(timeout, dir, "git", "fetch", "--no-tags", "--depth", "1"); err != nil {
+ if err := clone(dir, repo, branch); err != nil {
return "", err
}
}
@@ -44,6 +37,25 @@ func Poll(dir, repo, branch string) (string, error) {
return HeadCommit(dir)
}
+func clone(dir, repo, branch string) error {
+ if err := os.RemoveAll(dir); err != nil {
+ return fmt.Errorf("failed to remove repo dir: %v", err)
+ }
+ if err := os.MkdirAll(dir, 0700); err != nil {
+ return fmt.Errorf("failed to create repo dir: %v", err)
+ }
+ args := []string{
+ "clone",
+ repo,
+ "--depth", "1",
+ "--single-branch",
+ "--branch", branch,
+ dir,
+ }
+ _, err := osutil.RunCmd(timeout, "", "git", args...)
+ return err
+}
+
// HeadCommit returns hash of the HEAD commit of the current branch of git repository in dir.
func HeadCommit(dir string) (string, error) {
output, err := osutil.RunCmd(timeout, dir, "git", "log", "--pretty=format:'%H'", "-n", "1")