aboutsummaryrefslogtreecommitdiff
path: root/git-codereview
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2016-06-10 07:03:25 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2016-06-14 15:11:52 +0000
commitc79b2cb375e8d2264b5cb308ce9849148c48b443 (patch)
treedfcd1acc39384c49c0d615ccb0a21944451aae2c /git-codereview
parent9f7b28f5a3254d248b82a181bef7195f722ff762 (diff)
downloadgo-x-review-c79b2cb375e8d2264b5cb308ce9849148c48b443.tar.xz
git-codereview: use codereview.cfg from working tree
Loading codereview.cfg from origin/master effictively means that users have to ask permission to use git-codereview. With this change, users can opt to add the file, .gitignore it, and forget about it. Looking in origin/master also makes it hard to try out git-codereview on a project without having to commit to it. Instead of requiring codereview.cfg be checked in anywhere, just look on the filesystem for it. I can't figure out why I ever thought doing otherwise was a good idea. There are some other related fixes floating around, which might also be good to put in, but this is seems like a good stop-gap, since it is a minimal change; codereview.cfg continues to work for anyone currently using it. Related: golang/go#15616 Related: golang/go#15073 Change-Id: I1e377819f8eb8c8fecf9f022459551a3e8b93d48 Reviewed-on: https://go-review.googlesource.com/24001 Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'git-codereview')
-rw-r--r--git-codereview/api.go2
-rw-r--r--git-codereview/config.go10
-rw-r--r--git-codereview/hook_test.go9
3 files changed, 9 insertions, 12 deletions
diff --git a/git-codereview/api.go b/git-codereview/api.go
index 910900f..a81fc9e 100644
--- a/git-codereview/api.go
+++ b/git-codereview/api.go
@@ -109,7 +109,7 @@ func loadGerritOriginInternal(origin, remoteOrigin string) error {
auth.host = originUrl.Host
if hasGerritConfig {
if !strings.HasPrefix(remoteOrigin, origin) {
- return fmt.Errorf("Gerrit origin %q from %q different then git origin url %q", origin, configRef, originUrl)
+ return fmt.Errorf("Gerrit origin %q from %q different than git origin url %q", origin, configPath, originUrl)
}
auth.project = strings.Trim(strings.TrimPrefix(remoteOrigin, origin), "/")
diff --git a/git-codereview/config.go b/git-codereview/config.go
index 9843fcf..8bf87fd 100644
--- a/git-codereview/config.go
+++ b/git-codereview/config.go
@@ -6,11 +6,13 @@ package main
import (
"fmt"
+ "io/ioutil"
+ "path/filepath"
"strings"
)
var (
- configRef = "refs/remotes/origin/master:codereview.cfg"
+ configPath string
cachedConfig map[string]string
)
@@ -23,9 +25,11 @@ func config() map[string]string {
if cachedConfig != nil {
return cachedConfig
}
- raw, err := cmdOutputErr("git", "show", configRef)
+ configPath = filepath.Join(repoRoot(), "codereview.cfg")
+ b, err := ioutil.ReadFile(configPath)
+ raw := string(b)
if err != nil {
- verbosef("%sfailed to load config from %q: %v", raw, configRef, err)
+ verbosef("%sfailed to load config from %q: %v", raw, configPath, err)
cachedConfig = make(map[string]string)
return cachedConfig
}
diff --git a/git-codereview/hook_test.go b/git-codereview/hook_test.go
index fe083bb..ca1fff3 100644
--- a/git-codereview/hook_test.go
+++ b/git-codereview/hook_test.go
@@ -109,14 +109,8 @@ func TestHookCommitMsgIssueRepoRewrite(t *testing.T) {
}
}
- // Add issuerepo config.
+ // Add issuerepo config, clear any previous config.
write(t, gt.client+"/codereview.cfg", "issuerepo: golang/go")
- trun(t, gt.client, "git", "add", "codereview.cfg")
- trun(t, gt.client, "git", "commit", "-m", "add issuerepo codereview config")
-
- // Look in master rather than origin/master for the config
- savedConfigRef := configRef
- configRef = "master:codereview.cfg"
cachedConfig = nil
// Check for the rewrite
@@ -137,7 +131,6 @@ func TestHookCommitMsgIssueRepoRewrite(t *testing.T) {
}
// Reset config state
- configRef = savedConfigRef
cachedConfig = nil
}