Skip to content
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

Blank lines after title cause gitlint to ignore missing body (B6) #176

Closed
dan-cohn-sabre opened this issue Feb 10, 2021 · 1 comment · Fixed by #179
Closed

Blank lines after title cause gitlint to ignore missing body (B6) #176

dan-cohn-sabre opened this issue Feb 10, 2021 · 1 comment · Fixed by #179
Labels
bug User-facing bugs

Comments

@dan-cohn-sabre
Copy link

I've discovered an unusual problem. We have folks creating commits with only a title, and gitlint isn't complaining. There's nothing in the .gitlint file to disable this check.

What I've found through testing is that a title followed by 2 or more blank lines passes gitlint even though the message contains no body.

Here's an example with debug:

$ gitlint --debug --msg-filename ~/COMMIT_EDITMSG run-hook
DEBUG: gitlint.cli To report issues, please visit https://github.com/jorisroovers/gitlint/issues
DEBUG: gitlint.cli Platform: Linux-5.4.39-linuxkit-x86_64-with-centos-8.2.2004-Core
DEBUG: gitlint.cli Python version: 3.6.8 (default, Apr 16 2020, 01:36:27) 
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
DEBUG: gitlint.git ('--version',)
DEBUG: gitlint.cli Git version: git version 2.27.0
DEBUG: gitlint.cli Gitlint version: 0.14.0
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: [NOT SET]
DEBUG: gitlint.cli DEFAULT_ENCODING: UTF-8
DEBUG: gitlint.cli Configuration
config-path: /home/sabre2/src/sabre2/.gitlint
[GENERAL]
extra-path: None
contrib: ['contrib-title-conventional-commits']
ignore: 
ignore-merge-commits: True
ignore-fixup-commits: True
ignore-squash-commits: True
ignore-revert-commits: True
ignore-stdin: False
staged: False
verbosity: 3
debug: True
target: /home/sabre2/src/sabre2
[RULES]
  I1: ignore-by-title
     ignore=all
     regex=None
  I2: ignore-by-body
     ignore=all
     regex=None
  I3: ignore-body-lines
     regex=None
  T1: title-max-length
     line-length=72
  T2: title-trailing-whitespace
  T6: title-leading-whitespace
  T3: title-trailing-punctuation
  T4: title-hard-tab
  T5: title-must-not-contain-word
     words=WIP
  T7: title-match-regex
     regex=None
  T8: title-min-length
     min-length=5
  B1: body-max-line-length
     line-length=80
  B5: body-min-length
     min-length=20
  B6: body-is-missing
     ignore-merge-commits=True
  B2: body-trailing-whitespace
  B3: body-hard-tab
  B4: body-first-line-empty
  B7: body-changed-file-mention
     files=
  B8: body-match-regex
     regex=None
  M1: author-valid-email
     regex=[^@ ]+@[^@ ]+\.[^@ ]+
  CT1: contrib-title-conventional-commits
     types=fix,feat,chore,docs,style,refactor,perf,test,revert,ci,build

gitlint: checking commit message...
DEBUG: gitlint.cli Using --msg-filename.
DEBUG: gitlint.git ('config', '--get', 'core.commentchar')
DEBUG: gitlint.cli Linting 1 commit(s)
DEBUG: gitlint.lint Linting commit [SHA UNKNOWN]
DEBUG: gitlint.lint Commit Object
--- Commit Message ----
feat: test



--- Meta info ---------
Author: None <None>
Date:   None
is-merge-commit:  False
is-fixup-commit:  False
is-squash-commit: False
is-revert-commit: False
Branches: []
Changed Files: []
-----------------------
DEBUG: gitlint.cli Exit Code = 0
gitlint: OK (no violations in commit message)

I updated to version 0.15.0 and had the same problem.

@jorisroovers
Copy link
Owner

Good find, thanks for opening the issue!

Seems such a basic issue that I'm surprised it was never caught before. I think that's probably because git commit prunes trailing newlines (I believe by default).

In any case, I was able to reproduce this like so:

# These work as expected
echo "foo" | gitlint
echo "foo\n" | gitlint

# These don't, they're not showing the B6 rule
echo "foo\n\n" | gitlint
echo "foo\n\n\n" | gitlint

Will be double checking the fix in #179 shortly, but looks pretty good.

@jorisroovers jorisroovers added the bug User-facing bugs label Mar 7, 2021
jorisroovers added a commit that referenced this issue Apr 16, 2021
Bugfixes:
  - Git commit message body with only new lines is not longer considered empty
    by `body-is-missing` (#176)
  - Added compatibility with `git commit -s` for
    `contrib-requires-signed-off-by` rule (#178)
- Minor tweak to gitlint commit-hook output (#173)
- All dependencies have been upgraded to the latest available versions
- Minor doc fixes

Full Release details in CHANGELOG.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug User-facing bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants