Skip to content

Commit 7e65de2

Browse files
t3dotggclaude
andcommitted
Mark origin default ref as default when no local copy exists
listRefs only flagged local branches as isDefault, so the new default-branch worktree base selection fell back to the checked-out branch when the local default branch had been deleted. Flag the origin/<default> remote ref too, derived from origin/HEAD. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent df9fea5 commit 7e65de2

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,26 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
523523
}),
524524
);
525525

526+
it.effect("marks the origin default ref as default when no local copy exists", () =>
527+
Effect.gen(function* () {
528+
const cwd = yield* makeTmpDir();
529+
const remote = yield* makeTmpDir("git-vcs-driver-remote-");
530+
const { initialBranch } = yield* initRepoWithCommit(cwd);
531+
yield* git(remote, ["init", "--bare"]);
532+
yield* git(cwd, ["remote", "add", "origin", remote]);
533+
yield* git(cwd, ["push", "-u", "origin", initialBranch]);
534+
yield* git(cwd, ["remote", "set-head", "origin", initialBranch]);
535+
yield* git(cwd, ["checkout", "-b", "feature/only-local"]);
536+
yield* git(cwd, ["branch", "-D", initialBranch]);
537+
const driver = yield* GitVcsDriver.GitVcsDriver;
538+
539+
const refs = yield* driver.listRefs({ cwd });
540+
const remoteDefault = refs.refs.find((ref) => ref.name === `origin/${initialBranch}`);
541+
assert.equal(remoteDefault?.isRemote, true);
542+
assert.equal(remoteDefault?.isDefault, true);
543+
}),
544+
);
545+
526546
it.effect("creates, checks out, renames, and lists refs", () =>
527547
Effect.gen(function* () {
528548
const cwd = yield* makeTmpDir();

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
22022202
name: refName.name,
22032203
current: false,
22042204
isRemote: true,
2205-
isDefault: false,
2205+
// origin/HEAD's target is the repo default even when no local
2206+
// copy of the default branch exists.
2207+
isDefault:
2208+
defaultBranch !== null &&
2209+
parsedRemoteRef?.remoteName === "origin" &&
2210+
parsedRemoteRef.branchName === defaultBranch,
22062211
worktreePath: null,
22072212
};
22082213
if (parsedRemoteRef) {

0 commit comments

Comments
 (0)