Skip to content
Open
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
14 changes: 14 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ cli(
alias: 's',
default: false,
},
yes: {
type: Boolean,
description: 'Skip approval and commit immediately',
alias: 'y',
default: false,
},
noVerify: {
type: Boolean,
description: 'Bypass pre-commit and commit-msg hooks',
alias: 'n',
default: false,
},
},

commands: [configCommand, hookCommand],
Expand All @@ -75,6 +87,8 @@ cli(
argv.flags.all,
argv.flags.type,
argv.flags.split,
argv.flags.yes,
argv.flags.noVerify,
rawArgv
);
}
Expand Down
15 changes: 13 additions & 2 deletions src/commands/lazycommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ export default async (
stageAll: boolean,
commitType: string | undefined,
splitCommits: boolean,
skipApproval: boolean,
noVerify: boolean,
rawArgv: string[]
) =>
(async () => {
Expand Down Expand Up @@ -239,7 +241,11 @@ export default async (
let message: string;
let editedAlready = false;
let useAsIs = false;
if (messages.length === 1) {

if (skipApproval) {
message = messages[0];
useAsIs = true;
} else if (messages.length === 1) {
[message] = messages;
const choice = await select({
message: `Review generated commit message:\n\n ${message}\n`,
Expand Down Expand Up @@ -313,7 +319,12 @@ export default async (
}
}

await execa('git', ['commit', '-m', message, ...rawArgv]);
const commitArgs = ['commit', '-m', message];
if (noVerify) {
commitArgs.push('--no-verify');
}
commitArgs.push(...rawArgv);
await execa('git', commitArgs);

outro(`${green('✔')} Successfully committed!`);
})().catch((error) => {
Expand Down
24 changes: 24 additions & 0 deletions tests/specs/cli/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ export default testSuite(({ describe }) => {
await fixture.rm();
});

test('Skips approval with --yes flag', async () => {
const { fixture, lazycommit } = await createFixture(files);
const git = await createGit(fixture.path);

await git('add', ['data.json']);

// With --yes, should commit immediately without prompts
await lazycommit(['--yes']);

const statusAfter = await git('status', [
'--porcelain',
'--untracked-files=no',
]);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', [
'--pretty=format:%s',
]);
expect(commitMessage).toBeTruthy();
expect(commitMessage?.length).toBeLessThanOrEqual(50);

await fixture.rm();
});

test('Generated commit message must be under 20 characters', async () => {
const { fixture, lazycommit } = await createFixture({
...files,
Expand Down
1 change: 1 addition & 0 deletions tests/specs/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default testSuite(({ describe }) => {
describe('CLI', ({ runTestSuite }) => {
runTestSuite(import('./error-cases.js'));
runTestSuite(import('./commits.js'));
runTestSuite(import('./no-verify.js'));
});
});
39 changes: 39 additions & 0 deletions tests/specs/cli/no-verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { testSuite, expect } from 'manten';
import fs from 'fs/promises';
import path from 'path';
import {
assertGroqToken,
createFixture,
createGit,
files,
} from '../../utils.js';

export default testSuite(({ describe }) => {
describe('no-verify', async ({ test }) => {
if (!assertGroqToken()) {
return;
}

test('Bypasses pre-commit hook', async () => {
const { fixture, lazycommit } = await createFixture(files);
const git = await createGit(fixture.path);

// Create a pre-commit hook that fails
const hookPath = path.join(fixture.path, '.git/hooks/pre-commit');
await fs.writeFile(hookPath, '#!/bin/sh\nexit 1');
await fs.chmod(hookPath, '755');

await git('add', ['data.json']);

// Should fail without --no-verify
const { exitCode: failExitCode } = await lazycommit(['--yes'], { reject: false });
expect(failExitCode).toBe(1);

// Should pass with --no-verify
const { exitCode: successExitCode } = await lazycommit(['--no-verify', '--yes'], { reject: false });
expect(successExitCode).toBe(0);

await fixture.rm();
});
});
});