Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ function buildHydrationPlan(records, { cacheRoot = DEFAULT_CACHE_ROOT, targetRoo
}));
}

function runGit(args, cwd) {
function runGit(args, cwd, stderr = "pipe") {
return childProcess.execFileSync("git", args, {
cwd,
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
stdio: ["ignore", "pipe", stderr],
});
}

Expand Down Expand Up @@ -178,6 +178,7 @@ if (require.main === module) {
}

module.exports = {
runGit,
DEFAULT_CACHE_ROOT,
parseArgs,
repositoryCacheId,
Expand Down
16 changes: 2 additions & 14 deletions evals/triage-finding/scripts/hydrate-calibration-repos.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
"use strict";

const childProcess = require("node:child_process");
const { runGit } = require("../sastbench/scripts/hydrate-sastbench-repos");
const fs = require("node:fs");
const path = require("node:path");

Expand Down Expand Up @@ -67,21 +67,9 @@ function plannedJobs(dataset, args) {
return jobs;
}

function runGit(args, cwd) {
childProcess.execFileSync("git", args, {
cwd,
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
});
}

function gitOutput(args, cwd) {
try {
return childProcess.execFileSync("git", args, {
cwd,
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
}).trim();
return runGit(args, cwd, "ignore").trim();
} catch {
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions plugins/codex-security/mcp-app/scripts/git.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { ExecFileSyncOptions } from "node:child_process";

export function gitText(
args: readonly string[],
options?: Omit<ExecFileSyncOptions, "encoding">,
): string;
5 changes: 5 additions & 0 deletions plugins/codex-security/mcp-app/scripts/git.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { execFileSync } from "node:child_process";

export function gitText(args, options) {
return execFileSync("git", args, { ...options, encoding: "utf8" });
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { gitText } from "../scripts/git.mjs";
import { readOnlyParentSandboxState } from "./sandbox-state.mjs";
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
Expand Down Expand Up @@ -65,8 +66,7 @@ async function testCompactDiffScanCompletion(bundle, runtimeLabel) {
mkdir(scanRoot, { recursive: true }),
]);
const git = (...arguments_) =>
execFileSync(
"git",
gitText(
[
"-c",
"user.name=Fixture",
Expand Down
9 changes: 3 additions & 6 deletions plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { gitText } from "../scripts/git.mjs";
import { assertNoError } from "./assertions.mjs";
import { readOnlyParentSandboxState } from "./sandbox-state.mjs";
import assert from "node:assert/strict";
Expand Down Expand Up @@ -161,9 +162,7 @@ execFileSync("git", [
"-qm",
"fixture",
]);
const gitBase = execFileSync("git", ["-C", gitTarget, "rev-parse", "HEAD"], {
encoding: "utf8",
}).trim();
const gitBase = gitText(["-C", gitTarget, "rev-parse", "HEAD"]).trim();
await writeFile(path.join(gitTarget, "fixture.txt"), "fixture\nupdated\n");
execFileSync("git", ["-C", gitTarget, "add", "fixture.txt"]);
execFileSync("git", [
Expand All @@ -177,9 +176,7 @@ execFileSync("git", [
"-qm",
"update fixture",
]);
const gitHead = execFileSync("git", ["-C", gitTarget, "rev-parse", "HEAD"], {
encoding: "utf8",
}).trim();
const gitHead = gitText(["-C", gitTarget, "rev-parse", "HEAD"]).trim();

function startTestServer({
args = [serverPath, "--stdio"],
Expand Down
7 changes: 2 additions & 5 deletions sdk/typescript/scripts/release-pr.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { gitText } from "../../../plugins/codex-security/mcp-app/scripts/git.mjs";
import { execFileSync } from "node:child_process";
import { hash } from "node:crypto";
import { setTimeout as delay } from "node:timers/promises";
Expand Down Expand Up @@ -223,11 +224,7 @@ export function createReleasePlan(history, previous = null) {

export function createGitRepository(directory) {
const git = (...args) =>
execFileSync("git", args, {
cwd: directory,
encoding: "utf8",
stdio: ["pipe", "pipe", "pipe"],
});
gitText(args, { cwd: directory, stdio: ["pipe", "pipe", "pipe"] });
return {
git,
ensureCommit(sha) {
Expand Down
7 changes: 3 additions & 4 deletions sdk/typescript/tests-ts/git-fixture.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { execFileSync } from "node:child_process";
import { gitText } from "./support/shell.js";

export function git(repository: string, ...args: string[]): string {
return execFileSync(
"git",
return gitText(
[
"-c",
"user.name=Fixture",
"-c",
"user.email=fixture@example.com",
...args,
],
{ cwd: repository, encoding: "utf8" },
{ cwd: repository },
).trim();
}
5 changes: 2 additions & 3 deletions sdk/typescript/tests-ts/release-pr.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execFileSync } from "node:child_process";
import { gitText } from "./support/shell.js";
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
Expand Down Expand Up @@ -219,10 +219,9 @@ class Fixture {
if (content === null) {
this.git("update-index", "--force-remove", "--", path);
} else {
const blob = execFileSync("git", ["hash-object", "-w", "--stdin"], {
const blob = gitText(["hash-object", "-w", "--stdin"], {
cwd: this.directory,
input: content,
encoding: "utf8",
stdio: ["pipe", "pipe", "pipe"],
}).trim();
this.git("update-index", "--add", "--cacheinfo", "100644", blob, path);
Expand Down
1 change: 1 addition & 0 deletions sdk/typescript/tests-ts/support/shell.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { gitText } from "../../../../plugins/codex-security/mcp-app/scripts/git.mjs";
import { execFile } from "node:child_process";
import { existsSync } from "node:fs";
import { dirname, join } from "node:path";
Expand Down
Loading