mirror of
https://github.com/golang/go
synced 2024-11-18 10:54:40 -07:00
cmd/go-contrib-init: add some git origin checks
Updates golang/go#17802 Change-Id: I70d30c5ff12837d51d13b5ca7e73be96eb535286 Reviewed-on: https://go-review.googlesource.com/45079 Reviewed-by: Steve Francia <spf@golang.org>
This commit is contained in:
parent
851770f01f
commit
fe66dd2e3e
@ -11,9 +11,11 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
@ -28,6 +30,7 @@ func main() {
|
||||
checkCLA()
|
||||
checkGoroot()
|
||||
checkWorkingDir()
|
||||
checkGitOrigin()
|
||||
}
|
||||
|
||||
func checkCLA() {
|
||||
@ -81,3 +84,40 @@ func checkGoroot() {
|
||||
func checkWorkingDir() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// mostly check that they didn't clone from github
|
||||
func checkGitOrigin() {
|
||||
if _, err := exec.LookPath("git"); err != nil {
|
||||
log.Fatalf("You don't appear to have git installed. Do that.")
|
||||
}
|
||||
if _, err := os.Stat(".git"); err != nil {
|
||||
log.Fatalf("You are not currently in a git checkout of https://go.googlesource.com/%s", *repo)
|
||||
}
|
||||
remotes, err := exec.Command("git", "remote", "-v").Output()
|
||||
if err != nil {
|
||||
log.Fatalf("Error running git remote -v: %v", cmdErr(err))
|
||||
}
|
||||
matches := 0
|
||||
wantRemote := "https://go.googlesource.com/" + *repo
|
||||
for _, line := range strings.Split(string(remotes), "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if !strings.HasPrefix(line, "origin") {
|
||||
continue
|
||||
}
|
||||
if !strings.Contains(line, wantRemote) {
|
||||
curRemote := strings.Fields(strings.TrimPrefix(line, "origin"))[0]
|
||||
log.Fatalf("Current directory's git was cloned from %q; origin should be %q", curRemote, wantRemote)
|
||||
}
|
||||
matches++
|
||||
}
|
||||
if matches == 0 {
|
||||
log.Fatalf("git remote -v output didn't contain expected %q. Got:\n%s", wantRemote, remotes)
|
||||
}
|
||||
}
|
||||
|
||||
func cmdErr(err error) string {
|
||||
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
|
||||
return fmt.Sprintf("%s: %s", err, ee.Stderr)
|
||||
}
|
||||
return fmt.Sprint(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user