diff --git a/gitlint/cli.py b/gitlint/cli.py index 3b51b27e..154d203f 100644 --- a/gitlint/cli.py +++ b/gitlint/cli.py @@ -141,8 +141,10 @@ def lint(ctx): linter = GitLinter(lint_config) first_violation = True + exit_code = 0 for commit in gitcontext.commits: violations = linter.lint(commit) + exit_code += len(violations) if violations: # Display the commit hash & new lines intelligently if number_of_commits > 1 and commit.sha: @@ -153,7 +155,7 @@ def lint(ctx): linter.print_violations(violations) first_violation = False - exit_code = min(MAX_VIOLATION_ERROR_CODE, len(violations)) + exit_code = min(MAX_VIOLATION_ERROR_CODE, exit_code) ctx.exit(exit_code) diff --git a/gitlint/tests/test_cli.py b/gitlint/tests/test_cli.py index 73a295aa..fe502d02 100644 --- a/gitlint/tests/test_cli.py +++ b/gitlint/tests/test_cli.py @@ -76,7 +76,7 @@ def test_lint_multiple_commits(self, sys, sh): u"Commit 4da2656b0d:\n" u'3: B5 Body message is too short (12<20): "commït-body3"\n') self.assertEqual(stderr.getvalue(), expected) - self.assertEqual(result.exit_code, 1) + self.assertEqual(result.exit_code, 3) def test_input_stream(self): expected_output = u"1: T2 Title has trailing whitespace: \"WIP: tïtle \"\n" + \ diff --git a/qa/test_commits.py b/qa/test_commits.py index ed3a850e..82deafbc 100644 --- a/qa/test_commits.py +++ b/qa/test_commits.py @@ -29,7 +29,7 @@ def test_violations(self): self._create_simple_commit(u"Sïmple title3.\n") commit_sha2 = self.get_last_commit_hash()[:10] output = gitlint("--commits", "test-branch-commits-violations-base...test-branch-commits-violations", - _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2]) + _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[4]) expected = (u"Commit {0}:\n".format(commit_sha2) + u"1: T3 Title has trailing punctuation (.): \"Sïmple title3.\"\n" + u"3: B6 Body message is missing\n" @@ -38,7 +38,7 @@ def test_violations(self): u"1: T3 Title has trailing punctuation (.): \"Sïmple title2.\"\n" u"3: B6 Body message is missing\n") - self.assertEqual(output.exit_code, 2) + self.assertEqual(output.exit_code, 4) self.assertEqual(output, expected) def test_single_commit(self):