aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/config.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-11-03 17:10:43 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-11-03 17:10:43 +0100
commit3f7fbc6c49e50eb22e3de8a5143817fa7c0c54dd (patch)
tree0bf81a6dd858278000d1d7f7afc578d993fba791 /storage/filesystem/config.go
parent94f5e9c949963893d1c3d3e987a591ee15265327 (diff)
downloadgo-git-3f7fbc6c49e50eb22e3de8a5143817fa7c0c54dd.tar.gz
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.
Diffstat (limited to 'storage/filesystem/config.go')
-rw-r--r--storage/filesystem/config.go19
1 files changed, 12 insertions, 7 deletions
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 {