cmd/go-contrib-init: match subdomain-less .gitcookies file

My `.gitcookies` file starts with ".googlesource.com", which
errored because it did not match "go.googlesource.com" or
"go-review.googlesource.com". Fix this by optionally matching on
"go.googlesource.com" or ".googlesource.com".

Fixes golang/go#20992.

Change-Id: I29d3c0b1e958382495a90502f280bdb52868c2c7
Reviewed-on: https://go-review.googlesource.com/48230
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Kevin Burke 2017-07-12 21:39:45 -06:00
parent bce9606b3f
commit 76622760f0

View File

@ -18,6 +18,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp"
"runtime" "runtime"
"strings" "strings"
) )
@ -62,13 +63,14 @@ func detectrepo() string {
return "go" return "go"
} }
var googleSourceRx = regexp.MustCompile(`(?m)^(go|go-review)?\.googlesource.com\b`)
func checkCLA() { func checkCLA() {
slurp, err := ioutil.ReadFile(cookiesFile()) slurp, err := ioutil.ReadFile(cookiesFile())
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
log.Fatal(err) log.Fatal(err)
} }
if bytes.Contains(slurp, []byte("go.googlesource.com")) && if googleSourceRx.Match(slurp) {
bytes.Contains(slurp, []byte("go-review.googlesource.com")) {
// Probably good. // Probably good.
return return
} }