aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2019-03-04 15:30:51 +0100
committerGitHub <noreply@github.com>2019-03-04 15:30:51 +0100
commitdb522f11113a9ec240d8bd9c203687ddb4fd330c (patch)
tree94d4bb6c6281d92fec6cd4753cd2db2131983dfd
parentaf1e3817a80cccb560b25b0fd3343894754020ba (diff)
parentb2e0af997b79f45e99de4330473f110f01b68681 (diff)
downloadgo-git-db522f11113a9ec240d8bd9c203687ddb4fd330c.tar.gz
Merge pull request #1070 from fbsb/fix/enable-excluded-patterns
worktree: allow manual ignore patterns when no .gitignore is available
-rw-r--r--worktree_status.go6
-rw-r--r--worktree_test.go28
2 files changed, 33 insertions, 1 deletions
diff --git a/worktree_status.go b/worktree_status.go
index 0e113d0..16ce937 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -142,12 +142,16 @@ func (w *Worktree) diffStagingWithWorktree(reverse bool) (merkletrie.Changes, er
func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.Changes {
patterns, err := gitignore.ReadPatterns(w.Filesystem, nil)
- if err != nil || len(patterns) == 0 {
+ if err != nil {
return changes
}
patterns = append(patterns, w.Excludes...)
+ if len(patterns) == 0 {
+ return changes
+ }
+
m := gitignore.NewMatcher(patterns)
var res merkletrie.Changes
diff --git a/worktree_test.go b/worktree_test.go
index 872cd82..afedc91 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -1129,6 +1129,34 @@ func (s *WorktreeSuite) TestIgnored(c *C) {
c.Assert(file.Worktree, Equals, Untracked)
}
+func (s *WorktreeSuite) TestExcludedNoGitignore(c *C) {
+ f := fixtures.ByTag("empty").One()
+ r := s.NewRepository(f)
+
+ fs := memfs.New()
+ w := &Worktree{
+ r: r,
+ Filesystem: fs,
+ }
+
+ _, err := fs.Open(".gitignore")
+ c.Assert(err, Equals, os.ErrNotExist)
+
+ w.Excludes = make([]gitignore.Pattern, 0)
+ w.Excludes = append(w.Excludes, gitignore.ParsePattern("foo", nil))
+
+ err = util.WriteFile(w.Filesystem, "foo", []byte("FOO"), 0755)
+ c.Assert(err, IsNil)
+
+ status, err := w.Status()
+ c.Assert(err, IsNil)
+ c.Assert(status, HasLen, 0)
+
+ file := status.File("foo")
+ c.Assert(file.Staging, Equals, Untracked)
+ c.Assert(file.Worktree, Equals, Untracked)
+}
+
func (s *WorktreeSuite) TestAddModified(c *C) {
fs := memfs.New()
w := &Worktree{