-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added 'isIgnored' command (#1413)
- Loading branch information
1 parent
3b9c17c
commit f7ca4d0
Showing
10 changed files
with
102 additions
and
2 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
title: isIgnored | ||
sidebar_label: isIgnored | ||
id: version-1.x-isIgnored | ||
original_id: isIgnored | ||
--- | ||
|
||
Test whether a filepath should be ignored (because of .gitignore or .git/exclude) | ||
|
||
| param | type [= default] | description | | ||
| -------------- | -------------------------- | --------------------------------------------------- | | ||
| [**fs**](./fs) | FsClient | a file system client | | ||
| **dir** | string | The [working tree](dir-vs-gitdir.md) directory path | | ||
| **gitdir** | string = join(dir, '.git') | The [git directory](dir-vs-gitdir.md) path | | ||
| **filepath** | string | The filepath to test | | ||
| return | Promise\<boolean\> | Resolves to true if the file should be ignored | | ||
|
||
Example Code: | ||
|
||
```js live | ||
await git.isIgnored({ fs, dir: '/tutorial', filepath: 'docs/add.md' }) | ||
``` | ||
|
||
|
||
--- | ||
|
||
<details> | ||
<summary><i>Tip: If you need a clean slate, expand and run this snippet to clean up the file system.</i></summary> | ||
|
||
```js live | ||
window.fs = new LightningFS('fs', { wipe: true }) | ||
window.pfs = window.fs.promises | ||
console.log('done') | ||
``` | ||
</details> | ||
|
||
<script> | ||
(function rewriteEditLink() { | ||
const el = document.querySelector('a.edit-page-link.button'); | ||
if (el) { | ||
el.href = 'https://github.com/isomorphic-git/isomorphic-git/edit/main/src/api/isIgnored.js'; | ||
} | ||
})(); | ||
</script> |
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