summaryrefslogtreecommitdiffstats
path: root/qa/test_commits.py
diff options
context:
space:
mode:
Diffstat (limited to 'qa/test_commits.py')
-rw-r--r--qa/test_commits.py47
1 files changed, 44 insertions, 3 deletions
diff --git a/qa/test_commits.py b/qa/test_commits.py
index 389ad66..92e1087 100644
--- a/qa/test_commits.py
+++ b/qa/test_commits.py
@@ -40,19 +40,60 @@ 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")
+ first_commit_sha = self.get_last_commit_hash()
self.create_simple_commit("Sïmple title2.\n")
commit_sha = self.get_last_commit_hash()
refspec = f"{commit_sha}^...{commit_sha}"
self.create_simple_commit("Sïmple title3.\n")
- output = gitlint("--commits", refspec, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2])
+
expected = ("1: T3 Title has trailing punctuation (.): \"Sïmple title2.\"\n" +
"3: B6 Body message is missing\n")
+
+ # Lint using --commit <commit sha>
+ output = gitlint("--commit", commit_sha, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2])
self.assertEqual(output.exit_code, 2)
self.assertEqualStdout(output, expected)
+ # Lint a single commit using --commits <refspec> pointing to the single commit
+ output = gitlint("--commits", refspec, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2])
+ self.assertEqual(output.exit_code, 2)
+ self.assertEqualStdout(output, expected)
+
+ # Lint the first commit in the repository. This is a use-case that is not supported by --commits
+ # As <sha>^...<sha> is not correct refspec in case <sha> points to the initial commit (which has no parents)
+ expected = ("1: T3 Title has trailing punctuation (.): \"Sïmple title.\"\n" +
+ "3: B6 Body message is missing\n")
+ output = gitlint("--commit", first_commit_sha, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2])
+ self.assertEqual(output.exit_code, 2)
+ self.assertEqualStdout(output, expected)
+
+ # Assert that indeed --commits <refspec> is not supported when <refspec> points the the first commit
+ refspec = f"{first_commit_sha}^...{first_commit_sha}"
+ output = gitlint("--commits", refspec, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[254])
+ self.assertEqual(output.exit_code, 254)
+
def test_lint_staged_stdin(self):
""" Tests linting a staged commit. Gitint should lint the passed commit message andfetch additional meta-data
from the underlying repository. The easiest way to test this is by inspecting `--debug` output.
@@ -139,7 +180,7 @@ class CommitsTests(BaseTestCase):
self.assertEqualStdout(output, self.get_expected("test_commits/test_lint_head_1", expected_kwargs))
def test_ignore_commits(self):
- """ Tests multiple commits of which some rules get igonored because of ignore-* rules """
+ """ Tests multiple commits of which some rules get ignored because of ignore-* rules """
# Create repo and some commits
tmp_git_repo = self.create_tmp_git_repo()
self.create_simple_commit("Sïmple title.\n\nSimple bödy describing the commit", git_repo=tmp_git_repo)