1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-19 00:24:31 +00:00
gitea/vendor/gopkg.in/src-d/go-git.v4/storage/filesystem/config.go
Lauris BH 08bf443016 Implement git refs API for listing references (branches, tags and other) (#5354)
* Inital routes to git refs api

* Git refs API implementation

* Update swagger

* Fix copyright

* Make swagger happy add basic test

* Fix test

* Fix test again :)
2018-11-27 16:52:20 -05:00

62 lines
962 B
Go

package filesystem
import (
stdioutil "io/ioutil"
"os"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/storage/filesystem/dotgit"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
)
type ConfigStorage struct {
dir *dotgit.DotGit
}
func (c *ConfigStorage) Config() (conf *config.Config, err error) {
cfg := config.NewConfig()
f, err := c.dir.Config()
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 nil, err
}
if err = cfg.Unmarshal(b); err != nil {
return nil, err
}
return cfg, err
}
func (c *ConfigStorage) SetConfig(cfg *config.Config) (err error) {
if err = cfg.Validate(); err != nil {
return err
}
f, err := c.dir.ConfigWriter()
if err != nil {
return err
}
defer ioutil.CheckClose(f, &err)
b, err := cfg.Marshal()
if err != nil {
return err
}
_, err = f.Write(b)
return err
}