--tag-callback only executes on annotated tags, not lightweight tags
Context on annotated vs lightweight tags.
So, the fuller story here goes:
- We use GitHub Enterprise internally
- We use tags that start with
vto indicate a release. For example,v1.2.3. Sometimesv1.2.3.4depending on the use case. Can have as many parts as one wants. Can also have a suffix, as well as a numerical one. E.g.v.1.2.3-suffixis less thanv1.2.4-suffixand both of these are incommensurable with - Our CI system interacts with GHES via the API to make releases, which makes tags when they don't exist.
- Apparently, any time this happens / is done on the GHES web UI, it's a lightweight tag. GitHub doesn't care about the above link.
¯\_(ツ)_/¯
- Apparently, any time this happens / is done on the GHES web UI, it's a lightweight tag. GitHub doesn't care about the above link.
- I want to rename all the tags to have a suffix, since I'm merging repos, and I want to reference the old tag at least if the tag is a "full" (e.g. annotated) tag.
- I can't use
--tag-renamesince that only does prefixes (maybe I should do another feature request that expands--tag-renameto a full callback, so one can just f-string rather than be limited to prefixes and suffixes)? - I can't use
--tag-callbackbecause it only acts upon annotated tags.- Even on the annotated tags, changing the ref here only creates a new tag.
- It would be nice, but not a "dealbreaker", to be able to reference the tag information in
--commit-callbackif it exists, and add that information to the commit, in the case of lightweight and/or annotated tags (if annotated, would be nice to be able to access more than just the tag-ref-name.
- I can't use
For now, to be perfectly honest, I'm just hard-code-changing the content of my installed git-filter-repo's _do_tag_rename function to act upon a python format-string, since it is the easiest path forward to get my minimum requirement (all tags renamed with a suffix, annotated tag messages backreferencing the old annotated tag via --tag-callback).
@staticmethod
def _do_tag_rename(rename_str, tagname):
if not tagname.startswith(b'refs/tags/'):
return tagname
tagname = tagname.removeprefix(b'refs/tags/').decode()
return ("refs/tags/" + rename_str.decode().format(tagname=tagname)).encode()
Why not use --refname-callback? e.g.
git filter-repo --refname-callback '
if not refname.startswith(b'refs/tags/'):
return refname
# whatever logic you want to rename the tag, including using f-strings and whatnot
'
I'll try this out. I assume this will work for renaming the lightweight tags, but in general it's still a bit unexpected that the --tag-callback only works on annotated tags and silently ignores the lightweight ones (especially since it appears as though at least GH decided to use lightweight ones instead of annotated ones for releases).
I'm okay with this as a solution as I assume it gets me to where I need, but I think the docs should be updated to reflect that due to compatibility purposes (or whatever), --tag-callback only acts upon annotated tags.
Sorry for the delay.
I'll try this out. I assume this will work for renaming the lightweight tags, but in general it's still a bit unexpected that the --tag-callback only works on annotated tags and silently ignores the lightweight ones (especially since it appears as though at least GH decided to use lightweight ones instead of annotated ones for releases).
I'm okay with this as a solution as I assume it gets me to where I need, but I think the docs should be updated to reflect that due to compatibility purposes (or whatever), --tag-callback only acts upon annotated tags.
The docs actually do already cover this:
--tag-callback <function_body>::
Python code body for processing tag objects
But I see how the distinction between a tag reference and a tag object is a subtle point that will probably be missed by many users. Most aren't that familiar with git's object model of blobs, trees, commits, and tags, and how tag objects include a tagger and tag message and a pointer to the commit in question. Lightweight tags do not point at tag objects, they instead just point straight to a commit object, and as such, we do not have a tagger and tag message to populate the tag object with. Since the tag callback is supposed to operate on a tag object, there simply isn't anything for the tag callback to be called with or on when dealing with a lightweight tag; --tag-callback is all about operating on tag objects so lightweight tags are naturally excluded.
Anyway, I updated the docs. They now have a few extra sentences to make this clear:
--tag-callback <function_body>::
Python code body for processing tag objects; see <<CALLBACKS>>.
Note that lightweight tags have no tag object and thus are not
handled by this callback. The only thing you really could do with a
lightweight tag is rename it, but for that you should see
--refname-callback instead.