aboutsummaryrefslogtreecommitdiffstats
path: root/config/config_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2020-10-30 11:35:16 +0100
committerGitHub <noreply@github.com>2020-10-30 11:35:16 +0100
commitd525a514057f97bc2b183e2c67f542dd6f0ac0aa (patch)
tree8fa62a4f2430b9d6d9681ee9c821a7682c50b4bf /config/config_test.go
parente9c56de2575147bbd38576e94f6e677917d208be (diff)
parent125fb621b9bd0ebc1adff2895ee646d4452459f4 (diff)
downloadgo-git-d525a514057f97bc2b183e2c67f542dd6f0ac0aa.tar.gz
Merge pull request #178 from tomlazar/defaultbranch
config: add init.defaultBranch to the config
Diffstat (limited to 'config/config_test.go')
-rw-r--r--config/config_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/config/config_test.go b/config/config_test.go
index 5a88c19..8108a94 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
+ "strings"
"github.com/go-git/go-git/v5/plumbing"
. "gopkg.in/check.v1"
@@ -46,6 +47,8 @@ func (s *ConfigSuite) TestUnmarshal(c *C) {
[branch "master"]
remote = origin
merge = refs/heads/master
+[init]
+ defaultBranch = main
`)
cfg := NewConfig()
@@ -77,6 +80,7 @@ func (s *ConfigSuite) TestUnmarshal(c *C) {
c.Assert(cfg.Submodules["qux"].Branch, Equals, "bar")
c.Assert(cfg.Branches["master"].Remote, Equals, "origin")
c.Assert(cfg.Branches["master"].Merge, Equals, plumbing.ReferenceName("refs/heads/master"))
+ c.Assert(cfg.Init.DefaultBranch, Equals, "main")
}
func (s *ConfigSuite) TestMarshal(c *C) {
@@ -99,12 +103,15 @@ func (s *ConfigSuite) TestMarshal(c *C) {
[branch "master"]
remote = origin
merge = refs/heads/master
+[init]
+ defaultBranch = main
`)
cfg := NewConfig()
cfg.Core.IsBare = true
cfg.Core.Worktree = "bar"
cfg.Pack.Window = 20
+ cfg.Init.DefaultBranch = "main"
cfg.Remotes["origin"] = &RemoteConfig{
Name: "origin",
URLs: []string{"git@github.com:mcuadros/go-git.git"},
@@ -315,3 +322,29 @@ func (s *ConfigSuite) TestRemoteConfigDefaultValues(c *C) {
c.Assert(config.Raw, NotNil)
c.Assert(config.Pack.Window, Equals, DefaultPackWindow)
}
+
+func (s *ConfigSuite) TestLoadConfigLocalScope(c *C) {
+ cfg, err := LoadConfig(LocalScope)
+ c.Assert(err, NotNil)
+ c.Assert(cfg, IsNil)
+}
+
+func (s *ConfigSuite) TestRemoveUrlOptions(c *C) {
+ buf := []byte(`
+[remote "alt"]
+ url = git@github.com:mcuadros/go-git.git
+ url = git@github.com:src-d/go-git.git
+ fetch = +refs/heads/*:refs/remotes/origin/*
+ fetch = +refs/pull/*:refs/remotes/origin/pull/*`)
+
+ cfg := NewConfig()
+ err := cfg.Unmarshal(buf)
+ c.Assert(err, IsNil)
+ c.Assert(len(cfg.Remotes), Equals, 1)
+ cfg.Remotes["alt"].URLs = []string{}
+
+ buf, err = cfg.Marshal()
+ if strings.Contains(string(buf), "url") {
+ c.Fatal("conifg should not contain any url sections")
+ }
+}