Skip to content

Commit 5077a1b

Browse files
committed
fix(pending): defer backslash HEAD symlink targets to Git
Gatekeeper round 4 on #909 found that HEAD symlink targets were normalised from backslashes to slashes on every platform. Git for Windows performs that conversion, but Linux and macOS Git compare the raw target with refs/, reject a backslash target and continue discovery, so the filesystem read could trust a .git that Git skips. Any HEAD symlink target containing a backslash now defers to Git, which applies its platform rules. The regression runs everywhere symbolic links are available: the result must equal git rev-parse, and on POSIX the directory must not share the workspace repository (exercised by the Linux CI server suite). Pending broker and Git preflight suites pass 36/36.
1 parent ba44737 commit 5077a1b

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎packages/server/src/workspaces/__tests__/git-common-directory.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,27 @@ describe("Git ownership preflight admission", () => {
109109
}
110110
})
111111

112+
it("leaves backslash HEAD symlink targets to Git's platform rules", async (context) => {
113+
const other = path.join(temp, "other repo")
114+
git(temp, "init", "--quiet", other)
115+
const vendor = path.join(repo, "vendor")
116+
const checkout = path.join(vendor, "x")
117+
const administrative = path.join(checkout, ".git")
118+
mkdirSync(administrative, { recursive: true })
119+
writeFileSync(path.join(vendor, "HEAD"), "ref: refs/heads/main\n")
120+
writeFileSync(path.join(vendor, "commondir"), `${path.relative(vendor, path.join(other, ".git")).replaceAll("\\", "/")}\n`)
121+
writeFileSync(path.join(administrative, "commondir"), `${path.relative(administrative, path.join(repo, ".git")).replaceAll("\\", "/")}\n`)
122+
writeFileSync(path.join(administrative, "gitdir"), `${administrative.replaceAll("\\", "/")}\n`)
123+
try {
124+
symlinkSync("refs\\heads\\main", path.join(administrative, "HEAD"))
125+
} catch {
126+
context.skip("Symbolic links are unavailable")
127+
return
128+
}
129+
assert.equal(await readGitCommonDirectory(checkout), realpathSync(git(checkout, "rev-parse", "--path-format=absolute", "--git-common-dir")))
130+
if (process.platform !== "win32") assert.equal(await sharesGitCommonDirectory(repo, checkout), false)
131+
})
132+
112133
it("leaves a nested bare repository with a dangling HEAD symlink to Git", async (context) => {
113134
const bare = path.join(repo, "vendor", "linked-head")
114135
mkdirSync(path.join(bare, "objects"), { recursive: true })

‎packages/server/src/workspaces/git-common-directory.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ async function readCheckoutCommonDirectory(directory: string): Promise<string> {
7878
async function hasValidHead(gitDirectory: string): Promise<boolean> {
7979
const head = path.join(gitDirectory, "HEAD")
8080
const info = await lstat(head)
81-
if (info.isSymbolicLink()) return (await readlink(head)).replaceAll("\\", "/").startsWith("refs/")
81+
// Backslash targets are platform-dependent for Git (accepted only on Windows).
82+
if (info.isSymbolicLink()) {
83+
const target = await readlink(head)
84+
return !target.includes("\\") && target.startsWith("refs/")
85+
}
8286
if (!info.isFile()) return false
8387
const content = (await readFile(head, "utf8")).replace(/\r?\n$/, "")
8488
return /^ref:\s*refs\//.test(content) || /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(content)

0 commit comments

Comments
 (0)