Repository navigation
fix: return no version instead of an error when no tag matches - #40
Open
nathanklick wants to merge 2 commits into
Open
nathanklick wants to merge 2 commits into
nathanklick wants to merge 2 commits into
Conversation
`findLatestVersionTag` turned "no matching tags" into a fatal error, which
made `latest` and `next` unusable on two ordinary repositories:
* a repository which has not been released yet (no tags at all), and
* a repository whose only tags are pre-releases, because the release
lookup filters pre-releases out.
`next` is affected in both cases even when a pre-release is requested,
since `Next` always resolves the latest *release* tag before it looks at
`--pre-release-tag`:
$ git-semver next --stable=false --pre-release-tag=alpha --pre-release-counter
level=fatal msg="Error while trying to find latest release version tag: no matching semantic version tags found"
Both callers already treat a nil tag as "no previous version" and fall
back to the empty version (0.0.0) — `version_log` even documents it — so
return nil instead of an error, restoring the upstream behavior.
The three integration tests covering repositories without tags were
disabled for this regression; re-enable them. The two remaining disabled
tests cover the reachability assertion this fork intentionally removed,
so they stay disabled with an accurate reason.
Signed-off-by: Nathan Klick <nathan@swirldslabs.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016kVCwjXgKkUCtQz7n1Yitd
`findLatestVersionTag` shelled out to `git rev-list --tags --max-count=1`
and discarded the result — its own comment says "We no longer need to
capture the output of the command". The call had no effect on the tags
that are considered, since those come from `repo.Tags()`, but it did make
the lookup fail outright wherever the git binary is missing or the
repository has no worktree:
exec: "git": executable file not found in $PATH
That is not hypothetical: the build stage of this repository's own
Dockerfile runs on `golang:1.24-alpine`, which does not ship git, so any
test touching this code path fails during `docker build`.
Drop the dead exec so the lookup relies on go-git alone.
Signed-off-by: Nathan Klick <nathan@swirldslabs.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016kVCwjXgKkUCtQz7n1Yitd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
findLatestVersionTagturns "no matching tags" into a fatal error, which makeslatestandnextunusable on two ordinary repositories:nextis affected in both cases even when a pre-release is requested, becauseNextalways resolves the latest release tag (FindLatestVersion(repo, filter, false), next.go:37) before it ever looks at--pre-release-tag:This bit a real release pipeline: a repository whose only tags were
v0.1.0-alpha.1..4could not compute any next version, stable or alpha, and the release workflow failed with the second error above.Fix
Return
nil, nilinstead of an error when no tag matches. Both callers already treat a nil tag as "no previous version" and fall back to the empty version (0.0.0) —version_log.goeven documents it ("fromVersionTag may be null if there is no latest version") — so this is the contract they were written against, and it matches upstreamPSanetra/git-semver. The reachability assertion this fork intentionally removed stays removed.Tests
Seven new Go tests over real on-disk repositories, all of which fail on
masterand pass here:latest: no tags → no version; only pre-release tags → no version; only pre-release tags with--include-pre-releases→ the latest pre-release; pre-releases ignored when a release tag exists.next: first version on a repo without tags; next stable version when only pre-release tags exist; pre-release counter increments when only pre-release tags exist.Three integration tests were
@Disabled("Skipping as it requires a specific version from fork source")for exactly this regression —LatestCmdTests.shouldReturnEmptyVersionOnRepoWithoutTags,LatestCmdIncludingPreReleasesTests.shouldReturnEmptyVersionOnRepoWithoutTagsandNextCmdTests.shouldReturnFirstVersionOnRepoWithoutTags— and are re-enabled. The two that remain disabled cover the reachability assertion this fork deliberately dropped; their@Disabledreason now says so instead of implying a version problem.Verification against the affected repository
Built from this branch and run against the repo that was stuck (only
v0.1.0-alpha.1..4, no stable tag):masterlatest0.0.00.0.0latest --include-pre-releases0.1.0-alpha.40.1.0-alpha.40.1.0-alpha.4next --stable=false0.1.00.1.0next --stable=false --pre-release-tag=alpha --pre-release-counter0.1.0-alpha.50.1.0-alpha.5Run from a branch where the newest tag is not reachable from HEAD, this branch still returns
0.1.0-alpha.5while upstream fatals — the fork's intended relaxation is preserved.Second commit: the
git rev-listexecAdding the tests above surfaced a second, independent failure in the same function.
findLatestVersionTagshelled out togit rev-list --tags --max-count=1and threw the result away — its own comment reads "We no longer need to capture the output of the command" — but still propagated the exec error. The tags it considers come fromrepo.Tags(), so the call changed nothing except to make the lookup fail wherever the git binary is absent:That is exactly what happens in this repository's own
Dockerfile, whose build stage isgolang:1.24-alpine— no git — soRUN go test -v -vet=off ./...fails there for any test touching this path, and with it every integration test, since they build that image. The dead exec is removed; the lookup now relies on go-git alone.Verified in the shipping image (
docker build ., thengit semverinside the container):latest0.0.0latest --include-pre-releases0.0.0next1.0.0v0.1.0-alpha.1..4,next --stable=false --pre-release-tag=alpha --pre-release-counter0.1.0-alpha.5v1.2.3+ afeatcommit,latest/next1.2.3/1.3.0(unchanged)