commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

Using same commit for --from and --to does nothing and returns exit-code=0 (success)

Open knocte opened this issue 3 years ago • 3 comments

Using same commit hash for --from and --to flags makes commitlint do nothing and return exit-code=0 (success).

Steps to Reproduce

  1. Do a commit that violates your commitlint policies.
  2. Grab the last commit hash from your repo, e.g. with git-log.
  3. Run npx commitlint --verbose --from <commitHash> --to <commitHash>

Current Behavior

It does nothing and returns exit-code = 0 (success). This is quite misleading because it could make anyone think that the validation was successful on the last commit (especially in CI scenarios).

Expected Behavior

If commit-hash supplied for --from and --to is the same, it should just analyze one single commit message for the supplied commit hash. Or at least return an exit-code different than 0 to denote that the supplied params were invalid (invalid in the sense that commitlint didn't validate anything).

Affected packages

  • [x] cli
  • [x] core
  • [ ] prompt
  • [ ] config-angular

Context

I was trying to develop a simple GitHub actions CI workflow that checks the single last commit hash. The flag --edit didn't work in this scenario so I tried --from and --to with ${{ github.sha } but, as you can see from this bug I just filed, it didn't work.

You might want to suggest that I should use the previous commit hash for the from flag, but I believe that in order to achieve this I probably need to tweak the actions/checkout@v2 step with a fetch-depth: 0 option; which is not ideal (because it's not easy to figure out). Fixing this bug should probably be better.

Your Environment

Executable Version
commitlint --version @commitlint/[email protected]
git --version git version 2.32.0 (Apple Git-132)
node --version v18.9.0

knocte avatar Sep 11 '22 06:09 knocte

@escapedcat this should be labeled as bug, not question.

knocte avatar Sep 11 '22 09:09 knocte

#2568 is related

escapedcat avatar Sep 12 '22 03:09 escapedcat

Just related, not the same.

knocte avatar Sep 12 '22 07:09 knocte