aboutsummaryrefslogtreecommitdiffstats
path: root/repository/gogit_config.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-08-30 11:56:34 +0200
committerMichael Muré <batolettre@gmail.com>2020-09-29 20:42:21 +0200
commit9c1087e18d2b4f7d5d9f0e98136933d05ce13827 (patch)
tree7b2e8864877ef3f434adaeaa3e19b2d53d252c59 /repository/gogit_config.go
parent30d1640bf47fcd14b1d26e8f5965bb61ae61859f (diff)
downloadgit-bug-9c1087e18d2b4f7d5d9f0e98136933d05ce13827.tar.gz
repository: fix a todo in the gogit repo
Diffstat (limited to 'repository/gogit_config.go')
-rw-r--r--repository/gogit_config.go51
1 files changed, 31 insertions, 20 deletions
diff --git a/repository/gogit_config.go b/repository/gogit_config.go
index 0f91b092..000658a8 100644
--- a/repository/gogit_config.go
+++ b/repository/gogit_config.go
@@ -105,19 +105,40 @@ func (ggc *goGitConfig) ReadString(key string) (string, error) {
split := strings.Split(key, ".")
- // TODO: return ErrNoConfigEntry and ErrMultipleConfigEntry
- // Can use forked go-git: https://github.com/go-git/go-git/pull/112
+ if len(split) <= 1 {
+ return "", fmt.Errorf("invalid key")
+ }
+
+ sectionName := split[0]
+ if !cfg.Raw.HasSection(sectionName) {
+ return "", ErrNoConfigEntry
+ }
+ section := cfg.Raw.Section(sectionName)
switch {
- case len(split) <= 1:
- return "", fmt.Errorf("invalid key")
case len(split) == 2:
- return cfg.Raw.Section(split[0]).Option(split[1]), nil
+ optionName := split[1]
+ if !section.HasOption(optionName) {
+ return "", ErrNoConfigEntry
+ }
+ if len(section.OptionAll(optionName)) > 1 {
+ return "", ErrMultipleConfigEntry
+ }
+ return section.Option(optionName), nil
default:
- section := split[0]
- subsection := strings.Join(split[1:len(split)-2], ".")
- option := split[len(split)-1]
- return cfg.Raw.Section(section).Subsection(subsection).Option(option), nil
+ subsectionName := strings.Join(split[1:len(split)-2], ".")
+ optionName := split[len(split)-1]
+ if !section.HasSubsection(subsectionName) {
+ return "", ErrNoConfigEntry
+ }
+ subsection := section.Subsection(subsectionName)
+ if !subsection.HasOption(optionName) {
+ return "", ErrNoConfigEntry
+ }
+ if len(subsection.OptionAll(optionName)) > 1 {
+ return "", ErrMultipleConfigEntry
+ }
+ return subsection.Option(optionName), nil
}
}
@@ -137,16 +158,6 @@ func (ggc *goGitConfig) RemoveAll(keyPrefix string) error {
split := strings.Split(keyPrefix, ".")
- // missing in go-git
- hasOption := func(options config.Options, key string) bool {
- for _, option := range options {
- if option.IsKey(key) {
- return true
- }
- }
- return false
- }
-
switch {
case len(split) < 1:
return fmt.Errorf("invalid key prefix")
@@ -163,7 +174,7 @@ func (ggc *goGitConfig) RemoveAll(keyPrefix string) error {
if cfg.Raw.Section(section).HasSubsection(rest) {
cfg.Raw.RemoveSubsection(section, rest)
} else {
- if hasOption(cfg.Raw.Section(section).Options, rest) {
+ if cfg.Raw.Section(section).HasOption(rest) {
cfg.Raw.Section(section).RemoveOption(rest)
} else {
return fmt.Errorf("invalid key prefix")