aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2022-12-11 11:41:38 +0100
committerGitHub <noreply@github.com>2022-12-11 11:41:38 +0100
commitc7050e7c96c49b94ec0033255aed302081ee145e (patch)
treec39b970b1403d10693795ad6d61dd1ea59db4a2d /worktree_test.go
parent3e07c5030b4e3b2fcbcb461f9f6b23212f978335 (diff)
parenta513415283c4628259c016587858fe56d7b0fa13 (diff)
downloadgo-git-c7050e7c96c49b94ec0033255aed302081ee145e.tar.gz
Merge pull request #623 from pjbgf/empty-commit
Return error instead of creating empty commits
Diffstat (limited to 'worktree_test.go')
-rw-r--r--worktree_test.go36
1 files changed, 33 insertions, 3 deletions
diff --git a/worktree_test.go b/worktree_test.go
index 4a14126..4c06333 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -3,7 +3,6 @@ package git
import (
"bytes"
"context"
- "errors"
"io"
"io/ioutil"
"os"
@@ -2167,6 +2166,8 @@ func (s *WorktreeSuite) TestGrep(c *C) {
}
func (s *WorktreeSuite) TestAddAndCommit(c *C) {
+ expectedFiles := 2
+
dir, clean := s.TemporalDir()
defer clean()
@@ -2176,17 +2177,23 @@ func (s *WorktreeSuite) TestAddAndCommit(c *C) {
w, err := repo.Worktree()
c.Assert(err, IsNil)
+ os.WriteFile(filepath.Join(dir, "foo"), []byte("bar"), 0o644)
+ os.WriteFile(filepath.Join(dir, "bar"), []byte("foo"), 0o644)
+
_, err = w.Add(".")
c.Assert(err, IsNil)
- w.Commit("Test Add And Commit", &CommitOptions{Author: &object.Signature{
+ _, err = w.Commit("Test Add And Commit", &CommitOptions{Author: &object.Signature{
Name: "foo",
Email: "foo@foo.foo",
When: time.Now(),
}})
+ c.Assert(err, IsNil)
iter, err := w.r.Log(&LogOptions{})
c.Assert(err, IsNil)
+
+ filesFound := 0
err = iter.ForEach(func(c *object.Commit) error {
files, err := c.Files()
if err != nil {
@@ -2194,11 +2201,34 @@ func (s *WorktreeSuite) TestAddAndCommit(c *C) {
}
err = files.ForEach(func(f *object.File) error {
- return errors.New("Expected no files, got at least 1")
+ filesFound++
+ return nil
})
return err
})
c.Assert(err, IsNil)
+ c.Assert(filesFound, Equals, expectedFiles)
+}
+
+func (s *WorktreeSuite) TestAddAndCommitEmpty(c *C) {
+ dir, clean := s.TemporalDir()
+ defer clean()
+
+ repo, err := PlainInit(dir, false)
+ c.Assert(err, IsNil)
+
+ w, err := repo.Worktree()
+ c.Assert(err, IsNil)
+
+ _, err = w.Add(".")
+ c.Assert(err, IsNil)
+
+ _, err = w.Commit("Test Add And Commit", &CommitOptions{Author: &object.Signature{
+ Name: "foo",
+ Email: "foo@foo.foo",
+ When: time.Now(),
+ }})
+ c.Assert(err, Equals, ErrEmptyCommit)
}
func (s *WorktreeSuite) TestLinkedWorktree(c *C) {