diff --git a/gitlint-core/gitlint/cli.py b/gitlint-core/gitlint/cli.py index 134fb2e2..ffd44edd 100644 --- a/gitlint-core/gitlint/cli.py +++ b/gitlint-core/gitlint/cli.py @@ -48,7 +48,7 @@ def setup_logging(): # Root log, mostly used for debug root_log = logging.getLogger("gitlint") root_log.propagate = False # Don't propagate to child loggers, the gitlint root logger handles everything - root_log.setLevel(logging.ERROR) + root_log.setLevel(logging.WARN) handler = logging.StreamHandler() formatter = logging.Formatter(LOG_FORMAT) handler.setFormatter(formatter) diff --git a/gitlint-core/gitlint/rules.py b/gitlint-core/gitlint/rules.py index 492de6d6..ca4a05bd 100644 --- a/gitlint-core/gitlint/rules.py +++ b/gitlint-core/gitlint/rules.py @@ -459,6 +459,17 @@ def apply(self, config, commit): if not self.options["regex"].value: return + # If commit.author_name is not available, log warning and return + if commit.author_name is None: + warning_msg = ( + "%s - %s: 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.log.warning(warning_msg, self.name, self.id) + return + regex_method = Deprecation.get_regex_method(self, self.options["regex"]) if regex_method(commit.author_name): diff --git a/gitlint-core/gitlint/tests/rules/test_configuration_rules.py b/gitlint-core/gitlint/tests/rules/test_configuration_rules.py index eeb74c77..d5b70a98 100644 --- a/gitlint-core/gitlint/tests/rules/test_configuration_rules.py +++ b/gitlint-core/gitlint/tests/rules/test_configuration_rules.py @@ -92,6 +92,19 @@ def test_ignore_by_author_name(self): 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) + # Matching regex -> expect config to ignore all rules rule = rules.IgnoreByAuthorName({"regex": "(.*)ëst(.*)"}) expected_config = LintConfig() @@ -99,7 +112,7 @@ def test_ignore_by_author_name(self): 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(.*)',"