Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(git_operations): suppress an external diff with --no-ext-diff, not an empty config

M3gA-Mind30ba798fe8bb
diff --git a/src/openhuman/tools/impl/filesystem/git_operations.rs b/src/openhuman/tools/impl/filesystem/git_operations.rs
index 0186ce495e..c96d1dd7fa 100644
--- a/src/openhuman/tools/impl/filesystem/git_operations.rs
+++ b/src/openhuman/tools/impl/filesystem/git_operations.rs
@@ -174,7 +174,10 @@ impl GitOperationsTool {
// Validate files argument against injection patterns
self.sanitize_git_args(files)?;
- let mut git_args = vec!["diff", "--unified=3"];
+ // `--no-ext-diff` is where external-diff suppression has to live: it is
+ // a diff-command flag, and the `-c diff.external=` that used to stand in
+ // for it made git exec the empty string instead of disabling anything.
+ let mut git_args = vec!["diff", "--no-ext-diff", "--unified=3"];
if cached {
git_args.push("--cached");
}
diff --git a/src/openhuman/tools/impl/filesystem/git_operations_config.rs b/src/openhuman/tools/impl/filesystem/git_operations_config.rs
index d4143a1b9a..20f11429f1 100644
--- a/src/openhuman/tools/impl/filesystem/git_operations_config.rs
+++ b/src/openhuman/tools/impl/filesystem/git_operations_config.rs
@@ -125,7 +125,14 @@ pub(super) const NEUTRALISED_CONFIG: &[&str] = &[
"core.sshCommand=",
"core.pager=cat",
"core.editor=false",
- "diff.external=",
+ // NOT `diff.external=`. An empty value does not disable an external diff —
+ // git tries to *execute* the empty string and the whole command dies with
+ // `error: cannot run : No such file or directory` / `fatal: external diff
+ // died`, so every `diff` operation failed rather than being hardened.
+ // Suppression belongs on the command instead: `git diff --no-ext-diff`,
+ // which ignores `diff.external` however the repository set it. Verified
+ // both ways against a repo with `diff.external=/bin/false`: plain `diff`
+ // dies, `--no-ext-diff` prints the patch.
"sequence.editor=false",
"uploadpack.packObjectsHook=",
];
diff --git a/src/openhuman/tools/impl/filesystem/git_operations_config_tests.rs b/src/openhuman/tools/impl/filesystem/git_operations_config_tests.rs
index 3cdcc4e8d6..e52af52109 100644
--- a/src/openhuman/tools/impl/filesystem/git_operations_config_tests.rs
+++ b/src/openhuman/tools/impl/filesystem/git_operations_config_tests.rs
@@ -463,3 +463,73 @@ fn a_subsection_is_elided_so_one_entry_covers_every_remote() {
// A key with no dot at all is returned unchanged rather than panicking.
assert_eq!(normalise_config_key("bare"), "bare");
}
+
+// ── External diff suppression ─────────────────────────────────────────────
+
+/// An ordinary repository's `diff` must produce its patch.
+///
+/// That reads like it could not possibly regress, and it did. Suppression of
+/// an external diff was attempted with `-c diff.external=` in
+/// `NEUTRALISED_CONFIG`, and an empty value does not disable one — git tries
+/// to *execute* the empty string, so **every** diff died with
+/// `error: cannot run : No such file or directory` /
+/// `fatal: external diff died`, on every repository, hostile or not. The
+/// hardening removed the operation instead of hardening it. `--no-ext-diff`
+/// on the diff command is the real suppression.
+///
+/// This lives in the lib suite deliberately. The integration test that caught
+/// it sits in `raw_coverage_all`, and a change to `git_operations.rs` maps to
+/// the `openhuman::tools` libtest filter — which never selects that target. So
+/// the lane the change picks did not run the test covering the change, and the
+/// breakage sat until an unrelated PR happened to select the other filter.
+/// A test here runs whenever this file is touched.
+///
+/// A repository that *sets* `diff.external` is a separate matter and is
+/// already refused before reaching the invocation: the key is on neither
+/// allowlist, so `first_disallowed_repo_config_key` rejects the repository
+/// outright. `--no-ext-diff` is the second layer, covering the gap between
+/// that inspection and the command.
+#[tokio::test]
+async fn an_ordinary_repository_still_produces_a_diff() {
+ let tmp = TempDir::new().unwrap();
+ init_git_repo(tmp.path());
+
+ let tracked = tmp.path().join("tracked.txt");
+ std::fs::write(&tracked, "first\n").unwrap();
+ // `hermetic` closes the ambient git config the way the fixtures do —
+ // without it a developer's global `commit.gpgsign` or hooks path can fail
+ // this commit for reasons unrelated to the test.
+ // Slices, not arrays: `["add", "tracked.txt"]` and `["commit", "-m", "one"]`
+ // are `[&str; 2]` and `[&str; 3]`, which are different types and cannot
+ // share an array literal.
+ for args in [&["add", "tracked.txt"][..], &["commit", "-m", "one"][..]] {
+ let ok = hermetic(
+ std::process::Command::new("git")
+ .args(args)
+ .current_dir(tmp.path()),
+ )
+ .status()
+ .unwrap()
+ .success();
+ assert!(ok, "failed to run `git {}` in the test workspace", args[0]);
+ }
+ std::fs::write(&tracked, "first\nsecond\n").unwrap();
+
+ let tool = test_tool(tmp.path());
+ let result = tool
+ .execute(json!({"operation": "diff", "files": "tracked.txt"}))
+ .await
+ .expect("a diff on a plain repository must not error out");
+
+ assert!(!result.is_error, "got: {}", result.output());
+ assert!(
+ result.output().contains("second"),
+ "the added line must appear in the patch: {}",
+ result.output()
+ );
+ assert!(
+ !result.output().contains("external diff died"),
+ "git must not be handed an empty `diff.external` to execute: {}",
+ result.output()
+ );
+}