aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_commit_test.go
diff options
context:
space:
mode:
authorMoran Cohen <moran@wiz.io>2024-01-11 17:30:44 +0200
committerMoran Cohen <moran@wiz.io>2024-01-17 15:10:40 +0200
commitd5f1dd61fb79389218a9fe3b5574acf8409737b1 (patch)
tree5650e2ad0d26811d596a9e6140437ba3b24a2f19 /worktree_commit_test.go
parenta6e934f1f76996c7f92cb4fde708170c1eb5d032 (diff)
downloadgo-git-d5f1dd61fb79389218a9fe3b5574acf8409737b1.tar.gz
git: Worktree.AddWithOptions, add skipStatus option. #993
Diffstat (limited to 'worktree_commit_test.go')
-rw-r--r--worktree_commit_test.go113
1 files changed, 112 insertions, 1 deletions
diff --git a/worktree_commit_test.go b/worktree_commit_test.go
index 1ac1990..a3103b7 100644
--- a/worktree_commit_test.go
+++ b/worktree_commit_test.go
@@ -131,7 +131,6 @@ func (s *WorktreeSuite) TestCommitAmend(c *C) {
_, err = w.Commit("foo\n", &CommitOptions{Author: defaultSignature()})
c.Assert(err, IsNil)
-
amendedHash, err := w.Commit("bar\n", &CommitOptions{Amend: true})
c.Assert(err, IsNil)
@@ -144,6 +143,118 @@ func (s *WorktreeSuite) TestCommitAmend(c *C) {
assertStorageStatus(c, s.Repository, 13, 11, 11, amendedHash)
}
+func (s *WorktreeSuite) TestAddAndCommitWithSkipStatus(c *C) {
+ expected := plumbing.NewHash("375a3808ffde7f129cdd3c8c252fd0fe37cfd13b")
+
+ fs := memfs.New()
+ w := &Worktree{
+ r: s.Repository,
+ Filesystem: fs,
+ }
+
+ err := w.Checkout(&CheckoutOptions{})
+ c.Assert(err, IsNil)
+
+ util.WriteFile(fs, "LICENSE", []byte("foo"), 0644)
+ util.WriteFile(fs, "foo", []byte("foo"), 0644)
+
+ err = w.AddWithOptions(&AddOptions{
+ Path: "foo",
+ SkipStatus: true,
+ })
+ c.Assert(err, IsNil)
+
+ hash, err := w.Commit("commit foo only\n", &CommitOptions{
+ Author: defaultSignature(),
+ })
+
+ c.Assert(hash, Equals, expected)
+ c.Assert(err, IsNil)
+
+ assertStorageStatus(c, s.Repository, 13, 11, 10, expected)
+}
+
+func (s *WorktreeSuite) TestAddAndCommitWithSkipStatusPathNotModified(c *C) {
+ expected := plumbing.NewHash("375a3808ffde7f129cdd3c8c252fd0fe37cfd13b")
+ expected2 := plumbing.NewHash("8691273baf8f6ee2cccfc05e910552c04d02d472")
+
+ fs := memfs.New()
+ w := &Worktree{
+ r: s.Repository,
+ Filesystem: fs,
+ }
+
+ err := w.Checkout(&CheckoutOptions{})
+ c.Assert(err, IsNil)
+
+ util.WriteFile(fs, "foo", []byte("foo"), 0644)
+
+ status, err := w.Status()
+ c.Assert(err, IsNil)
+ foo := status.File("foo")
+ c.Assert(foo.Staging, Equals, Untracked)
+ c.Assert(foo.Worktree, Equals, Untracked)
+
+ err = w.AddWithOptions(&AddOptions{
+ Path: "foo",
+ SkipStatus: true,
+ })
+ c.Assert(err, IsNil)
+
+ status, err = w.Status()
+ c.Assert(err, IsNil)
+ foo = status.File("foo")
+ c.Assert(foo.Staging, Equals, Added)
+ c.Assert(foo.Worktree, Equals, Unmodified)
+
+ hash, err := w.Commit("commit foo only\n", &CommitOptions{All: true,
+ Author: defaultSignature(),
+ })
+ c.Assert(hash, Equals, expected)
+ c.Assert(err, IsNil)
+ commit1, err := w.r.CommitObject(hash)
+
+ status, err = w.Status()
+ c.Assert(err, IsNil)
+ foo = status.File("foo")
+ c.Assert(foo.Staging, Equals, Untracked)
+ c.Assert(foo.Worktree, Equals, Untracked)
+
+ assertStorageStatus(c, s.Repository, 13, 11, 10, expected)
+
+ err = w.AddWithOptions(&AddOptions{
+ Path: "foo",
+ SkipStatus: true,
+ })
+ c.Assert(err, IsNil)
+
+ status, err = w.Status()
+ c.Assert(err, IsNil)
+ foo = status.File("foo")
+ c.Assert(foo.Staging, Equals, Untracked)
+ c.Assert(foo.Worktree, Equals, Untracked)
+
+ hash, err = w.Commit("commit with no changes\n", &CommitOptions{
+ Author: defaultSignature(),
+ })
+ c.Assert(hash, Equals, expected2)
+ c.Assert(err, IsNil)
+ commit2, err := w.r.CommitObject(hash)
+
+ status, err = w.Status()
+ c.Assert(err, IsNil)
+ foo = status.File("foo")
+ c.Assert(foo.Staging, Equals, Untracked)
+ c.Assert(foo.Worktree, Equals, Untracked)
+
+ patch, err := commit2.Patch(commit1)
+ c.Assert(err, IsNil)
+ files := patch.FilePatches()
+ c.Assert(files, IsNil)
+
+ assertStorageStatus(c, s.Repository, 13, 11, 11, expected2)
+}
+
func (s *WorktreeSuite) TestCommitAll(c *C) {
expected := plumbing.NewHash("aede6f8c9c1c7ec9ca8d287c64b8ed151276fa28")