Skip to content

Commit

Permalink
3.3.5: fixes #16: ensure the test result by using git check-ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelzhang committed Aug 29, 2017
1 parent 3d58272 commit b0dc08e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ ig.filter(['.abc\\a.js', '.abc\\d\\e.js'])
- Handle trailing whitespaces:
- `'a '`(one space) should not match `'a '`(two spaces).
- `'a \ '` matches `'a '`
- All test cases are verified with the result of `git check-ignore`.

## Methods

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ignore",
"version": "3.3.4",
"version": "3.3.5",
"description": "Ignore is a manager and filter for .gitignore rules.",
"main": "./ignore.js",
"files": [
Expand Down
33 changes: 16 additions & 17 deletions test/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,10 @@ var cases = [
[
'abc\\ ', // only one space left -> (abc )
'bcd ', // no space left -> (bcd)
'cde \\ ' // -> (cde )
'cde \\ ' // two spaces -> (cde )
],
{
// nothing to do with backslashes
'abc\\ ': 0,
'abc ': 0,
'abc ': 1,
Expand All @@ -273,8 +274,7 @@ var cases = [
'cde ': 1,
'cde ': 0,
'cde ': 0
},
true
}
],
[
'An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again',
Expand Down Expand Up @@ -650,7 +650,6 @@ describe("cases", function() {
&& it('test for test: ' + description, function () {
var result = getNativeGitIgnoreResults(patterns, paths).sort()

console.log(JSON.stringify(result, null, 2), JSON.stringify(expected, null, 2))
expect_result(result)
})

Expand Down Expand Up @@ -710,7 +709,6 @@ function createUniqueTmp () {
// Make sure the dir not exists,
// clean up dirty things
rm(dir)
console.log('exists', fs.existsSync(dir))
mkdirp(dir)
return dir
}
Expand All @@ -719,12 +717,11 @@ function createUniqueTmp () {
function getNativeGitIgnoreResults (rules, paths) {
var dir = createUniqueTmp()

var gitignore = rules.join('\n')
console.log('gitignore', gitignore)
var gitignore = typeof rules === 'string'
? rules
: rules.join('\n')

touch(dir, '.gitignore', gitignore)
console.log('dir', dir)
var content = fs.readFileSync(path.join(dir, '.gitignore')).toString()
console.log('.gitignore content', fs.readFileSync(path.join(dir, '.gitignore')).toString(), content === gitignore)

paths.forEach(function (path, i) {
if (path === '.gitignore') {
Expand Down Expand Up @@ -758,9 +755,10 @@ console.log('.gitignore content', fs.readFileSync(path.join(dir, '.gitignore')).
path
], {
cwd: dir
}).stdout.toString().trim()
}).stdout.toString()

out = removeEnding(out, '\n')

console.log('out:', out, path)
var ignored = out === path
return !ignored
})
Expand All @@ -779,8 +777,10 @@ function touch (root, file, content) {
mkdirp(path.posix.join(root, dir))
}

console.log(path.join(root, file), content)
fs.writeFileSync(path.join(root, file), content || '')
// abc/ -> should not create file, but only dir
if (basename) {
fs.writeFileSync(path.join(root, file), content || '')
}
}


Expand All @@ -792,9 +792,8 @@ function containsInOthers (path, index, paths) {
return
}

p = removeEnding(p, '/')

return p.indexOf(path) === 0 && p[path.length] === '/'
return p === path
|| p.indexOf(path) === 0 && p[path.length] === '/'
})
}

Expand Down

0 comments on commit b0dc08e

Please sign in to comment.