From 3f7fbc6c49e50eb22e3de8a5143817fa7c0c54dd Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Thu, 3 Nov 2016 17:10:43 +0100 Subject: storage/filesystem: implement missing functionality. (#110) * storage/filesystem: added ObjectStorage Set. * storage/filesystem: now passes all tests, except those specific to transactions. * formats/config: Encoder now encodes subsections with no options. * formats/config: add HasSubsection on Section. * dotgit: add Ref method to get specific reference. --- storage/filesystem/config.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'storage/filesystem/config.go') diff --git a/storage/filesystem/config.go b/storage/filesystem/config.go index ba7e40b..b32265f 100644 --- a/storage/filesystem/config.go +++ b/storage/filesystem/config.go @@ -24,12 +24,12 @@ func (c *ConfigStorage) Remote(name string) (*config.RemoteConfig, error) { return nil, err } - s := cfg.Section(remoteSection).Subsection(name) - if s == nil { + s := cfg.Section(remoteSection) + if !s.HasSubsection(name) { return nil, config.ErrRemoteConfigNotFound } - return parseRemote(s), nil + return parseRemote(s.Subsection(name)), nil } func (c *ConfigStorage) Remotes() ([]*config.RemoteConfig, error) { @@ -48,6 +48,10 @@ func (c *ConfigStorage) Remotes() ([]*config.RemoteConfig, error) { } func (c *ConfigStorage) SetRemote(r *config.RemoteConfig) error { + if err := r.Validate(); err != nil { + return err + } + cfg, err := c.read() if err != nil { return err @@ -55,7 +59,9 @@ func (c *ConfigStorage) SetRemote(r *config.RemoteConfig) error { s := cfg.Section(remoteSection).Subsection(r.Name) s.Name = r.Name - s.SetOption(urlKey, r.URL) + if r.URL != "" { + s.SetOption(urlKey, r.URL) + } s.RemoveOption(fetchKey) for _, rs := range r.Fetch { s.AddOption(fetchKey, rs.String()) @@ -103,15 +109,14 @@ func (c *ConfigStorage) write(cfg *gitconfig.Config) error { return err } - defer f.Close() - e := gitconfig.NewEncoder(f) err = e.Encode(cfg) if err != nil { + f.Close() return err } - return nil + return f.Close() } func parseRemote(s *gitconfig.Subsection) *config.RemoteConfig { -- cgit