commitlint: no such file or directory COMMIT_EDITMSG on new checkout
When checking out a repo, there is no COMMIT_EDITMSG
file until a new commit is made. In the case of elastic-apm-node, we trigger the commit lint automatically, as part of the test process. This currently means a fresh checkout can’t run the tests because @commitling/cli will crash due to being unable to find that file.
Expected Behavior
There was no commit to have a failing message on, so it should not be a failure.
Current Behavior
It crashes with this output:
/home/stephenbelanger/Code/elastic-apm-node/node_modules/@commitlint/cli/lib/cli.js:113
throw err;
^
Error: ENOENT: no such file or directory, open '/home/stephenbelanger/Code/elastic-apm-node/.git/COMMIT_EDITMSG'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! elastic-apm-node@2.5.1 lint-commit: `test/lint-commits.sh`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the elastic-apm-node@2.5.1 lint-commit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/stephenbelanger/.npm/_logs/2019-03-03T19_30_57_446Z-debug.log
Affected packages
- cli
- core
- prompt
- config-angular
Possible Solution
Consider it a “pass” if the file is not found.
Steps to Reproduce (for bugs)
- Checkout any repo for the first time, which uses @commitlint/cli
- Trigger @commitlint/cli
- ???
- 😢
Context
Currently this makes the contributing process painful, as new contributors will always run into this the first time they try to run our tests.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 8
- Comments: 18 (5 by maintainers)
Commits related to this issue
- fix: remove escape of commit lint file param due to macOS support More information in: https://github.com/conventional-changelog/commitlint/issues/589 — committed to Sifchain/sifchain-ui-next by oieduardorabelo 2 years ago
I’m quite certain this is the result of a miss-configuration and not a fault in the commitlint itself.
This happens if you by mistake add commitlint to
pre-commit
instead ofcommit-msg
hook (I know it by doing)I faced this problem today, I’ve created the COMMIT_EDITMSG file on .git folder and my hook backs to work:
touch ./.git/COMMIT_EDITMSG
Take a look at file permission, this need to be:
-rw-rw-r-- 1 example example 9 jan 31 15:17 COMMIT_EDITMSG
The issue here is the unconditional usage of the
--edit
flag.An excerpt from
commitlint --help
reveals the flag triggers commitlint to read from fs instead of stdin or the commit history:Based on the comment in your linting script you want to call commitlint like this:
Let me know if this works for you.
I have the same issue. Disabling commintlint until fixed.
I’m using it with husky
npx --no-install commitlint --edit $1
Also, sometimes it checks the PREVIOUS commit msg and not the one I’m currently trying to commit, resulting in an error if the previous one was in error.
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360010605439/comments/4406713360018
Thanks
I suggest to put this on the documentation, so Windows users could save their time.
For some reason, the commitlint script isn’t looking in the correct place for the git message when I run the husky command.
A fix for me was using the PWD command to tell commitlint where the git message needs linting.
Maybe a separate flag that augments the
--edit
flag like--edit --skip-empty
and then change the default to produce a more useful error when the file is not found?