Skip to content

Commit

Permalink
5.1.3: gitignore rules 2.22.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelzhang committed Aug 14, 2019
1 parent e61421e commit 0a95a91
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
17 changes: 9 additions & 8 deletions index.js
Expand Up @@ -111,14 +111,6 @@ const REPLACERS = [
// > A leading slash matches the beginning of the pathname.
// > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
// A leading slash matches the beginning of the pathname

// WTF! https://git-scm.com/docs/gitignore changes, the new rules are

// > If there is a separator at the beginning or middle (or both)
// > of the pattern, then the pattern is relative to the directory level of
// >.the particular .gitignore file itself. Otherwise the pattern may also
// > match at any level below the .gitignore level.

/^\//,
() => '^'
],
Expand Down Expand Up @@ -174,11 +166,20 @@ const REPLACERS = [
// If starts with '**', adding a '^' to the regular expression also works
/^(?=[^^])/,
function startingReplacer () {
// If has a slash `/` at the beginning or middle
return !/\/(?!$)/.test(this)
// > Prior to 2.22.1
// > If the pattern does not contain a slash /,
// > Git treats it as a shell glob pattern
// Actually, if there is only a trailing slash,
// git also treats it as a shell glob pattern

// After 2.22.1 (but compatible)
// > If there is a separator at the beginning or middle (or both)
// > of the pattern, then the pattern is relative to the directory
// > level of the particular .gitignore file itself.
// > Otherwise the pattern may also match at any level below
// > the .gitignore level.
? '(?:^|\\/)'

// > Otherwise, Git treats the pattern as a shell glob suitable for
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ignore",
"version": "5.1.2",
"version": "5.1.3",
"description": "Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.",
"files": [
"legacy.js",
Expand Down
31 changes: 20 additions & 11 deletions test/fixtures/cases.js
Expand Up @@ -9,17 +9,26 @@ function readPatterns (file) {
}

const cases = [
// [
// '#56',
// [
// '/*/',
// '!/foo/'
// ],
// {
// 'foo/bar.js': 0
// },
// true
// ],
[
'gitignore 2.22.1 example',
[
'doc/frotz/'
],
{
'doc/frotz/': 1,
'a/doc/frotz/': 0
}
],
[
'#56',
[
'/*/',
'!/foo/'
],
{
'foo/bar.js': 0
}
],
[
'object prototype',
[
Expand Down

0 comments on commit 0a95a91

Please sign in to comment.