aboutsummaryrefslogtreecommitdiffstats
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
parentfb6b2d873e1bbc653aa84ddce56c842202e00c33 (diff)
downloadgit-bug-890c014d919f705eac624547031c79205a71321b.tar.gz
repo: fix various config issues around case insentivity
-rw-r--r--bridge/core/auth/credential.go6
-rw-r--r--bug/bug_test.go5
-rw-r--r--repository/config_mem.go19
-rw-r--r--repository/config_testing.go39
-rw-r--r--repository/gogit_config.go2
5 files changed, 61 insertions, 10 deletions
diff --git a/bridge/core/auth/credential.go b/bridge/core/auth/credential.go
index 2327a6fc..20343c9c 100644
--- a/bridge/core/auth/credential.go
+++ b/bridge/core/auth/credential.go
@@ -3,12 +3,13 @@ package auth
import (
"encoding/base64"
"encoding/json"
- "errors"
"fmt"
"strconv"
"strings"
"time"
+ "github.com/pkg/errors"
+
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/repository"
)
@@ -159,7 +160,8 @@ func List(repo repository.RepoKeyring, opts ...ListOption) ([]Credential, error)
item, err := repo.Keyring().Get(key)
if err != nil {
- return nil, err
+ // skip unreadable items, nothing much we can do for them anyway
+ continue
}
cred, err := decode(item)
diff --git a/bug/bug_test.go b/bug/bug_test.go
index 6363f4e9..d6ef6fa1 100644
--- a/bug/bug_test.go
+++ b/bug/bug_test.go
@@ -25,10 +25,7 @@ func TestBugId(t *testing.T) {
bug1.Append(createOp)
err = bug1.Commit(mockRepo)
-
- if err != nil {
- t.Fatal(err)
- }
+ require.NoError(t, err)
bug1.Id()
}
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