From 753688fcfc267b6659f647eeac5f40992b27710b Mon Sep 17 00:00:00 2001
From: Lars Jansen <lars@ljpc.nl>
Date: Wed, 15 Mar 2023 08:48:48 +0100
Subject: [PATCH 1/3] feat(config.ts): add skipCommitMessageCheck config key
 feat(prepare-commit-msg-hook.ts): add support for skipCommitMessageCheck
 config key to skip commit message check if set to true

---
 src/commands/config.ts                  | 14 ++++++++++++--
 src/commands/prepare-commit-msg-hook.ts |  7 ++++---
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/commands/config.ts b/src/commands/config.ts
index e1040351..7cadf755 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',
+  skipCommitMessageCheck = 'skipCommitMessageCheck'
 }
 
 export enum CONFIG_MODES {
@@ -64,7 +65,16 @@ export const configValidators = {
     );
 
     return value;
-  }
+  },
+  [CONFIG_KEYS.skipCommitMessageCheck](value: any) {
+    validateConfig(
+      CONFIG_KEYS.skipCommitMessageCheck,
+      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..9b5e10b7 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?.skipCommitMessageCheck && 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'

From 36437c93d3f11618793b1a581722a49cf5f72734 Mon Sep 17 00:00:00 2001
From: Lars Jansen <lars@ljpc.nl>
Date: Wed, 15 Mar 2023 09:34:18 +0100
Subject: [PATCH 2/3] refactor(config.ts): rename skipCommitMessageCheck to
 skipCommitMsgHookSourceCheck refactor(prepare-commit-msg-hook.ts): update
 reference to skipCommitMessageCheck to skipCommitMsgHookSourceCheck update
 variable name

---
 src/commands/config.ts                  | 6 +++---
 src/commands/prepare-commit-msg-hook.ts | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/commands/config.ts b/src/commands/config.ts
index 7cadf755..2dbdd994 100644
--- a/src/commands/config.ts
+++ b/src/commands/config.ts
@@ -11,7 +11,7 @@ export enum CONFIG_KEYS {
   OPENAI_API_KEY = 'OPENAI_API_KEY',
   description = 'description',
   emoji = 'emoji',
-  skipCommitMessageCheck = 'skipCommitMessageCheck'
+  skipCommitMsgHookSourceCheck = 'skipCommitMsgHookSourceCheck'
 }
 
 export enum CONFIG_MODES {
@@ -66,9 +66,9 @@ export const configValidators = {
 
     return value;
   },
-  [CONFIG_KEYS.skipCommitMessageCheck](value: any) {
+  [CONFIG_KEYS.skipCommitMsgHookSourceCheck](value: any) {
     validateConfig(
-      CONFIG_KEYS.skipCommitMessageCheck,
+      CONFIG_KEYS.skipCommitMsgHookSourceCheck,
       typeof value === 'boolean',
       'Must be true or false'
     );
diff --git a/src/commands/prepare-commit-msg-hook.ts b/src/commands/prepare-commit-msg-hook.ts
index 9b5e10b7..1bc5c0ba 100644
--- a/src/commands/prepare-commit-msg-hook.ts
+++ b/src/commands/prepare-commit-msg-hook.ts
@@ -18,7 +18,7 @@ export const prepareCommitMessageHook = async () => {
     const config = getConfig();
 
     // Skip commit message check if the user has set the skipCommitMessageCheck flag to true
-    if (!config?.skipCommitMessageCheck && commitSource) return;
+    if (!config?.skipCommitMsgHookSourceCheck && commitSource) return;
 
     const staged = await getStagedGitDiff();
 

From 5023fc470cda9b1a548bc5b43c303409fa8ee97c Mon Sep 17 00:00:00 2001
From: Lars Jansen <lars@ljpc.nl>
Date: Wed, 15 Mar 2023 09:34:42 +0100
Subject: [PATCH 3/3] docs(README.md): add instructions for skipping commit
 message check in hook Added explanation to readme

---
 README.md | 6 ++++++
 1 file changed, 6 insertions(+)

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