devcam: review: fix origin in git config

Fixes #1176

Change-Id: I18222fd7b2d9ac47d4ab01740ef55b14d44b8b11
This commit is contained in:
mpl 2018-05-25 02:54:15 +02:00
parent a140b28f5d
commit 64f77af5b6
1 changed files with 39 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"perkeep.org/pkg/cmdmain"
)
@ -33,6 +34,7 @@ import (
var (
defaultHook = filepath.FromSlash("misc/commit-msg.githook")
hookFile = filepath.FromSlash(".git/hooks/commit-msg")
configFile = filepath.FromSlash(".git/config")
)
type reviewCmd struct {
@ -61,6 +63,7 @@ func (c *reviewCmd) RunCommand(args []string) error {
}
goToCamliRoot()
c.checkHook()
checkOrigin()
c.gitPush()
return nil
}
@ -117,6 +120,42 @@ func (c *reviewCmd) checkHook() {
}
}
const newOrigin = "https://perkeep.googlesource.com/perkeep"
var (
newFetch = regexp.MustCompile(`.*Fetch\s+URL:\s+` + newOrigin + `.*`)
newPush = regexp.MustCompile(`.*Push\s+URL:\s+` + newOrigin + `.*`)
)
func checkOrigin() {
out, err := exec.Command("git", "remote", "show", "origin").CombinedOutput()
if err != nil {
log.Fatalf("%v, %s", err, out)
}
if !newPush.Match(out) {
setPushOrigin()
}
if !newFetch.Match(out) {
setFetchOrigin()
}
}
func setPushOrigin() {
out, err := exec.Command("git", "remote", "set-url", "--push", "origin", newOrigin).CombinedOutput()
if err != nil {
log.Fatal("%v, %s", err, out)
}
}
func setFetchOrigin() {
out, err := exec.Command("git", "remote", "set-url", "origin", newOrigin).CombinedOutput()
if err != nil {
log.Fatal("%v, %s", err, out)
}
}
func (c *reviewCmd) gitPush() {
args := []string{"push", "origin"}
if c.releaseBranch != "" {