Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion apps/server/src/vcs/worktreeCheckoutCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ const setup = Effect.gen(function* () {
return delegate.spawn(command);
});
const clone = yield* testCloner;
const environment = yield* HostProcess.Environment;
const provide = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
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",
}),
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/vcs/worktreeCheckoutCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Loading