Skip to content

Commit

Permalink
Normalize filepaths to posix for gitignore calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed May 25, 2020
1 parent 45ac58a commit 87a45cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions gitignore.js
Expand Up @@ -44,6 +44,7 @@ const reduceIgnore = files => {
};

const ensureAbsolutePathForCwd = (cwd, p) => {
cwd = slash(cwd);
if (path.isAbsolute(p)) {
if (p.startsWith(cwd)) {
return p;
Expand Down
7 changes: 7 additions & 0 deletions gitignore.test.js
@@ -1,5 +1,6 @@
import path from 'path';
import test from 'ava';
import slash from 'slash';
import gitignore from './gitignore';

test('gitignore', async t => {
Expand All @@ -10,6 +11,12 @@ test('gitignore', async t => {
t.deepEqual(actual, expected);
});

test('gitignore - mixed path styles', async t => {
const cwd = path.join(__dirname, 'fixtures/gitignore');
const isIgnored = await gitignore({cwd});
t.true(isIgnored(slash(path.resolve(cwd, 'foo.js'))));
});

test('gitignore - sync', t => {
const cwd = path.join(__dirname, 'fixtures/gitignore');
const isIgnored = gitignore.sync({cwd});
Expand Down

0 comments on commit 87a45cf

Please sign in to comment.