Skip to content

Commit d2082ef

Browse files
fix(server): exclude receiver hook output from handoff
1 parent eaeccfc commit d2082ef

2 files changed

Lines changed: 51 additions & 18 deletions

File tree

‎apps/server/src/peer/handoff/HandoffGit.test.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ it.layer(nativeLayer)("HandoffGit", (it) => {
143143
assert.equal(missingTip._tag, "VcsProcessExitError");
144144
assert.deepEqual(yield* f.fs.readDirectory(f.outDir), [f.path.basename(packed.bundlePath)]);
145145

146+
yield* f.write(
147+
f.receiver,
148+
".git/hooks/post-checkout",
149+
"#!/bin/sh\nprintf 'receiver-only hook output\\n' > secret.txt\n",
150+
);
151+
yield* f.fs.chmod(f.path.join(f.receiver, ".git/hooks/post-checkout"), 0o755);
146152
const input = {
147153
...packed,
148154
repoRoot: f.receiver,
@@ -171,14 +177,16 @@ it.layer(nativeLayer)("HandoffGit", (it) => {
171177
"library\n",
172178
);
173179
assert.isFalse(yield* f.fs.exists(f.path.join(f.worktreePath, "deleted.txt")));
174-
assert.isFalse(yield* f.fs.exists(f.path.join(f.worktreePath, "secret.txt")));
180+
assert.equal(
181+
yield* f.fs.readFileString(f.path.join(f.worktreePath, "secret.txt")),
182+
"receiver-only hook output\n",
183+
);
175184
assert.equal(
176185
yield* f.fs.readFileString(f.path.join(f.worktreePath, "forced.txt")),
177186
"source forced\n",
178187
);
179188
assert.equal(yield* git(f.worktreePath, ["diff", "--cached"]), "");
180189

181-
yield* f.write(f.worktreePath, "secret.txt", "receiver secret\n");
182190
const acceptedBefore = yield* checkoutState(f.worktreePath);
183191
const repacked = yield* handoff.pack({
184192
cwd: f.worktreePath,

‎apps/server/src/peer/handoff/HandoffGit.ts‎

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -373,27 +373,52 @@ const make = Effect.gen(function* () {
373373
// No-overlay checkout carries deletions; read-tree unstages edits without moving the branch.
374374
yield* git(input.worktreePath, ["checkout", "--no-overlay", input.snapshot, "--", "."]);
375375
yield* git(input.worktreePath, ["read-tree", "-m", input.tip]);
376-
// Keep carried force-added ignored files visible to the next commit or handoff.
377-
const ignored = yield* git(
376+
// Only snapshot additions qualify; checkout hooks can also produce ignored local files.
377+
// Prefix paths so check-ignore does not interpret literal names as pathspec magic.
378+
const added = yield* git(
378379
input.worktreePath,
379-
["ls-files", "-z", "--others", "--ignored", "--exclude-standard"],
380+
[
381+
"diff",
382+
"-z",
383+
"--name-only",
384+
"--line-prefix=./",
385+
"--no-renames",
386+
"--diff-filter=A",
387+
input.tip,
388+
input.snapshot,
389+
],
380390
{ maxOutputBytes: 16 * 1024 * 1024, outputMode: "error" },
381391
);
382-
if (ignored.stdout !== "") {
383-
yield* git(
392+
if (added.stdout !== "") {
393+
const ignored = yield* git(
384394
input.worktreePath,
385-
[
386-
"--literal-pathspecs",
387-
"add",
388-
"--intent-to-add",
389-
"--force",
390-
"--pathspec-from-file=-",
391-
"--pathspec-file-nul",
392-
],
393-
{ stdin: ignored.stdout },
395+
["check-ignore", "-z", "--stdin", "--no-index"],
396+
{
397+
stdin: added.stdout,
398+
allowNonZeroExit: true,
399+
maxOutputBytes: 16 * 1024 * 1024,
400+
outputMode: "error",
401+
},
394402
);
395-
// An intent entry can displace a tracked ancestor in a file-to-directory replacement.
396-
yield* git(input.worktreePath, ["diff", "--cached", "--quiet", input.tip]);
403+
if (ignored.exitCode !== 0 && ignored.exitCode !== 1) {
404+
return yield* new HandoffGitStepError({ step: "check-ignore", cause: ignored });
405+
}
406+
if (ignored.stdout !== "") {
407+
yield* git(
408+
input.worktreePath,
409+
[
410+
"--literal-pathspecs",
411+
"add",
412+
"--intent-to-add",
413+
"--force",
414+
"--pathspec-from-file=-",
415+
"--pathspec-file-nul",
416+
],
417+
{ stdin: ignored.stdout },
418+
);
419+
// An intent entry can displace a tracked ancestor in a file-to-directory replacement.
420+
yield* git(input.worktreePath, ["diff", "--cached", "--quiet", input.tip]);
421+
}
397422
}
398423
return {
399424
branch,

0 commit comments

Comments
 (0)