fix: diff command for filenames with special characters (#954)
## Summary - fix quoting issues in `/diff` to correctly handle files with special characters - add regression test for `getGitDiff` when filenames contain `$` - relax timeout in raw-exec-process-group test Fixes https://github.com/openai/codex/issues/943 ## Testing - `pnpm test`
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { execSync } from "node:child_process";
|
||||
import { execSync, execFileSync } from "node:child_process";
|
||||
|
||||
// The objects thrown by `child_process.execSync()` are `Error` instances that
|
||||
// include additional, undocumented properties such as `status` (exit code) and
|
||||
@@ -89,12 +89,18 @@ export function getGitDiff(): {
|
||||
//
|
||||
// `git diff --color --no-index /dev/null <file>` exits with status 1
|
||||
// when differences are found, so we capture stdout from the thrown
|
||||
// error object instead of letting it propagate.
|
||||
execSync(`git diff --color --no-index -- "${nullDevice}" "${file}"`, {
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "ignore"],
|
||||
maxBuffer: 10 * 1024 * 1024,
|
||||
});
|
||||
// error object instead of letting it propagate. Using `execFileSync`
|
||||
// avoids shell interpolation issues with special characters in the
|
||||
// path.
|
||||
execFileSync(
|
||||
"git",
|
||||
["diff", "--color", "--no-index", "--", nullDevice, file],
|
||||
{
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "ignore"],
|
||||
maxBuffer: 10 * 1024 * 1024,
|
||||
},
|
||||
);
|
||||
} catch (err) {
|
||||
if (
|
||||
isExecSyncError(err) &&
|
||||
|
||||
Reference in New Issue
Block a user