Skip to content

Commit a26b0b6

Browse files
committed
fix(review): use Git-compatible null device on Windows
1 parent 9f4da93 commit a26b0b6

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎src/pr-review-evidence.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import type { ItemContext } from "./clawsweeper-types.js";
77
const OBJECT_ID = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/;
88
const MAX_FILES = 80;
99
const MAX_PATCH_CHARS = 24_000;
10+
// Git for Windows accepts the DOS device spelling but rejects Node's `\\\\.\\nul`
11+
// spelling when it is supplied through GIT_CONFIG_GLOBAL.
12+
const gitNullDevice = process.platform === "win32" ? "NUL" : devNull;
1013

1114
type MergeBase =
1215
| { status: "verified"; sha: string }
@@ -88,7 +91,7 @@ export function readReviewGit(
8891
"-c",
8992
"core.fsmonitor=false",
9093
"-c",
91-
"core.hooksPath=" + devNull,
94+
"core.hooksPath=" + gitNullDevice,
9295
"-c",
9396
"diff.external=",
9497
...args,
@@ -111,14 +114,14 @@ export function readReviewGit(
111114
}
112115
: {
113116
GIT_CONFIG_NOSYSTEM: "1",
114-
GIT_CONFIG_GLOBAL: devNull,
117+
GIT_CONFIG_GLOBAL: gitNullDevice,
115118
GIT_ATTR_NOSYSTEM: "1",
116119
}),
117120
GIT_NO_LAZY_FETCH: "1",
118121
GIT_OPTIONAL_LOCKS: "0",
119122
GIT_NO_REPLACE_OBJECTS: "1",
120123
// Legacy graft files alter ancestry independently of replacement refs.
121-
GIT_GRAFT_FILE: devNull,
124+
GIT_GRAFT_FILE: gitNullDevice,
122125
GIT_TERMINAL_PROMPT: "0",
123126
GIT_LFS_SKIP_SMUDGE: "1",
124127
},

‎test/pr-review-evidence.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import assert from "node:assert/strict";
2+
import { execFileSync } from "node:child_process";
3+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
4+
import { tmpdir } from "node:os";
5+
import { join } from "node:path";
6+
import test from "node:test";
7+
8+
import { readReviewGit } from "../dist/pr-review-evidence.js";
9+
10+
test("readReviewGit keeps raw reads isolated with a Git-compatible null device", () => {
11+
const root = mkdtempSync(join(tmpdir(), "clawsweeper-review-git-"));
12+
const repo = join(root, "repo");
13+
const malformedGlobalConfig = join(root, "malformed-global.gitconfig");
14+
const previousGlobalConfig = process.env.GIT_CONFIG_GLOBAL;
15+
try {
16+
execFileSync("git", ["init", "-q", repo], { stdio: "pipe" });
17+
writeFileSync(malformedGlobalConfig, "[broken\n");
18+
process.env.GIT_CONFIG_GLOBAL = malformedGlobalConfig;
19+
20+
const output = readReviewGit(repo, ["rev-parse", "--is-inside-work-tree"]);
21+
22+
assert.equal(output?.toString("utf8").trim(), "true");
23+
assert.equal(process.env.GIT_CONFIG_GLOBAL, malformedGlobalConfig);
24+
} finally {
25+
if (previousGlobalConfig === undefined) delete process.env.GIT_CONFIG_GLOBAL;
26+
else process.env.GIT_CONFIG_GLOBAL = previousGlobalConfig;
27+
rmSync(root, { recursive: true, force: true });
28+
}
29+
});

0 commit comments

Comments
 (0)