commitizen / cz-cli

The commitizen command line utility. #BlackLivesMatter
http://commitizen.github.io/cz-cli/
MIT License
16.81k stars 551 forks source link

[Question] commitizen and standard-version together doesn't work (prepare-commit-msg hook can't be skipped) #631

Closed natterstefan closed 5 years ago

natterstefan commented 5 years ago

Hi,

I have the following issue, which was somehow discussed in the PR of the feature "feat(cli): Implement --hook option for git hooks integration":

The Problem

When using the proposed hook solution together with husky, I am not able to skip the git hooks when using standard-version's release command (see command here).

What I do

Basically, this is what I have and do (used in my react-component-catalog package):

// package.json
"scripts": {
    "release": "standard-version"
  },
"husky": {
    "hooks": {
      "pre-commit": "lint-staged",
      "prepare-commit-msg": "exec < /dev/tty && git cz --hook"
    }
  },

Whenever I release something, I execute one of these commands:

npm run release -- --no-verify
# or
npx standard-version --no-verify

This results in the following error:

image

What I expect and need

I want to be able to use commitizen together with standard-version when creating a new release.

How? Either it would be great to tell the git cz command to skip interactive mode or entirely for this specific task, or I should use another hook (which I have not yet tested though).

Whatever is better, I am happy if someone can assist me here. 👍

Hints, Links etc.

During my research I stumbled upon an issue raised in the husky package. He wanted to create "(...) a custom prepare-commit-msg hook that appends an ID to the commit msg." and also had troubles skipping it.

He got a response containing the following hint:

commit-msg hook better suits your needs.

Because prepare-commit-msg does not allow --no-verify...

prepare-commit-msg [...] The purpose of the hook is to edit the message file in place, and it is not suppressed by the --no-verify option.

commit-msg [...] can be bypassed with the --no-verify option. [...] It can also be used to refuse the commit after inspecting the message file.

https://git-scm.com/docs/githooks#_prepare_commit_msg

Does that mean I should use commit-msg instead to make this work? But then people are not enforced anymore to use commitizen...

Thank you for your help!

olgn commented 5 years ago

@natterstefan I remember using the prepare-commit-msg for exactly the reason you're describing above about wanting to enforce the users to enter a properly formatted commit message via commitizen.

Even though the prepare-commit-msg hook isn't suppressed with the no-verify option, maybe we can check if --no-verify is also present, and give an exit code.

I'll take a look at it - in the meantime, something useful would be to generate a sandbox environment to make it easier for me to replicate the error

natterstefan commented 5 years ago

Hi @olgn, thanks for your response. Yes I can. I added a todo onto my list and let you know when it's ready. Should be simple and not complicated, but still I can't do it immediatelly.

olgn commented 5 years ago

@natterstefan thanks!

natterstefan commented 5 years ago

Hi @olgn, here's an example repository: https://github.com/natterstefan/example-commitizen-standard-version.

I've set up git-hooks (husky with prepare-commit-msg), and standard-version (available with npm run release and npm run release -- --no-verify).

Hopefully this helps, if not let me know how I can be of help for you.

best, Stefan

natterstefan commented 5 years ago

Hi @olgn 👋,

were you able to take a look at the provided example already? Thank you for your help.

best, Stefan

olgn commented 5 years ago

Howdy @natterstefan - try this - Husky just put out a check for the HUSKY_SKIP_HOOKS variable (issue here)- this will skip all husky hooks, which I think gets the bahaviour you would like.

package.json:

{
  ...
  "scripts": {
    ....
    "release": "HUSKY_SKIP_HOOKS=1 standard-version",
    ...
  }
}

Please let me know how this works for you.

natterstefan commented 5 years ago

@olgn Awesome, it worked. Thanks for helping me!

image

olgn commented 5 years ago

@natterstefan happy to help.

natterstefan commented 5 years ago

@olgn Thank you!

rickstaa commented 3 years ago

HUSKY_SKIP_HOOKS no longer works (as of at least 6.0.0). The HUSKY=0 variable should be now be used instead (see https://typicode.github.io/husky/#/?id=bypass-hooks).

TimeBandit commented 2 years ago

Howdy @natterstefan - try this - Husky just put out a check for the HUSKY_SKIP_HOOKS variable (issue here)- this will skip all husky hooks, which I think gets the bahaviour you would like.

package.json:

{
  ...
  "scripts": {
    ....
    "release": "HUSKY_SKIP_HOOKS=1 standard-version",
    ...
  }
}

Please let me know how this works for you.

Due to a breaking change in Huksy if the above does not work use

{

  "scripts": {

    "release": "HUSKY=0 standard-version",

  }
}