Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(cli): keep repo-config commands out of the remaining git calls; test the callers rg argv

KageBinaryf9e0f3722d22
diff --git a/ix-cli/src/cli/__tests__/callers-rg-args.test.ts b/ix-cli/src/cli/__tests__/callers-rg-args.test.ts
new file mode 100644
index 00000000..cb465977
--- /dev/null
+++ b/ix-cli/src/cli/__tests__/callers-rg-args.test.ts
@@ -0,0 +1,54 @@
+// Copyright 2026 Ix Infrastructure Inc.
+
+import { afterAll, beforeAll, describe, expect, it } from "vitest";
+import { spawnSync } from "node:child_process";
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { callersTextSearchArgs } from "../commands/callers.js";
+
+const hasRg = spawnSync("rg", ["--version"]).status === 0;
+
+/**
+ * `ix callers` falls back to rg with the target's name. A name is whatever the
+ * graph or the caller says, so it must reach rg as a literal pattern: a name
+ * shaped like an option used to be parsed as one (`--pre=cat` made rg wait on
+ * a preprocessor until killed, `-mt-4` became flags).
+ */
+describe.skipIf(!hasRg)("ix callers text fallback passes the name to rg as a literal", () => {
+ let root: string;
+
+ beforeAll(() => {
+ root = mkdtempSync(join(tmpdir(), "ix-callers-rg-"));
+ mkdirSync(join(root, "src"));
+ writeFileSync(
+ join(root, "src", "a.ts"),
+ ["call(--pre=cat);", "x = a-mt-4;", "operator()", "const $scope = 1;", "--files"].join("\n") + "\n",
+ );
+ });
+
+ afterAll(() => rmSync(root, { recursive: true, force: true }));
+
+ function search(name: string): { status: number | null; lines: string[] } {
+ const r = spawnSync("rg", callersTextSearchArgs(name, root), { encoding: "utf-8", timeout: 10_000 });
+ const lines = (r.stdout ?? "")
+ .split("\n")
+ .filter(Boolean)
+ .map((l) => JSON.parse(l))
+ .filter((e) => e.type === "match")
+ .map((e) => String(e.data.lines.text).trim());
+ return { status: r.status, lines };
+ }
+
+ it.each([
+ ["--pre=cat", "call(--pre=cat);"],
+ ["-mt-4", "x = a-mt-4;"],
+ ["operator()", "operator()"],
+ ["$scope", "const $scope = 1;"],
+ ["--files", "--files"],
+ ])("finds %s as text", (name, line) => {
+ const r = search(name);
+ expect(r.status).toBe(0);
+ expect(r.lines).toEqual([line]);
+ });
+});
diff --git a/ix-cli/src/cli/__tests__/git-repo-config-commands.test.ts b/ix-cli/src/cli/__tests__/git-repo-config-commands.test.ts
new file mode 100644
index 00000000..f46bd81e
--- /dev/null
+++ b/ix-cli/src/cli/__tests__/git-repo-config-commands.test.ts
@@ -0,0 +1,56 @@
+// Copyright 2026 Ix Infrastructure Inc.
+
+import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
+import { execFileSync } from "node:child_process";
+import { chmodSync, existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { tryGitLsFiles } from "../commands/ingest.js";
+import { gitRootFor } from "../config.js";
+import { readGitState } from "../explain/bm25-cache.js";
+import { gitDiffHead, gitTopLevel } from "../hook/session.js";
+
+/**
+ * A checkout's own .git/config can name commands git runs on its behalf:
+ * core.fsmonitor runs whenever the index is read (ls-files, grep, diff HEAD),
+ * and a textconv driver whenever a diff renders a matching file. Every git
+ * call the CLI and its hooks make inside a user's checkout must run neither.
+ */
+describe.skipIf(process.platform === "win32")("git calls do not run commands from the repository's config", () => {
+ let dir: string;
+ let repo: string;
+ let marker: string;
+
+ beforeAll(() => {
+ dir = mkdtempSync(join(tmpdir(), "ix-git-config-"));
+ repo = join(dir, "repo");
+ marker = join(dir, "ran.log");
+ const hook = join(dir, "hook.sh");
+ writeFileSync(hook, `#!/bin/sh\necho "$@" >> "${marker}"\nexit 1\n`);
+ chmodSync(hook, 0o755);
+ const git = (...args: string[]) => execFileSync("git", args, { cwd: repo, stdio: "ignore" });
+ execFileSync("git", ["init", "-q", repo]);
+ writeFileSync(join(repo, "a.txt"), "needle\n");
+ writeFileSync(join(repo, ".gitattributes"), "*.txt diff=conv\n");
+ git("add", ".");
+ git("-c", "user.email=t@t", "-c", "user.name=t", "commit", "-qm", "init");
+ git("config", "core.fsmonitor", hook);
+ git("config", "diff.conv.textconv", hook);
+ writeFileSync(join(repo, "a.txt"), "needle\nmore\n");
+ });
+
+ afterAll(() => rmSync(dir, { recursive: true, force: true }));
+
+ beforeEach(() => rmSync(marker, { force: true }));
+
+ it.each<[string, () => unknown]>([
+ ["ix ingest's git ls-files", () => tryGitLsFiles(repo, true)],
+ ["the workspace root lookup", () => gitRootFor(repo)],
+ ["the bm25 cache's git state", () => readGitState(repo)],
+ ["the session hook's top level", () => gitTopLevel(repo)],
+ ["the session hook's diff", () => gitDiffHead(repo)],
+ ])("%s", (_name, call) => {
+ call();
+ expect(existsSync(marker)).toBe(false);
+ });
+});
diff --git a/ix-cli/src/cli/commands/callers.ts b/ix-cli/src/cli/commands/callers.ts
index 7db46db2..52bd86da 100644
--- a/ix-cli/src/cli/commands/callers.ts
+++ b/ix-cli/src/cli/commands/callers.ts
@@ -17,6 +17,15 @@ import { renderWarning } from "../ui.js";
const execFileAsync = promisify(execFile);
+/**
+ * rg's argv for the text fallback. -F and -e: the name is a literal pattern,
+ * never a regex or a flag (a symbol named `--pre=x` would otherwise run an rg
+ * preprocessor). `--` ends the options before the root.
+ */
+export function callersTextSearchArgs(name: string, root: string): string[] {
+ return ["--json", "--max-count", "10", "-F", "-e", name, "--", root];
+}
+
/**
* The graph's health, as edge-result diagnostics. On a hollowed graph "no
* callers" is a count of lost edges, not an answer. llm and json carry a
@@ -66,13 +75,10 @@ export function registerCallersCommand(program: Command): void {
// Fallback to text search
try {
const root = resolveWorkspaceRoot();
- // -F and -e: the name is a literal pattern, never a regex or a flag
- // (a symbol named `--pre=x` would otherwise run an rg preprocessor).
- // `--` ends the options before the root; the timeout bounds a search
- // that rg could otherwise run for ever.
- const { stdout } = await execFileAsync("rg", [
- "--json", "--max-count", "10", "-F", "-e", target.name, "--", root,
- ], { maxBuffer: 5 * 1024 * 1024, timeout: 10_000 });
+ // The timeout bounds a search that rg could otherwise run for ever.
+ const { stdout } = await execFileAsync("rg", callersTextSearchArgs(target.name, root), {
+ maxBuffer: 5 * 1024 * 1024, timeout: 10_000,
+ });
const allTextResults: any[] = [];
for (const line of stdout.split("\n")) {
diff --git a/ix-cli/src/cli/explain/bm25-cache.ts b/ix-cli/src/cli/explain/bm25-cache.ts
index 11a0f099..cf190823 100644
--- a/ix-cli/src/cli/explain/bm25-cache.ts
+++ b/ix-cli/src/cli/explain/bm25-cache.ts
@@ -83,11 +83,15 @@ export function bm25IndexPath(root: string): string {
/**
* HEAD and the files that differ from it, or undefined outside a checkout (or
* on an unborn branch). `--no-optional-locks` because this runs in whatever
- * checkout the user is in, and a read must not rewrite its index file.
+ * checkout the user is in, and a read must not rewrite its index file. `-c`
+ * because `diff HEAD` reads the index, which runs a core.fsmonitor command the
+ * repository's own config names.
*/
export function readGitState(root: string): GitState | undefined {
try {
- const run = (args: string[]) => execFileSync("git", ["--no-optional-locks", ...args], {
+ const run = (args: string[]) => execFileSync("git", [
+ "--no-optional-locks", "-c", "core.fsmonitor=false", "-c", "core.hooksPath=/dev/null", ...args,
+ ], {
cwd: root, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 64 * 1024 * 1024,
});
const head = run(["rev-parse", "--verify", "-q", "HEAD"]).trim();
diff --git a/ix-cli/src/cli/hook/session.ts b/ix-cli/src/cli/hook/session.ts
index 83fb0b81..907f12d0 100644
--- a/ix-cli/src/cli/hook/session.ts
+++ b/ix-cli/src/cli/hook/session.ts
@@ -55,8 +55,11 @@ export function canonicalPath(p: string): string {
return parent === resolved ? resolved : path.join(canonicalPath(parent), path.basename(resolved));
}
+// This runs from session hooks in whatever checkout the agent is in. Reading
+// the index (diff HEAD) runs a core.fsmonitor command the repository's own
+// config names; never let it.
function git(cwd: string, args: string[]): string {
- return execFileSync("git", ["-C", cwd, ...args], {
+ return execFileSync("git", ["-C", cwd, "-c", "core.fsmonitor=false", "-c", "core.hooksPath=/dev/null", ...args], {
encoding: "utf-8",
stdio: ["ignore", "pipe", "ignore"],
timeout: GIT_TIMEOUT_MS,
@@ -81,9 +84,11 @@ export function gitTopLevel(dir: string): string | undefined {
export function gitDiffHead(repoRoot: string): string {
// The prefixes are spelled out because the user's config can change them:
// `diff.mnemonicPrefix` writes `c/` and `w/`, `diff.noprefix` none, and
- // `parseUnifiedDiff` strips `a/` and `b/`.
+ // `parseUnifiedDiff` strips `a/` and `b/`. --no-textconv: a textconv driver
+ // is a command from the repository's config, and the line numbers wanted
+ // here are the file's own, not a converted rendering's.
return git(repoRoot, [
- "diff", "-U0", "--no-color", "--no-ext-diff", "--no-renames", "--src-prefix=a/", "--dst-prefix=b/", "HEAD", "--",
+ "diff", "-U0", "--no-color", "--no-ext-diff", "--no-textconv", "--no-renames", "--src-prefix=a/", "--dst-prefix=b/", "HEAD", "--",
]);
}