Description
When git cannot be found in PATH and the user runs commitlint with parameters to read from the git log, commitlint exits with status 0 and no output.
Expected Behavior
When git is needed and cannot be found, commitlint should exit with a non-zero status and print an error.
Current Behavior
When git cannot be found in PATH, commitlint exits with status 0 and no output.
Affected packages
- cli
- core
- prompt
- config-angular
Possible Solution
Checking the exit status of git would be a good idea. That takes place in git-raw-commits; I will open a PR there soon.
Steps to Reproduce (for bugs)
- Go to repo
cd /path/to/repo
- Add a commit with a bad message
touch foo && git add foo && git commit --no-verify -m 'Bad Commit Msg'
- Remove git from PATH somehow, e.g.
sudo mv /usr/bin/git /usr/bin/git.bak
- Run commitlint; note zero exit status and no output
commitlint --from HEAD~1
- Don't forget to put git back if needed, e.g.
sudo mv /usr/bin/git.bak /usr/bin/git
Context
The reproduction steps above may make this seem like a convoluted edge case, but it is not too difficult to run into.
I encountered this bug when setting up CI jobs to run in an alpine linux container. The repository is made available to the container via a bind mount and git is not installed by default. I didn't realize at first that git was missing and was confused by commitlint succeeding when it should not.
Another way a dev could be affected by this is if git is uninstalled for some reason (accidental, troubleshooting, etc).
Your Environment
Executable | Version |
---|---|
commitlint --version |
@commitlint/[email protected] |
git --version |
git version 2.28.0 |
node --version |
v14.11.0 |