-
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b9c17c
commit 5fc110c
Showing
7 changed files
with
70 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// @ts-check | ||
import '../typedefs.js' | ||
|
||
import { GitIgnoreManager } from '../managers/GitIgnoreManager.js' | ||
import { FileSystem } from '../models/FileSystem.js' | ||
import { assertParameter } from '../utils/assertParameter.js' | ||
import { join } from '../utils/join.js' | ||
|
||
/** | ||
* Test whether a filepath should be ignored (because of .gitignore or .git/exclude) | ||
* | ||
* @param {object} args | ||
* @param {FsClient} args.fs - a file system client | ||
* @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path | ||
* @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path | ||
* @param {string} args.filepath - The filepath to test | ||
* | ||
* @returns {Promise<boolean>} Resolves to true if the file should be ignored | ||
* | ||
* @example | ||
* await git.isIgnored({ fs, dir: '/tutorial', filepath: 'docs/add.md' }) | ||
* | ||
*/ | ||
export async function isIgnored({ | ||
fs, | ||
dir, | ||
gitdir = join(dir, '.git'), | ||
filepath, | ||
}) { | ||
try { | ||
assertParameter('fs', fs) | ||
assertParameter('dir', dir) | ||
assertParameter('gitdir', gitdir) | ||
assertParameter('filepath', filepath) | ||
|
||
return GitIgnoreManager.isIgnored({ | ||
fs: new FileSystem(fs), | ||
dir, | ||
gitdir, | ||
filepath, | ||
}) | ||
} catch (err) { | ||
err.caller = 'git.isIgnored' | ||
throw err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,8 @@ | |
"add", | ||
"remove", | ||
"listFiles", | ||
"status" | ||
"status", | ||
"isIgnored" | ||
], | ||
"Notes": [ | ||
"addNote", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters