Skip to content

Commit

Permalink
Fix invalid tag check for lightweight tags
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-dG committed Dec 18, 2019
1 parent 0a1465c commit eb76c48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tagbot/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ def _invalid_tag_exists(self, version: str, sha: str) -> bool:
"""Check whether or not an existing tag points at the wrong commit."""
if not git("tag", "--list", version, repo=self._dir()):
return False
expected = f"{sha} refs/tags/{version}^{{}}"
lines = git("show-ref", "-d", version, repo=self._dir()).splitlines()
return expected not in lines
# For annotated tags, there are two entries.
# The one with the ^{} suffix uses the commit hash.
expected = f"{sha} refs/tags/{version}"
return expected not in lines and f"{expected}^{{}}" not in lines

def _release_exists(self, version) -> bool:
"""Check whether or not a GitHub release exists."""
Expand Down
9 changes: 9 additions & 0 deletions test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def test_commit_from_tree(git):
"fedcba refs/tags/v2.3.4^{}",
"v3.4.5",
"abcdef refs/tags/v3.4.5^{}",
"v4.5.6",
"abcdef refs/tags/v4.5.6",
],
)
def test_invalid_tag_exists(git):
Expand All @@ -84,6 +86,13 @@ def test_invalid_tag_exists(git):
call("show-ref", "-d", "v3.4.5", repo="dir"),
]
)
assert not r._invalid_tag_exists("v4.5.6", "abcdef")
git.assert_has_calls(
[
call("tag", "--list", "v4.5.6", repo="dir"),
call("show-ref", "-d", "v4.5.6", repo="dir"),
]
)


def test_release_exists():
Expand Down

0 comments on commit eb76c48

Please sign in to comment.