@@ -25,6 +25,9 @@ export type AddParams = {
2525 /** The path to the file to add to the index. */
2626 filepath : string
2727
28+ /** Allow adding otherwise ignored files. */
29+ force ?: boolean
30+
2831 /** A cache object. */
2932 cache ?: Cache
3033}
@@ -49,6 +52,7 @@ export async function add({
4952 dir,
5053 gitdir = join ( dir , '.git' ) ,
5154 filepath,
55+ force = false ,
5256 cache = { }
5357} : AddParams ) : Promise < void > {
5458 try {
@@ -59,7 +63,7 @@ export async function add({
5963
6064 const fs = new FileSystem ( _fs )
6165 await GitIndexManager . acquire ( { fs, gitdir, cache } , async function ( index ) {
62- await addToIndex ( { dir, gitdir, fs, filepath, index } )
66+ await addToIndex ( { dir, gitdir, fs, filepath, index, force } )
6367 } )
6468 } catch ( err : any ) {
6569 err . caller = 'git.add'
@@ -68,17 +72,19 @@ export async function add({
6872}
6973
7074async function addToIndex (
71- { dir, gitdir, fs, filepath, index } :
72- { dir : string , gitdir : string , fs : FileSystem , filepath : string , index : GitIndex } ) {
75+ { dir, gitdir, fs, filepath, index, force } :
76+ { dir : string , gitdir : string , fs : FileSystem , filepath : string , index : GitIndex , force : boolean } ) {
7377 // TODO: Should ignore UNLESS it's already in the index.
74- const ignored = await GitIgnoreManager . isIgnored ( {
75- fs,
76- dir,
77- gitdir,
78- filepath,
79- } )
78+ if ( ! force ) {
79+ const ignored = await GitIgnoreManager . isIgnored ( {
80+ fs,
81+ dir,
82+ gitdir,
83+ filepath,
84+ } )
8085
81- if ( ignored ) return
86+ if ( ignored ) return
87+ }
8288
8389 const stats = await fs . lstat ( join ( dir , filepath ) )
8490
@@ -87,7 +93,7 @@ async function addToIndex(
8793 if ( stats . isDirectory ( ) ) {
8894 const children = await fs . readdir ( join ( dir , filepath ) )
8995 const promises = ( children || [ ] ) . map ( child =>
90- addToIndex ( { dir, gitdir, fs, filepath : join ( filepath , child ) , index } )
96+ addToIndex ( { dir, gitdir, fs, filepath : join ( filepath , child ) , index, force } )
9197 )
9298
9399 await Promise . all ( promises )
0 commit comments