From b46f0e30b8f22c159b55053a8502fd2b7e78101a Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Fri, 9 Oct 2015 10:59:26 +0100 Subject: [PATCH 1/2] Checkout SHA of origin/master rather than merging --- scripts/speculator/main.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/scripts/speculator/main.go b/scripts/speculator/main.go index d807bf78..ad0a897b 100644 --- a/scripts/speculator/main.go +++ b/scripts/speculator/main.go @@ -82,11 +82,8 @@ func gitCheckout(path, sha string) error { return runGitCommand(path, []string{"checkout", sha}) } -func gitFetchAndMerge(path string) error { - if err := runGitCommand(path, []string{"fetch"}); err != nil { - return err - } - return runGitCommand(path, []string{"merge", "origin/master"}) +func gitFetch(path string) error { + return runGitCommand(path, []string{"fetch"}) } func runGitCommand(path string, args []string) error { @@ -145,7 +142,7 @@ type server struct { // generateAt generates spec from repo at sha. // Returns the path where the generation was done. func (s *server) generateAt(sha string) (dst string, err error) { - err = gitFetchAndMerge(s.matrixDocCloneURL) + err = gitFetch(s.matrixDocCloneURL) if err != nil { return } @@ -162,11 +159,27 @@ func (s *server) generateAt(sha string) (dst string, err error) { return } +func (s *server) getSHAOf(ref string) (string, error) { + cmd := exec.Command("git", "rev-list", ref, "-n1") + cmd.Dir = path.Join(s.matrixDocCloneURL) + var b bytes.Buffer + cmd.Stdout = &b + err := cmd.Run() + if err != nil { + return "", fmt.Errorf("error generating spec: %v\nOutput from gendoc:\n%v", err, b.String()) + } + return strings.TrimSpace(b.String()), nil +} + func (s *server) serveSpec(w http.ResponseWriter, req *http.Request) { var sha string if strings.ToLower(req.URL.Path) == "/spec/head" { - sha = "HEAD" + originHead, err := s.getSHAOf("origin/master") + if err != nil { + writeError(w, 500, err) + } + sha = originHead } else { pr, err := lookupPullRequest(*req.URL, "/spec") if err != nil { From 69228506432f8e6781cfb89b2f378f0ad3ce5782 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Fri, 9 Oct 2015 11:02:27 +0100 Subject: [PATCH 2/2] Add missing return --- scripts/speculator/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/speculator/main.go b/scripts/speculator/main.go index ad0a897b..d641d7da 100644 --- a/scripts/speculator/main.go +++ b/scripts/speculator/main.go @@ -178,6 +178,7 @@ func (s *server) serveSpec(w http.ResponseWriter, req *http.Request) { originHead, err := s.getSHAOf("origin/master") if err != nil { writeError(w, 500, err) + return } sha = originHead } else {