diff options
author | Michael Muré <batolettre@gmail.com> | 2021-03-28 22:25:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-28 22:25:12 +0200 |
commit | 919227c6dafffaa2e4c497c0a514d75dcf168045 (patch) | |
tree | 062d022679c941cd7eabb40f5b22a3da35efd8af /repository/config_mem.go | |
parent | fb6b2d873e1bbc653aa84ddce56c842202e00c33 (diff) | |
parent | 890c014d919f705eac624547031c79205a71321b (diff) | |
download | git-bug-919227c6dafffaa2e4c497c0a514d75dcf168045.tar.gz |
Merge pull request #608 from MichaelMure/fix-config
repo: fix various config issues around case insentivity
Diffstat (limited to 'repository/config_mem.go')
-rw-r--r-- | repository/config_mem.go | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/repository/config_mem.go b/repository/config_mem.go index 9725e8d5..019bc111 100644 --- a/repository/config_mem.go +++ b/repository/config_mem.go @@ -20,6 +20,7 @@ func NewMemConfig() *MemConfig { } func (mc *MemConfig) StoreString(key, value string) error { + key = normalizeKey(key) mc.config[key] = value return nil } @@ -33,6 +34,7 @@ func (mc *MemConfig) StoreTimestamp(key string, value time.Time) error { } func (mc *MemConfig) ReadAll(keyPrefix string) (map[string]string, error) { + keyPrefix = normalizeKey(keyPrefix) result := make(map[string]string) for key, val := range mc.config { if strings.HasPrefix(key, keyPrefix) { @@ -44,6 +46,7 @@ func (mc *MemConfig) ReadAll(keyPrefix string) (map[string]string, error) { func (mc *MemConfig) ReadString(key string) (string, error) { // unlike git, the mock can only store one value for the same key + key = normalizeKey(key) val, ok := mc.config[key] if !ok { return "", ErrNoConfigEntry @@ -54,9 +57,9 @@ func (mc *MemConfig) ReadString(key string) (string, error) { func (mc *MemConfig) ReadBool(key string) (bool, error) { // unlike git, the mock can only store one value for the same key - val, ok := mc.config[key] - if !ok { - return false, ErrNoConfigEntry + val, err := mc.ReadString(key) + if err != nil { + return false, err } return strconv.ParseBool(val) @@ -78,6 +81,7 @@ func (mc *MemConfig) ReadTimestamp(key string) (time.Time, error) { // RmConfigs remove all key/value pair matching the key prefix func (mc *MemConfig) RemoveAll(keyPrefix string) error { + keyPrefix = normalizeKey(keyPrefix) found := false for key := range mc.config { if strings.HasPrefix(key, keyPrefix) { @@ -92,3 +96,12 @@ func (mc *MemConfig) RemoveAll(keyPrefix string) error { return nil } + +func normalizeKey(key string) string { + // this feels so wrong, but that's apparently how git behave. + // only section and final segment are case insensitive, subsection in between are not. + s := strings.Split(key, ".") + s[0] = strings.ToLower(s[0]) + s[len(s)-1] = strings.ToLower(s[len(s)-1]) + return strings.Join(s, ".") +} |