GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — get all the lightweight tags created for a specific annotated tag · gitpython-developers/GitPython · Discussion #1940

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 AlesyaSeliazniova30032012
Jul 9, 2024 · 2 comments · 1 reply
Return to top
Discussion options
  • Uh oh!

    There was an error while loading. Please reload this page.

  • Uh oh!

    There was an error while loading. Please reload this page.

AlesyaSeliazniova30032012
Jul 9, 2024

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
All reactions

Replies: 2 comments · 1 reply

Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

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

    There was an error while loading. Please reload this page.

AlesyaSeliazniova30032012 Jul 9, 2024
Author

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

All reactions
Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

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

You must be logged in to vote
All reactions
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
@AlesyaSeliazniova30032012 @Byron
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.