Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion out/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -85950,7 +85950,7 @@ ${excludedFiles.join(
const diffableFiles = files.filter((file) => !isFileExcludedFromDiff(file));
const { stdout: diff } = await execa(
"git",
["diff", "--staged", "--", ...diffableFiles],
["diff", "--staged", "--no-ext-diff", "--", ...diffableFiles],
{ cwd: gitDir }
);
return diff;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const getDiff = async ({ files }: { files: string[] }) => {

const { stdout: diff } = await execa(
'git',
['diff', '--staged', '--', ...diffableFiles],
['diff', '--staged', '--no-ext-diff', '--', ...diffableFiles],
{ cwd: gitDir }
);

Expand Down
56 changes: 55 additions & 1 deletion test/e2e/oneFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import {
prepareEnvironment,
prepareRepo,
runCli,
runGit,
startMockOpenAiServer,
appendRepoFile,
waitForExit
waitForExit,
writeRepoFile
} from './utils';

it('cli flow to generate commit message for 1 new file (staged)', async () => {
Expand Down Expand Up @@ -63,6 +65,58 @@ it('cli flow to generate commit message for 1 new file (staged)', async () => {
}
});

it('cli ignores configured external diff tools when generating the prompt', async () => {
const { gitDir, cleanup } = await prepareEnvironment({ remotes: 0 });
const server = await startMockOpenAiServer(
'fix(diff): use the staged patch in the prompt'
);

try {
await prepareRepo(
gitDir,
{
'index.ts': 'console.log("before");\n'
},
{
stage: true,
commitMessage: 'add initial file'
}
);
writeRepoFile(gitDir, 'index.ts', 'console.log("after");\n');
await runGit(['add', 'index.ts'], gitDir);
await runGit(
['config', 'diff.external', 'echo OCO_EXTERNAL_DIFF_USED'],
gitDir
);

const oco = await runCli(['--yes'], {
cwd: gitDir,
env: getMockOpenAiEnv(server.baseUrl)
});

expect(await waitForExit(oco)).toBe(0);
await assertHeadCommit(
gitDir,
'fix(diff): use the staged patch in the prompt'
);

const requestContents = server.requestBodies
.flatMap(
(body) =>
(body as { messages?: Array<{ content: string }> }).messages ?? []
)
.map((message) => message.content)
.join('\n');

expect(requestContents).toContain('-console.log("before");');
expect(requestContents).toContain('+console.log("after");');
expect(requestContents).not.toContain('OCO_EXTERNAL_DIFF_USED');
} finally {
await server.cleanup();
await cleanup();
}
});

it('cli flow to generate commit message for 1 changed file (not staged)', async () => {
const { gitDir, cleanup } = await prepareEnvironment();
const server = await startMockOpenAiServer(
Expand Down
Loading