GitIgnoreManager
The GitIgnoreManager class provides methods to determine whether a file is ignored based on .gitignore rules and exclusion files.
Methods
GitIgnoreManager.isIgnored
Determines whether a given file is ignored based on .gitignore rules and exclusion files.
Parameters
| param | type | description |
|---|---|---|
| fs | FsClient | A file system implementation. |
| dir | string | The working directory. |
| gitdir | string = join(dir, '.git') | The git directory. |
| filepath | string | The path of the file to check. |
Returns
Promise<boolean>
true if the file is ignored, false otherwise.
Example Usage
import { GitIgnoreManager } from 'isomorphic-git/managers'
const isIgnored = await GitIgnoreManager.isIgnored({
fs,
dir: '/path/to/repo',
filepath: 'src/example.js',
})
console.log(isIgnored) // true or false
Notes
- The
.gitfolder is always ignored. - The root directory (
.) is never ignored, as it is not a valid.gitignoreentry. - The method checks
.gitignorefiles in the file's directory and its parent directories, as well as the.git/info/excludefile. - If a parent directory is excluded, the file is automatically ignored, as per Git's behavior.
- The method uses the
ignorelibrary to parse and apply.gitignorerules.