Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork937
get all the lightweight tags created for a specific annotated tag#1940
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hi, I created 2 annotated tag for one commit and manually added different lightweight tags to these annotated tags. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 2 comments 1 reply
-
The response of ChatGPT seems reasonable, it's reproduced here. importgit# Open the repositoryrepo=git.Repo('/path/to/your/repo')defget_lightweight_tags_for_annotated_tag(repo,annotated_tag_name):# Get the commit associated with the annotated tagannotated_tag=repo.tags[annotated_tag_name]ifannotated_tag.tag:annotated_commit=annotated_tag.tag.commitelse:raiseValueError(f"{annotated_tag_name} is not an annotated tag")# List all lightweight tags that point to the same commitlightweight_tags= []fortaginrepo.tags:iftag.tagisNoneandtag.commit==annotated_commit:lightweight_tags.append(tag.name)returnlightweight_tags# Example usageannotated_tag_name='annotated_tag1'lw_tags=get_lightweight_tags_for_annotated_tag(repo,annotated_tag_name)print(f"Lightweight tags for{annotated_tag_name}:{lw_tags}") |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thank you. Yes, I already realized that I need to look for a commit dependency). I made it like your code |
BetaWas this translation helpful?Give feedback.
All reactions
-
Just the thought of the question was as follows: is it possible to create several annotated tags within one commit, and register your own lightweight tags for each one. and so that the annotated tags are linked to the corresponding lightweight tags. But as far as I understand, everything is related to commit, and only through commit can you get all the tags associated with it |
BetaWas this translation helpful?Give feedback.