Skip to content

Commit

Permalink
cmd/tip: improve precondition checking, less ambiguous arguments
Browse files Browse the repository at this point in the history
Check that the required repository HEAD revisions are present before
attempting to clone said repositories.

Use '--' to separate paths and make git invocations less ambiguous.

Updates golang/go#32949

Change-Id: Ie0c771c38a047d674fea5a74318ed396fd03c7ce
Reviewed-on: https://go-review.googlesource.com/c/build/+/185138
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
  • Loading branch information
dmitshur committed Jul 9, 2019
1 parent 0fd1ffd commit 7e427ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cmd/tip/golangorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func (b golangorgBuilder) Signature(heads map[string]string) string {
}

func (b golangorgBuilder) Init(logger *log.Logger, dir, hostport string, heads map[string]string) (*exec.Cmd, error) {
if _, ok := heads["go"]; !ok {
return nil, fmt.Errorf("missing HEAD revision for 'go' repo")
}
if _, ok := heads["website"]; !ok {
return nil, fmt.Errorf("missing HEAD revision for 'website' repo")
}
goDir := filepath.Join(dir, "go")
websiteDir := filepath.Join(dir, "website")
logger.Printf("checking out go repo ...")
Expand Down
3 changes: 3 additions & 0 deletions cmd/tip/talks.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func (b talksBuilder) Signature(heads map[string]string) string {
const talksToolsRev = "8cab8a1319f0be9798e7fe78b15da75e5f94b2e9"

func (b talksBuilder) Init(logger *log.Logger, dir, hostport string, heads map[string]string) (*exec.Cmd, error) {
if _, ok := heads["talks"]; !ok {
return nil, fmt.Errorf("missing HEAD revision for 'talks' repo")
}
// TODO: use logger
toolsDir := filepath.Join(dir, "gopath/src/golang.org/x/tools")
if err := checkout(repoURL+"tools", talksToolsRev, toolsDir); err != nil {
Expand Down
6 changes: 4 additions & 2 deletions cmd/tip/tip.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func checkout(repo, hash, path string) error {
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
return fmt.Errorf("mkdir: %v", err)
}
if err := runErr(exec.Command("git", "clone", "--depth", "1", repo, path)); err != nil {
if err := runErr(exec.Command("git", "clone", "--depth", "1", "--", repo, path)); err != nil {
return fmt.Errorf("clone: %v", err)
}
} else if err != nil {
Expand All @@ -315,7 +315,7 @@ func checkout(repo, hash, path string) error {
if err := runErr(cmd); err != nil {
return fmt.Errorf("fetch: %v", err)
}
cmd = exec.Command("git", "reset", "--hard", hash)
cmd = exec.Command("git", "reset", "--hard", hash, "--")
cmd.Dir = path
if err := runErr(cmd); err != nil {
return fmt.Errorf("reset: %v", err)
Expand All @@ -334,6 +334,8 @@ var timeoutClient = &http.Client{Timeout: 10 * time.Second}
// latest master hash.
// The returned map is nil on any transient error.
func gerritMetaMap() map[string]string {
// TODO(dmitshur): Replace with a Gerrit client implementation like in gitmirror.

res, err := timeoutClient.Get(metaURL)
if err != nil {
log.Printf("Error getting Gerrit meta map: %v", err)
Expand Down

0 comments on commit 7e427ad

Please sign in to comment.