repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

refactor(git-safe): drop --no-verify rejection

13a3cf54e1ca86564a31e07fee43333a49c9c0ab

Oliver Jan Krylow <oliver@bugabinga.net> ·

SSH signature · not checked

Browse filesCompare with HEAD

jj shells out to git push with --no-verify by design, so the wrapper
blocked a legitimate VCS workflow. The Git wrapper now only enforces
noninteractive editor settings and delegates everything else.

Changed files (7)

extensions/git-safe/CHANGELOG.md

Modified
3 3 # Changelog
5 5 ## Unreleased
7 7 - Prevent agent-issued Git commands from opening interactive editors
8 -- Reject hook-skipping `--no-verify` options through normal Git, aliases, shell indirection, nested Bash, `xargs`, child-process PATH lookup, and literal bypasses
9 8 - Launch through Git Bash even when callers disable MSYS argument conversion, and hide launcher internals when Git cannot start
10 9 - Document explicit `git.exe` child-process and unrestricted-Bash residual bypasses
11 10 - Keep safe-clone behavior unchanged

extensions/git-safe/README.md

Modified
40 40 A generated Git executable wrapper receives parsed arguments from normal Bash calls, `command git`, `env git`, `xargs git`, nested Bash, and unqualified child-process PATH lookup.
41 41 The first Bash call creates it with fixed Node and Git paths; later calls and reloads reuse it.
42 -It rejects hook-skipping `--no-verify` options, including accepted abbreviations, short `commit -n`, and non-shell alias chains.
43 42 It resets the editor environment immediately before invoking real Git and delegates ordinary commands unchanged.
44 -Bash `git()` and `git.exe()` functions route direct calls to that wrapper, while narrow preflight checks cover simple literal bypasses.
43 +Bash `git()` and `git.exe()` functions route direct calls to that wrapper.
45 44 Windows paths are converted for Git Bash, and common `git.exe` shell forms route through the wrapper.
46 45 The layers are defense in depth, not a security boundary; unrestricted Bash can still address or construct alternate executable paths.
47 46 On Windows, a non-Bash child process that explicitly launches `git.exe` can bypass the script wrapper because the extension does not ship a native PE launcher.

extensions/git-safe/__tests__/git-policy.test.ts

Modified
10 10 import { tmpdir } from "node:os";
11 11 import path from "node:path";
12 12 import { afterEach, describe, expect, it } from "vitest";
13 -import {
14 - applyGitPolicy,
15 - blockedGitCommandReason,
16 - createGitPolicyRuntime,
17 -} from "../git-policy";
13 +import { applyGitPolicy, createGitPolicyRuntime } from "../git-policy";
19 15 const testDirs: string[] = [];
20 16 afterEach(() => {
25 21 describe("git-safe agent Git policy", () => {
26 - it("blocks literal command-git no-verify bypasses", () => {
27 - for (const command of [
28 - "command git commit --no-verify",
29 - "command -p git push --no-verify",
30 - " command -- git rebase --no-verify",
31 - ]) {
32 - expect(blockedGitCommandReason(command)).toContain("blocked --no-verify");
33 - }
34 - });
36 - it("does not classify ordinary Git or quoted documentation as command bypasses", () => {
37 - for (const command of [
38 - "git commit --no-verify",
39 - "printf '%s' 'command git commit --no-verify'",
40 - "command git status",
41 - "command git commit -m 'Document --no-verify usage'",
42 - "command git merge --no-verify-signatures topic",
43 - ]) {
44 - expect(blockedGitCommandReason(command)).toBeUndefined();
45 - }
46 - });
48 22 it("generates and reuses a wrapper with fixed executables", async () => {
49 23 const bin = mkdtempSync(path.join(tmpdir(), "pi-git-policy-bin-"));
50 24 testDirs.push(bin);
138 112 it("does not trust an agent-supplied policy marker", () => {
139 - const command = "# pi-git-safe-policy-v1\ngit commit --no-verify";
113 + const command = "# pi-git-safe-policy-v1\ngit status";
140 114 const wrapped = applyGitPolicy(command, {
141 115 wrapperDir: "/tmp/wrapper",
142 116 realGit: "/usr/bin/git",

extensions/git-safe/__tests__/harness.test.ts

Modified
105 105 bashShebang(),
106 - "if [[ \"$*\" == '--list-cmds=builtins' ]]; then printf 'status\\n'; exit 0; fi",
107 - "if [[ \"$*\" == *'config --get alias.'* ]]; then exit 1; fi",
108 106 "printf 'FAKE_GIT\\n'",
109 107 "printf 'ARGS:'",
110 108 "printf '<%s>' \"$@\"",
125 123 bashShebang(),
126 124 "if [[ \"$1\" == '--version' ]]; then printf 'rtk 0.42.4\\n'; exit 0; fi",
127 - "if [[ \"$1\" == 'rewrite' && \"$2\" == 'git commit --no-verify' ]]; then printf 'rtk git commit --no-verify\\n'; exit 0; fi",
128 125 "if [[ \"$1\" == 'rewrite' && \"$2\" == 'git status' ]]; then printf 'rtk git status\\n'; exit 0; fi",
129 126 'if [[ "$1" == \'git\' ]]; then shift; exec git "$@"; fi',
130 127 "exit 1",
158 155 describe("git-safe pi-test-harness", () => {
159 156 let t: TestSession | undefined;
160 157 let root: string | undefined;
161 - let fakeGit: string | undefined;
163 159 afterEach(() => {
164 160 t?.dispose();
165 161 if (root) rmSync(root, { recursive: true, force: true });
166 162 t = undefined;
167 163 root = undefined;
168 - fakeGit = undefined;
171 166 async function startWithFakeGit(useRtk = false): Promise<void> {
172 167 root = mkdtempSync(path.join(tmpdir(), "pi-git-safe-test-"));
173 168 const installed = installFakeGit(root);
174 169 if (useRtk) installFakeRtk(installed.bin);
175 - fakeGit = installed.executable;
176 170 t = await createTestSession({
177 171 cwd: root,
178 172 env: { PATH: `${installed.bin}${path.delimiter}${process.env.PATH}` },
212 - async function expectRejected(command: string): Promise<void> {
206 + async function expectGitOutput(command: string): Promise<void> {
213 207 const result = await execute(command);
214 - expect(result.output, command).toContain("git-safe blocked --no-verify");
215 - expect(result.output, command).not.toContain("FAKE_GIT");
208 + expect(result.blocked, command).toBeUndefined();
209 + expect(result.output, command).toContain("FAKE_GIT");
218 212 it("loads in real Pi extension runtime", async () => {
345 339 expect(result.output).toContain("EDITOR=<true> SEQUENCE=<true> MERGE=<no>");
348 - it("rejects no-verify after shell expansion and indirect PATH lookup", async () => {
349 - await startWithFakeGit();
351 - for (const command of [
352 - 'flag=--no-verify; git commit "$flag"',
353 - "git am --no-v patch.mbox",
354 - "git am -n patch.mbox",
355 - 'command git commit --no-"verify"',
356 - "command -p git -C . commit --no-verify",
357 - "env git push --no-verify",
358 - "env --uns PATH git commit --no-verify",
359 - "bash -p -c 'git rebase --no-verify'",
360 - "bash -c 'command git commit --no-verify'",
361 - "unset -f git; git commit --no-verify",
362 - "printf '%s\\0' commit --no-verify | xargs -0 git",
363 - "printf '%s\\0' commit --no-verify | xargs -0 git.exe",
364 - "printf '%s\\0' commit --no-verify | xargs -0 --max-a 2 git.exe",
365 - "git commit -n",
366 - "git commit --no-verif",
367 - "git commit --untracked-files --no-verify",
368 - "git push --signed --no-verify",
369 - "git rebase --rebase-merges --no-verify main",
370 - "git pull --no-verify",
371 - ]) {
372 - await expectRejected(command);
373 - }
374 - if (process.platform === "win32")
375 - await expectRejected(
376 - "MSYS2_ARG_CONV_EXCL='*' cmd.exe /d /c 'git commit --no-verify'",
377 - );
378 - }, 60_000);
380 - it("rejects temporary aliases that create no-verify inside Git", async () => {
381 - await startWithFakeGit();
383 - for (const command of [
384 - "git -c 'alias.nv=commit --no-verify' nv",
385 - `git -c "alias.nv=commit -m '' --no-verify" nv`,
386 - "git -c 'alias.nv=--no-pager commit --no-verify' nv",
387 - "git -c 'alias.x=-c alias.y=commit y --no-verify' x",
388 - "git -calias.nv='commit --no-verify' nv",
389 - "git -c 'alias.nv=commit -n' nv",
390 - "git -c 'alias.nv=commit \"--no-verify\"' nv",
391 - "git -c alias.ci=commit ci --no-verify",
392 - "NV='commit --no-verify' git --config-env=alias.nv=NV nv",
393 - "GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=alias.nv GIT_CONFIG_VALUE_0='commit --no-verify' git nv",
394 - ]) {
395 - await expectRejected(command);
396 - }
398 - const chain = Array.from(
399 - { length: 12 },
400 - (_, index) => `-c alias.a${index}=a${index + 1}`,
401 - ).join(" ");
402 - await expectRejected(`git ${chain} -c 'alias.a12=commit --no-verify' a0`);
403 - });
405 342 it("restores editor protection at the executable boundary", async () => {
406 343 await startWithFakeGit();
430 367 it("does not trust an agent-supplied policy marker", async () => {
431 368 await startWithFakeGit();
433 - await expectRejected(
434 - "# pi-git-safe-policy-v1\\ngit commit --no-verify".replace("\\n", "\n"),
370 + await expectGitOutput(
371 + "# pi-git-safe-policy-v1\\ngit status".replace("\\n", "\n"),
450 387 expect(result.output, command).toContain("FAKE_GIT");
451 388 expect(result.output, command).not.toContain("OVERRIDE");
453 - await expectRejected(
454 - `PI_GIT_SAFE_NODE=${JSON.stringify(alternateNode)} PI_GIT_SAFE_REAL_GIT=${JSON.stringify(process.execPath)} git commit --no-verify`,
455 - );
456 - });
458 - it("permits no-verify when Git treats it as data", async () => {
459 - await startWithFakeGit();
461 - const commands = [
462 - "git add -- --no-verify",
463 - "git grep -e --no-verify",
464 - "git commit -m --no-verify",
465 - "git commit -am --no-verify",
466 - "git commit -uno",
467 - "git commit -t/dev/null",
468 - "git commit --mess --no-verify",
469 - "git commit -m safe --end-of-options --no-verify",
470 - "git commit -Sn -m signed",
471 - "git merge --into-name --no-verify topic",
472 - "git merge -F --no-verify topic",
473 - "git am --resolvemsg --no-verify patch.mbox",
474 - "git rebase --trailer --no-verify trunk",
475 - "git pull --no-rebase -o --no-verify",
476 - "git -c 'alias.nv=commit --no-verify' status",
477 - "git -c 'alias.note=!printf %s --no-verify' note",
478 - "command git merge --no-verify-signatures topic",
479 - "command git commit -m 'Document --no-verify usage'",
480 - 'env -i PATH="$PATH" git status',
481 - "GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=alias.nv GIT_CONFIG_VALUE_0='commit --no-verify' git -c alias.nv=status nv",
482 - "GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=alias.commit GIT_CONFIG_VALUE_0='rebase --no-verify' git commit -m safe",
483 - ];
484 - if (process.platform !== "win32") {
485 - commands.push(
486 - "GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=alias.status GIT_CONFIG_VALUE_0='commit --no-verify' git status",
487 - );
488 - }
489 - for (const command of commands) {
490 - const result = await execute(command);
491 - expect(result.blocked, command).toBeUndefined();
492 - if (process.platform !== "win32" || !command.includes("git -c ")) {
493 - expect(result.output, command).toContain("FAKE_GIT");
494 - }
495 - }
496 - }, 60_000);
498 - it("blocks literal command-git bypasses before execution", async () => {
499 - await startWithFakeGit();
501 - const result = await execute("command git commit --no-verify");
503 - expect(result.blocked).toMatchObject({ block: true });
504 - expect(result.blocked?.reason).toContain("git-safe blocked --no-verify");
505 - });
507 - it("rejects literal absolute Git paths", async () => {
508 - await startWithFakeGit();
509 - if (!fakeGit) throw new Error("missing fake Git path");
511 - for (const command of ["commit", "pull"]) {
512 - const result = await execute(
513 - `${JSON.stringify(fakeGit)} ${command} --no-verify`,
514 - );
515 - expect(result.blocked).toMatchObject({ block: true });
516 - }
519 392 it("keeps policy active after RTK rewrites Git", async () => {
520 393 await startWithFakeGit(true);
522 - await expectRejected("git commit --no-verify");
523 395 const ordinary = await execute("git status");
524 396 expect(ordinary.output).toContain("FAKE_GIT");
525 397 expect(ordinary.output).toContain("ARGS:<status>");

extensions/git-safe/git-policy.ts

Modified
13 13 const POLICY_MARKER = "# pi-git-safe-policy-v1";
14 14 const COMMAND_PREFIX_END = "# pi-command-prefix-end";
16 -const BLOCK_REASON =
17 - "git-safe blocked --no-verify. Fix the hook failure or ask the user for help.";
19 -const DIRECT_COMMAND_GIT_NO_VERIFY_RE =
20 - /^\s*command\s+(?:(?:-p|--)\s+)*git(?:\.exe)?\s+(?:am|commit|merge|pull|push|rebase)\s+--no-verify(?:\s|$)/u;
22 16 export interface GitPolicyRuntime {
23 17 wrapperDir: string;
24 18 realGit: string;
148 142 return drive ? `/${drive[1].toLowerCase()}/${drive[2]}` : normalized;
151 -export function blockedGitCommandReason(
152 - command: string,
153 - runtime?: GitPolicyRuntime,
154 -): string | undefined {
155 - if (DIRECT_COMMAND_GIT_NO_VERIFY_RE.test(command)) return BLOCK_REASON;
156 - if (!runtime) return undefined;
157 - const trimmed = command.trimStart();
158 - const literalPaths = [
159 - runtime.realGit,
160 - bashPath(runtime.realGit),
161 - shellQuote(runtime.realGit),
162 - shellQuote(bashPath(runtime.realGit)),
163 - JSON.stringify(runtime.realGit),
164 - ];
165 - for (const path of literalPaths) {
166 - if (!trimmed.startsWith(`${path} `)) continue;
167 - const args = trimmed.slice(path.length).trimStart();
168 - if (
169 - /^(?:am|commit|merge|pull|push|rebase)\s+--no-verify(?:\s|$)/u.test(args)
170 - )
171 - return BLOCK_REASON;
172 - }
173 - return undefined;
176 145 export function applyGitPolicy(
177 146 command: string,
178 147 runtime: GitPolicyRuntime,

extensions/git-safe/git-wrapper.cjs

Modified
3 3 #!/usr/bin/env node
5 5 const { spawnSync } = require("node:child_process");
7 7 const realGit = "__PI_GIT_SAFE_REAL_GIT__";
8 -const protectedCommands = new Set([
9 - "am",
10 - "commit",
11 - "merge",
12 - "pull",
13 - "push",
14 - "rebase",
15 -]);
16 9 const globalValueOptions = new Set([
17 10 "-C",
18 11 "-c",
21 14 "--super-prefix",
22 15 "--work-tree",
24 -const commandValueOptions = {
25 - am: new Set([
26 - "-C",
27 - "-p",
28 - "--directory",
29 - "--empty",
30 - "--exclude",
31 - "--include",
32 - "--patch-format",
33 - "--quoted-cr",
34 - "--resolvemsg",
35 - "--whitespace",
36 - ]),
37 - commit: new Set([
38 - "-C",
39 - "-F",
40 - "-c",
41 - "-m",
42 - "--author",
43 - "--cleanup",
44 - "--date",
45 - "--file",
46 - "--fixup",
47 - "--message",
48 - "--pathspec-from-file",
49 - "--reedit-message",
50 - "--reuse-message",
51 - "--squash",
52 - "--template",
53 - "--trailer",
54 - ]),
55 - merge: new Set([
56 - "-F",
57 - "-m",
58 - "-s",
59 - "-X",
60 - "--cleanup",
61 - "--file",
62 - "--into-name",
63 - "--message",
64 - "--strategy",
65 - "--strategy-option",
66 - ]),
67 - pull: new Set([
68 - "-s",
69 - "-X",
70 - "--cleanup",
71 - "--depth",
72 - "--deepen",
73 - "--negotiation-tip",
74 - "--server-option",
75 - "--shallow-exclude",
76 - "--shallow-since",
77 - "--strategy",
78 - "--strategy-option",
79 - "--upload-pack",
80 - ]),
81 - push: new Set(["-o", "--exec", "--push-option", "--receive-pack", "--repo"]),
82 - rebase: new Set([
83 - "-s",
84 - "-X",
85 - "-x",
86 - "--empty",
87 - "--exec",
88 - "--onto",
89 - "--strategy",
90 - "--strategy-option",
91 - "--trailer",
92 - "--whitespace",
93 - ]),
94 -};
95 -const shortValueOptions = {
96 - am: new Set(["C", "p"]),
97 - commit: new Set(["C", "F", "c", "m", "t"]),
98 - merge: new Set(["F", "m", "s", "X"]),
99 - pull: new Set(["o", "s", "X"]),
100 - push: new Set(["o"]),
101 - rebase: new Set(["s", "X", "x"]),
102 -};
103 -const shortAttachedValueOptions = {
104 - am: new Set(),
105 - commit: new Set(["S", "u"]),
106 - merge: new Set(),
107 - pull: new Set(),
108 - push: new Set(),
109 - rebase: new Set(),
110 -};
112 18 function optionName(argument) {
113 19 const equals = argument.indexOf("=");
118 24 return !argument.includes("=") && options.has(optionName(argument));
121 -function consumesCommandValue(argument, options) {
122 - if (argument.includes("=")) return false;
123 - if (options.has(argument)) return true;
124 - if (!argument.startsWith("--")) return false;
125 - return [...options].filter((option) => option.startsWith(argument)).length === 1;
128 27 function commandPosition(args) {
129 28 for (let index = 0; index < args.length; index++) {
130 29 const argument = args[index];
135 34 return -1;
138 -function addAlias(aliases, config) {
139 - const match = config.match(/^alias\.([^=]+)=(.*)$/isu);
140 - if (match) aliases.set(match[1].toLowerCase(), match[2]);
143 -function addArgumentAliases(aliases, args, commandIndex) {
144 - for (let index = 0; index < commandIndex; index++) {
145 - const argument = args[index];
146 - if (argument === "-c") {
147 - addAlias(aliases, args[++index] ?? "");
148 - continue;
149 - }
150 - if (argument.startsWith("-c") && argument.length > 2) {
151 - addAlias(aliases, argument.slice(2));
152 - continue;
153 - }
154 - const configEnv = argument.startsWith("--config-env=")
155 - ? argument.slice("--config-env=".length)
156 - : argument === "--config-env"
157 - ? (args[++index] ?? "")
158 - : undefined;
159 - if (configEnv !== undefined) {
160 - const equals = configEnv.indexOf("=");
161 - if (equals >= 0) {
162 - const name = configEnv.slice(0, equals);
163 - const variable = configEnv.slice(equals + 1);
164 - addAlias(aliases, `${name}=${process.env[variable] ?? ""}`);
165 - }
166 - }
167 - }
170 -function temporaryAliases(args, commandIndex) {
171 - const aliases = new Map();
172 - const count = Number.parseInt(process.env.GIT_CONFIG_COUNT ?? "0", 10);
173 - for (let index = 0; index < count; index++) {
174 - const key = process.env[`GIT_CONFIG_KEY_${index}`] ?? "";
175 - const value = process.env[`GIT_CONFIG_VALUE_${index}`] ?? "";
176 - addAlias(aliases, `${key}=${value}`);
177 - }
178 - addArgumentAliases(aliases, args, commandIndex);
179 - return aliases;
182 -function splitAlias(value) {
183 - const words = [];
184 - let word = "";
185 - let quote = "";
186 - let escaped = false;
187 - let started = false;
188 - for (const character of value.trim()) {
189 - if (escaped) {
190 - word += character;
191 - escaped = false;
192 - started = true;
193 - continue;
194 - }
195 - if (character === "\\" && quote !== "'") {
196 - escaped = true;
197 - continue;
198 - }
199 - if ((character === "'" || character === '"') && !quote) {
200 - quote = character;
201 - started = true;
202 - continue;
203 - }
204 - if (character === quote) {
205 - quote = "";
206 - continue;
207 - }
208 - if (/\s/u.test(character) && !quote) {
209 - if (started) words.push(word);
210 - word = "";
211 - started = false;
212 - continue;
213 - }
214 - word += character;
215 - started = true;
216 - }
217 - if (escaped) {
218 - word += "\\";
219 - started = true;
220 - }
221 - if (started) words.push(word);
222 - return words;
225 -function configuredAlias(globalArgs, command) {
226 - const result = spawnSync(
227 - realGit,
228 - [...globalArgs, "config", "--get", `alias.${command}`],
229 - {
230 - encoding: "utf8",
231 - env: process.env,
232 - },
233 - );
234 - return result.status === 0 ? result.stdout.trim() : undefined;
237 -function isBuiltinCommand(command) {
238 - const result = spawnSync(realGit, ["--list-cmds=builtins"], {
239 - encoding: "utf8",
240 - env: process.env,
241 - });
242 - return result.status === 0 && result.stdout.split(/\s+/u).includes(command);
245 -function resolveCommand(args) {
246 - const position = commandPosition(args);
247 - if (position < 0 || position >= args.length) return undefined;
248 - const globalArgs = args.slice(0, position);
249 - const aliases = temporaryAliases(args, position);
250 - const seen = new Set();
251 - let command = args[position];
252 - let commandArgs = args.slice(position + 1);
253 - while (!protectedCommands.has(command)) {
254 - const key = command.toLowerCase();
255 - if (seen.has(key)) break;
256 - seen.add(key);
257 - const alias = aliases.get(key) ?? configuredAlias(globalArgs, command);
258 - if (!alias || alias.startsWith("!") || isBuiltinCommand(command)) break;
259 - const expansion = [...splitAlias(alias), ...commandArgs];
260 - const expandedPosition = commandPosition(expansion);
261 - if (expandedPosition < 0 || expandedPosition >= expansion.length) break;
262 - addArgumentAliases(aliases, expansion, expandedPosition);
263 - globalArgs.push(...expansion.slice(0, expandedPosition));
264 - command = expansion[expandedPosition];
265 - commandArgs = expansion.slice(expandedPosition + 1);
266 - }
267 - return { command, args: commandArgs };
270 -function isNoVerifyLongOption(command, argument) {
271 - const minimum = command === "am" ? "--no-v" : "--no-veri";
272 - return argument.length >= minimum.length && "--no-verify".startsWith(argument);
275 -function inspectShortOptions(command, argument) {
276 - if (!/^-[^-]/u.test(argument)) return { blocked: false, consumesNext: false };
277 - const options = argument.slice(1);
278 - const values = shortValueOptions[command];
279 - const attachedValues = shortAttachedValueOptions[command];
280 - for (let index = 0; index < options.length; index++) {
281 - const option = options[index];
282 - if ((command === "am" || command === "commit") && option === "n") {
283 - return { blocked: true, consumesNext: false };
284 - }
285 - if (values.has(option)) {
286 - return {
287 - blocked: false,
288 - consumesNext: index === options.length - 1,
289 - };
290 - }
291 - if (attachedValues.has(option)) {
292 - return { blocked: false, consumesNext: false };
293 - }
294 - }
295 - return { blocked: false, consumesNext: false };
298 -function hasNoVerifyOption(args) {
299 - const resolved = resolveCommand(args);
300 - if (!resolved || !protectedCommands.has(resolved.command)) return false;
301 - const valueOptions = commandValueOptions[resolved.command];
302 - for (let index = 0; index < resolved.args.length; index++) {
303 - const argument = resolved.args[index];
304 - if (argument === "--" || argument === "--end-of-options") return false;
305 - if (isNoVerifyLongOption(resolved.command, argument)) return true;
306 - const short = inspectShortOptions(resolved.command, argument);
307 - if (short.blocked) return true;
308 - if (short.consumesNext || consumesCommandValue(argument, valueOptions)) index++;
309 - }
310 - return false;
313 37 const args = process.argv.slice(2);
314 -if (hasNoVerifyOption(args)) {
315 - console.error(
316 - "git-safe blocked --no-verify. Fix the hook failure or ask the user for help.",
317 - );
318 - process.exit(126);
39 +const commandIndex = commandPosition(args);
321 40 const editorQuery =
322 - args[commandPosition(args)] === "var" &&
323 - (args[commandPosition(args) + 1] === "GIT_EDITOR" ||
324 - args[commandPosition(args) + 1] === "GIT_SEQUENCE_EDITOR");
41 + args[commandIndex] === "var" &&
42 + (args[commandIndex + 1] === "GIT_EDITOR" ||
43 + args[commandIndex + 1] === "GIT_SEQUENCE_EDITOR");
325 45 const env = { ...process.env };
326 46 if (!editorQuery) {
327 47 env.GIT_EDITOR = "true";
328 48 env.GIT_SEQUENCE_EDITOR = "true";
329 49 env.GIT_MERGE_AUTOEDIT = "no";
331 52 const result = spawnSync(realGit, args, { stdio: "inherit", env });
332 53 if (result.error) {
333 54 console.error(result.error.message);

extensions/git-safe/index.ts

Modified
29 29 import type { SafeCloneResult } from "./clone.js";
30 30 import {
31 31 applyGitPolicy,
32 - blockedGitCommandReason,
33 32 createGitPolicyRuntime,
34 33 type GitPolicyRuntime,
35 34 } from "./git-policy.js";
134 133 if (!isToolCallEventType("bash", event)) return;
135 134 const runtime = await ensureGitPolicy(ctx);
136 135 if (!runtime) return;
137 - const reason = blockedGitCommandReason(event.input.command, runtime);
138 - if (reason) return { block: true, reason };
139 136 event.input.command = applyGitPolicy(event.input.command, runtime);