From f2bdce653462e798ee6285c73e2e3eb2c0e89ec5 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Mon, 1 Jun 2020 23:21:18 -0700 Subject: [PATCH] Normalize file paths to posix for gitignore calculation (#143) Refs #133 --- gitignore.js | 1 + gitignore.test.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/gitignore.js b/gitignore.js index 3feaad6..6a1a57a 100644 --- a/gitignore.js +++ b/gitignore.js @@ -44,6 +44,7 @@ const reduceIgnore = files => { }; const ensureAbsolutePathForCwd = (cwd, p) => { + cwd = slash(cwd); if (path.isAbsolute(p)) { if (p.startsWith(cwd)) { return p; diff --git a/gitignore.test.js b/gitignore.test.js index eb02221..72ae0f2 100644 --- a/gitignore.test.js +++ b/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 => { @@ -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});