From 93048080705cb9f3806fa456dc0642e3a143849b Mon Sep 17 00:00:00 2001 From: amine Date: Fri, 1 Nov 2019 21:37:16 +0100 Subject: [PATCH] repository: use `repo.runGitCommand` and `flagLocality` instead of execFn --- repository/config_git.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/repository/config_git.go b/repository/config_git.go index 67ca3436..bdc86201 100644 --- a/repository/config_git.go +++ b/repository/config_git.go @@ -14,27 +14,24 @@ import ( var _ Config = &gitConfig{} type gitConfig struct { - execFn func(args ...string) (string, error) + repo *GitRepo + localityFlag string } func newGitConfig(repo *GitRepo, global bool) *gitConfig { - configCmdFlag := "--local" + localityFlag := "--local" if global { - configCmdFlag = "--global" + localityFlag = "--global" } return &gitConfig{ - execFn: func(args ...string) (string, error) { - if len(args) > 0 && args[0] == "config" { - args = append([]string{args[0], configCmdFlag}, args[1:]...) - } - return repo.runGitCommand(args...) - }, + repo: repo, + localityFlag: localityFlag, } } // StoreConfig store a single key/value pair in the config of the repo func (gc *gitConfig) StoreString(key string, value string) error { - _, err := gc.execFn("config", "--replace-all", key, value) + _, err := gc.repo.runGitCommand("config", "gc.localityFlag", "--replace-all", key, value) return err } @@ -48,7 +45,7 @@ func (gc *gitConfig) StoreTimestamp(key string, value time.Time) error { // ReadConfigs read all key/value pair matching the key prefix func (gc *gitConfig) ReadAll(keyPrefix string) (map[string]string, error) { - stdout, err := gc.execFn("config", "--get-regexp", keyPrefix) + stdout, err := gc.repo.runGitCommand("config", "gc.localityFlag", "--get-regexp", keyPrefix) // / \ // / ! \ @@ -81,7 +78,7 @@ func (gc *gitConfig) ReadAll(keyPrefix string) (map[string]string, error) { } func (gc *gitConfig) ReadString(key string) (string, error) { - stdout, err := gc.execFn("config", "--get-all", key) + stdout, err := gc.repo.runGitCommand("config", "gc.localityFlag", "--get-all", key) // / \ // / ! \ @@ -123,12 +120,12 @@ func (gc *gitConfig) ReadTimestamp(key string) (*time.Time, error) { } func (gc *gitConfig) rmSection(keyPrefix string) error { - _, err := gc.execFn("config", "--remove-section", keyPrefix) + _, err := gc.repo.runGitCommand("config", "gc.localityFlag", "--remove-section", keyPrefix) return err } func (gc *gitConfig) unsetAll(keyPrefix string) error { - _, err := gc.execFn("config", "--unset-all", keyPrefix) + _, err := gc.repo.runGitCommand("config", "gc.localityFlag", "--unset-all", keyPrefix) return err } @@ -187,7 +184,7 @@ func (gc *gitConfig) RemoveAll(keyPrefix string) error { } func (gc *gitConfig) gitVersion() (*semver.Version, error) { - versionOut, err := gc.execFn("version") + versionOut, err := gc.repo.runGitCommand("version") if err != nil { return nil, err }