Closed 13steinj closed 1 month ago
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.
Context on annotated vs lightweight tags.
So, the fuller story here goes:
v
to indicate a release. For example,v1.2.3
. Sometimesv1.2.3.4
depending 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-suffix
is less thanv1.2.4-suffix
and both of these are incommensurable with¯\_(ツ)_/¯
--tag-rename
since that only does prefixes (maybe I should do another feature request that expands--tag-rename
to a full callback, so one can just f-string rather than be limited to prefixes and suffixes)?--tag-callback
because it only acts upon annotated tags.--commit-callback
if 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.