Skip to content

Commit

Permalink
fix: handling of nested ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
mohd-akram committed Nov 28, 2023
1 parent 8e9b2fd commit ffb9b48
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Walker extends EE {
this.result = this.parent ? this.parent.result : new Set()
this.entries = null
this.sawError = false
this.exact = opts.exact
}

sort (a, b) {
Expand Down Expand Up @@ -164,7 +165,7 @@ class Walker extends EE {
} else {
// is a directory
if (dir) {
this.walker(entry, { isSymbolicLink }, then)
this.walker(entry, { isSymbolicLink, exact: file || this.filterEntry(entry + '/') }, then)
} else {
then()
}
Expand Down Expand Up @@ -218,7 +219,7 @@ class Walker extends EE {
const parentEntry = this.basename + '/' + entry
const parentBasename = entryBasename || entry
included = this.parent.filterEntry(parentEntry, partial, parentBasename)
if (!included && partial) {
if (!included && !this.exact) {
return false
}
}
Expand Down
3 changes: 0 additions & 3 deletions test/nested-ignores.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ var expected = [
'c/d/c/ccc',
'c/d/d/ccc',
'd/c/h/.dch',
'h/c/d/.hcd',
'h/c/d/dch',
'h/c/d/ddd',
'h/c/d/hcd',
]

Expand Down
17 changes: 15 additions & 2 deletions test/preserve-ignores.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@ const path = resolve(__dirname, 'fixtures')
// set the ignores just for this test
var c = require('./common.js')
c.ignores({
'.ignore': ['*', '!/c', '!/d'],
'.ignore': ['*', '!/c/d', '!/d/c', '!/d/d/', '!/d/h/h'],
'c/.ignore': ['!*', '.ignore'], // unignore everything
'd/c/.ignore': ['!h', '!cc*', '.ignore'], // unignore directory
'd/d/.ignore': ['!h/', '!cc*', '.ignore'], // unignore directory with slash
'd/h/h/.ignore': ['!dd*', '.ignore'], // unignore files
})

// the only files we expect to see
var expected = []
var expected = [
'd/c/h/ccc',
'd/c/h/ccd',
'd/c/h/cch',
'd/d/h/ccc',
'd/d/h/ccd',
'd/d/h/cch',
'd/h/h/ddc',
'd/h/h/ddd',
'd/h/h/ddh',
]

const t = require('tap')

Expand Down

0 comments on commit ffb9b48

Please sign in to comment.