Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Submodules init and update #270

Merged
merged 12 commits into from
Feb 21, 2017
9 changes: 9 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change name to WorkTtree.

Add full stop at the end of the phrase.

We should call it WorkTreePath.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worktree is a single word, is a concept. I think that is enough to explained that is a path, since a worktree and is a string.

}
// Remote list of repository remotes
Remotes map[string]*RemoteConfig
Expand Down Expand Up @@ -76,6 +78,7 @@ const (
fetchKey = "fetch"
urlKey = "url"
bareKey = "bare"
worktreeKey = "worktree"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to workTreeKey.

)

// Unmarshal parses a git-config file and stores it
Expand All @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
25 changes: 25 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var _ = Suite(&ConfigSuite{})
func (s *ConfigSuite) TestUnmarshall(c *C) {
input := []byte(`[core]
bare = true
worktree = foo
[remote "origin"]
url = [email protected]:mcuadros/go-git.git
fetch = +refs/heads/*:refs/remotes/origin/*
Expand All @@ -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, "[email protected]: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 = [email protected]:mcuadros/go-git.git
`)

cfg := NewConfig()
cfg.Core.IsBare = true
cfg.Core.Worktree = "bar"
cfg.Remotes["origin"] = &RemoteConfig{
Name: "origin",
URL: "[email protected]: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 = [email protected]:mcuadros/go-git.git
Expand Down