aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--worktree.go4
-rw-r--r--worktree_status.go9
-rw-r--r--worktree_test.go52
3 files changed, 58 insertions, 7 deletions
diff --git a/worktree.go b/worktree.go
index 595dcea..f9c01af 100644
--- a/worktree.go
+++ b/worktree.go
@@ -368,7 +368,7 @@ func (w *Worktree) resetIndex(t *object.Tree, dirs []string) error {
}
func (w *Worktree) resetWorktree(t *object.Tree) error {
- changes, err := w.diffStagingWithWorktree(true)
+ changes, err := w.diffStagingWithWorktree(true, false)
if err != nil {
return err
}
@@ -420,7 +420,7 @@ func (w *Worktree) checkoutChange(ch merkletrie.Change, t *object.Tree, idx *ind
}
func (w *Worktree) containsUnstagedChanges() (bool, error) {
- ch, err := w.diffStagingWithWorktree(false)
+ ch, err := w.diffStagingWithWorktree(false, true)
if err != nil {
return false, err
}
diff --git a/worktree_status.go b/worktree_status.go
index 61bb6f7..7301087 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -74,7 +74,7 @@ func (w *Worktree) status(commit plumbing.Hash) (Status, error) {
}
}
- right, err := w.diffStagingWithWorktree(false)
+ right, err := w.diffStagingWithWorktree(false, true)
if err != nil {
return nil, err
}
@@ -113,7 +113,7 @@ func nameFromAction(ch *merkletrie.Change) string {
return name
}
-func (w *Worktree) diffStagingWithWorktree(reverse bool) (merkletrie.Changes, error) {
+func (w *Worktree) diffStagingWithWorktree(reverse, excludeIgnoredChanges bool) (merkletrie.Changes, error) {
idx, err := w.r.Storer.Index()
if err != nil {
return nil, err
@@ -138,7 +138,10 @@ func (w *Worktree) diffStagingWithWorktree(reverse bool) (merkletrie.Changes, er
return nil, err
}
- return w.excludeIgnoredChanges(c), nil
+ if excludeIgnoredChanges {
+ return w.excludeIgnoredChanges(c), nil
+ }
+ return c, nil
}
func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.Changes {
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{