Skip to content

pnpm cz no longer updates the COMMIT_EDITMSG file before precommit lifecycle event #3617

Open
@mrb1994

Description

Expected Behavior

We should be able to create a commit formatted with cz and check that it's done correctly with a husky hook (pre-commit).

Current Behavior

When I use pnpm gitcommit (cz), I have the right prompt but I have this issue after I filled it

[Error: ENOENT: no such file or directory, open 'C:\<PROJECT_PATH>\.git\COMMIT_EDITMSG'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\<PROJECT_PATH>\\.git\\COMMIT_EDITMSG'
}

 

Node.js v18.12.1
husky - pre-commit hook exited with code 1 (error)
git exited with error code 1

And if the file exists the hook will validate its content (not the commit currently being created)
Since I switched to pnpm, cz won't update COMMIT_EDITMSG before the hook is triggered

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

"scripts": {
    "gitcommit": "cz --hook && git commit -eF .git/COMMIT_EDITMSG --no-edit"
}

Steps to Reproduce

1) create a project which uses pnpm
2) setup cz with pnpm
3) create a pre-commit husky hook (check context part)
4) try to create a commit with cz

Context

My configuration:

pnpm: 8.6.0
@commitlint/cli: "^17.4.4",
@commitlint/config-conventional: "^17.4.4",
@types/node: "^18.11.9",
commit-and-tag-version: "^11.2.1",
commitizen: "^4.3.0",
cz-conventional-changelog: "^3.3.0",
husky: "^8.0.3"

How I configured cz:

pnpm commitizen init cz-conventional-changelog --pnpm --save-dev --save-exact
"scripts": {
    "gitcommit": "cz",
    "recommit": "cz --retry"
},
"config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
}

Husky pre-commit:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

previousCommitsCount=$(git --no-pager rev-list master..HEAD --count)

if [ $previousCommitsCount -gt 0 ]
then
    echo this is a fix commit
else
   pnpm commitlint --edit ${1} --verbose --color
fi

commitlint --version

@commitlint/cli: "^17.4.4",

git --version

git version 2.37.3.windows.1

node --version

v16.17.0

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