@@ -242,7 +242,8 @@ line, where <value> is taken to be the standard output of the
specified command with any leading and trailing whitespace trimmed
off.
+
-If the command contains the `$ARG` string, this string will be
+If the command contains the `$ARG` string (`$ARG` is an exported
+environment variable), this string will be
replaced with the <value> part of an existing trailer with the same
<token>, if any, before the command is launched.
+
@@ -1291,6 +1291,23 @@ test_expect_success 'with command using $ARG' '
test_cmp expected actual
'
+test_expect_success 'with command using more than one $ARG' '
+ git config trailer.fix.ifExists "replace" &&
+ git config trailer.fix.command "test -n $ARG && git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG || true" &&
+ FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
+ cat complex_message_body >expected &&
+ sed -e "s/ Z\$/ /" >>expected <<-EOF &&
+ Fixes: $FIXED
+ Acked-by= Z
+ Reviewed-by:
+ Signed-off-by: Z
+ Signed-off-by: A U Thor <author@example.com>
+ EOF
+ git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
+ <complex_message >actual &&
+ test_cmp expected actual
+'
+
test_expect_success 'with failing command using $ARG' '
git config trailer.fix.ifExists "replace" &&
git config trailer.fix.command "false \$ARG" &&
@@ -44,7 +44,7 @@ static char *separators = ":";
static int configured;
-#define TRAILER_ARG_STRING "$ARG"
+#define TRAILER_ARG_STRING "ARG"
static const char *git_generated_prefixes[] = {
"Signed-off-by: ",
@@ -222,13 +222,16 @@ static char *apply_command(const char *command, const char *arg)
struct strbuf buf = STRBUF_INIT;
struct child_process cp = CHILD_PROCESS_INIT;
char *result;
+ const char *const *var;
strbuf_addstr(&cmd, command);
+ for (var = local_repo_env; *var; var++)
+ strvec_push(&cp.env_array, *var);
if (arg)
- strbuf_replace(&cmd, TRAILER_ARG_STRING, arg);
+ strvec_pushf(&cp.env_array, "%s=%s", TRAILER_ARG_STRING, arg);
strvec_push(&cp.args, cmd.buf);
- cp.env = local_repo_env;
+
cp.no_stdin = 1;
cp.use_shell = 1;