fix(cli): strip -c/--context from extraArgs to prevent git commit conflict

cleye's ignoreArgv passes unconsumed flags and arguments through to
the internal `git commit` execa call. Although -c/--context is
defined as a known cleye flag, a defensive guard is needed to strip
it from extraArgs in case it leaks through, which would conflict
with git's own handling.

Add a sanitization step at the entry of commit() that filters -c,
--context, and their values from extraArgs before they are forwarded
to the git commit invocation.
This commit is contained in:
SOV710
2026-04-05 03:36:11 +00:00
parent f300b5dd4e
commit a48d33096a

View File

@@ -22,7 +22,29 @@ import { runMigrations } from './migrations/_run.js';
const config = getConfig();
setupProxy(config.OCO_PROXY);
const extraArgs = process.argv.slice(2);
const OCO_FLAGS_WITH_VALUE = new Set(['-c', '--context']);
const OCO_EQUALS_PREFIXES = ['-c=', '--context='];
const stripOcoFlags = (argv: string[]): string[] => {
const out: string[] = [];
for (let i = 0; i < argv.length; i++) {
const a = argv[i];
// String flags with a separate value token: -c <val>, --context <val>
if (OCO_FLAGS_WITH_VALUE.has(a)) {
i++; // skip the value token too
continue;
}
// Equals form: -c=…, --context=…
if (OCO_EQUALS_PREFIXES.some((prefix) => a.startsWith(prefix))) {
continue;
}
out.push(a);
}
return out;
};
const rawArgv = process.argv.slice(2);
const extraArgs = stripOcoFlags(rawArgv);
cli(
{
@@ -82,5 +104,5 @@ cli(
commit(extraArgs, flags.context, false, flags.fgm, flags.yes);
},
extraArgs
rawArgv
);