Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handling of nested unignores #119

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 → test/nested-unignores.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*'], // unignore directory
'd/d/.ignore': ['!h/', '!cc*'], // unignore directory with slash
'd/h/h/.ignore': ['!dd*'], // 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