Skip to content

Conversation

@am1r021
Copy link

@am1r021 am1r021 commented Jul 3, 2020

Write linter to check that commit messages have a new line before the body or no body at all. fixes issue #19091.

Copy link
Member

@adamjonas adamjonas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warm welcome @ghorbanian and excited to see more contributions for you in the future!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is failing the linter for having a trailing whitespace.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just put 2020 here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ git log origin..HEAD --format=%s%b+ isn't working for me while testing locally. I get:

fatal: ambiguous argument 'origin..HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to git log origin/master..HEAD. My intent is to get the last N commits that have not yet been pushed in a portable way. I did some research and I believe the change that I have made achieves this, but please let me know if not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If successfully passed, you'd want this to exit silently. Following the format of the other linters, I'd suggest replacing this line:

Suggested change
echo "No commit message formatting errors detected."
exit ${EXIT_CODE}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

@troygiorshev troygiorshev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ghorbanian thanks for picking this up!

When manually testing this script, I don't think it actually works :/

I've suggested below why I think this may be happening.

Copy link
Contributor

@troygiorshev troygiorshev Jul 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "+" idea is clever! However, I don't think it's one we can live with. The "+" character is actually used surprisingly often in commit messages.

git log --grep='+' --oneline | wc -l
> 706

Two suggested solutions, if you're looking for somewhere to start

  • Try and find a list of valid characters in commit messages, and see if you can use one that isn't in the list. Maybe "#" would work? I know that emojis work in commit messages, so maybe this isn't a viable option, but check it out :)
  • Try iterate over each commit, as opposed to getting them all at once.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking at the script some more, I decided to iterate over each commit by hash value in order to circumvent this delimiter problem. Thank you for the suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out what this outputs, I don't think it's what you want.
Possibly you're looking for --format=%B+, and then see if you can think of a way to deal with the "+" issue.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message isn't quite right. Maybe something like one of these is better.

Suggested change
echo "Your subject line follows a non-empty line. Subject lines should always be followed by a blank line."
echo "Your body follows a non-empty line. Subject lines should always be followed by a blank line."
Suggested change
echo "Your subject line follows a non-empty line. Subject lines should always be followed by a blank line."
echo "Your subject line is followed by a non-empty line. Subject lines should always be followed by a blank line."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for including this reference! Let's keep it out of the code though, can you move it to the body of your commit message?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@am1r021 am1r021 force-pushed the linter-addition branch from acc86bd to 6e8feaa Compare July 8, 2020 15:11
Copy link
Author

@am1r021 am1r021 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@troygiorshev Thank you for the code review!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could make sense to default this to TRAVIS_COMMIT_RANGE if available?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@am1r021 am1r021 force-pushed the linter-addition branch 2 times, most recently from cf714e4 to a62b825 Compare July 12, 2020 20:17
Copy link
Contributor

@troygiorshev troygiorshev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below \/

Copy link
Contributor

@troygiorshev troygiorshev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed, manually tested. Works great!

Just need the message changed.

Write linter to check that commit messages have a new line before the body or no body at all.

reference: gist.github.com/agnivade/67b42d664ece2d4210c7

Fixes issue bitcoin#19091.
@troygiorshev
Copy link
Contributor

troygiorshev commented Jul 16, 2020

ACK 284a969 Reviewed, manually tested. Works great!

@fjahr
Copy link
Contributor

fjahr commented Jul 17, 2020

tested ACK 284a969

Test

$ touch foo
$ git add foo
$ git commit -am "Foo
→ Bar"
$ test/lint/lint-git-commit-check.sh
The subject line of commit hash 1b6e02448bcced186160815a986d65ca38144940 is followed by a non-empty line. Subject lines should always be followed by a blank line.
$ test/lint/lint-git-commit-check.sh 0
$ test/lint/lint-git-commit-check.sh 1
The subject line of commit hash 1b6e02448bcced186160815a986d65ca38144940 is followed by a non-empty line. Subject lines should always be followed by a blank line.

@adamjonas
Copy link
Member

utACK 284a969

@maflcko maflcko merged commit edec7f7 into bitcoin:master Jul 30, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 31, 2020
284a969 Linter to check commit message formatting (Amir Ghorbanian)

Pull request description:

  Write linter to check that commit messages have a new line before the body or no body at all. fixes issue bitcoin#19091.

ACKs for top commit:
  troygiorshev:
    ACK 284a969 Reviewed, manually tested. Works great!
  fjahr:
    tested ACK 284a969
  adamjonas:
    utACK 284a969

Tree-SHA512: fa278f090780b54e4fa6e2967a62b4c1a4da55d112ec1ad6dd7e1181ac490c5c1af0165524b5781b463fdd6d0f79fd3d95b5160184e6eca432ccff1189f77390
@fjahr
Copy link
Contributor

fjahr commented Aug 2, 2020

The linter seems to fail in the CI for commit messages without a body, at least it did for me here https://travis-ci.org/github/bitcoin/bitcoin/builds/714296380 and I can not reproduce it locally. Can somebody else confirm this or is able to reproduce this locally?

@fjahr
Copy link
Contributor

fjahr commented Aug 4, 2020

The linter seems to fail in the CI for commit messages without a body, at least it did for me here https://travis-ci.org/github/bitcoin/bitcoin/builds/714296380 and I can not reproduce it locally. Can somebody else confirm this or is able to reproduce this locally?

My initial analysis of what caused the failure was wrong so ignore that part. But I think I have found what the issue was and proposed a fix here: #19654

maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Aug 5, 2020
…ssage linter

7235178 lint: Remove travis env var from commit linter (Fabian Jahr)

Pull request description:

  bitcoin#19439 was recently merged and seemed to work fine but I now noticed strange behavior when it was running in Travis, which I could not reproduce locally. It turns out `TRAVIS_COMMIT_RANGE` which is used in Travis to get the commits for the linter, uses all the commits that were in a push, which includes all rebase commits for example. This means that the linter can fail on a commit that the developer has never even seen before, which can be very confusing. See an example here which caused me to look into this: https://travis-ci.org/github/bitcoin/bitcoin/jobs/714296381 The commit that is reported as failing in my PR is not part of my PR.

  I think we rather want to use something like `git merge-base` to get the commit range by default and in Travis. I am leaving the env variable functionality in place with a different name but this is not a variable that can be expected to be present in the CI environments so the `merge-base` range should be used there by default.

ACKs for top commit:
  hebasto:
    ACK 7235178, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: afb27bb386855cb8d5cf84fd3a6c11ef1160b25af6175ed0aa146bf04b9a26eb77298df70df0a855f8c46f19f08b3f62c49872c12974fcfa5526a15ee05b3c10
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 1, 2021
284a969 Linter to check commit message formatting (Amir Ghorbanian)

Pull request description:

  Write linter to check that commit messages have a new line before the body or no body at all. fixes issue bitcoin#19091.

ACKs for top commit:
  troygiorshev:
    ACK 284a969 Reviewed, manually tested. Works great!
  fjahr:
    tested ACK 284a969
  adamjonas:
    utACK 284a969

Tree-SHA512: fa278f090780b54e4fa6e2967a62b4c1a4da55d112ec1ad6dd7e1181ac490c5c1af0165524b5781b463fdd6d0f79fd3d95b5160184e6eca432ccff1189f77390
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 1, 2021
…ssage linter

7235178 lint: Remove travis env var from commit linter (Fabian Jahr)

Pull request description:

  bitcoin#19439 was recently merged and seemed to work fine but I now noticed strange behavior when it was running in Travis, which I could not reproduce locally. It turns out `TRAVIS_COMMIT_RANGE` which is used in Travis to get the commits for the linter, uses all the commits that were in a push, which includes all rebase commits for example. This means that the linter can fail on a commit that the developer has never even seen before, which can be very confusing. See an example here which caused me to look into this: https://travis-ci.org/github/bitcoin/bitcoin/jobs/714296381 The commit that is reported as failing in my PR is not part of my PR.

  I think we rather want to use something like `git merge-base` to get the commit range by default and in Travis. I am leaving the env variable functionality in place with a different name but this is not a variable that can be expected to be present in the CI environments so the `merge-base` range should be used there by default.

ACKs for top commit:
  hebasto:
    ACK 7235178, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: afb27bb386855cb8d5cf84fd3a6c11ef1160b25af6175ed0aa146bf04b9a26eb77298df70df0a855f8c46f19f08b3f62c49872c12974fcfa5526a15ee05b3c10
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 16, 2021
284a969 Linter to check commit message formatting (Amir Ghorbanian)

Pull request description:

  Write linter to check that commit messages have a new line before the body or no body at all. fixes issue bitcoin#19091.

ACKs for top commit:
  troygiorshev:
    ACK 284a969 Reviewed, manually tested. Works great!
  fjahr:
    tested ACK 284a969
  adamjonas:
    utACK 284a969

Tree-SHA512: fa278f090780b54e4fa6e2967a62b4c1a4da55d112ec1ad6dd7e1181ac490c5c1af0165524b5781b463fdd6d0f79fd3d95b5160184e6eca432ccff1189f77390
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 16, 2021
…ssage linter

7235178 lint: Remove travis env var from commit linter (Fabian Jahr)

Pull request description:

  bitcoin#19439 was recently merged and seemed to work fine but I now noticed strange behavior when it was running in Travis, which I could not reproduce locally. It turns out `TRAVIS_COMMIT_RANGE` which is used in Travis to get the commits for the linter, uses all the commits that were in a push, which includes all rebase commits for example. This means that the linter can fail on a commit that the developer has never even seen before, which can be very confusing. See an example here which caused me to look into this: https://travis-ci.org/github/bitcoin/bitcoin/jobs/714296381 The commit that is reported as failing in my PR is not part of my PR.

  I think we rather want to use something like `git merge-base` to get the commit range by default and in Travis. I am leaving the env variable functionality in place with a different name but this is not a variable that can be expected to be present in the CI environments so the `merge-base` range should be used there by default.

ACKs for top commit:
  hebasto:
    ACK 7235178, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: afb27bb386855cb8d5cf84fd3a6c11ef1160b25af6175ed0aa146bf04b9a26eb77298df70df0a855f8c46f19f08b3f62c49872c12974fcfa5526a15ee05b3c10
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants