aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'git-codereview/config.go')
-rw-r--r--git-codereview/config.go25
1 files changed, 15 insertions, 10 deletions
diff --git a/git-codereview/config.go b/git-codereview/config.go
index cc9286c..8c86abf 100644
--- a/git-codereview/config.go
+++ b/git-codereview/config.go
@@ -17,26 +17,29 @@ var (
cachedConfig map[string]string
)
-// Config returns the code review config.
+// config returns the code review config.
// Configs consist of lines of the form "key: value".
// Lines beginning with # are comments.
// If there is no config, it returns an empty map.
// If the config is malformed, it dies.
func config() map[string]string {
- if cachedConfig != nil {
- return cachedConfig
- }
configPath = filepath.Join(repoRoot(), "codereview.cfg")
b, err := os.ReadFile(configPath)
raw := string(b)
if err != nil {
verbosef("%sfailed to load config from %q: %v", raw, configPath, err)
cachedConfig = make(map[string]string)
- return cachedConfig
+ } else {
+ cachedConfig, err = parseConfig(raw)
+ if err != nil {
+ dief("%v", err)
+ }
}
- cachedConfig, err = parseConfig(raw)
- if err != nil {
- dief("%v", err)
+ if cachedConfig["remote"] == "" {
+ cachedConfig["remote"] = "origin"
+ }
+ if cachedConfig["branch"] == "" {
+ cachedConfig["branch"] = "main"
}
return cachedConfig
}
@@ -46,8 +49,10 @@ func config() map[string]string {
// the gerrit https URL or the git origin must be to
// "https://<project>.googlesource.com/<repo>".
func haveGerrit() bool {
- gerrit := config()["gerrit"]
- origin := trim(cmdOutput("git", "config", "remote.origin.url"))
+ cfg := config()
+ cfgRemote := cfg["remote"]
+ gerrit := cfg["gerrit"]
+ origin := trim(cmdOutput("git", "config", "remote."+cfgRemote+".url"))
return haveGerritInternal(gerrit, origin)
}