aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_commit_test.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-08-05 10:20:38 +0100
committerGitHub <noreply@github.com>2023-08-05 10:20:38 +0100
commite6f68d2e4cd1bc4447126816c7c27e1fc2098e30 (patch)
tree15c5e333b93641f9eadcb4bf4b34c338135f7a23 /worktree_commit_test.go
parent5882d60fb7ccd4cfc0fe69286aa96e198c9d1eb0 (diff)
parent4ec6b3f4fa9cdfe8f10d0953ac7d398d01a90f17 (diff)
downloadgo-git-e6f68d2e4cd1bc4447126816c7c27e1fc2098e30.tar.gz
Merge branch 'master' into jc/commit-ammend
Diffstat (limited to 'worktree_commit_test.go')
-rw-r--r--worktree_commit_test.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/worktree_commit_test.go b/worktree_commit_test.go
index 547c820..1ac1990 100644
--- a/worktree_commit_test.go
+++ b/worktree_commit_test.go
@@ -26,12 +26,18 @@ import (
)
func (s *WorktreeSuite) TestCommitEmptyOptions(c *C) {
- r, err := Init(memory.NewStorage(), memfs.New())
+ fs := memfs.New()
+ r, err := Init(memory.NewStorage(), fs)
c.Assert(err, IsNil)
w, err := r.Worktree()
c.Assert(err, IsNil)
+ util.WriteFile(fs, "foo", []byte("foo"), 0644)
+
+ _, err = w.Add("foo")
+ c.Assert(err, IsNil)
+
hash, err := w.Commit("foo", &CommitOptions{})
c.Assert(err, IsNil)
c.Assert(hash.IsZero(), Equals, false)
@@ -65,6 +71,24 @@ func (s *WorktreeSuite) TestCommitInitial(c *C) {
assertStorageStatus(c, r, 1, 1, 1, expected)
}
+func (s *WorktreeSuite) TestNothingToCommit(c *C) {
+ expected := plumbing.NewHash("838ea833ce893e8555907e5ef224aa076f5e274a")
+
+ r, err := Init(memory.NewStorage(), memfs.New())
+ c.Assert(err, IsNil)
+
+ w, err := r.Worktree()
+ c.Assert(err, IsNil)
+
+ hash, err := w.Commit("failed empty commit\n", &CommitOptions{Author: defaultSignature()})
+ c.Assert(hash, Equals, plumbing.ZeroHash)
+ c.Assert(err, Equals, ErrEmptyCommit)
+
+ hash, err = w.Commit("enable empty commits\n", &CommitOptions{Author: defaultSignature(), AllowEmptyCommits: true})
+ c.Assert(hash, Equals, expected)
+ c.Assert(err, IsNil)
+}
+
func (s *WorktreeSuite) TestCommitParent(c *C) {
expected := plumbing.NewHash("ef3ca05477530b37f48564be33ddd48063fc7a22")