@@ -105,10 +105,15 @@ export interface GitInfo {
105105 */
106106function isGitRepo ( directory : string = process . cwd ( ) ) : boolean {
107107 try {
108- // Check if .git directory exists or if git rev-parse succeeds
109- execSync ( 'git rev-parse --is-inside-work-tree' , { cwd : directory , encoding : 'utf-8' , stdio : 'ignore' } ) ;
110- return true ;
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}
@@ -127,16 +132,16 @@ export function getGitInfo(directory: string = process.cwd()): GitInfo {
127132 error : "Telemetry disabled"
128133 } ;
129134 }
130-
131- // First check if this is a git repository
132- if ( ! isGitRepo ( directory ) ) {
133- return {
134- uncommittedChanges : false ,
135- error : "Not a git repository"
136- } ;
137- }
138135
139136 try {
137+ // First check if this is a git repository
138+ if ( ! isGitRepo ( directory ) ) {
139+ return {
140+ uncommittedChanges : false ,
141+ error : "Not a git repository"
142+ } ;
143+ }
144+
140145 const commitHash = execSync ( 'git rev-parse HEAD' , { cwd : directory , encoding : 'utf-8' } ) . trim ( ) ;
141146 const branch = execSync ( 'git rev-parse --abbrev-ref HEAD' , { cwd : directory , encoding : 'utf-8' } ) . trim ( ) ;
142147 const repoUrl = execSync ( 'git config --get remote.origin.url' , { cwd : directory , encoding : 'utf-8' } ) . trim ( ) . replace ( / \. g i t $ / , '' ) ;
@@ -395,16 +400,6 @@ export class HoneyHiveTracer {
395400 sessionId : this . sessionId
396401 }
397402 } ;
398-
399- // Gather git information
400- const gitInfo = getGitInfo ( ) ;
401-
402- // Only add git info to metadata if there's no error
403- if ( ! gitInfo . error && requestBody . session ) {
404- requestBody . session . metadata = {
405- git : gitInfo
406- } ;
407- }
408403
409404 if ( ! HoneyHiveTracer . sdkInstance ) {
410405 throw new Error ( "SDK instance is not initialized" ) ;
0 commit comments