get all the lightweight tags created for a specific annotated tag · gitpython-developers/GitPython · Discussion #1940
Repository navigation
get all the lightweight tags created for a specific annotated tag #1940
Unanswered AlesyaSeliazniova30032012 asked this question in Q&A get all the lightweight tags created for a specific annotated tag #1940 AlesyaSeliazniova30032012 Jul 9, 2024 · 2 comments · 1 reply Return to top Discussion optionsAlesyaSeliazniova30032012 Jul 9, 2024
|
Hi, I created 2 annotated tag for one commit and manually added different lightweight tags to these annotated tags. |
Replies: 2 comments 1 reply
Comment options
Byron
Jul 9, 2024
Maintainer
|
The response of ChatGPT seems reasonable, it's reproduced here. import git
# Open the repository
repo = git.Repo('/path/to/your/repo')
def get_lightweight_tags_for_annotated_tag(repo, annotated_tag_name):
# Get the commit associated with the annotated tag
annotated_tag = repo.tags[annotated_tag_name]
if annotated_tag.tag:
annotated_commit = annotated_tag.tag.commit
else:
raise ValueError(f"{annotated_tag_name} is not an annotated tag")
# List all lightweight tags that point to the same commit
lightweight_tags = []
for tag in repo.tags:
if tag.tag is None and tag.commit == annotated_commit:
lightweight_tags.append(tag.name)
return lightweight_tags
# Example usage
annotated_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}")
|
AlesyaSeliazniova30032012
Jul 10, 2024
Author
|
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 |