list_remote_tags.py
import subprocess
def list_all_tags_for_remote_git_repo(url):
"""
Given a repository URL, list all tags for that repository
without cloning it.
This function use "git ls-remote", so the
"git" command line program must be available.
"""
# 'git'-Befehl ausführen, um Remote-Tags abzurufen und aufzulisten
result = subprocess.run([
"git", "ls-remote", "--tags", repo_url
], stdout=subprocess.PIPE, text=True)
# Ausgabe verarbeiten, um Tag-Namen zu extrahieren
output_lines = result.stdout.splitlines()
tags = [
line.split("refs/tags/")[-1] for line in output_lines
if "refs/tags/" in line and "^{}" not in line
]
return tagsVerwendungsbeispiel:
usage_example.py
list_all_tags_for_remote_git_repo("https://github.com/EmbeddedRPC/erpc.git")Ergebnis:
tags_output.txt
['1.10.0',
'1.11.0',
'1.4.0',
'1.4.1',
'1.5.0',
'1.6.0',
'1.7.0',
'1.7.1',
'1.7.2',
'1.7.3',
'1.7.4',
'1.8.0',
'1.8.1',
'1.9.0',
'1.9.1']Wenn dieser Beitrag dir geholfen hat, erwäge, mir einen Kaffee zu spendieren oder per PayPal zu spenden, um die Recherche und Veröffentlichung neuer Beiträge auf TechOverflow zu unterstützen