From 0ee4aa7670cd0086c9604b6cb6d00162173e2230 Mon Sep 17 00:00:00 2001 From: pat-s Date: Wed, 15 Jul 2026 15:03:45 +0000 Subject: [PATCH] fix(local): shell-quote git args in the auto-patch push and trial-build gate The autonomous --open-pr run failed at `git commit` with `sh: syntax error: unexpected "("`: R's system2() with captured output runs the command through /bin/sh, and the commit message `feat(patches): ...` (and the `^{commit}` / `ref:path` git refs in the trial-build gate) contain shell metacharacters that were passed unquoted. shQuote() every git argument in propose-patches.R's git() helper and in trial-build-registry.R's base-ref reads. Reproduced the failure and verified the fix against a real git repo (commit with "()" in the message now succeeds; a `HEAD^{commit}` rev-parse resolves). --- local/propose-patches.R | 4 +++- local/trial-build-registry.R | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/local/propose-patches.R b/local/propose-patches.R index 11085f0..7008251 100644 --- a/local/propose-patches.R +++ b/local/propose-patches.R @@ -435,7 +435,9 @@ if (do_write) { save_ledger(merge_ledger(load_ledger(), new_ledger_records)) git <- function(...) { - st <- system2("git", c(...), stdout = TRUE, stderr = TRUE) + # system2() with captured output runs via /bin/sh, so shell-quote every arg + # (commit messages contain "()", refs contain "^{}", etc.). + st <- system2("git", shQuote(c(...)), stdout = TRUE, stderr = TRUE) if (!identical(attr(st, "status"), NULL)) { stop(sprintf( "git %s failed:\n%s", diff --git a/local/trial-build-registry.R b/local/trial-build-registry.R index f649b62..0749bf7 100644 --- a/local/trial-build-registry.R +++ b/local/trial-build-registry.R @@ -52,9 +52,16 @@ current <- if (file.exists(registry_file)) { # silently treating the base as empty would trial-build the WHOLE registry # instead of just the entries the branch adds. registry_rel <- "local/patches/registry.json" +# system2() with captured output runs via /bin/sh, so shell-quote the git args +# (refs contain "^{}" and ":" that the shell would otherwise mangle). ref_ok <- suppressWarnings(system2( "git", - c("rev-parse", "--verify", "--quiet", sprintf("%s^{commit}", base_ref)), + shQuote(c( + "rev-parse", + "--verify", + "--quiet", + sprintf("%s^{commit}", base_ref) + )), stdout = TRUE, stderr = FALSE )) @@ -63,14 +70,14 @@ if (!is.null(attr(ref_ok, "status"))) { } in_base <- suppressWarnings(system2( "git", - c("ls-tree", base_ref, "--", registry_rel), + shQuote(c("ls-tree", base_ref, "--", registry_rel)), stdout = TRUE, stderr = FALSE )) file_in_base <- length(in_base) > 0L && any(nzchar(in_base)) base_json <- suppressWarnings(system2( "git", - c("show", sprintf("%s:%s", base_ref, registry_rel)), + shQuote(c("show", sprintf("%s:%s", base_ref, registry_rel))), stdout = TRUE, stderr = FALSE )) -- 2.54.0