Skip to content

Commit 052ae60

Browse files
committed
make the git repo check safer
1 parent 9eb2090 commit 052ae60

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/sdk/tracer.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,15 @@ export interface GitInfo {
105105
*/
106106
function 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
}

0 commit comments

Comments
 (0)