feat: Add support for extra args to be passed to the git commit command (#17)
* feat: Add support for extra args to be passed to the git commit command
This commit is contained in:
@@ -84,6 +84,20 @@ To remove description:
|
|||||||
oc config set description=false
|
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
|
## 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.
|
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.
|
||||||
|
|||||||
+3
-3
@@ -8,7 +8,7 @@ import { hookCommand, isHookCalled } from './commands/githook.js';
|
|||||||
import { prepareCommitMessageHook } from './commands/prepare-commit-msg-hook';
|
import { prepareCommitMessageHook } from './commands/prepare-commit-msg-hook';
|
||||||
import { commit } from './commands/commit';
|
import { commit } from './commands/commit';
|
||||||
|
|
||||||
const rawArgv = process.argv.slice(2);
|
const extraArgs = process.argv.slice(2);
|
||||||
|
|
||||||
cli(
|
cli(
|
||||||
{
|
{
|
||||||
@@ -23,8 +23,8 @@ cli(
|
|||||||
if (isHookCalled) {
|
if (isHookCalled) {
|
||||||
prepareCommitMessageHook();
|
prepareCommitMessageHook();
|
||||||
} else {
|
} else {
|
||||||
commit();
|
commit(extraArgs);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
rawArgv
|
extraArgs
|
||||||
);
|
);
|
||||||
|
|||||||
+12
-6
@@ -22,7 +22,8 @@ import chalk from 'chalk';
|
|||||||
import { trytm } from '../utils/trytm';
|
import { trytm } from '../utils/trytm';
|
||||||
|
|
||||||
const generateCommitMessageFromGitDiff = async (
|
const generateCommitMessageFromGitDiff = async (
|
||||||
diff: string
|
diff: string,
|
||||||
|
extraArgs: string[]
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
await assertGitRepo();
|
await assertGitRepo();
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ ${chalk.grey('——————————————————')}`
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) {
|
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`);
|
outro(`${chalk.green('✔')} successfully committed`);
|
||||||
|
|
||||||
@@ -74,6 +75,7 @@ ${chalk.grey('——————————————————')}`
|
|||||||
|
|
||||||
pushSpinner.start('Running `git push`');
|
pushSpinner.start('Running `git push`');
|
||||||
const { stdout } = await execa('git', ['push']);
|
const { stdout } = await execa('git', ['push']);
|
||||||
|
|
||||||
pushSpinner.stop(`${chalk.green('✔')} successfully pushed all commits`);
|
pushSpinner.stop(`${chalk.green('✔')} successfully pushed all commits`);
|
||||||
|
|
||||||
if (stdout) outro(stdout);
|
if (stdout) outro(stdout);
|
||||||
@@ -81,9 +83,11 @@ ${chalk.grey('——————————————————')}`
|
|||||||
} else outro(`${chalk.gray('✖')} process cancelled`);
|
} else outro(`${chalk.gray('✖')} process cancelled`);
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function commit(isStageAllFlag = false) {
|
|
||||||
|
export async function commit(extraArgs=[], isStageAllFlag = false) {
|
||||||
if (isStageAllFlag) {
|
if (isStageAllFlag) {
|
||||||
const changedFiles = await getChangedFiles();
|
const changedFiles = await getChangedFiles();
|
||||||
|
|
||||||
if (changedFiles) await gitAdd({ files: changedFiles });
|
if (changedFiles) await gitAdd({ files: changedFiles });
|
||||||
else {
|
else {
|
||||||
outro('No changes detected, write some code and run `oc` again');
|
outro('No changes detected, write some code and run `oc` again');
|
||||||
@@ -106,6 +110,7 @@ export async function commit(isStageAllFlag = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const stagedFilesSpinner = spinner();
|
const stagedFilesSpinner = spinner();
|
||||||
|
|
||||||
stagedFilesSpinner.start('Counting staged files');
|
stagedFilesSpinner.start('Counting staged files');
|
||||||
|
|
||||||
if (!stagedFiles.length) {
|
if (!stagedFiles.length) {
|
||||||
@@ -118,7 +123,8 @@ export async function commit(isStageAllFlag = false) {
|
|||||||
isStageAllAndCommitConfirmedByUser &&
|
isStageAllAndCommitConfirmedByUser &&
|
||||||
!isCancel(isStageAllAndCommitConfirmedByUser)
|
!isCancel(isStageAllAndCommitConfirmedByUser)
|
||||||
) {
|
) {
|
||||||
await commit(true);
|
|
||||||
|
await commit(extraArgs, true);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +142,7 @@ export async function commit(isStageAllFlag = false) {
|
|||||||
await gitAdd({ files });
|
await gitAdd({ files });
|
||||||
}
|
}
|
||||||
|
|
||||||
await commit(false);
|
await commit(extraArgs, false);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +153,7 @@ export async function commit(isStageAllFlag = false) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const [, generateCommitError] = await trytm(
|
const [, generateCommitError] = await trytm(
|
||||||
generateCommitMessageFromGitDiff(await getDiff({ files: stagedFiles }))
|
generateCommitMessageFromGitDiff(await getDiff({ files: stagedFiles }), extraArgs)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (generateCommitError) {
|
if (generateCommitError) {
|
||||||
|
|||||||
Reference in New Issue
Block a user