aboutsummaryrefslogtreecommitdiffstats
path: root/repository_test.go
diff options
context:
space:
mode:
authortechknowlogick <techknowlogick@gitea.io>2023-05-21 02:24:18 -0400
committertechknowlogick <techknowlogick@gitea.io>2023-05-21 02:24:39 -0400
commit1aa8e8940336aa80eccdd8dd9b46b0e6547e7127 (patch)
treec08670331d0845a58d33166079d7e0d665ae610d /repository_test.go
parent1dbd729a387edb61c89f088cd68040085e6c81bb (diff)
downloadgo-git-1aa8e8940336aa80eccdd8dd9b46b0e6547e7127.tar.gz
git: Allow Initial Branch to be configurable
Diffstat (limited to 'repository_test.go')
-rw-r--r--repository_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go
index 0080a83..f992672 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -52,6 +52,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) {