aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--worktree_status.go8
-rw-r--r--worktree_test.go34
2 files changed, 35 insertions, 7 deletions
diff --git a/worktree_status.go b/worktree_status.go
index 7116445..728d7a0 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -68,8 +68,6 @@ func (w *Worktree) status(commit plumbing.Hash) (Status, error) {
return nil, err
}
- right = w.excludeIgnoredChanges(right)
-
for _, ch := range right {
a, err := ch.Action()
if err != nil {
@@ -117,7 +115,11 @@ func (w *Worktree) diffStagingWithWorktree() (merkletrie.Changes, error) {
}
to := filesystem.NewRootNode(w.fs, submodules)
- return merkletrie.DiffTree(from, to, diffTreeIsEquals)
+ res, err := merkletrie.DiffTree(from, to, diffTreeIsEquals)
+ if err == nil {
+ res = w.excludeIgnoredChanges(res)
+ }
+ return res, err
}
func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.Changes {
diff --git a/worktree_test.go b/worktree_test.go
index 5d0d131..875f8d5 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -307,6 +307,35 @@ func (s *WorktreeSuite) testCheckoutBisect(c *C, url string) {
})
}
+func (s *WorktreeSuite) TestCheckoutWithGitignore(c *C) {
+ fs := memfs.New()
+ w := &Worktree{
+ r: s.Repository,
+ fs: fs,
+ }
+
+ err := w.Checkout(&CheckoutOptions{})
+ c.Assert(err, IsNil)
+
+ f, _ := fs.Create("file")
+ f.Close()
+
+ err = w.Checkout(&CheckoutOptions{})
+ c.Assert(err.Error(), Equals, "worktree contains unstagged changes")
+
+ f, _ = fs.Create(".gitignore")
+ f.Write([]byte("file"))
+ f.Close()
+
+ err = w.Checkout(&CheckoutOptions{})
+ c.Assert(err.Error(), Equals, "worktree contains unstagged changes")
+
+ w.Add(".gitignore")
+
+ err = w.Checkout(&CheckoutOptions{})
+ c.Assert(err, IsNil)
+}
+
func (s *WorktreeSuite) TestStatus(c *C) {
fs := memfs.New()
w := &Worktree{
@@ -458,10 +487,7 @@ func (s *WorktreeSuite) TestStatusModified(c *C) {
}
func (s *WorktreeSuite) TestStatusIgnored(c *C) {
- dir, _ := ioutil.TempDir("", "status")
- defer os.RemoveAll(dir)
-
- fs := osfs.New(filepath.Join(dir, "worktree"))
+ fs := memfs.New()
w := &Worktree{
r: s.Repository,
fs: fs,