Skip to content

Commit 8fce2fc

Browse files
committed
fix(server): git fast path names the common directory a .git directory points to
A .git directory with a commondir file was answered with '.git' for rev-parse --git-common-dir, while git prints the directory commondir names.
1 parent 24cdbbc commit 8fce2fc

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,22 @@ describe("GitMetadataFastPath on repositories git treats differently", () => {
802802
});
803803
});
804804

805+
it("names the common directory a .git directory points to", async () => {
806+
const shared = makeRepo("commonDirTarget");
807+
const cwd = makeRepo("commonDirPointer");
808+
NodeFS.writeFileSync(
809+
NodePath.join(cwd, ".git", "commondir"),
810+
`${NodePath.relative(NodePath.join(cwd, ".git"), NodePath.join(shared, ".git"))}\n`,
811+
);
812+
const args = ["rev-parse", "--git-common-dir"];
813+
const real = NodeChildProcess.spawnSync("git", args, { cwd, encoding: "utf8" });
814+
expect(await tryAnswerGitCommand({ cwd, args })).toEqual({
815+
exitCode: 0,
816+
stdout: real.stdout,
817+
stderr: "",
818+
});
819+
});
820+
805821
it("reads only the refs under the name asked for", async () => {
806822
const cwd = makeRepo("targetedRefs", (dir) => {
807823
git(dir, "update-ref", "refs/remotes/origin/main", "HEAD");

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,11 @@ async function answerRevParse(
916916
if (sameArgs(args, ["--git-common-dir"])) {
917917
// Below the worktree root git prints a relative path; leave that form to git.
918918
if (realCwd !== repo.workTree) unsure("common dir from a subdirectory");
919-
return ok(repo.dotGitIsDirectory ? ".git\n" : `${toGitPath(repo.commonDir)}\n`);
919+
return ok(
920+
repo.dotGitIsDirectory && repo.commonDir === repo.gitDir
921+
? ".git\n"
922+
: `${toGitPath(repo.commonDir)}\n`,
923+
);
920924
}
921925
if (sameArgs(args, ["--abbrev-ref", "HEAD"])) {
922926
const head = await readHead(repo);

0 commit comments

Comments
 (0)