diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-02-13 23:38:57 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-02-13 23:38:57 +0100 |
commit | f8b5557875513c5b0aff24bb7b8e28f8f680976f (patch) | |
tree | 56ae4d1b2cde8644216c594e6913b9c6f763cd8b | |
parent | 940a16ca68457beded1eff551f23febeffb32f3e (diff) | |
download | go-git-f8b5557875513c5b0aff24bb7b8e28f8f680976f.tar.gz |
config: adding Config.Core.Worktree
-rw-r--r-- | config/config.go | 9 | ||||
-rw-r--r-- | config/config_test.go | 25 |
2 files changed, 34 insertions, 0 deletions
diff --git a/config/config.go b/config/config.go index 866ae8e..b3a3fcc 100644 --- a/config/config.go +++ b/config/config.go @@ -37,6 +37,8 @@ type Config struct { // IsBare if true this repository is assumed to be bare and has no // working directory associated with it IsBare bool + // Worktree is the path to the root of the working tree + Worktree string } // Remote list of repository remotes Remotes map[string]*RemoteConfig @@ -76,6 +78,7 @@ const ( fetchKey = "fetch" urlKey = "url" bareKey = "bare" + worktreeKey = "worktree" ) // Unmarshal parses a git-config file and stores it @@ -97,6 +100,8 @@ func (c *Config) unmarshalCore() { if s.Options.Get(bareKey) == "true" { c.Core.IsBare = true } + + c.Core.Worktree = s.Options.Get(worktreeKey) } func (c *Config) unmarshalRemotes() error { @@ -129,6 +134,10 @@ func (c *Config) Marshal() ([]byte, error) { func (c *Config) marshalCore() { s := c.raw.Section(coreSection) s.SetOption(bareKey, fmt.Sprintf("%t", c.Core.IsBare)) + + if c.Core.Worktree != "" { + s.SetOption(worktreeKey, c.Core.Worktree) + } } func (c *Config) marshalRemotes() { diff --git a/config/config_test.go b/config/config_test.go index 2bcefe4..313c96c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -9,6 +9,7 @@ var _ = Suite(&ConfigSuite{}) func (s *ConfigSuite) TestUnmarshall(c *C) { input := []byte(`[core] bare = true + worktree = foo [remote "origin"] url = git@github.com:mcuadros/go-git.git fetch = +refs/heads/*:refs/remotes/origin/* @@ -22,15 +23,39 @@ func (s *ConfigSuite) TestUnmarshall(c *C) { c.Assert(err, IsNil) c.Assert(cfg.Core.IsBare, Equals, true) + c.Assert(cfg.Core.Worktree, Equals, "foo") c.Assert(cfg.Remotes, HasLen, 1) c.Assert(cfg.Remotes["origin"].Name, Equals, "origin") c.Assert(cfg.Remotes["origin"].URL, Equals, "git@github.com:mcuadros/go-git.git") c.Assert(cfg.Remotes["origin"].Fetch, DeepEquals, []RefSpec{"+refs/heads/*:refs/remotes/origin/*"}) } +func (s *ConfigSuite) TestMarshall(c *C) { + output := []byte(`[core] + bare = true + worktree = bar +[remote "origin"] + url = git@github.com:mcuadros/go-git.git +`) + + cfg := NewConfig() + cfg.Core.IsBare = true + cfg.Core.Worktree = "bar" + cfg.Remotes["origin"] = &RemoteConfig{ + Name: "origin", + URL: "git@github.com:mcuadros/go-git.git", + } + + b, err := cfg.Marshal() + c.Assert(err, IsNil) + + c.Assert(string(b), Equals, string(output)) +} + func (s *ConfigSuite) TestUnmarshallMarshall(c *C) { input := []byte(`[core] bare = true + worktree = foo custom = ignored [remote "origin"] url = git@github.com:mcuadros/go-git.git |