Skip to content

Commit

Permalink
Add wildcard in front of and after each entry in .gitignore (#25)
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
cederstrom authored and stofolus committed May 4, 2018
1 parent b27a1b6 commit cee71d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
11 changes: 7 additions & 4 deletions lib/finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ class Finder {
.readFileSync(pathToGitIgnore)
.toString()
.split("\n")
.filter(line => line.length > 0 && !line.startsWith("#"));
ignores.forEach(function(part, index) {
ignores[index] = `**/${part}`;
});
.filter(line => line.length > 0 && !line.startsWith("#"))
.reduce((acc, value) => {
acc.push(`${searchPath}/${value}`);
acc.push(`${searchPath}/**/${value}/**`);
return acc;
}, []);
}
console.log(ignores);
return ignores;
}
}
Expand Down
16 changes: 13 additions & 3 deletions lib/finder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,20 @@ describe(`_getIgnoreGlobs`, () => {
beforeEach(() => {
delete mockFsData["/path/.gitignore"];
});
test(`prepend **/ on each glob in .gitignore`, () => {
mockFsData["/path/.gitignore"] = "*.java";
test(`prepend path on each glob in .gitignore`, () => {
mockFsData["/path/.gitignore"] = "dist";
const result = Finder._getIgnoreGlobs("/path");
expect(result).toEqual(expect.arrayContaining(["**/*.java"]));
expect(result).toEqual(expect.arrayContaining(["/path/dist"]));
});
test(`adds two entries per row in .gitignore`, () => {
mockFsData["/path/.gitignore"] = "dist";
const result = Finder._getIgnoreGlobs("/path");
expect(result.length).toEqual(2);
});
test(`prepend **/ and append /** on each glob in .gitignore`, () => {
mockFsData["/path/.gitignore"] = "dist";
const result = Finder._getIgnoreGlobs("/path");
expect(result).toEqual(expect.arrayContaining(["/path/**/dist/**"]));
});
test(`removes comments from .gitignore`, () => {
mockFsData["/path/.gitignore"] = "#comment";
Expand Down

0 comments on commit cee71d8

Please sign in to comment.