diff options
author | Joris Roovers <joris.roovers@gmail.com> | 2021-09-27 12:55:50 +0200 |
---|---|---|
committer | Joris Roovers <joris.roovers@gmail.com> | 2021-09-27 13:11:54 +0200 |
commit | fe200c2e51dbd5c44f670d1a4a4f32bbc52b9a3b (patch) | |
tree | 04ac9300f4a2952cd1e44f5e2c1037c458546362 /qa | |
parent | 27671c575dfba6aecf06d8c01def73f1da23baa2 (diff) |
Implements --fail-without-commits option
Gitlint will now hard fail when passing an empty commit range via
--commits and specifying the --fail-without-commits option.
Fixes #193
Diffstat (limited to 'qa')
-rw-r--r-- | qa/base.py | 1 | ||||
-rw-r--r-- | qa/test_commits.py | 21 |
2 files changed, 21 insertions, 1 deletions
@@ -29,6 +29,7 @@ class BaseTestCase(TestCase): GITLINT_USE_SH_LIB = os.environ.get("GITLINT_USE_SH_LIB", "[NOT SET]") GIT_CONTEXT_ERROR_CODE = 254 + GITLINT_USAGE_ERROR = 253 @classmethod def setUpClass(cls): diff --git a/qa/test_commits.py b/qa/test_commits.py index 389ad66..238614c 100644 --- a/qa/test_commits.py +++ b/qa/test_commits.py @@ -40,8 +40,27 @@ class CommitsTests(BaseTestCase): expected_kwargs = {'commit_sha1': commit_sha1, 'commit_sha2': commit_sha2} self.assertEqualStdout(output, self.get_expected("test_commits/test_violations_1", expected_kwargs)) + def test_lint_empty_commit_range(self): + """ Tests `gitlint --commits <sha>^...<sha>` --fail-without-commits where the provided range is empty. """ + self.create_simple_commit("Sïmple title.\n") + self.create_simple_commit("Sïmple title2.\n") + commit_sha = self.get_last_commit_hash() + # git revspec -> 2 dots: <exclusive sha>..<inclusive sha> -> empty range when using same start and end sha + refspec = f"{commit_sha}..{commit_sha}" + + # Regular gitlint invocation should run without issues + output = gitlint("--commits", refspec, _cwd=self.tmp_git_repo, _tty_in=True) + self.assertEqual(output.exit_code, 0) + self.assertEqualStdout(output, "") + + # Gitlint should fail when --fail-without-commits is used + output = gitlint("--commits", refspec, "--fail-without-commits", _cwd=self.tmp_git_repo, _tty_in=True, + _ok_code=[self.GITLINT_USAGE_ERROR]) + self.assertEqual(output.exit_code, self.GITLINT_USAGE_ERROR) + self.assertEqualStdout(output, f"Error: No commits in range \"{refspec}\"\n") + def test_lint_single_commit(self): - """ Tests `gitlint --commits <sha>` """ + """ Tests `gitlint --commits <sha>^...<same sha>` """ self.create_simple_commit("Sïmple title.\n") self.create_simple_commit("Sïmple title2.\n") commit_sha = self.get_last_commit_hash() |