Skip to content

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

Description

@brpaz

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.

Activity

  1. holson1 commented on Feb 26, 2020

    @holson1

    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.

  2. tomdyqin commented on Apr 8, 2020

    @tomdyqin

    i am having the same issue.

  3. hdmr14 commented on Apr 29, 2020

    @hdmr14
    Contributor

    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.

  4. commitizen-bot commented on Oct 20, 2020

    @commitizen-bot

    🎉 This issue has been resolved in version 4.2.2 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

  5. jaikme commented on Jan 25, 2021

    @jaikme

    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?

  6. praveenpuglia commented on Jan 5, 2022

    @praveenpuglia

    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.

  7. Dunky13 commented on Jan 28, 2022

    @Dunky13

    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"
  8. OmarZeidan commented on Jun 3, 2024

    @OmarZeidan

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions