1
0
Fork 0

Merging upstream version 0.15.1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 06:04:41 +01:00
parent 37665242cd
commit 833baf28b6
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
32 changed files with 87 additions and 66 deletions

View file

@ -1,5 +1,16 @@
# Changelog #
## v0.15.1 (2021-04-16) ##
Contributors:
Special thanks to all contributors for this release, in particular [PW999](https://github.com/PW999), [gsemet](https://github.com/gsemet) and [Lorac](https://github.com/Lorac).
Bugfixes:
- Git commit message body with only new lines is not longer considered empty by `body-is-missing` ([#176](https://github.com/jorisroovers/gitlint/issues/176))
- Added compatibility with `git commit -s` for `contrib-requires-signed-off-by` rule ([#178](https://github.com/jorisroovers/gitlint/pull/178))
- Minor tweak to gitlint commit-hook output ([#173](https://github.com/jorisroovers/gitlint/pull/173))
- All dependencies have been upgraded to the latest available versions (`Click==7.1.2`, `arrow==1.0.3`, `sh==1.14.1`).
- Minor doc fixes
## v0.15.0 (2020-11-27) ##
Contributors:

View file

@ -10,7 +10,7 @@ re-implement these commonly used rules themselves as [user-defined](user_defined
To enable certain contrib rules, you can use the `--contrib` flag.
```sh
$ cat examples/commit-message-1 | gitlint --contrib contrib-title-conventional-commits,CC1
1: CC1 Body does not contain a 'Signed-Off-By' line
1: CC1 Body does not contain a 'Signed-off-by' line
1: CL1 Title does not start with one of fix, feat, chore, docs, style, refactor, perf, test: "WIP: This is the title of a commit message."
# These are the default violations
@ -41,7 +41,7 @@ You can also configure contrib rules using [any of the other ways to configure g
ID | Name | gitlint version | Description
------|-------------------------------------|------------------ |-------------------------------------------
CT1 | contrib-title-conventional-commits | >= 0.12.0 | Enforces [Conventional Commits](https://www.conventionalcommits.org/) commit message style on the title.
CC1 | contrib-requires-signed-off-by | >= 0.12.0 | Commit body must contain a `Signed-Off-By` line.
CC1 | contrib-body-requires-signed-off-by | >= 0.12.0 | Commit body must contain a `Signed-off-by` line.
## CT1: contrib-title-conventional-commits ##
@ -56,11 +56,11 @@ Name | gitlint version | Default | Description
types | >= 0.12.0 | `fix,feat,chore,docs,style,refactor,perf,test,revert,ci,build` | Comma separated list of allowed commit types.
## CC1: contrib-requires-signed-off-by ##
## CC1: contrib-body-requires-signed-off-by ##
ID | Name | gitlint version | Description
------|---------------------------------------|--------------------|-------------------------------------------
CC1 | contrib-requires-signed-off-by | >= 0.12.0 | Commit body must contain a `Signed-Off-By` line. This means, a line that starts with the `Signed-Off-By` keyword.
CC1 | contrib-body-requires-signed-off-by | >= 0.12.0 | Commit body must contain a `Signed-off-by` line. This means, a line that starts with the `Signed-off-by` keyword.
## Contributing Contrib rules

View file

@ -2412,7 +2412,7 @@
],
[
0.000020,
"gitlint: \u001b[31mYour commit message contains the above violations.\u001b[0m\r\n"
"gitlint: \u001b[31mYour commit message contains violations.\u001b[0m\r\n"
],
[
0.002541,

View file

@ -17,7 +17,7 @@ T4 | title-hard-tab | >= 0.1.0 | Title cannot contain h
T5 | title-must-not-contain-word | >= 0.1.0 | Title cannot contain certain words (default: "WIP")
T6 | title-leading-whitespace | >= 0.4.0 | Title cannot have leading whitespace (space or tab)
T7 | title-match-regex | >= 0.5.0 | Title must match a given regex (default: None)
T8 | title-max-length | >= 0.14.0 | Title length must be &gt; 5 chars.
T8 | title-min-length | >= 0.14.0 | Title length must be &gt; 5 chars.
B1 | body-max-line-length | >= 0.1.0 | Lines in the body must be &lt; 80 chars
B2 | body-trailing-whitespace | >= 0.1.0 | Body cannot have trailing whitespace (space or tab)
B3 | body-hard-tab | >= 0.1.0 | Body cannot contain hard tab characters (\t)
@ -397,9 +397,9 @@ regex | >= 0.14.0 | None | [Pyt
[ignore-body-lines]
regex=^Co-Authored-By
# Ignore lines that start with 'Co-Authored-By' or with 'Signed-Off-By'
# Ignore lines that start with 'Co-Authored-By' or with 'Signed-off-by'
[ignore-body-lines]
regex=(^Co-Authored-By)|(^Signed-Off-By)
regex=(^Co-Authored-By)|(^Signed-off-by)
# Ignore lines that contain 'foobar'
[ignore-body-lines]

View file

@ -9,8 +9,8 @@ for python files containing gitlint rule classes. You can also specify a single
```sh
cat examples/commit-message-1 | gitlint --extra-path examples/
# Example output of a user-defined Signed-Off-By rule
1: UC2 Body does not contain a 'Signed-Off-By Line'
# Example output of a user-defined Signed-off-by rule
1: UC2 Body does not contain a 'Signed-off-by Line'
# other violations were removed for brevity
```
@ -23,9 +23,9 @@ which is part of the examples directory that was passed via `--extra-path`:
from gitlint.rules import CommitRule, RuleViolation
class SignedOffBy(CommitRule):
""" This rule will enforce that each commit contains a "Signed-Off-By" line.
""" This rule will enforce that each commit contains a "Signed-off-by" line.
We keep things simple here and just check whether the commit body contains a
line that starts with "Signed-Off-By".
line that starts with "Signed-off-by".
"""
# A rule MUST have a human friendly name
@ -39,10 +39,10 @@ class SignedOffBy(CommitRule):
self.log.debug("SignedOffBy: This will be visible when running `gitlint --debug`")
for line in commit.message.body:
if line.startswith("Signed-Off-By"):
if line.startswith("Signed-off-by"):
return
msg = "Body does not contain a 'Signed-Off-By' line"
msg = "Body does not contain a 'Signed-off-by' line"
return [RuleViolation(self.id, msg, line_nr=1)]
```
@ -95,9 +95,9 @@ Consider the following `CommitRule` that can be found in [examples/my_commit_rul
from gitlint.rules import CommitRule, RuleViolation
class SignedOffBy(CommitRule):
""" This rule will enforce that each commit contains a "Signed-Off-By" line.
""" This rule will enforce that each commit contains a "Signed-off-by" line.
We keep things simple here and just check whether the commit body contains a
line that starts with "Signed-Off-By".
line that starts with "Signed-off-by".
"""
# A rule MUST have a human friendly name
@ -111,10 +111,10 @@ class SignedOffBy(CommitRule):
self.log.debug("SignedOffBy: This will be visible when running `gitlint --debug`")
for line in commit.message.body:
if line.startswith("Signed-Off-By"):
if line.startswith("Signed-off-by"):
return
msg = "Body does not contain a 'Signed-Off-By' line"
msg = "Body does not contain a 'Signed-off-by' line"
return [RuleViolation(self.id, msg, line_nr=1)]
```
Note the use of the `name` and `id` class attributes and the `validate(...)` method taking a single `commit` parameter.
@ -368,7 +368,7 @@ class ReleaseConfigurationRule(ConfigurationRule):
# NOT modify your actual commit in git)
commit.message.body = [line for line in commit.message.body if not line.startswith("$")]
# You can add any extra properties you want to the commit object,
# You can add any extra properties you want to the commit object,
# these will be available later on in all rules.
commit.my_property = "This is my property"
```

View file

@ -40,8 +40,8 @@ class BodyMaxLineCount(CommitRule):
class SignedOffBy(CommitRule):
""" This rule will enforce that each commit contains a "Signed-Off-By" line.
We keep things simple here and just check whether the commit body contains a line that starts with "Signed-Off-By".
""" This rule will enforce that each commit contains a "Signed-off-by" line.
We keep things simple here and just check whether the commit body contains a line that starts with "Signed-off-by".
"""
# A rule MUST have a human friendly name
@ -54,10 +54,10 @@ class SignedOffBy(CommitRule):
self.log.debug("SignedOffBy: This will be visible when running `gitlint --debug`")
for line in commit.message.body:
if line.startswith("Signed-Off-By"):
if line.startswith("Signed-off-by"):
return
return [RuleViolation(self.id, "Body does not contain a 'Signed-Off-By' line", line_nr=1)]
return [RuleViolation(self.id, "Body does not contain a 'Signed-off-by' line", line_nr=1)]
class BranchNamingConventions(CommitRule):

View file

@ -1 +1 @@
__version__ = "0.15.0"
__version__ = "0.15.1"

View file

@ -366,7 +366,7 @@ def run_hook(ctx):
continue
click.echo("-----------------------------------------------")
click.echo("gitlint: " + click.style("Your commit message contains the above violations.", fg='red'))
click.echo("gitlint: " + click.style("Your commit message contains violations.", fg='red'))
value = None
while value not in ["y", "n", "e"]:

View file

@ -3,8 +3,8 @@ from gitlint.rules import CommitRule, RuleViolation
class SignedOffBy(CommitRule):
""" This rule will enforce that each commit body contains a "Signed-Off-By" line.
We keep things simple here and just check whether the commit body contains a line that starts with "Signed-Off-By".
""" This rule will enforce that each commit body contains a "Signed-off-by" line.
We keep things simple here and just check whether the commit body contains a line that starts with "Signed-off-by".
"""
name = "contrib-body-requires-signed-off-by"
@ -12,7 +12,7 @@ class SignedOffBy(CommitRule):
def validate(self, commit):
for line in commit.message.body:
if line.startswith("Signed-Off-By"):
if line.lower().startswith("signed-off-by"):
return []
return [RuleViolation(self.id, "Body does not contain a 'Signed-Off-By' line", line_nr=1)]
return [RuleViolation(self.id, "Body does not contain a 'Signed-off-by' line", line_nr=1)]

View file

@ -290,7 +290,7 @@ class BodyMissing(CommitRule):
# ignore merges when option tells us to, which may have no body
if self.options['ignore-merge-commits'].value and commit.is_merge_commit:
return
if len(commit.message.body) < 2:
if len(commit.message.body) < 2 or not ''.join(commit.message.body).strip():
return [RuleViolation(self.id, "Body message is missing", None, 3)]

View file

@ -17,16 +17,16 @@ class ContribSignedOffByTests(BaseTestCase):
self.assertIn(SignedOffBy(), config.rules)
def test_signedoff_by(self):
# No violations when 'Signed-Off-By' line is present
# No violations when 'Signed-off-by' line is present
rule = SignedOffBy()
violations = rule.validate(self.gitcommit("Föobar\n\nMy Body\nSigned-Off-By: John Smith"))
violations = rule.validate(self.gitcommit("Föobar\n\nMy Body\nSigned-off-by: John Smith"))
self.assertListEqual([], violations)
# Assert violation when no 'Signed-Off-By' line is present
# Assert violation when no 'Signed-off-by' line is present
violations = rule.validate(self.gitcommit("Föobar\n\nMy Body"))
expected_violation = RuleViolation("CC1", "Body does not contain a 'Signed-Off-By' line", line_nr=1)
expected_violation = RuleViolation("CC1", "Body does not contain a 'Signed-off-by' line", line_nr=1)
self.assertListEqual(violations, [expected_violation])
# Assert violation when no 'Signed-Off-By' in title but not in body
violations = rule.validate(self.gitcommit("Signed-Off-By\n\nFöobar"))
# Assert violation when no 'Signed-off-by' in title but not in body
violations = rule.validate(self.gitcommit("Signed-off-by\n\nFöobar"))
self.assertListEqual(violations, [expected_violation])

View file

@ -1,3 +1,3 @@
1: CC1 Body does not contain a 'Signed-Off-By' line
1: CC1 Body does not contain a 'Signed-off-by' line
1: CT1 Title does not start with one of fix, feat, chore, docs, style, refactor, perf, test, revert, ci, build: "Test tïtle"
1: CT1 Title does not follow ConventionalCommits.org format 'type(optional-scope): description': "Test tïtle"

View file

@ -1,5 +1,5 @@
gitlint: checking commit message...
-----------------------------------------------
gitlint: Your commit message contains the above violations.
gitlint: Your commit message contains violations.
Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)]
Aborted!

View file

@ -1,12 +1,12 @@
gitlint: checking commit message...
-----------------------------------------------
gitlint: Your commit message contains the above violations.
gitlint: Your commit message contains violations.
Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)] gitlint: checking commit message...
-----------------------------------------------
gitlint: Your commit message contains the above violations.
gitlint: Your commit message contains violations.
Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)] gitlint: checking commit message...
-----------------------------------------------
gitlint: Your commit message contains the above violations.
gitlint: Your commit message contains violations.
Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)] Commit aborted.
Your commit message:
-----------------------------------------------

View file

@ -1,4 +1,4 @@
gitlint: checking commit message...
-----------------------------------------------
gitlint: Your commit message contains the above violations.
gitlint: Your commit message contains violations.
Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)] Editing only possible when --msg-filename is specified.

View file

@ -1,6 +1,6 @@
gitlint: checking commit message...
-----------------------------------------------
gitlint: Your commit message contains the above violations.
gitlint: Your commit message contains violations.
Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)] Commit aborted.
Your commit message:
-----------------------------------------------

View file

@ -1,5 +1,5 @@
gitlint: checking commit message...
-----------------------------------------------
gitlint: Your commit message contains the above violations.
gitlint: Your commit message contains violations.
Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)]
Aborted!

View file

@ -1,5 +1,5 @@
gitlint: checking commit message...
-----------------------------------------------
gitlint: Your commit message contains the above violations.
gitlint: Your commit message contains violations.
Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)]
Aborted!

View file

@ -1,4 +1,4 @@
gitlint: checking commit message...
-----------------------------------------------
gitlint: Your commit message contains the above violations.
gitlint: Your commit message contains violations.
Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)]

View file

@ -126,6 +126,16 @@ class BodyRuleTests(BaseTestCase):
violations = rule.validate(commit)
self.assertListEqual(violations, [expected_violation])
def test_body_missing_multiple_empty_new_lines(self):
rule = rules.BodyMissing()
# body is too short
expected_violation = rules.RuleViolation("B6", "Body message is missing", None, 3)
commit = self.gitcommit("Tïtle\n\n\n\n")
violations = rule.validate(commit)
self.assertListEqual(violations, [expected_violation])
def test_body_missing_merge_commit(self):
rule = rules.BodyMissing()

View file

@ -71,7 +71,7 @@ def getpreferredencoding():
# This scenario is fairly common on Windows where git sets LC_CTYPE=C when invoking the commit-msg hook, which
# is not a valid encoding in Python on Windows.
try:
codecs.lookup(default_encoding)
codecs.lookup(default_encoding) # pylint: disable=no-member
except LookupError:
default_encoding = fallback_encoding

View file

@ -85,7 +85,7 @@ is-revert-commit: False
Branches: ['master']
Changed Files: {changed_files}
-----------------------
1: CC1 Body does not contain a 'Signed-Off-By' line
1: CC1 Body does not contain a 'Signed-off-by' line
1: CT1 Title does not start with one of fix, feat, chore, docs, style, refactor, perf, test, revert, ci, build
1: T3 Title has trailing punctuation (.)
1: T5 Title contains the word 'WIP' (case-insensitive)

View file

@ -1,4 +1,4 @@
1: CC1 Body does not contain a 'Signed-Off-By' line
1: CC1 Body does not contain a 'Signed-off-by' line
1: CT1 Title does not start with one of fix, feat, chore, docs, style, refactor, perf, test, revert, ci, build: "WIP Thi$ is å title"
1: CT1 Title does not follow ConventionalCommits.org format 'type(optional-scope): description': "WIP Thi$ is å title"
1: T5 Title contains the word 'WIP' (case-insensitive): "WIP Thi$ is å title"

View file

@ -1,4 +1,4 @@
1: CC1 Body does not contain a 'Signed-Off-By' line
1: CC1 Body does not contain a 'Signed-off-by' line
1: CT1 Title does not start with one of föo, bår: "WIP Thi$ is å title"
1: CT1 Title does not follow ConventionalCommits.org format 'type(optional-scope): description': "WIP Thi$ is å title"
1: T5 Title contains the word 'WIP' (case-insensitive): "WIP Thi$ is å title"

View file

@ -1,5 +1,5 @@
1: T5 Title contains the word 'WIP' (case-insensitive): "WIP: Thi$ is å title"
1: UC2 Body does not contain a 'Signed-Off-By' line
1: UC2 Body does not contain a 'Signed-off-by' line
1: UC3 Branch name 'master' does not start with one of ['feature/', 'hotfix/', 'release/']
1: UL1 Title contains the special character '$': "WIP: Thi$ is å title"
2: B4 Second line is not empty: "Content on the second line"

View file

@ -1,4 +1,4 @@
1: UC2 Body does not contain a 'Signed-Off-By' line
1: UC2 Body does not contain a 'Signed-off-by' line
1: UC3 Branch name 'master' does not start with one of ['feature/', 'hotfix/', 'release/']
1: UL1 Title contains the special character '$'
2: B4 Second line is not empty

View file

@ -1,6 +1,6 @@
1: T5 Title contains the word 'WIP' (case-insensitive): "WIP: Thi$ is å title"
1: UC1 Body contains too many lines (2 > 1)
1: UC2 Body does not contain a 'Signed-Off-By' line
1: UC2 Body does not contain a 'Signed-off-by' line
1: UC3 Branch name 'master' does not start with one of ['feature/', 'hotfix/', 'release/']
1: UL1 Title contains the special character '$': "WIP: Thi$ is å title"
2: B4 Second line is not empty: "Content on the second line"

View file

@ -1,4 +1,4 @@
sh==1.14.1
pytest==6.1.2;
arrow==0.17.0;
pytest==6.2.3;
arrow==1.0.3;
gitlint # no version as you want to test the currently installed version

View file

@ -14,7 +14,7 @@ class HookTests(BaseTestCase):
u'2: B4 Second line is not empty: "Contënt on the second line"\n',
'3: B6 Body message is missing\n',
'-----------------------------------------------\n',
'gitlint: \x1b[31mYour commit message contains the above violations.\x1b[0m\n']
'gitlint: \x1b[31mYour commit message contains violations.\x1b[0m\n']
def setUp(self):
self.responses = []
@ -48,7 +48,7 @@ class HookTests(BaseTestCase):
def _interact(self, line, stdin):
self.githook_output.append(line)
# Answer 'yes' to question to keep violating commit-msg
if "Your commit message contains the above violations" in line:
if "Your commit message contains violations" in line:
response = self.responses[self.response_index]
stdin.put(f"{response}\n")
self.response_index = (self.response_index + 1) % len(self.responses)

View file

@ -1,5 +1,5 @@
setuptools
wheel==0.35.1
wheel==0.36.2
Click==7.1.2
sh==1.14.1; sys_platform != 'win32' # sh is not supported on windows
arrow==0.17.0
arrow==1.0.3

View file

@ -60,7 +60,7 @@ setup(
python_requires=">=3.6",
install_requires=[
'Click==7.1.2',
'arrow==0.17.0',
'arrow==1.0.3',
],
extras_require={
':sys_platform != "win32"': [

View file

@ -1,8 +1,8 @@
flake8==3.8.4
coverage==5.3
python-coveralls==2.9.2
radon==4.3.2
flake8==3.9.1
coverage==5.5
python-coveralls==2.9.3
radon==4.5.0
flake8-polyfill==1.0.2 # Required when installing both flake8 and radon>=4.3.1
pytest==6.1.2;
pylint==2.6.0;
pytest==6.2.3;
pylint==2.7.4;
-e .