Merge pull request #919 from zhbdesign/patch-14

修复非git项目在新会话执行git命令导致加载慢
This commit is contained in:
程序员阿江-Relakkes 2026-07-02 15:42:57 +08:00 committed by GitHub
commit 705f34b535
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -712,6 +712,21 @@ async function getGitInfo(sessionId: string): Promise<Response> {
}
: null
// Fast check: if workDir is not inside a git repo, skip spawning git commands.
// findGitRoot uses fs.stat traversal with LRU cache (<5ms), avoiding 3 slow git
// spawns on non-git directories (each can take seconds as git searches upward).
const gitRoot = findGitRoot(workDir)
if (!gitRoot) {
const dirName = workDir.split('/').pop() || workDir.split(path.sep).pop() || ''
return Response.json({
branch: sessionBranch,
repoName: dirName,
workDir,
changedFiles: 0,
worktree,
})
}
try {
// Get branch name
const branchProc = Bun.spawn(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], {