Skip to content

Commit 82e622a

Browse files
authored
Merge pull request #307 from mpsonntag/useLocalConf
Use only local git config keys
2 parents da98609 + 30d04c3 commit 82e622a

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

ginclient/repos.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,12 @@ func CommitIfNew() (bool, error) {
481481
// DefaultRemote returns the name of the configured default gin remote.
482482
// If a remote is not set in the config, the remote of the default git upstream is set and returned.
483483
func DefaultRemote() (string, error) {
484-
defremote, err := git.ConfigGet("gin.remote")
484+
defremote, err := git.ConfigGetLocal("gin.remote")
485485
if err == nil {
486486
return defremote, nil
487487
}
488488
log.Write("Default remote not set. Checking master remote.")
489-
defremote, err = git.ConfigGet("branch.master.remote")
489+
defremote, err = git.ConfigGetLocal("branch.master.remote")
490490
if err == nil {
491491
SetDefaultRemote(defremote)
492492
log.Write("Set default remote to %s", defremote)

git/git.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,27 @@ func SetGitUser(name, email string) error {
360360
return ConfigSet("user.email", email)
361361
}
362362

363-
// ConfigGet returns the value of a given git configuration key.
363+
// ConfigGetLocal returns the value of a given git configuration key
364+
// using the local git configuration only.
365+
// The returned key is always a string.
366+
// (git config --local --get)
367+
func ConfigGetLocal(key string) (string, error) {
368+
fn := fmt.Sprintf("ConfigGet(%s)", key)
369+
cmd := Command("config", "--local", "--get", key)
370+
stdout, stderr, err := cmd.OutputError()
371+
if err != nil {
372+
gerr := giterror{UError: string(stderr), Origin: fn}
373+
log.Write("Error during config get")
374+
logstd(stdout, stderr)
375+
return "", gerr
376+
}
377+
value := string(stdout)
378+
value = strings.TrimSpace(value)
379+
return value, nil
380+
}
381+
382+
// ConfigGet returns the value of a given git configuration key
383+
// using the default git configuration.
364384
// The returned key is always a string.
365385
// (git config --get)
366386
func ConfigGet(key string) (string, error) {
@@ -544,7 +564,7 @@ func Checkwd() error {
544564
return NotRepository
545565
}
546566

547-
annexver, err := ConfigGet("annex.version")
567+
annexver, err := ConfigGetLocal("annex.version")
548568
if err != nil {
549569
// Annex version config key missing: Annex not initialised
550570
return NotAnnex

git/git_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestInit(t *testing.T) {
4747
t.Fatalf("Failed to initialise (non-bare) repository: %s", err.Error())
4848
}
4949

50-
bare, _ := ConfigGet("core.bare")
50+
bare, _ := ConfigGetLocal("core.bare")
5151
if bare != "false" {
5252
t.Fatalf("Expected non-bare repository: %s", bare)
5353
}
@@ -63,7 +63,7 @@ func TestInit(t *testing.T) {
6363
t.Fatalf("Failed to initialise bare repository: %s", err.Error())
6464
}
6565

66-
bare, _ = ConfigGet("core.bare")
66+
bare, _ = ConfigGetLocal("core.bare")
6767
if bare != "true" {
6868
t.Fatalf("Expected bare repository: %s", bare)
6969
}

0 commit comments

Comments
 (0)