aboutsummaryrefslogtreecommitdiffstats
path: root/repository
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2021-03-28 22:18:01 +0200
committerMichael Muré <batolettre@gmail.com>2021-03-28 22:18:01 +0200
commit890c014d919f705eac624547031c79205a71321b (patch)
tree062d022679c941cd7eabb40f5b22a3da35efd8af /repository
parentfb6b2d873e1bbc653aa84ddce56c842202e00c33 (diff)
downloadgit-bug-890c014d919f705eac624547031c79205a71321b.tar.gz
repo: fix various config issues around case insentivity
Diffstat (limited to 'repository')
-rw-r--r--repository/config_mem.go19
-rw-r--r--repository/config_testing.go39
-rw-r--r--repository/gogit_config.go2
3 files changed, 56 insertions, 4 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, ".")
+}
diff --git a/repository/config_testing.go b/repository/config_testing.go
index 445f8721..f8a2762b 100644
--- a/repository/config_testing.go
+++ b/repository/config_testing.go
@@ -113,4 +113,43 @@ func testConfig(t *testing.T, config Config) {
"section.subsection.subsection.opt1": "foo5",
"section.subsection.subsection.opt2": "foo6",
}, all)
+
+ // missing section + case insensitive
+ val, err = config.ReadString("section2.opt1")
+ require.Error(t, err)
+
+ val, err = config.ReadString("section.opt1")
+ require.NoError(t, err)
+ require.Equal(t, "foo", val)
+
+ val, err = config.ReadString("SECTION.OPT1")
+ require.NoError(t, err)
+ require.Equal(t, "foo", val)
+
+ _, err = config.ReadString("SECTION2.OPT3")
+ require.Error(t, err)
+
+ // missing subsection + case insensitive
+ val, err = config.ReadString("section.subsection.opt1")
+ require.NoError(t, err)
+ require.Equal(t, "foo3", val)
+
+ // for some weird reason, subsection ARE case sensitive
+ _, err = config.ReadString("SECTION.SUBSECTION.OPT1")
+ require.Error(t, err)
+
+ _, err = config.ReadString("SECTION.SUBSECTION1.OPT1")
+ require.Error(t, err)
+
+ // missing sub-subsection + case insensitive
+ val, err = config.ReadString("section.subsection.subsection.opt1")
+ require.NoError(t, err)
+ require.Equal(t, "foo5", val)
+
+ // for some weird reason, subsection ARE case sensitive
+ _, err = config.ReadString("SECTION.SUBSECTION.SUBSECTION.OPT1")
+ require.Error(t, err)
+
+ _, err = config.ReadString("SECTION.SUBSECTION.SUBSECTION1.OPT1")
+ require.Error(t, err)
}
diff --git a/repository/gogit_config.go b/repository/gogit_config.go
index ba61adca..891e3ffb 100644
--- a/repository/gogit_config.go
+++ b/repository/gogit_config.go
@@ -134,7 +134,7 @@ func (cr *goGitConfigReader) ReadString(key string) (string, error) {
}
return section.Option(optionName), nil
default:
- subsectionName := strings.Join(split[1:len(split)-2], ".")
+ subsectionName := strings.Join(split[1:len(split)-1], ".")
optionName := split[len(split)-1]
if !section.HasSubsection(subsectionName) {
return "", ErrNoConfigEntry