Skip to content

Commit

Permalink
Fix exception when Git has a broken ref
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Feb 16, 2024
1 parent 4a3973e commit 33281c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

* Fixed an exception when a Git repository had a broken ref.
Git would print a warning that Dunamai failed to parse.

## v1.19.1 (2024-02-07)

* Relaxed Python bounds from `^3.5` to `>=3.5` since Python does not follow Semantic Versioning.
Expand Down
2 changes: 2 additions & 0 deletions dunamai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,8 @@ def from_git(

for line in msg.strip().splitlines():
parts = line.split("@{")
if len(parts) != 5:
continue
detailed_tags.append(_GitRefInfo(*parts).with_tag_topo_lookup(tag_topo_lookup))

tags = [t.ref for t in sorted(detailed_tags, key=lambda x: x.sort_key, reverse=True)]
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/test_dunamai.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,24 @@ def test__version__from_git__exclude_decoration(tmp_path) -> None:
assert from_vcs() == Version("0.1.0", dirty=False, branch=b)


def test__version__from_git__broken_ref(tmp_path) -> None:
vcs = tmp_path / "dunamai-git-broken-ref"
vcs.mkdir()
run = make_run_callback(vcs)
from_vcs = make_from_callback(Version.from_git)
b = "master"

with chdir(vcs):
run("git init")
(vcs / "foo.txt").write_text("hi")
run("git add .")
run("git commit --no-gpg-sign -m Initial")
run("git tag v0.1.0 -m Release")
(vcs / ".git/refs/tags/bad.txt").touch()

assert from_vcs() == Version("0.1.0", dirty=False, branch=b)


@pytest.mark.skipif(shutil.which("git") is None, reason="Requires Git")
def test__version__not_a_repository(tmp_path) -> None:
vcs = tmp_path / "dunamai-not-a-repo"
Expand Down

0 comments on commit 33281c8

Please sign in to comment.