diff options
Diffstat (limited to 'repository')
-rw-r--r-- | repository/config_git.go | 4 | ||||
-rw-r--r-- | repository/git_test.go | 32 | ||||
-rw-r--r-- | repository/mock_repo.go | 51 | ||||
-rw-r--r-- | repository/repo.go | 4 |
4 files changed, 21 insertions, 70 deletions
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 } |