aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/config.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-21 01:06:59 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-21 01:06:59 +0200
commitc9f0c29f423f9bb26f32d6e8c7098f275171afb9 (patch)
tree9c746b16c92a6820f34d504a2a2dd6881d65f559 /storage/filesystem/config.go
parent4652c0e753c88e63ba111d49aa58edc655806c03 (diff)
downloadgo-git-c9f0c29f423f9bb26f32d6e8c7098f275171afb9.tar.gz
storage/filesystem: ConfigStore implementation
Diffstat (limited to 'storage/filesystem/config.go')
-rw-r--r--storage/filesystem/config.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/storage/filesystem/config.go b/storage/filesystem/config.go
new file mode 100644
index 0000000..c83a59e
--- /dev/null
+++ b/storage/filesystem/config.go
@@ -0,0 +1,76 @@
+package filesystem
+
+import (
+ "fmt"
+ "io"
+
+ "gopkg.in/gcfg.v1"
+ "gopkg.in/src-d/go-git.v4/config"
+ "gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
+)
+
+type ConfigStorage struct {
+ dir *dotgit.DotGit
+}
+
+func (c *ConfigStorage) Remote(name string) (*config.RemoteConfig, error) {
+ file, err := c.read()
+ if err != nil {
+ return nil, err
+ }
+
+ r, ok := file.Remotes[name]
+ if ok {
+ return r, nil
+ }
+
+ return nil, config.ErrRemoteConfigNotFound
+}
+
+func (c *ConfigStorage) Remotes() ([]*config.RemoteConfig, error) {
+ file, err := c.read()
+ if err != nil {
+ return nil, err
+ }
+
+ remotes := make([]*config.RemoteConfig, len(file.Remotes))
+
+ var i int
+ for _, r := range file.Remotes {
+ remotes[i] = r
+ }
+
+ return remotes, nil
+}
+
+func (c *ConfigStorage) SetRemote(r *config.RemoteConfig) error {
+ return fmt.Errorf("not implemented yet")
+}
+
+func (c *ConfigStorage) DeleteRemote(name string) error {
+ return fmt.Errorf("not implemented yet")
+}
+
+func (c *ConfigStorage) read() (*ConfigFile, error) {
+ fs, path, err := c.dir.Config()
+ if err != nil {
+ return nil, err
+ }
+
+ r, err := fs.Open(path)
+ if err != nil {
+ return nil, err
+ }
+
+ f := &ConfigFile{}
+ return f, f.Decode(r)
+}
+
+type ConfigFile struct {
+ Remotes map[string]*config.RemoteConfig `gcfg:"remote"`
+}
+
+// Decode decode a git config file intro the ConfigStore
+func (c *ConfigFile) Decode(r io.Reader) error {
+ return gcfg.FatalOnly(gcfg.ReadInto(c, r))
+}