carloscuesta / gitmoji-cli

A gitmoji interactive cli tool for using emojis on commits. πŸ’»

Home Page:https://www.npmjs.com/package/gitmoji-cli

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable hook if commit message already starts with emoji

thdk opened this issue Β· comments

Description of the problem

Context: automating bumping versions of node packages

❯ gitmoji -i
❯ git commit -a -m "πŸ”– Bump version to $npm_package_version"
? Choose a gitmoji: πŸ”–  - Release / Version tags.
? Enter the commit title [18/48]: πŸ”– Bump version to 0.1.0
? Enter the commit message: 
[feature/abc 468583a] πŸ”– πŸ”– Bump version to 0.1.0
 2 files changed, 4 insertions(+), 4 deletions(-)

Could we detect in the prepare commit message hook that the commit message already contains an emoji and if so skip the emoji prompt?

Or still show the prompt but preselect the result with the emoji from the commit message?

Solution

const commit = (options: CommitOptions): Function => {
  if (options.mode === COMMIT_MODES.HOOK) {
  registerHookInterruptionHandler()
    if (options.message?.startsWith(anyEmoji)) {
        commit(options)
     else {
        
        return cancelIfNeeded().then(() => promptAndCommit(options))
    }
  }

  return promptAndCommit(options)
}

Alternatives

git commit --no-verify doesn't seem to prevent the gitmoji hook.

Additional context

No response

Validations

Hey!

Thanks for opening the issue, I think it makes sense but we should probably aim to support the --no-verify option instead of doing this "magic" of skipping the hook if the emoji is provided already

Feel free to raise a Pull Request! πŸ™πŸΌ

Hey! So I took at stab at this and found out it's not possible to use --no-verify for the prepare-commit-msg hook (it is ignored) as mentioned in the docs

CleanShot 2023-05-31 at 17 44 37@2x

I implemented the PR as an alternative solution to this.

We might want to explore switching from prepare-commit-msg to commit-msg to support --no-verify