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

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

Open
1 of 4 tasks
mrb1994 opened this issue Jun 13, 2023 · 0 comments
Open
1 of 4 tasks

Comments

@mrb1994
Copy link

mrb1994 commented Jun 13, 2023

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

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

No branches or pull requests

2 participants