aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_commit_test.go
diff options
context:
space:
mode:
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")