Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

husky falls back to original git commit message prompt if I cancel when displaying commitizen prompt #688

Closed
brpaz opened this issue Dec 8, 2019 · 9 comments · Fixed by #736

Comments

@brpaz
Copy link

brpaz commented Dec 8, 2019

Hello.
I am using Husky together with Commitizen to execute git-cz when doing a git commit.

I have defined the following configuration as stated in the documentation:

  "husky": {
    "hooks": {
      "prepare-commit-msg": "exec < /dev/tty && git cz --hook || true"
    }
  },

Everything works fine and I am prompted to choose the commit message from commitizen.
The problem is if I hit CTRL-C to cancel my commit, it just closes the commitizen prompt and falls back to the original git commit prompt. I want to abort everything in this case and dont do the commit.

I have tried to remove the "|| true" from the prepare-commit-msg command but it´s the same.

Not sure if it´s an issue of husky or commitizen.

Thanks for the help.

@ghost
Copy link

ghost commented Dec 24, 2019

I am having the same issue. Also, the commitizen prompt is reprinting the options each time I type something.

@holson1
Copy link

holson1 commented Feb 26, 2020

Having the same issue - it looks like git-cz returns a 0 exit code even when CTRL-C'd. Not sure why commitizen traps the SIGINT but it should probably be surfaced. If it returns a non-zero exit code it should work with husky and prevent the standard git message from showing.

@tomdyqin
Copy link

tomdyqin commented Apr 8, 2020

i am having the same issue.

@hdmr14
Copy link
Contributor

hdmr14 commented Apr 29, 2020

commitizen using Inquirer.js for prompt.
Inquirer.js traps SIGINT, and It have not any exit handlers.
I found implementation workarounds in their discussion, and related issue that SIGINT trap not work normally.

It might be a Inquirer.js's issue.
but the workaround looks like work enough.

process.stdin.on("data", (key) => {
  if (key == "\u0003") {
    process.exit(1);
  }
});

add above to bin/git-cz.js, CTRL-C will work with Inquire.js's hooks.

@commitizen-bot
Copy link

🎉 This issue has been resolved in version 4.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jaikme
Copy link

jaikme commented Jan 25, 2021

For me, I'm trying to use the single command git commit and it prompt to choose my type:

husky > pre-commit (node v12.17.0)
ℹ No staged files match any configured task.
husky > prepare-commit-msg (node v12.17.0)
? Select the type of change that you're committing: (Use arrow keys or type to search)
❯ test:       Adding missing tests 
  feat:       A new feature 
  fix:        A bug fix 
  chore:      Build process or auxiliary tool changes 
  docs:       Documentation only changes 
  refactor:   A code change that neither fixes a bug or adds a feature 
  style:      Markup, white-space, formatting, missing semi-colons... 

Then I make de description:

...
? Select the type of change that you're committing: chore:      Build process or auxiliary tool changes
? Write a short, imperative mood description of the change: 
  [-------------------------------------------------------------] 34 chars left
   chore: husky hook on git-cz

But it's falling back to VIM to edit COMMIT_EDITMSG:

chore: husky hook on git-cz
~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                           
~                                                                                                                                           
"~/repo/.git/COMMIT_EDITMSG" [noeol] 1L, 27C

My pakcage.json husky config and version:

...
"dependencies": {
    "@commitlint/cli": "^11.0.0",
    "@commitlint/config-conventional": "^11.0.0",
    "@commitlint/config-lerna-scopes": "^11.0.0",
    "commitizen": "^4.2.3",
    "cz-conventional-changelog": "^3.3.0",
    "eslint": ">=6.0.0",
    "git-cz": "^4.7.6",
    "husky": "^4.3.8",
    "lerna": "^3.22.1",
    "lint-staged": "^10.5.3",
    "prettier": "^2.2.1",
    "stylelint": "^13.9.0"
  },
"husky": {
    "hooks": {
      "pre-commit": "lint-staged",
      "prepare-commit-msg": "exec < /dev/tty && git cz --hook || true",
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  },

-> Some can help me with this issue? There is some "thing" to avoid open the COMMIT_EDITMSG or is the default behavior?

@praveenpuglia
Copy link

Has there been any fix to this?
I am on 4.2.4 but I still have the same issue. If I hit Ctrl + C while answering all the questions, it falls back to vim and then that commit message is used.

@Dunky13
Copy link

Dunky13 commented Jan 28, 2022

Having this issue as well, sadly throws me to vim commit message if I use CTRL+C

    "commitizen": "^4.2.4",
    "git-cz": "^4.8.0",
    "husky": "^7.0.4"

@OmarZeidan
Copy link

So, this has been closed without actually being fixed 🤔 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants