fix: handling of nested annotated tags#1360
Conversation
Fix handling of nested annotated tags (tags pointing to other tags instead of commits directly).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1360 +/- ##
==========================================
+ Coverage 44.14% 44.17% +0.03%
==========================================
Files 24 24
Lines 2286 2287 +1
==========================================
+ Hits 1009 1010 +1
Misses 1277 1277
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| #[test] | ||
| fn git_nested_tags() -> Result<()> { |
There was a problem hiding this comment.
Would also love to have a test fixture for this so that we would see how this behaves in the changelog generation context.
There was a problem hiding this comment.
Added a test fixture test-nested-tags that covers this scenario.
The fixture creates a 3-level nested tag chain:
v0.1.0-stable → v0.1.0-rc → v0.1.0-staging → commit
With tag_pattern = "v.*-stable$", only the nested v0.1.0-stable tag is matched. The test verifies that it correctly resolves to the underlying commit and appears in the changelog.
Without the fix, the output shows [unreleased] instead of [v0.1.0-stable] because the nested tag fails to resolve
There was a problem hiding this comment.
Also updated the fixture to show this more clearly.
Now the template strips v prefix and -stable suffix, so the changelog shows clean versions:
Tags: v0.1.0-staging → v0.1.0-rc → v0.1.0-stable
Output: ## [0.1.0] - 2022-04-06
This better reflects the actual use case — promotion workflow with clean changelog output.
There was a problem hiding this comment.
@orhun could you please review changes? Is there anything alse I can do to help you merge this PR?
Fix handling of nested annotated tags (tags pointing to other tags instead of commits directly).
Description
When an annotated tag points to another annotated tag (instead of directly to a commit), git-cliff silently skips it. This PR fixes the issue by using
obj.peel(ObjectType::Commit)to follow the entire chain of tag objects until reaching the final commit.Motivation and Context
In some workflows, tags are "promoted" by creating new tags pointing to existing ones. For example:
v1.0.0-stable -> v1.0.0-rc (tag) -> v1.0.0-staging (tag) -> commit
The current code uses
tag.target().into_commit()which only resolves one level of indirection. When the target is another tag object (not a commit),into_commit()fails and the tag is silently skipped from the changelog.How Has This Been Tested?
Added
git_nested_tagstest that:v1.0.0-stagingpointing to the commitv1.0.0-stablepointing tov1.0.0-stagingv1.0.0-stablecorrectly resolves to the original commitThe test fails without the fix and passes with it.
Screenshots / Logs (if applicable)
Before fix - nested tag is missing:
After fix - nested tag is included correctly.
Types of Changes
Checklist:
cargo +nightly fmt --allcargo clippy --tests --verbose -- -D warningscargo test