Skip to content

Commit

Permalink
Fix: --commits returns the wrong exit code
Browse files Browse the repository at this point in the history
Before, when linting multiple commits, gitlint returned the number of
violations found in the last commit message, not e.g. the total count of
violations in all linted messages.

This fixes #27.
  • Loading branch information
jroovers-cisco committed Apr 5, 2017
1 parent e2a04bf commit 88d1c7c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion gitlint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion gitlint/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" + \
Expand Down
4 changes: 2 additions & 2 deletions qa/test_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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):
Expand Down

0 comments on commit 88d1c7c

Please sign in to comment.