diff --git a/README.md b/README.md index c6131154..7d964289 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,12 @@ To unset the hook: oc hook unset ``` +In the hook, there is a check that checks if the commit message is not empty. If it is not, the hook will not run. To skip that check and always replace the commit message run: + +```sh +oc config set skipCommitMsgHookSourceCheck=true +``` + To use the hook: ```sh diff --git a/src/commands/config.ts b/src/commands/config.ts index e1040351..2dbdd994 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -10,7 +10,8 @@ import { COMMANDS } from '../CommandsEnum'; export enum CONFIG_KEYS { OPENAI_API_KEY = 'OPENAI_API_KEY', description = 'description', - emoji = 'emoji' + emoji = 'emoji', + skipCommitMsgHookSourceCheck = 'skipCommitMsgHookSourceCheck' } export enum CONFIG_MODES { @@ -64,7 +65,16 @@ export const configValidators = { ); return value; - } + }, + [CONFIG_KEYS.skipCommitMsgHookSourceCheck](value: any) { + validateConfig( + CONFIG_KEYS.skipCommitMsgHookSourceCheck, + typeof value === 'boolean', + 'Must be true or false' + ); + + return value; + }, }; export type ConfigType = { diff --git a/src/commands/prepare-commit-msg-hook.ts b/src/commands/prepare-commit-msg-hook.ts index 512cd52b..1bc5c0ba 100644 --- a/src/commands/prepare-commit-msg-hook.ts +++ b/src/commands/prepare-commit-msg-hook.ts @@ -15,7 +15,10 @@ export const prepareCommitMessageHook = async () => { ); } - if (commitSource) return; + const config = getConfig(); + + // Skip commit message check if the user has set the skipCommitMessageCheck flag to true + if (!config?.skipCommitMsgHookSourceCheck && commitSource) return; const staged = await getStagedGitDiff(); @@ -23,8 +26,6 @@ export const prepareCommitMessageHook = async () => { intro('opencommit'); - const config = getConfig(); - if (!config?.OPENAI_API_KEY) { throw new Error( 'No OPEN_AI_API exists. Set your OPEN_AI_API=<key> in ~/.opencommit'