feat: --all flag (#182)

Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
This commit is contained in:
Rocktim
2023-04-01 15:49:34 +05:30
committed by GitHub
parent ad2533eb2f
commit ebe83a493e
5 changed files with 55 additions and 5 deletions

View File

@@ -31,7 +31,7 @@ export default testSuite(({ describe }) => {
const { stdout, exitCode } = await aicommits(['--exclude', 'data.json'], { reject: false });
expect(exitCode).toBe(1);
expect(stdout).toMatch('No staged changes found. Make sure to stage your changes with `git add`.');
expect(stdout).toMatch('No staged changes found.');
await fixture.rm();
});
@@ -61,6 +61,38 @@ export default testSuite(({ describe }) => {
await fixture.rm();
});
test('Accepts --all flag, staging all changes before commit', async () => {
const { fixture, aicommits } = await createFixture(files);
const git = await createGit(fixture.path);
await git('add', ['data.json']);
await git('commit', ['-m', 'wip']);
await fixture.writeFile('data.json', 'Test');
const statusBefore = await git('status', ['--short', '--untracked-files=no']);
expect(statusBefore.stdout).toBe(' M data.json');
const committing = aicommits(['--all']);
committing.stdout!.on('data', (buffer: Buffer) => {
const stdout = buffer.toString();
if (stdout.match('└')) {
committing.stdin!.write('y');
committing.stdin!.end();
}
});
await committing;
const statusAfter = await git('status', ['--short', '--untracked-files=no']);
expect(statusAfter.stdout).toBe('');
const { stdout: commitMessage } = await git('log', ['-n1', '--oneline']);
console.log('Committed with:', commitMessage);
await fixture.rm();
});
test('Accepts --generate flag, overriding config', async ({ onTestFail }) => {
const { fixture, aicommits } = await createFixture({
...files,

View File

@@ -17,7 +17,7 @@ export default testSuite(({ describe }) => {
const { stdout, exitCode } = await aicommits([], { reject: false });
expect(exitCode).toBe(1);
expect(stdout).toMatch('No staged changes found. Make sure to stage your changes with `git add`.');
expect(stdout).toMatch('No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.');
await fixture.rm();
});
});