diff options
author | Stephan <stephan.bechter@gmail.com> | 2023-07-28 11:08:55 +0200 |
---|---|---|
committer | Stephan <stephan.bechter@gmail.com> | 2023-09-04 08:13:33 +0200 |
commit | 753b0d5cef6d8ef27c35de884b3c1673a33d1916 (patch) | |
tree | 2b8dfeb9a5a75d9bd290c851dccb6cc2506e7b01 /worktree_test.go | |
parent | cd3a21c619126288123c32f4a714181f9e1a68f8 (diff) | |
download | go-git-753b0d5cef6d8ef27c35de884b3c1673a33d1916.tar.gz |
git: worktree, reset ignored files that are part of the worktree: Fixes #819
Diffstat (limited to 'worktree_test.go')
-rw-r--r-- | worktree_test.go | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/worktree_test.go b/worktree_test.go index 24d5bd5..c69c617 100644 --- a/worktree_test.go +++ b/worktree_test.go @@ -29,6 +29,10 @@ import ( . "gopkg.in/check.v1" ) +var ( + defaultTestCommitOptions = &CommitOptions{Author: &object.Signature{Name: "testuser", Email: "testemail"}} +) + type WorktreeSuite struct { BaseSuite } @@ -884,14 +888,15 @@ func (s *WorktreeSuite) TestStatusCheckedInBeforeIgnored(c *C) { c.Assert(err, IsNil) _, err = w.Add("fileToIgnore") c.Assert(err, IsNil) - _, err = w.Commit("Added file that will be ignored later", &CommitOptions{}) + + _, err = w.Commit("Added file that will be ignored later", defaultTestCommitOptions) c.Assert(err, IsNil) err = util.WriteFile(fs, ".gitignore", []byte("fileToIgnore\nsecondIgnoredFile"), 0755) c.Assert(err, IsNil) _, err = w.Add(".gitignore") c.Assert(err, IsNil) - _, err = w.Commit("Added .gitignore", &CommitOptions{}) + _, err = w.Commit("Added .gitignore", defaultTestCommitOptions) c.Assert(err, IsNil) status, err := w.Status() c.Assert(err, IsNil) @@ -1097,6 +1102,49 @@ func (s *WorktreeSuite) TestResetHard(c *C) { c.Assert(branch.Hash(), Equals, commit) } +func (s *WorktreeSuite) TestResetHardWithGitIgnore(c *C) { + fs := memfs.New() + w := &Worktree{ + r: s.Repository, + Filesystem: fs, + } + + err := w.Checkout(&CheckoutOptions{}) + c.Assert(err, IsNil) + + tf, err := fs.Create("newTestFile.txt") + c.Assert(err, IsNil) + _, err = tf.Write([]byte("testfile content")) + c.Assert(err, IsNil) + err = tf.Close() + c.Assert(err, IsNil) + _, err = w.Add("newTestFile.txt") + c.Assert(err, IsNil) + _, err = w.Commit("testcommit", &CommitOptions{Author: &object.Signature{Name: "name", Email: "email"}}) + c.Assert(err, IsNil) + + err = fs.Remove("newTestFile.txt") + c.Assert(err, IsNil) + f, err := fs.Create(".gitignore") + c.Assert(err, IsNil) + _, err = f.Write([]byte("foo\n")) + _, err = f.Write([]byte("newTestFile.txt\n")) + c.Assert(err, IsNil) + err = f.Close() + c.Assert(err, IsNil) + + status, err := w.Status() + c.Assert(err, IsNil) + c.Assert(status.IsClean(), Equals, false) + + err = w.Reset(&ResetOptions{Mode: HardReset}) + c.Assert(err, IsNil) + + status, err = w.Status() + c.Assert(err, IsNil) + c.Assert(status.IsClean(), Equals, true) +} + func (s *WorktreeSuite) TestStatusAfterCheckout(c *C) { fs := memfs.New() w := &Worktree{ |