From 2fbdbe2b407ee78b27bc7dbdaa91a171008feecb Mon Sep 17 00:00:00 2001 From: Simone <185146821+Lucenx9@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:47:51 +0100 Subject: [PATCH] fix(server): preserve home paths in checkout attribute fingerprints --- .../src/vcs/worktreeCheckoutCache.test.ts | 36 ++++++++++++++++++- apps/server/src/vcs/worktreeCheckoutCache.ts | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/apps/server/src/vcs/worktreeCheckoutCache.test.ts b/apps/server/src/vcs/worktreeCheckoutCache.test.ts index 0c81504eedb67..2140af9feab67 100644 --- a/apps/server/src/vcs/worktreeCheckoutCache.test.ts +++ b/apps/server/src/vcs/worktreeCheckoutCache.test.ts @@ -72,12 +72,13 @@ const setup = Effect.gen(function* () { return delegate.spawn(command); }); const clone = yield* testCloner; + const environment = yield* HostProcess.Environment; const provide = (effect: Effect.Effect) => effect.pipe( Effect.provideService(CheckoutCloner.CheckoutCloner, clone), Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner), Effect.provideService(HostProcess.Environment, { - ...process.env, + ...environment, GIT_CONFIG_GLOBAL: "/dev/null", GIT_CONFIG_NOSYSTEM: "1", }), @@ -178,6 +179,39 @@ describe.skipIf(!symlinksSupported)("worktree checkout cache", () => { }).pipe(Effect.scoped, Effect.provide(layerTest)), ); + it.effect("matches Git after home-relative external attributes change", () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const homeDirectory = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "worktree-cache-home-$&-$$-", + }); + const environment = yield* HostProcess.Environment; + yield* Effect.gen(function* () { + const fixture = yield* setup; + const attributes = NodePath.join(homeDirectory, "attributes"); + NodeFS.writeFileSync(attributes, "README.md text eol=lf\n"); + sh(fixture.repo, ["config", "core.attributesfile", "~/attributes"]); + yield* fixture.build(yield* fixture.create("base", "main", false)); + assert.equal( + NodeFS.readFileSync(NodePath.join(cacheEntry(fixture), "README.md"), "utf8"), + "# test\n", + ); + + NodeFS.writeFileSync(attributes, "README.md text eol=crlf\n"); + const created = yield* fixture.create("changed"); + const stock = yield* fixture.create("stock", "main", false); + assert.deepStrictEqual(snapshot(created), snapshot(stock)); + }).pipe( + Effect.provideService(HostProcess.HomeDirectory, homeDirectory), + Effect.provideService(HostProcess.Environment, { + ...environment, + HOME: homeDirectory, + GIT_ATTR_NOSYSTEM: "1", + }), + ); + }).pipe(Effect.scoped, Effect.provide(layerTest)), + ); + it.effect("caches a far newer commit by moving the older cached checkout", () => Effect.gen(function* () { const fixture = yield* setup; diff --git a/apps/server/src/vcs/worktreeCheckoutCache.ts b/apps/server/src/vcs/worktreeCheckoutCache.ts index a72d6d859fc54..fde5f276d5169 100644 --- a/apps/server/src/vcs/worktreeCheckoutCache.ts +++ b/apps/server/src/vcs/worktreeCheckoutCache.ts @@ -212,7 +212,7 @@ export const makeWorktreeCheckoutCache = Effect.fn("WorktreeCheckoutCache.make") if (sparse !== undefined && !GIT_FALSE.has(sparse.toLowerCase())) return null; const attributesFile = pairs .findLast(([key]) => key === "core.attributesfile")?.[1] - ?.replace(/^~(?=$|\/)/, homeDirectory); + ?.replace(/^~(?=$|\/)/, () => homeDirectory); // Git reads a relative path from each checkout, which differs between the cache and the worktree. if (attributesFile !== undefined && !path.isAbsolute(attributesFile)) return null; const attributePaths = [