notes¶
For git-notes(1).
Overview¶
Manage git notes using GitNotesManager (collection-level)
and GitNoteCmd (per-note operations).
Example¶
from libvcs.cmd.git import Git
git = Git(path='/path/to/repo')
# Add a note to a commit
git.notes.add(object='HEAD', message='This is a note')
# List all notes
notes = git.notes.ls()
# Get a specific note and operate on it
note = git.notes.get(object='HEAD')
note.show()
note.append(message='Additional info')
note.remove()
# Prune notes for non-existent objects
git.notes.prune()
API Reference¶
- class libvcs.cmd.git.GitNotesManager(*, path, cmd=None, ref=None)[source]¶
Bases:
objectTraverse and manage git notes with ORM-like filtering via QueryList.
Wrap some of git-notes(1), manager.
- Parameters:
Examples
>>> GitNotesManager(path=tmp_path) <GitNotesManager path=...>
>>> GitNotesManager(path=tmp_path).run('list') 'fatal: not a git repository (or any of the parent directories): .git'
>>> GitNotesManager(path=example_git_repo.path).run('list') ''
- __init__(*, path, cmd=None, ref=None)[source]¶
Wrap some of git-notes(1), manager.
- Parameters:
- Return type:
None
Examples
>>> GitNotesManager(path=tmp_path) <GitNotesManager path=...>
>>> GitNotesManager(path=tmp_path).run('list') 'fatal: not a git repository (or any of the parent directories): .git'
>>> GitNotesManager(path=example_git_repo.path).run('list') ''
-
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 notes.
Wraps git notes.
- Return type:
- Parameters:
Examples
>>> GitNotesManager(path=example_git_repo.path).run('list') ''
- add(object_sha='HEAD', *, message=None, file=None, force=False, allow_empty=False, log_in_real_time=False, check_returncode=None)[source]¶
Add a note to an object.
- Parameters:
- Return type:
Examples
>>> result = GitNotesManager(path=example_git_repo.path).add( ... message='Test note', force=True ... ) >>> 'error' in result.lower() or 'Overwriting' in result or result == '' True
- prune(*, dry_run=False, verbose=False, log_in_real_time=False, check_returncode=None)[source]¶
Prune notes for non-existing objects.
- Parameters:
- Return type:
Examples
>>> GitNotesManager(path=example_git_repo.path).prune() ''
>>> GitNotesManager(path=example_git_repo.path).prune(dry_run=True) ''
- merge(notes_ref=None, *, strategy=None, commit=False, abort=False, quiet=False, verbose=False, log_in_real_time=False, check_returncode=None)[source]¶
Merge notes from another ref.
Git notes merge has three mutually exclusive forms:
git notes merge [-s <strategy>] <notes-ref>- Start a mergegit notes merge --commit- Finalize in-progress mergegit notes merge --abort- Abort in-progress merge
- Parameters:
notes_ref (
str|None) – Notes ref to merge from. Required for starting a merge, must be None when using commit or abort.strategy (
str|None) – Merge strategy (manual, ours, theirs, union, cat_sort_uniq). Only valid when starting a merge with notes_ref.commit (
bool) – Finalize in-progress merge. Cannot be combined with abort or notes_ref.abort (
bool) – Abort in-progress merge. Cannot be combined with commit or notes_ref.quiet (
bool) – Suppress output.verbose (
bool) – Verbose output.log_in_real_time (bool)
check_returncode (bool | None)
- Return type:
Examples
>>> result = GitNotesManager(path=example_git_repo.path).merge( ... 'refs/notes/other' ... ) >>> 'error' in result.lower() or 'fatal' in result.lower() or result == '' True
- get_ref(*, log_in_real_time=False, check_returncode=None)[source]¶
Get the current notes ref.
Examples
>>> GitNotesManager(path=example_git_repo.path).get_ref() 'refs/notes/commits'
- _ls()[source]¶
List notes (raw output).
Returns list of (note_sha, object_sha) tuples.
Examples
>>> GitNotesManager(path=example_git_repo.path)._ls() [...]
- ls()[source]¶
List notes.
Returns a QueryList of GitNoteCmd objects.
- Return type:
Examples
>>> notes = GitNotesManager(path=example_git_repo.path).ls() >>> isinstance(notes, list) True
- class libvcs.cmd.git.GitNoteCmd(*, path, cmd=None, object_sha, note_sha=None, ref=None)[source]¶
Bases:
objectRun git commands targeting a specific note.
Lite, typed, pythonic wrapper for a git-notes(1) entry.
- Parameters:
Examples
>>> GitNoteCmd( ... path=example_git_repo.path, ... object_sha='HEAD', ... ) <GitNoteCmd path=... object_sha=HEAD>
- __init__(*, path, cmd=None, object_sha, note_sha=None, ref=None)[source]¶
Lite, typed, pythonic wrapper for a git-notes(1) entry.
- Parameters:
- Return type:
None
Examples
>>> GitNoteCmd( ... path=example_git_repo.path, ... object_sha='HEAD', ... ) <GitNoteCmd path=... object_sha=HEAD>
-
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 git notes.
Wraps git notes.
- show(*, log_in_real_time=False, check_returncode=None)[source]¶
Show the note for this object.
Examples
>>> GitNoteCmd( ... path=example_git_repo.path, ... object_sha='HEAD', ... ).show() 'error: no note found for object...'
- remove(*, ignore_missing=False, log_in_real_time=False, check_returncode=None)[source]¶
Remove the note for this object.
- Parameters:
- Return type:
Examples
>>> GitNoteCmd( ... path=example_git_repo.path, ... object_sha='HEAD', ... ).remove(ignore_missing=True) ''
- append(*, message=None, file=None, allow_empty=False, log_in_real_time=False, check_returncode=None)[source]¶
Append to the note for this object.
- Parameters:
- Return type:
Examples
>>> GitNoteCmd( ... path=example_git_repo.path, ... object_sha='HEAD', ... ).append(message='Additional note') ''
- edit(*, allow_empty=False, log_in_real_time=False, check_returncode=None, **kwargs)[source]¶
Edit the note for this object.
Note: This typically opens an editor, so it’s mostly useful in non-interactive contexts with GIT_EDITOR set.
- Parameters:
- Return type:
Examples
Use config to override editor (avoids interactive editor):
>>> result = GitNoteCmd( ... path=example_git_repo.path, ... object_sha='HEAD', ... ).edit(allow_empty=True, config={'core.editor': 'true'}) >>> 'error' in result.lower() or result == '' True
- copy(to_object, *, force=False, log_in_real_time=False, check_returncode=None)[source]¶
Copy this note to another object.
- Parameters:
- Return type:
Examples
>>> result = GitNoteCmd( ... path=example_git_repo.path, ... object_sha='HEAD', ... ).copy('HEAD', force=True) >>> 'error' in result.lower() or result == '' True