Skip to content

Commit

Permalink
Fix gitignore paths applying as root-relative
Browse files Browse the repository at this point in the history
Changed code to ensure that the folder hierarchy is included in all gitignore entries.

Should fix #36.
  • Loading branch information
Nixinova committed Nov 4, 2024
1 parent 8d1b6c9 commit f842e14
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Next
- Fixed gitignore paths being applied as root-relative ([#36](https://github.com/Nixinova/LinguistJS/issues/36)).

## 2.8.0
*2024-09-15*
- Added checking of gitattributes override rule `linguist-detectable`.
Expand Down
8 changes: 7 additions & 1 deletion src/helpers/walk-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ export default function walk(data: WalkInput): WalkOutput {
if (FS.existsSync(gitignoreFilename)) {
const gitignoreContents = FS.readFileSync(gitignoreFilename, 'utf-8');
const ignoredPaths = parseGitignore(gitignoreContents);
ignored.add(ignoredPaths);
const rootRelIgnoredPaths = ignoredPaths.map(ignorePath =>
// get absolute path of the ignore glob
normPath(folder, ignorePath)
// convert abs ignore glob to be relative to the root folder
.replace(commonRoot + '/', '')
);
ignored.add(rootRelIgnoredPaths);
}

// Add gitattributes if present
Expand Down
2 changes: 1 addition & 1 deletion test/samples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Ignore this file
ignore*
.gitignore

0 comments on commit f842e14

Please sign in to comment.