Skip to content

Commit b866579

Browse files
committed
fix(server): git fast path leaves a HEAD that points at a symbolic ref to git
symbolic-ref --quiet --short HEAD printed the branch HEAD names even when that branch is itself a symbolic ref, while git follows the chain to its end.
1 parent 8fce2fc commit b866579

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,12 @@ describe("GitMetadataFastPath on repositories git treats differently", () => {
855855
});
856856
await declines(chained, "symbolic-ref", "refs/remotes/origin/HEAD");
857857

858+
const headChain = makeRepo("headChain", (dir) => {
859+
git(dir, "symbolic-ref", "refs/heads/alias", "refs/heads/main");
860+
git(dir, "symbolic-ref", "HEAD", "refs/heads/alias");
861+
});
862+
await declines(headChain, "symbolic-ref", "--quiet", "--short", "HEAD");
863+
858864
const headUpstream = makeRepo("headUpstream", (dir) => {
859865
git(dir, "remote", "add", "origin", "https://example.com/origin.git");
860866
git(dir, "update-ref", "refs/remotes/origin/HEAD", "HEAD");

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,9 @@ async function answerRevParse(
951951
async function answerSymbolicRef(repo: Repository, args: ReadonlyArray<string>) {
952952
if (sameArgs(args, ["--quiet", "--short", "HEAD"])) {
953953
const head = await readHead(repo);
954-
return head.ref === null ? silentFailure : ok(`${await shortBranchName(repo, head.ref)}\n`);
954+
if (head.ref === null) return silentFailure;
955+
await refObjectId(repo, head.ref);
956+
return ok(`${await shortBranchName(repo, head.ref)}\n`);
955957
}
956958
if (
957959
args.length === 1 &&

0 commit comments

Comments
 (0)