summaryrefslogtreecommitdiffstats
path: root/gitlint-core/gitlint/tests/rules/test_configuration_rules.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitlint-core/gitlint/tests/rules/test_configuration_rules.py')
-rw-r--r--gitlint-core/gitlint/tests/rules/test_configuration_rules.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/gitlint-core/gitlint/tests/rules/test_configuration_rules.py b/gitlint-core/gitlint/tests/rules/test_configuration_rules.py
index 9e3b07c..5935a4a 100644
--- a/gitlint-core/gitlint/tests/rules/test_configuration_rules.py
+++ b/gitlint-core/gitlint/tests/rules/test_configuration_rules.py
@@ -1,6 +1,9 @@
-from gitlint.tests.base import BaseTestCase, EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING
from gitlint import rules
from gitlint.config import LintConfig
+from gitlint.tests.base import (
+ EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING,
+ BaseTestCase,
+)
class ConfigurationRuleTests(BaseTestCase):
@@ -89,6 +92,25 @@ class ConfigurationRuleTests(BaseTestCase):
self.assertEqual(config, LintConfig())
self.assert_logged([]) # nothing logged -> nothing ignored
+ # No author available -> rule is skipped and warning logged
+ staged_commit = self.gitcommit("Tïtle\n\nThis is\n a relëase body\n line")
+ rule = rules.IgnoreByAuthorName({"regex": "foo"})
+ config = LintConfig()
+ rule.apply(config, staged_commit)
+ self.assertEqual(config, LintConfig())
+ expected_log_messages = [
+ "WARNING: gitlint.rules ignore-by-author-name - I4: skipping - commit.author_name unknown. "
+ "Suggested fix: Use the --staged flag (or set general.staged=True in .gitlint). "
+ "More details: https://jorisroovers.com/gitlint/configuration/#staged"
+ ]
+ self.assert_logged(expected_log_messages)
+
+ # Non-Matching regex -> expect config to stay the same
+ rule = rules.IgnoreByAuthorName({"regex": "foo"})
+ expected_config = LintConfig()
+ rule.apply(config, commit)
+ self.assertEqual(config, LintConfig())
+
# Matching regex -> expect config to ignore all rules
rule = rules.IgnoreByAuthorName({"regex": "(.*)ëst(.*)"})
expected_config = LintConfig()
@@ -96,7 +118,7 @@ class ConfigurationRuleTests(BaseTestCase):
rule.apply(config, commit)
self.assertEqual(config, expected_config)
- expected_log_messages = [
+ expected_log_messages += [
EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("I4", "ignore-by-author-name"),
"DEBUG: gitlint.rules Ignoring commit because of rule 'I4': "
"Commit Author Name 'Tëst nåme' matches the regex '(.*)ëst(.*)',"