fix: handle shadow repo init outside git repos (#3041)

Co-authored-by: jinye.djy <jinye.djy@alibaba-inc.com>
This commit is contained in:
jinye 2026-04-09 18:54:23 +08:00 committed by GitHub
parent 9c0bbfba6c
commit ea9c3196a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View file

@ -58,7 +58,14 @@ export class GitService {
await fs.writeFile(gitConfigPath, gitConfigContent);
const repo = simpleGit(repoDir);
const isRepoDefined = await repo.checkIsRepo(CheckRepoActions.IS_REPO_ROOT);
let isRepoDefined = false;
try {
isRepoDefined = await repo.checkIsRepo(CheckRepoActions.IS_REPO_ROOT);
} catch {
// Some Git/simple-git combinations throw for non-repo directories
// instead of returning false. Treat that as "not initialized yet".
isRepoDefined = false;
}
if (!isRepoDefined) {
await repo.init(false, {