mirror of
https://github.com/supermemoryai/claude-supermemory.git
synced 2026-09-14 14:58:03 +08:00
e9f018c6b6
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
const { execSync } = require('node:child_process');
|
|
const path = require('node:path');
|
|
|
|
function getGitRoot(cwd) {
|
|
const isolateWorktrees = process.env.SUPERMEMORY_ISOLATE_WORKTREES === 'true';
|
|
|
|
try {
|
|
if (isolateWorktrees) {
|
|
const gitRoot = execSync('git rev-parse --show-toplevel', {
|
|
cwd,
|
|
encoding: 'utf-8',
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
}).trim();
|
|
return gitRoot || null;
|
|
}
|
|
|
|
const gitCommonDir = execSync('git rev-parse --git-common-dir', {
|
|
cwd,
|
|
encoding: 'utf-8',
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
}).trim();
|
|
|
|
if (gitCommonDir === '.git') {
|
|
const gitRoot = execSync('git rev-parse --show-toplevel', {
|
|
cwd,
|
|
encoding: 'utf-8',
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
}).trim();
|
|
return gitRoot || null;
|
|
}
|
|
|
|
const resolved = path.resolve(cwd, gitCommonDir);
|
|
|
|
if (
|
|
path.basename(resolved) === '.git' &&
|
|
!resolved.includes(`${path.sep}.git${path.sep}`)
|
|
) {
|
|
return path.dirname(resolved);
|
|
}
|
|
|
|
const gitRoot = execSync('git rev-parse --show-toplevel', {
|
|
cwd,
|
|
encoding: 'utf-8',
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
}).trim();
|
|
return gitRoot || null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
module.exports = { getGitRoot };
|