Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions apps/runtime/tests/lanes/worktree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,40 @@ function createTempGitRepo(): string {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "helios-wt-test-"));
tmpDirs.push(dir);

// Initialize a git repo with an initial commit
Bun.spawnSync(["git", "init"], { cwd: dir });
// Prefer Git 2.28+ initial-branch support; retain an explicit legacy fallback.
const modernInit = Bun.spawnSync(["git", "init", "--initial-branch=main"], { cwd: dir });
const needsBranchRename = !modernInit.success;
if (needsBranchRename) {
const fallbackInit = Bun.spawnSync(["git", "init"], { cwd: dir });
if (!fallbackInit.success) {
const reason = new TextDecoder().decode(fallbackInit.stderr).trim();
throw new Error(
`Unable to initialize temporary Git repository with fallback \`git init\`: ${reason || `exit ${fallbackInit.exitCode}`}`,
);
}
}

Bun.spawnSync(["git", "config", "user.email", "test@test.com"], { cwd: dir });
Bun.spawnSync(["git", "config", "user.name", "Test"], { cwd: dir });
fs.writeFileSync(path.join(dir, "README.md"), "# test repo\n");
Bun.spawnSync(["git", "add", "."], { cwd: dir });
Bun.spawnSync(["git", "commit", "-m", "initial"], { cwd: dir });
const initialCommit = Bun.spawnSync(["git", "commit", "-m", "initial"], { cwd: dir });
if (!initialCommit.success) {
const reason = new TextDecoder().decode(initialCommit.stderr).trim();
throw new Error(
`Unable to create initial temporary Git commit: ${reason || `exit ${initialCommit.exitCode}`}`,
);
}

if (needsBranchRename) {
const renameBranch = Bun.spawnSync(["git", "branch", "-M", "main"], { cwd: dir });
if (!renameBranch.success) {
const reason = new TextDecoder().decode(renameBranch.stderr).trim();
throw new Error(
`Unable to rename temporary Git branch to main: ${reason || `exit ${renameBranch.exitCode}`}`,
);
}
}

return dir;
}
Expand Down
Loading