fix(non-interactive-env): prevent environment variable duplication on repeated executions

The non-interactive-env hook was prepending environment variables without checking
if the prefix was already applied to the command, causing duplication when multiple
git commands were executed in sequence.

This fix adds an idempotent check: if the command already starts with the env prefix,
the hook returns early without modification. This maintains the non-interactive behavior
while ensuring the operation is idempotent across multiple tool executions.
This commit is contained in:
Strocs
2026-02-13 13:21:58 -03:00
parent f876d60e87
commit ba571c1e72

View File

@@ -55,6 +55,13 @@ export function createNonInteractiveEnvHook(_ctx: PluginInput) {
// The bash tool always runs in a Unix-like shell (bash/sh), even on Windows
// (via Git Bash, WSL, etc.), so always use unix export syntax.
const envPrefix = buildEnvPrefix(NON_INTERACTIVE_ENV, "unix")
// Check if the command already starts with the prefix to avoid stacking.
// This maintain the non-interactive behaivor but make the operation idempotent.
if (command.trim().startsWith(envPrefix.trim())) {
return
}
output.args.command = `${envPrefix} ${command}`
log(`[${HOOK_NAME}] Prepended non-interactive env vars to git command`, {