diff --git a/README.md b/README.md index cd874ea..498ac0b 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,20 @@ To remove description: oc config set description=false ``` +### Git flags + +The `opencommit` or `oc` commands can be used in place of the `git commit -m "${generatedMessage}"` command. This means that any regular flags that are used with the `git commit` command will also be applied when using `opencommit` or `oc`. + +```sh +oc --no-verify +``` + +is translated to : + +```sh +git commit -m "${generatedMessage}" --no-verify +``` + ## Git hook You can set OpenCommit as Git [`prepare-commit-msg`](https://git-scm.com/docs/githooks#_prepare_commit_msg) hook. Hook integrates with you IDE Source Control and allows you edit the message before commit. diff --git a/src/cli.ts b/src/cli.ts index 5bc56e5..74c9800 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -8,7 +8,7 @@ import { hookCommand, isHookCalled } from './commands/githook.js'; import { prepareCommitMessageHook } from './commands/prepare-commit-msg-hook'; import { commit } from './commands/commit'; -const rawArgv = process.argv.slice(2); +const extraArgs = process.argv.slice(2); cli( { @@ -23,8 +23,8 @@ cli( if (isHookCalled) { prepareCommitMessageHook(); } else { - commit(); + commit(extraArgs); } }, - rawArgv + extraArgs ); diff --git a/src/commands/commit.ts b/src/commands/commit.ts index 381b959..a6ccf5b 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -22,7 +22,8 @@ import chalk from 'chalk'; import { trytm } from '../utils/trytm'; const generateCommitMessageFromGitDiff = async ( - diff: string + diff: string, + extraArgs: string[] ): Promise => { await assertGitRepo(); @@ -59,7 +60,7 @@ ${chalk.grey('——————————————————')}` }); if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) { - const { stdout } = await execa('git', ['commit', '-m', commitMessage]); + const { stdout } = await execa('git', ['commit', '-m', commitMessage, ...extraArgs]); outro(`${chalk.green('✔')} successfully committed`); @@ -74,6 +75,7 @@ ${chalk.grey('——————————————————')}` pushSpinner.start('Running `git push`'); const { stdout } = await execa('git', ['push']); + pushSpinner.stop(`${chalk.green('✔')} successfully pushed all commits`); if (stdout) outro(stdout); @@ -81,9 +83,11 @@ ${chalk.grey('——————————————————')}` } else outro(`${chalk.gray('✖')} process cancelled`); }; -export async function commit(isStageAllFlag = false) { + +export async function commit(extraArgs=[], isStageAllFlag = false) { if (isStageAllFlag) { const changedFiles = await getChangedFiles(); + if (changedFiles) await gitAdd({ files: changedFiles }); else { outro('No changes detected, write some code and run `oc` again'); @@ -106,6 +110,7 @@ export async function commit(isStageAllFlag = false) { } const stagedFilesSpinner = spinner(); + stagedFilesSpinner.start('Counting staged files'); if (!stagedFiles.length) { @@ -118,7 +123,8 @@ export async function commit(isStageAllFlag = false) { isStageAllAndCommitConfirmedByUser && !isCancel(isStageAllAndCommitConfirmedByUser) ) { - await commit(true); + + await commit(extraArgs, true); process.exit(1); } @@ -136,7 +142,7 @@ export async function commit(isStageAllFlag = false) { await gitAdd({ files }); } - await commit(false); + await commit(extraArgs, false); process.exit(1); } @@ -147,7 +153,7 @@ export async function commit(isStageAllFlag = false) { ); const [, generateCommitError] = await trytm( - generateCommitMessageFromGitDiff(await getDiff({ files: stagedFiles })) + generateCommitMessageFromGitDiff(await getDiff({ files: stagedFiles }), extraArgs) ); if (generateCommitError) {