Fix gitCoAuthor not added for combined flags like -am

This commit is contained in:
Alexander Farber
2025-12-15 11:00:21 +01:00
parent 65392a057d
commit 5bd1822b7d
2 changed files with 32 additions and 2 deletions

View File

@@ -608,6 +608,36 @@ describe('ShellTool', () => {
); );
}); });
it('should handle git commit with combined short flags like -am', async () => {
const command = 'git commit -am "Add feature"';
const invocation = shellTool.build({ command, is_background: false });
const promise = invocation.execute(mockAbortSignal);
resolveExecutionPromise({
rawOutput: Buffer.from(''),
output: '',
exitCode: 0,
signal: null,
error: null,
aborted: false,
pid: 12345,
executionMethod: 'child_process',
});
await promise;
expect(mockShellExecutionService).toHaveBeenCalledWith(
expect.stringContaining(
'Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>',
),
expect.any(String),
expect.any(Function),
mockAbortSignal,
false,
{},
);
});
it('should not modify non-git commands', async () => { it('should not modify non-git commands', async () => {
const command = 'npm install'; const command = 'npm install';
const invocation = shellTool.build({ command, is_background: false }); const invocation = shellTool.build({ command, is_background: false });

View File

@@ -350,8 +350,8 @@ export class ShellToolInvocation extends BaseToolInvocation<
Co-authored-by: ${gitCoAuthorSettings.name} <${gitCoAuthorSettings.email}>`; Co-authored-by: ${gitCoAuthorSettings.name} <${gitCoAuthorSettings.email}>`;
// Handle different git commit patterns // Handle different git commit patterns
// Match -m "message" or -m 'message' // Match -m "message" or -m 'message', including combined flags like -am
const messagePattern = /(-m\s+)(['"])((?:\\.|[^\\])*?)(\2)/; const messagePattern = /(-[a-zA-Z]*m\s+)(['"])((?:\\.|[^\\])*?)(\2)/;
const match = command.match(messagePattern); const match = command.match(messagePattern);
if (match) { if (match) {