Skip to content

fix: commitlint is reading previous commit message #3780

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

Closed
2 of 4 tasks
chandrashekhar07 opened this issue Nov 17, 2023 · 10 comments
Closed
2 of 4 tasks

fix: commitlint is reading previous commit message #3780

chandrashekhar07 opened this issue Nov 17, 2023 · 10 comments

Comments

@chandrashekhar07
Copy link

Expected Behavior

commitlint should evaluate the current/last commit message

Current Behavior

commitlint is reading the previous commit message while evaluating the result

My commit message is: testing
But npx --no -- commitlint --edit ${1} --verbose is evaluating the result of the previous commit.

image
the

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

No response

Steps to Reproduce

My configuration:


// eslint-disable-next-line unicorn/prefer-module
module.exports = { extends: ['@commitlint/config-conventional'] };

At first, I added a valid commit message, but in the middle of committing process (husky evaluation), I canceled the process using ctrl + c

Then I changed my message to something else but still commit lint is evaluating the result of the previous commit.



### Context

_No response_

### commitlint --version

^18.4.2

### git --version

2.34.1

### node --version

v18.17.1
@escapedcat
Copy link
Member

Does this work for you?:

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

npx commitlint --edit 

@chandrashekhar07
Copy link
Author

Does this work for you?:

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

npx commitlint --edit 

Nope it's still evaluating previous/old commits

image

@ehdlg

This comment was marked as duplicate.

1 similar comment
@whxmm0608

This comment was marked as duplicate.

@ernestyouniverse

This comment was marked as duplicate.

@SyedTayyabUlMazhar
Copy link
Contributor

Found the solution! You need to rename your hook from pre-commit to commit-msg.

From the git hooks docs:

The pre-commit hook is run first, before you even type in a commit message. It’s used to inspect the snapshot that’s about to be committed, to see if you’ve forgotten something, ....

The commit-msg hook takes one parameter, which again is the path to a temporary file that contains the commit message written by the developer. If this script exits non-zero, Git aborts the commit process, so you can use it to validate your project state or commit message before allowing a commit to go through....

@escapedcat
Copy link
Member

@SyedTayyabUlMazhar thanks for you comment!
So the readme is still correct, right?

@chandrashekhar07 how did you come up with using pre-commit? Is this mentioned in the docs?

@SyedTayyabUlMazhar
Copy link
Contributor

SyedTayyabUlMazhar commented Dec 12, 2023

@escapedcat
Yes, the readme is correct. However, I think it should explicitly mention that hook file name must be commit-msg, for those not familiar.

I found the solution by reading git's documentation on hooks.

@escapedcat
Copy link
Member

Thanks!

I think it should explicitly mention that hook file name must be pre-commit, for those not familiar.

Anyone up for a PR to improve the docs?

@escapedcat
Copy link
Member

Docs were improved, please see if this helps

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

No branches or pull requests

6 participants