fix: handle repos with no commits in getCurrentBranch

git rev-parse --abbrev-ref HEAD fails with exit code 128 on freshly
initialized repos with no commits. This error bubbled up through
workspace listing and showed a toast error on every app launch for
users with empty git repos.
This commit is contained in:
Mohamed Boudra
2026-04-14 20:49:54 +07:00
parent 2090d685ed
commit 25fd93d7e2
3 changed files with 23 additions and 14 deletions
+10 -6
View File
@@ -525,12 +525,16 @@ async function requireGitRepo(cwd: string): Promise<void> {
}
export async function getCurrentBranch(cwd: string): Promise<string | null> {
const { stdout } = await runGitCommand(["rev-parse", "--abbrev-ref", "HEAD"], {
cwd,
env: READ_ONLY_GIT_ENV,
});
const branch = stdout.trim();
return branch.length > 0 ? branch : null;
try {
const { stdout } = await runGitCommand(["rev-parse", "--abbrev-ref", "HEAD"], {
cwd,
env: READ_ONLY_GIT_ENV,
});
const branch = stdout.trim();
return branch.length > 0 ? branch : null;
} catch {
return null;
}
}
async function getWorktreeRoot(cwd: string): Promise<string | null> {