1package config 2 3import ( 4 "github.com/go-git/go-git/v5/plumbing" 5 6 . "gopkg.in/check.v1" 7) 8 9type BranchSuite struct{} 10 11var _ = Suite(&BranchSuite{}) 12 13func (b *BranchSuite) TestValidateName(c *C) { 14 goodBranch := Branch{ 15 Name: "master", 16 Remote: "some_remote", 17 Merge: "refs/heads/master", 18 } 19 badBranch := Branch{ 20 Remote: "some_remote", 21 Merge: "refs/heads/master", 22 } 23 c.Assert(goodBranch.Validate(), IsNil) 24 c.Assert(badBranch.Validate(), NotNil) 25} 26 27func (b *BranchSuite) TestValidateMerge(c *C) { 28 goodBranch := Branch{ 29 Name: "master", 30 Remote: "some_remote", 31 Merge: "refs/heads/master", 32 } 33 badBranch := Branch{ 34 Name: "master", 35 Remote: "some_remote", 36 Merge: "blah", 37 } 38 c.Assert(goodBranch.Validate(), IsNil) 39 c.Assert(badBranch.Validate(), NotNil) 40} 41 42func (b *BranchSuite) TestMarshal(c *C) { 43 expected := []byte(`[core] 44 bare = false 45[branch "branch-tracking-on-clone"] 46 remote = fork 47 merge = refs/heads/branch-tracking-on-clone 48 rebase = interactive 49`) 50 51 cfg := NewConfig() 52 cfg.Branches["branch-tracking-on-clone"] = &Branch{ 53 Name: "branch-tracking-on-clone", 54 Remote: "fork", 55 Merge: plumbing.ReferenceName("refs/heads/branch-tracking-on-clone"), 56 Rebase: "interactive", 57 } 58 59 actual, err := cfg.Marshal() 60 c.Assert(err, IsNil) 61 c.Assert(string(actual), Equals, string(expected)) 62} 63 64func (b *BranchSuite) TestUnmarshal(c *C) { 65 input := []byte(`[core] 66 bare = false 67[branch "branch-tracking-on-clone"] 68 remote = fork 69 merge = refs/heads/branch-tracking-on-clone 70 rebase = interactive 71`) 72 73 cfg := NewConfig() 74 err := cfg.Unmarshal(input) 75 c.Assert(err, IsNil) 76 branch := cfg.Branches["branch-tracking-on-clone"] 77 c.Assert(branch.Name, Equals, "branch-tracking-on-clone") 78 c.Assert(branch.Remote, Equals, "fork") 79 c.Assert(branch.Merge, Equals, plumbing.ReferenceName("refs/heads/branch-tracking-on-clone")) 80 c.Assert(branch.Rebase, Equals, "interactive") 81} 82