pi-ext
bugabingas pi extensions
owned by bugabinga
test: isolate nested git commands
554c76bb3c7aada5ddb5bbc003c3ad6b4c77fbff
Review <review@example.invalid> ·
unsigned
Browse filesCompare with HEAD
Changed files (5)
.markdownlint-cli2.yaml
Modified 7 7 -
"**/node_modules/**" 9 9 -
"skills/*/references/**" 10 + -
"skills/*/_research/**" 10 11 -
"skills/presenterm/templates/**" extensions/diff-review/__tests__/core.test.ts
Modified 12 12 const execFileAsync
= promisify(execFile);
13 13 const tempDirs
: string[]
= [];
14 +const GIT_LOCAL_ENV
= [
15 + "GIT_ALTERNATE_OBJECT_DIRECTORIES",
17 + "GIT_CONFIG_PARAMETERS",
19 + "GIT_OBJECT_DIRECTORY",
22 + "GIT_IMPLICIT_WORK_TREE",
25 + "GIT_NO_REPLACE_OBJECTS",
26 + "GIT_REPLACE_REF_BASE",
15 32 afterEach(
async ()
=> {
30 47 async function git(cwd
: string, args
: string[]) {
31 - await execFileAsync(
"git", args, { cwd, maxBuffer:
20 * 1024 * 1024 });
48 + await execFileAsync(
"git", args, {
51 + maxBuffer:
20 * 1024 * 1024,
55 +function cleanGitEnv() {
56 + const env
= {
...process.
env };
57 + for (
const key
of GIT_LOCAL_ENV)
delete env[key];
34 61 describe(
"diff-review core regressions", ()
=> {
extensions/diff-review/__tests__/harness.test.ts
Modified 7 7 import diffReviewExtension
from "../index";
9 9 const execFileAsync
= promisify(execFile);
10 +const GIT_LOCAL_ENV
= [
11 + "GIT_ALTERNATE_OBJECT_DIRECTORIES",
13 + "GIT_CONFIG_PARAMETERS",
15 + "GIT_OBJECT_DIRECTORY",
18 + "GIT_IMPLICIT_WORK_TREE",
21 + "GIT_NO_REPLACE_OBJECTS",
22 + "GIT_REPLACE_REF_BASE",
10 27 const sleep = (ms
: number)
=> new Promise((resolve)
=> setTimeout(resolve, ms));
12 29 describe(
"diff-review pi-test-harness", ()
=> {
103 120 async function git(cwd
: string, args
: string[]) {
104 - await execFileAsync(
"git", args, { cwd, maxBuffer:
20 * 1024 * 1024 });
121 + await execFileAsync(
"git", args, {
123 + env:
cleanGitEnv(),
124 + maxBuffer:
20 * 1024 * 1024,
128 +function cleanGitEnv() {
129 + const env
= {
...process.
env };
130 + for (
const key
of GIT_LOCAL_ENV)
delete env[key];
extensions/diff-review/git.ts
Modified 16 16 const STDERR_BUFFER_BYTES
= 64 * 1024;
17 17 const HUNK_HEADER
= /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
18 18 const DIFF_GIT_HEADER
= /^diff --git a\/(.*) b\/(.*)$/;
19 +const GIT_LOCAL_ENV
= [
20 + "GIT_ALTERNATE_OBJECT_DIRECTORIES",
22 + "GIT_CONFIG_PARAMETERS",
24 + "GIT_OBJECT_DIRECTORY",
27 + "GIT_IMPLICIT_WORK_TREE",
30 + "GIT_NO_REPLACE_OBJECTS",
31 + "GIT_REPLACE_REF_BASE",
20 37 type ChangedFileSpec = { paths
: string[]; displayPath
: string };
159 176 const { stdout }
= await execFileAsync(
"git", args, {
178 + env:
cleanGitEnv(),
161 179 maxBuffer: options.maxBuffer
?? DEFAULT_GIT_BUFFER_BYTES,
163 181 return String(stdout);
174 192 return new Promise((resolve, reject)
=> {
175 193 const child
= spawn(
"git", args, {
195 + env:
cleanGitEnv(),
177 196 stdio: [
"ignore",
"pipe",
"pipe"],
179 198 const stdout
: Buffer[]
= [];
245 +function cleanGitEnv() {
246 + const env
= {
...process.
env };
247 + for (
const key
of GIT_LOCAL_ENV)
delete env[key];
226 251 function gitError(err
: unknown) {
227 252 const e
= err
as { stderr
?: string | Buffer; message
?: string };
228 253 return String(e.stderr
?? "").
trim()
|| e.message
|| "git failed";
7 7 reporters: [
"minimal"],