diff options
Diffstat (limited to 'storage/filesystem/config.go')
-rw-r--r-- | storage/filesystem/config.go | 67 |
1 files changed, 5 insertions, 62 deletions
diff --git a/storage/filesystem/config.go b/storage/filesystem/config.go index dbdce54..78a6464 100644 --- a/storage/filesystem/config.go +++ b/storage/filesystem/config.go @@ -1,11 +1,9 @@ package filesystem import ( - stdioutil "io/ioutil" "os" "github.com/go-git/go-git/v5/config" - format "github.com/go-git/go-git/v5/plumbing/format/config" "github.com/go-git/go-git/v5/storage/filesystem/dotgit" "github.com/go-git/go-git/v5/utils/ioutil" ) @@ -14,73 +12,18 @@ type ConfigStorage struct { dir *dotgit.DotGit } -func (c *ConfigStorage) Config() (*config.Config, error) { - cfg := config.NewConfig() - - // local config (./.git/config) - f, err := c.dir.LocalConfig() - if err != nil { - if os.IsNotExist(err) { - return cfg, nil - } - - return nil, err - } - - defer ioutil.CheckClose(f, &err) - - b, err := stdioutil.ReadAll(f) - if err != nil { - return cfg, err - } - - if err = cfg.UnmarshalScoped(format.LocalScope, b); err != nil { - return cfg, err - } - - // global config (~/.gitconfig) - f, err = c.dir.GlobalConfig() +func (c *ConfigStorage) Config() (conf *config.Config, err error) { + f, err := c.dir.Config() if err != nil { if os.IsNotExist(err) { - return cfg, nil + return config.NewConfig(), nil } return nil, err } defer ioutil.CheckClose(f, &err) - - b, err = stdioutil.ReadAll(f) - if err != nil { - return cfg, err - } - - if err = cfg.UnmarshalScoped(format.GlobalScope, b); err != nil { - return cfg, err - } - - // system config (/etc/gitconfig) - f, err = c.dir.SystemConfig() - if err != nil { - if os.IsNotExist(err) { - return cfg, nil - } - - return nil, err - } - - defer ioutil.CheckClose(f, &err) - - b, err = stdioutil.ReadAll(f) - if err != nil { - return cfg, err - } - - if err = cfg.UnmarshalScoped(format.SystemScope, b); err != nil { - return cfg, err - } - - return cfg, err + return config.ReadConfig(f) } func (c *ConfigStorage) SetConfig(cfg *config.Config) (err error) { @@ -88,7 +31,7 @@ func (c *ConfigStorage) SetConfig(cfg *config.Config) (err error) { return err } - f, err := c.dir.LocalConfigWriter() + f, err := c.dir.ConfigWriter() if err != nil { return err } |