Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

get all the lightweight tags created for a specific annotated tag #1940

Unanswered
AlesyaSeliazniova30032012 asked this question in Q&A
Discussion options

Hi, I created 2 annotated tag for one commit and manually added different lightweight tags to these annotated tags.
I want to get all the lightweight tags created for a specific annotated tag. For example : annotated_tag1 - lw_tag1, lw_tag2.
How can this be done using GitPython? Thanks

You must be logged in to vote

Replies: 2 comments · 1 reply

Comment options

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}")
You must be logged in to vote
1 reply
@AlesyaSeliazniova30032012
Comment options

Thank you. Yes, I already realized that I need to look for a commit dependency). I made it like your code

Comment options

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

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.