fix(core): support older Git during repository initialization

Replace git init --initial-branch with git init followed by
  symbolic-ref HEAD refs/heads/main. This keeps new repositories on main
  without requiring Git 2.28 or newer.

  Also ensure checkpoint shadow repository setup uses its dedicated git
  config during the initial commit.
This commit is contained in:
Reid 2026-04-19 14:24:01 +08:00 committed by GitHub
parent 4bf5bf22de
commit cd8d9dce6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 77 additions and 7 deletions

View file

@ -11,6 +11,7 @@ import type { SimpleGit } from 'simple-git';
import { simpleGit, CheckRepoActions } from 'simple-git';
import type { Storage } from '../config/storage.js';
import { isNodeError } from '../utils/errors.js';
import { initRepositoryWithMainBranch } from './gitInit.js';
export class GitService {
private projectRoot: string;
@ -57,7 +58,11 @@ export class GitService {
'[user]\n name = Qwen Code\n email = qwen-code@qwen.ai\n[commit]\n gpgsign = false\n';
await fs.writeFile(gitConfigPath, gitConfigContent);
const repo = simpleGit(repoDir);
const repo = simpleGit(repoDir).env({
// Prevent git from using the user's global git config.
HOME: repoDir,
XDG_CONFIG_HOME: repoDir,
});
let isRepoDefined = false;
try {
isRepoDefined = await repo.checkIsRepo(CheckRepoActions.IS_REPO_ROOT);
@ -68,10 +73,7 @@ export class GitService {
}
if (!isRepoDefined) {
await repo.init(false, {
'--initial-branch': 'main',
});
await initRepositoryWithMainBranch(repo);
await repo.commit('Initial commit', { '--allow-empty': null });
}