Skip to content

Commit

Permalink
fix: handling of nested unignores (#119)
Browse files Browse the repository at this point in the history
The fix in #116 was not quite complete. git does allow unignoring
directories as long as its path to the root is unignored. This modifies
the check to handle this case. The test case in `nested-ignores.js` was
indeed wrong because it interpreted unignoring a specific file
`!/h/c/d/hcd` as unignoring the directory `!/h/c/d`. I added new tests
that specifically unignore a directory and therefore allow unignoring
anything else within it.

## References
Related to #116
  • Loading branch information
mohd-akram authored and wraithgar committed Nov 29, 2023
1 parent 493401a commit b587cc3
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 → 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

0 comments on commit b587cc3

Please sign in to comment.