1
0
Fork 0

Merging upstream version 0.16.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 06:05:35 +01:00
parent 40df5416c1
commit 72676ec535
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
56 changed files with 615 additions and 161 deletions

View file

@ -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_single_commit(self):
""" Tests `gitlint --commits <sha>` """
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>^...<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)