Skip to content

Commit a48d330

Browse files
committed
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.
1 parent f300b5d commit a48d330

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/cli.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,29 @@ import { runMigrations } from './migrations/_run.js';
2222
const config = getConfig();
2323
setupProxy(config.OCO_PROXY);
2424

25-
const extraArgs = process.argv.slice(2);
25+
const OCO_FLAGS_WITH_VALUE = new Set(['-c', '--context']);
26+
const OCO_EQUALS_PREFIXES = ['-c=', '--context='];
27+
28+
const stripOcoFlags = (argv: string[]): string[] => {
29+
const out: string[] = [];
30+
for (let i = 0; i < argv.length; i++) {
31+
const a = argv[i];
32+
// String flags with a separate value token: -c <val>, --context <val>
33+
if (OCO_FLAGS_WITH_VALUE.has(a)) {
34+
i++; // skip the value token too
35+
continue;
36+
}
37+
// Equals form: -c=…, --context=…
38+
if (OCO_EQUALS_PREFIXES.some((prefix) => a.startsWith(prefix))) {
39+
continue;
40+
}
41+
out.push(a);
42+
}
43+
return out;
44+
};
45+
46+
const rawArgv = process.argv.slice(2);
47+
const extraArgs = stripOcoFlags(rawArgv);
2648

2749
cli(
2850
{
@@ -82,5 +104,5 @@ cli(
82104

83105
commit(extraArgs, flags.context, false, flags.fgm, flags.yes);
84106
},
85-
extraArgs
107+
rawArgv
86108
);

0 commit comments

Comments
 (0)