diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-05-23 09:23:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-23 09:23:27 +0100 |
commit | 1feac1b95958fbce7eabffa671f3fc6aab2a8258 (patch) | |
tree | 69cfb8382a3fac7053e396e151c27027f82600ec /repository_test.go | |
parent | 90bfbf2c5cb34da7cfa59e09275d34b159aa57f3 (diff) | |
parent | 1aa8e8940336aa80eccdd8dd9b46b0e6547e7127 (diff) | |
download | go-git-1feac1b95958fbce7eabffa671f3fc6aab2a8258.tar.gz |
Merge pull request #764 from techknowlogick/init-options
git: Allow Initial Branch to be configurable
Diffstat (limited to 'repository_test.go')
-rw-r--r-- | repository_test.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go index 45af396..965f028 100644 --- a/repository_test.go +++ b/repository_test.go @@ -51,6 +51,54 @@ func (s *RepositorySuite) TestInit(c *C) { cfg, err := r.Config() c.Assert(err, IsNil) c.Assert(cfg.Core.IsBare, Equals, false) + + // check the HEAD to see what the default branch is + createCommit(c, r) + ref, err := r.Head() + c.Assert(err, IsNil) + c.Assert(ref.Name().String(), Equals, plumbing.Master.String()) +} + +func (s *RepositorySuite) TestInitWithOptions(c *C) { + r, err := InitWithOptions(memory.NewStorage(), memfs.New(), InitOptions{ + DefaultBranch: "refs/heads/foo", + }) + c.Assert(err, IsNil) + c.Assert(r, NotNil) + createCommit(c, r) + + ref, err := r.Head() + c.Assert(err, IsNil) + c.Assert(ref.Name().String(), Equals, "refs/heads/foo") + +} + +func createCommit(c *C, r *Repository) { + // Create a commit so there is a HEAD to check + wt, err := r.Worktree() + c.Assert(err, IsNil) + + rm, err := wt.Filesystem.Create("foo.txt") + c.Assert(err, IsNil) + + _, err = rm.Write([]byte("foo text")) + c.Assert(err, IsNil) + + _, err = wt.Add("foo.txt") + c.Assert(err, IsNil) + + author := object.Signature{ + Name: "go-git", + Email: "go-git@fake.local", + When: time.Now(), + } + _, err = wt.Commit("test commit message", &CommitOptions{ + All: true, + Author: &author, + Committer: &author, + }) + c.Assert(err, IsNil) + } func (s *RepositorySuite) TestInitNonStandardDotGit(c *C) { |