From 643bc3635e75121826fb878f46ca540ce210bace Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 19 Apr 2021 15:27:09 +0200 Subject: Adding upstream version 0.15.1. Signed-off-by: Daniel Baumann --- gitlint/__init__.py | 2 +- gitlint/cli.py | 2 +- gitlint/contrib/rules/signedoff_by.py | 8 ++++---- gitlint/rules.py | 2 +- gitlint/tests/contrib/rules/test_signedoff_by.py | 12 ++++++------ gitlint/tests/expected/cli/test_cli/test_contrib_1 | 2 +- .../expected/cli/test_cli_hooks/test_hook_config_1_stdout | 2 +- .../expected/cli/test_cli_hooks/test_hook_edit_1_stdout | 6 +++--- .../cli/test_cli_hooks/test_hook_local_commit_1_stdout | 2 +- .../tests/expected/cli/test_cli_hooks/test_hook_no_1_stdout | 2 +- .../expected/cli/test_cli_hooks/test_hook_no_tty_1_stdout | 2 +- .../cli/test_cli_hooks/test_hook_stdin_violations_1_stdout | 2 +- .../tests/expected/cli/test_cli_hooks/test_hook_yes_1_stdout | 2 +- gitlint/tests/rules/test_body_rules.py | 10 ++++++++++ gitlint/utils.py | 2 +- 15 files changed, 34 insertions(+), 24 deletions(-) (limited to 'gitlint') diff --git a/gitlint/__init__.py b/gitlint/__init__.py index 9da2f8f..903e77c 100644 --- a/gitlint/__init__.py +++ b/gitlint/__init__.py @@ -1 +1 @@ -__version__ = "0.15.0" +__version__ = "0.15.1" diff --git a/gitlint/cli.py b/gitlint/cli.py index b162e5b..9b16d47 100644 --- a/gitlint/cli.py +++ b/gitlint/cli.py @@ -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"]: diff --git a/gitlint/contrib/rules/signedoff_by.py b/gitlint/contrib/rules/signedoff_by.py index c2034e7..139a1b1 100644 --- a/gitlint/contrib/rules/signedoff_by.py +++ b/gitlint/contrib/rules/signedoff_by.py @@ -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)] diff --git a/gitlint/rules.py b/gitlint/rules.py index 3dc85b7..db21e56 100644 --- a/gitlint/rules.py +++ b/gitlint/rules.py @@ -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)] diff --git a/gitlint/tests/contrib/rules/test_signedoff_by.py b/gitlint/tests/contrib/rules/test_signedoff_by.py index c92f1a6..0369cdc 100644 --- a/gitlint/tests/contrib/rules/test_signedoff_by.py +++ b/gitlint/tests/contrib/rules/test_signedoff_by.py @@ -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]) diff --git a/gitlint/tests/expected/cli/test_cli/test_contrib_1 b/gitlint/tests/expected/cli/test_cli/test_contrib_1 index cdfb821..ed21eca 100644 --- a/gitlint/tests/expected/cli/test_cli/test_contrib_1 +++ b/gitlint/tests/expected/cli/test_cli/test_contrib_1 @@ -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" diff --git a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_config_1_stdout b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_config_1_stdout index 5d3f1fc..bee014b 100644 --- a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_config_1_stdout +++ b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_config_1_stdout @@ -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! diff --git a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_edit_1_stdout b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_edit_1_stdout index fa6b3bc..b57a35a 100644 --- a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_edit_1_stdout +++ b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_edit_1_stdout @@ -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: ----------------------------------------------- diff --git a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_local_commit_1_stdout b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_local_commit_1_stdout index a95bfea..0b8e90e 100644 --- a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_local_commit_1_stdout +++ b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_local_commit_1_stdout @@ -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. diff --git a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_no_1_stdout b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_no_1_stdout index 9cc53c1..98a83b1 100644 --- a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_no_1_stdout +++ b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_no_1_stdout @@ -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: ----------------------------------------------- diff --git a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_no_tty_1_stdout b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_no_tty_1_stdout index 5d3f1fc..bee014b 100644 --- a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_no_tty_1_stdout +++ b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_no_tty_1_stdout @@ -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! diff --git a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_stdin_violations_1_stdout b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_stdin_violations_1_stdout index 5d3f1fc..bee014b 100644 --- a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_stdin_violations_1_stdout +++ b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_stdin_violations_1_stdout @@ -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! diff --git a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_yes_1_stdout b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_yes_1_stdout index bb753b0..0414712 100644 --- a/gitlint/tests/expected/cli/test_cli_hooks/test_hook_yes_1_stdout +++ b/gitlint/tests/expected/cli/test_cli_hooks/test_hook_yes_1_stdout @@ -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)] \ No newline at end of file diff --git a/gitlint/tests/rules/test_body_rules.py b/gitlint/tests/rules/test_body_rules.py index 96ae998..a268585 100644 --- a/gitlint/tests/rules/test_body_rules.py +++ b/gitlint/tests/rules/test_body_rules.py @@ -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() diff --git a/gitlint/utils.py b/gitlint/utils.py index 6976aac..c91184b 100644 --- a/gitlint/utils.py +++ b/gitlint/utils.py @@ -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 -- cgit v1.2.3