tag¶
For git-tag(1).
Overview¶
Manage git tags using GitTagManager (collection-level) and GitTagCmd (per-tag operations).
Example¶
from libvcs.cmd.git import Git git = Git(path='/path/to/repo') # Create a tag git.tags.create(name='v1.0.0', message='Release 1.0.0') # List all tags tags = git.tags.ls() # Filter tags release_tags = git.tags.ls(pattern='v*') # Get a specific tag and operate on it tag = git.tags.get(tag_name='v1.0.0') tag.show() tag.delete() API Reference¶
- class libvcs.cmd.git.GitTagManager(*, path, cmd=None)[source]¶
Bases:
objectTraverse and manage git tags with ORM-like filtering via QueryList.
Wrap some of git-tag(1), manager.
- Parameters:
Examples
>>> GitTagManager(path=tmp_path) <GitTagManager path=...>
>>> GitTagManager(path=tmp_path).run() 'fatal: not a git repository (or any of the parent directories): .git'
>>> mgr = GitTagManager(path=example_git_repo.path) >>> mgr.create(name='init-doctest-tag', message='For doctest') '' >>> mgr.run() '...init-doctest-tag...'
- __init__(*, path, cmd=None)[source]¶
Wrap some of git-tag(1), manager.
- Parameters:
- Return type:
None
Examples
>>> GitTagManager(path=tmp_path) <GitTagManager path=...>
>>> GitTagManager(path=tmp_path).run() 'fatal: not a git repository (or any of the parent directories): .git'
>>> mgr = GitTagManager(path=example_git_repo.path) >>> mgr.create(name='init-doctest-tag', message='For doctest') '' >>> mgr.run() '...init-doctest-tag...'
- path:
Path¶ Directory to check out
- run(command=None, local_flags=None, *, log_in_real_time=False, check_returncode=None, **kwargs)[source]¶
Run a command against a git repository’s tags.
Wraps git tag.
- Return type:
- Parameters:
Examples
>>> mgr = GitTagManager(path=example_git_repo.path) >>> mgr.create(name='run-doctest-tag', message='For doctest') '' >>> mgr.run() '...run-doctest-tag...'
- create(*, name, ref=None, message=None, annotate=None, sign=None, local_user=None, force=None, file=None, log_in_real_time=False, check_returncode=None)[source]¶
Git tag create.
- Parameters:
name (
str) – Name of the tag to createref (
str|None) – Git reference (commit, branch) to tag. Defaults to HEAD.message (
str|None) – Tag message (implies annotated tag)local_user (
str|None) – Use specific GPG key for signingfile (
str|PathLike[str] |None) – Read message from filelog_in_real_time (bool)
check_returncode (bool | None)
- Return type:
Examples
Create a lightweight tag:
>>> GitTagManager(path=example_git_repo.path).create(name='lightweight-tag') ''
Create an annotated tag:
>>> GitTagManager(path=example_git_repo.path).create( ... name='annotated-tag', message='This is an annotated tag' ... ) ''
Create a tag on a specific commit:
>>> GitTagManager(path=example_git_repo.path).create( ... name='ref-tag', ref='HEAD', message='Tag at HEAD' ... ) ''
- _ls(*, pattern=None, sort=None, contains=None, no_contains=None, merged=None, no_merged=None, lines=None)[source]¶
List tags (raw output).
- Return type:
- Parameters:
Examples
>>> GitTagManager(path=example_git_repo.path).create( ... name='list-tag-1', message='First tag' ... ) '' >>> GitTagManager(path=example_git_repo.path).create( ... name='list-tag-2', message='Second tag' ... ) '' >>> 'list-tag-1' in GitTagManager(path=example_git_repo.path)._ls() True
- ls(*, pattern=None, sort=None, contains=None, no_contains=None, merged=None, no_merged=None)[source]¶
List tags.
- Parameters:
pattern (
str|None) – List tags matching pattern (shell wildcard)sort (
str|None) – Sort by key (e.g., ‘version:refname’, ‘-creatordate’)contains (
str|None) – Only tags containing the specified commitno_contains (
str|None) – Only tags not containing the specified commitmerged (
str|None) – Only tags merged into the specified commitno_merged (
str|None) – Only tags not merged into the specified commit
- Return type:
Examples
>>> GitTagManager(path=example_git_repo.path).create( ... name='ls-tag', message='Listing tag' ... ) '' >>> tags = GitTagManager(path=example_git_repo.path).ls() >>> any(t.tag_name == 'ls-tag' for t in tags) True
- get(*args, **kwargs)[source]¶
Get tag via filter lookup.
Examples
Create a tag first:
>>> GitTagManager(path=example_git_repo.path).create( ... name='get-tag', message='Get this tag' ... ) ''
>>> GitTagManager( ... path=example_git_repo.path ... ).get(tag_name='get-tag') <GitTagCmd path=... tag_name=get-tag>
>>> GitTagManager( ... path=example_git_repo.path ... ).get(tag_name='unknown') Traceback (most recent call last): exec(compile(example.source, filename, "single", ... return self.ls().get(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "..._internal/query_list.py", line ..., in get raise ObjectDoesNotExist libvcs._internal.query_list.ObjectDoesNotExist
- filter(*args, **kwargs)[source]¶
Get tags via filter lookup.
Examples
>>> GitTagManager(path=example_git_repo.path).create( ... name='filter-tag-a', message='Filter tag A' ... ) '' >>> GitTagManager(path=example_git_repo.path).create( ... name='filter-tag-b', message='Filter tag B' ... ) ''
>>> len(GitTagManager( ... path=example_git_repo.path ... ).filter(tag_name__contains='filter-tag')) >= 2 True
>>> GitTagManager( ... path=example_git_repo.path ... ).filter(tag_name__contains='unknown') []
- class libvcs.cmd.git.GitTagCmd(*, path, tag_name, cmd=None)[source]¶
Bases:
objectRun git commands targeting a specific tag.
Lite, typed, pythonic wrapper for git-tag(1).
- Parameters:
Examples
>>> GitTagCmd( ... path=example_git_repo.path, ... tag_name='v1.0.0', ... ) <GitTagCmd path=... tag_name=v1.0.0>
- __init__(*, path, tag_name, cmd=None)[source]¶
Lite, typed, pythonic wrapper for git-tag(1).
- Parameters:
- Return type:
None
Examples
>>> GitTagCmd( ... path=example_git_repo.path, ... tag_name='v1.0.0', ... ) <GitTagCmd path=... tag_name=v1.0.0>
- path:
Path¶ Directory to check out
- run(command=None, local_flags=None, *, log_in_real_time=False, check_returncode=None, **kwargs)[source]¶
Run command against a git tag.
Wraps git tag.
- Return type:
- Parameters:
Examples
>>> GitTagManager(path=example_git_repo.path).create( ... name='test-tag', message='Test tag' ... ) '' >>> GitTagCmd( ... path=example_git_repo.path, ... tag_name='test-tag', ... ).run() '...test-tag...'
- delete(*, log_in_real_time=False, check_returncode=None)[source]¶
Git tag delete.
Examples
Create a tag first:
>>> GitTagManager(path=example_git_repo.path).create( ... name='delete-me', message='Tag to delete' ... ) ''
Now delete it:
>>> GitTagCmd( ... path=example_git_repo.path, ... tag_name='delete-me', ... ).delete() "Deleted tag 'delete-me'..."
- verify(*, log_in_real_time=False, check_returncode=None)[source]¶
Git tag verify.
Verify a GPG-signed tag.
Examples
First create a lightweight tag:
>>> GitTagManager(path=example_git_repo.path).create(name='verify-tag') ''
Try to verify it (lightweight tags can’t be verified):
>>> GitTagCmd( ... path=example_git_repo.path, ... tag_name='verify-tag', ... ).verify() 'error: verify-tag: cannot verify a non-tag object...'
- show(*, log_in_real_time=False, check_returncode=None)[source]¶
Show tag details using git show.
Examples
Create an annotated tag first:
>>> GitTagManager(path=example_git_repo.path).create( ... name='show-tag', message='Show this tag' ... ) ''
Show the tag:
>>> print(GitTagCmd( ... path=example_git_repo.path, ... tag_name='show-tag', ... ).show()) tag show-tag Tagger: ... Show this tag ...