File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -105,10 +105,15 @@ export interface GitInfo {
105105 */
106106function isGitRepo ( directory : string = process . cwd ( ) ) : boolean {
107107 try {
108- // Check if .git directory exists
109- const gitDir = path . join ( directory , '.git' ) ;
110- return fs . existsSync ( gitDir ) && fs . lstatSync ( gitDir ) . isDirectory ( ) ;
108+ // Use git rev-parse --is-inside-work-tree instead of file I/O
109+ const result = execSync ( 'git rev-parse --is-inside-work-tree' , {
110+ cwd : directory ,
111+ encoding : 'utf-8' ,
112+ stdio : [ 'ignore' , 'pipe' , 'ignore' ] // Suppress stderr
113+ } ) . trim ( ) ;
114+ return result === 'true' ;
111115 } catch ( error ) {
116+ // Return false if git command fails (not a git repo or git not installed)
112117 return false ;
113118 }
114119}
You can’t perform that action at this time.
0 commit comments