Skip to content

Commit a909729

Browse files
committed
Config: allow the full key name to be recovered
1 parent 554bb8b commit a909729

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

git/gitconfig.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type ConfigEntry struct {
1414
}
1515

1616
type Config struct {
17+
Prefix string
1718
Entries []ConfigEntry
1819
}
1920

@@ -29,7 +30,9 @@ func (repo *Repository) Config(prefix string) (*Config, error) {
2930
return nil, fmt.Errorf("reading git configuration: %w", err)
3031
}
3132

32-
var config Config
33+
config := Config{
34+
Prefix: prefix,
35+
}
3336

3437
for len(out) > 0 {
3538
keyEnd := bytes.IndexByte(out, '\n')
@@ -60,6 +63,15 @@ func (repo *Repository) Config(prefix string) (*Config, error) {
6063
return &config, nil
6164
}
6265

66+
// FullKey returns the full gitconfig key name for the relative key
67+
// name `key`.
68+
func (config *Config) FullKey(key string) string {
69+
if config.Prefix == "" {
70+
return key
71+
}
72+
return fmt.Sprintf("%s.%s", config.Prefix, key)
73+
}
74+
6375
// configKeyMatchesPrefix checks whether `key` starts with `prefix` at
6476
// a component boundary (i.e., at a '.'). If yes, it returns `true`
6577
// and the part of the key after the prefix; e.g.:

0 commit comments

Comments
 (0)