aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bridge/core/bridge.go10
-rw-r--r--commands/webui.go2
-rw-r--r--repository/config_git.go4
-rw-r--r--repository/git_test.go32
-rw-r--r--repository/mock_repo.go51
-rw-r--r--repository/repo.go4
6 files changed, 27 insertions, 76 deletions
diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go
index 6fd28b03..47a89389 100644
--- a/bridge/core/bridge.go
+++ b/bridge/core/bridge.go
@@ -134,7 +134,7 @@ func DefaultBridge(repo *cache.RepoCache) (*Bridge, error) {
// ConfiguredBridges return the list of bridge that are configured for the given
// repo
func ConfiguredBridges(repo repository.RepoCommon) ([]string, error) {
- configs, err := repo.ReadConfigs(bridgeConfigKeyPrefix + ".")
+ configs, err := repo.LocalConfig().ReadAll(bridgeConfigKeyPrefix + ".")
if err != nil {
return nil, errors.Wrap(err, "can't read configured bridges")
}
@@ -171,7 +171,7 @@ func ConfiguredBridges(repo repository.RepoCommon) ([]string, error) {
func BridgeExist(repo repository.RepoCommon, name string) bool {
keyPrefix := fmt.Sprintf("git-bug.bridge.%s.", name)
- conf, err := repo.ReadConfigs(keyPrefix)
+ conf, err := repo.LocalConfig().ReadAll(keyPrefix)
return err == nil && len(conf) > 0
}
@@ -188,7 +188,7 @@ func RemoveBridge(repo repository.RepoCommon, name string) error {
}
keyPrefix := fmt.Sprintf("git-bug.bridge.%s", name)
- return repo.RmConfigs(keyPrefix)
+ return repo.LocalConfig().RemoveAll(keyPrefix)
}
// Configure run the target specific configuration process
@@ -211,7 +211,7 @@ func (b *Bridge) storeConfig(conf Configuration) error {
for key, val := range conf {
storeKey := fmt.Sprintf("git-bug.bridge.%s.%s", b.Name, key)
- err := b.repo.StoreConfig(storeKey, val)
+ err := b.repo.LocalConfig().StoreString(storeKey, val)
if err != nil {
return errors.Wrap(err, "error while storing bridge configuration")
}
@@ -235,7 +235,7 @@ func (b *Bridge) ensureConfig() error {
func loadConfig(repo repository.RepoCommon, name string) (Configuration, error) {
keyPrefix := fmt.Sprintf("git-bug.bridge.%s.", name)
- pairs, err := repo.ReadConfigs(keyPrefix)
+ pairs, err := repo.LocalConfig().ReadAll(keyPrefix)
if err != nil {
return nil, errors.Wrap(err, "error while reading bridge configuration")
}
diff --git a/commands/webui.go b/commands/webui.go
index d6b6a661..8e735e55 100644
--- a/commands/webui.go
+++ b/commands/webui.go
@@ -100,7 +100,7 @@ func runWebUI(cmd *cobra.Command, args []string) error {
fmt.Printf("Graphql Playground: http://%s/playground\n", addr)
fmt.Println("Press Ctrl+c to quit")
- configOpen, err := repo.ReadConfigBool(webUIOpenConfigKey)
+ configOpen, err := repo.LocalConfig().ReadBool(webUIOpenConfigKey)
if err == repository.ErrNoConfigEntry {
// default to true
configOpen = true
diff --git a/repository/config_git.go b/repository/config_git.go
index 22666de7..eac882a2 100644
--- a/repository/config_git.go
+++ b/repository/config_git.go
@@ -29,7 +29,7 @@ func newGitConfig(repo *GitRepo, global bool) *gitConfig {
}
}
-// StoreConfig store a single key/value pair in the config of the repo
+// StoreString store a single key/value pair in the config of the repo
func (gc *gitConfig) StoreString(key string, value string) error {
_, err := gc.repo.runGitCommand("config", gc.localityFlag, "--replace-all", key, value)
return err
@@ -43,7 +43,7 @@ func (gc *gitConfig) StoreTimestamp(key string, value time.Time) error {
return gc.StoreString(key, strconv.Itoa(int(value.Unix())))
}
-// ReadConfigs read all key/value pair matching the key prefix
+// ReadAll read all key/value pair matching the key prefix
func (gc *gitConfig) ReadAll(keyPrefix string) (map[string]string, error) {
stdout, err := gc.repo.runGitCommand("config", gc.localityFlag, "--get-regexp", keyPrefix)
diff --git a/repository/git_test.go b/repository/git_test.go
index cb115526..88587a15 100644
--- a/repository/git_test.go
+++ b/repository/git_test.go
@@ -11,57 +11,55 @@ func TestConfig(t *testing.T) {
repo := CreateTestRepo(false)
defer CleanupTestRepos(t, repo)
- config := repo.LocalConfig()
-
- err := config.StoreString("section.key", "value")
+ err := repo.LocalConfig().StoreString("section.key", "value")
assert.NoError(t, err)
- val, err := config.ReadString("section.key")
+ val, err := repo.LocalConfig().ReadString("section.key")
assert.Equal(t, "value", val)
- err = config.StoreString("section.true", "true")
+ err = repo.LocalConfig().StoreString("section.true", "true")
assert.NoError(t, err)
- val2, err := config.ReadBool("section.true")
+ val2, err := repo.LocalConfig().ReadBool("section.true")
assert.Equal(t, true, val2)
- configs, err := config.ReadAll("section")
+ configs, err := repo.LocalConfig().ReadAll("section")
assert.NoError(t, err)
assert.Equal(t, configs, map[string]string{
"section.key": "value",
"section.true": "true",
})
- err = config.RemoveAll("section.true")
+ err = repo.LocalConfig().RemoveAll("section.true")
assert.NoError(t, err)
- configs, err = config.ReadAll("section")
+ configs, err = repo.LocalConfig().ReadAll("section")
assert.NoError(t, err)
assert.Equal(t, configs, map[string]string{
"section.key": "value",
})
- _, err = config.ReadBool("section.true")
+ _, err = repo.LocalConfig().ReadBool("section.true")
assert.Equal(t, ErrNoConfigEntry, err)
- err = config.RemoveAll("section.nonexistingkey")
+ err = repo.LocalConfig().RemoveAll("section.nonexistingkey")
assert.Error(t, err)
- err = config.RemoveAll("section.key")
+ err = repo.LocalConfig().RemoveAll("section.key")
assert.NoError(t, err)
- _, err = config.ReadString("section.key")
+ _, err = repo.LocalConfig().ReadString("section.key")
assert.Equal(t, ErrNoConfigEntry, err)
- err = config.RemoveAll("nonexistingsection")
+ err = repo.LocalConfig().RemoveAll("nonexistingsection")
assert.Error(t, err)
- err = config.RemoveAll("section")
+ err = repo.LocalConfig().RemoveAll("section")
assert.Error(t, err)
- _, err = config.ReadString("section.key")
+ _, err = repo.LocalConfig().ReadString("section.key")
assert.Error(t, err)
- err = config.RemoveAll("section.key")
+ err = repo.LocalConfig().RemoveAll("section.key")
assert.Error(t, err)
}
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index bdf36ac2..26c02ede 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -3,8 +3,6 @@ package repository
import (
"crypto/sha1"
"fmt"
- "strconv"
- "strings"
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/lamport"
@@ -41,10 +39,12 @@ func NewMockRepoForTest() *mockRepoForTest {
}
}
+// LocalConfig give access to the repository scoped configuration
func (r *mockRepoForTest) LocalConfig() Config {
return newMemConfig(r.config)
}
+// GlobalConfig give access to the git global configuration
func (r *mockRepoForTest) GlobalConfig() Config {
return newMemConfig(r.globalConfig)
}
@@ -75,53 +75,6 @@ func (r *mockRepoForTest) GetRemotes() (map[string]string, error) {
}, nil
}
-func (r *mockRepoForTest) StoreConfig(key string, value string) error {
- r.config[key] = value
- return nil
-}
-
-func (r *mockRepoForTest) ReadConfigs(keyPrefix string) (map[string]string, error) {
- result := make(map[string]string)
-
- for key, val := range r.config {
- if strings.HasPrefix(key, keyPrefix) {
- result[key] = val
- }
- }
-
- return result, nil
-}
-
-func (r *mockRepoForTest) ReadConfigBool(key string) (bool, error) {
- // unlike git, the mock can only store one value for the same key
- val, ok := r.config[key]
- if !ok {
- return false, ErrNoConfigEntry
- }
-
- return strconv.ParseBool(val)
-}
-
-func (r *mockRepoForTest) ReadConfigString(key string) (string, error) {
- // unlike git, the mock can only store one value for the same key
- val, ok := r.config[key]
- if !ok {
- return "", ErrNoConfigEntry
- }
-
- return val, nil
-}
-
-// RmConfigs remove all key/value pair matching the key prefix
-func (r *mockRepoForTest) RmConfigs(keyPrefix string) error {
- for key := range r.config {
- if strings.HasPrefix(key, keyPrefix) {
- delete(r.config, key)
- }
- }
- return nil
-}
-
// PushRefs push git refs to a remote
func (r *mockRepoForTest) PushRefs(remote string, refSpec string) (string, error) {
return "", nil
diff --git a/repository/repo.go b/repository/repo.go
index f17d594b..7d655bde 100644
--- a/repository/repo.go
+++ b/repository/repo.go
@@ -30,10 +30,10 @@ type RepoCommon interface {
// GetRemotes returns the configured remotes repositories.
GetRemotes() (map[string]string, error)
- // LocalConfig .
+ // LocalConfig give access to the repository scoped configuration
LocalConfig() Config
- // GlobalConfig .
+ // GlobalConfig give access to the git global configuration
GlobalConfig() Config
}