diff --git a/CHANGELOG.md b/CHANGELOG.md index a29113d..b9145b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/dunamai/__init__.py b/dunamai/__init__.py index c95f533..e09e4b4 100644 --- a/dunamai/__init__.py +++ b/dunamai/__init__.py @@ -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)] diff --git a/tests/integration/test_dunamai.py b/tests/integration/test_dunamai.py index 932d030..ea1af52 100644 --- a/tests/integration/test_dunamai.py +++ b/tests/integration/test_dunamai.py @@ -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"