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¶
Bases:
objectTraverse and manage git notes with ORM-like filtering via QueryList.
Wrap some of git-notes(1), manager.
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') ''
Run a command against a git repository’s notes.
Wraps git notes.
Examples
>>> GitNotesManager(path=example_git_repo.path).run('list') ''
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 notes for non-existing objects.
Examples
>>> GitNotesManager(path=example_git_repo.path).prune() ''
>>> GitNotesManager(path=example_git_repo.path).prune(dry_run=True) ''
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)
- 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 the current notes ref.
Examples
>>> GitNotesManager(path=example_git_repo.path).get_ref() 'refs/notes/commits'
List notes (raw output).
Returns list of (note_sha, object_sha) tuples.
Examples
>>> GitNotesManager(path=example_git_repo.path)._ls() [...]
List notes.
Returns a QueryList of GitNoteCmd objects.
Examples
>>> notes = GitNotesManager(path=example_git_repo.path).ls() >>> isinstance(notes, list) True
- Return type:
Get note via filter lookup.
Examples
>>> GitNotesManager(path=example_git_repo.path).get(object_sha='HEAD') Traceback (most recent call last): ... libvcs._internal.query_list.ObjectDoesNotExist
- Parameters:
- Return type:
Bases:
objectRun git commands targeting a specific note.
Lite, typed, pythonic wrapper for a git-notes(1) entry.
Examples
>>> GitNoteCmd( ... path=example_git_repo.path, ... object_sha='HEAD', ... ) <GitNoteCmd path=... object_sha=HEAD>
Run command against git notes.
Wraps git notes.
Show the note for this object.
Examples
>>> GitNoteCmd( ... path=example_git_repo.path, ... object_sha='HEAD', ... ).show() 'error: no note found for object...'
Append to the note for this object.
Examples
>>> GitNoteCmd( ... path=example_git_repo.path, ... object_sha='HEAD', ... ).append(message='Additional note') ''
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.
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 this note to another object.
Examples
>>> result = GitNoteCmd( ... path=example_git_repo.path, ... object_sha='HEAD', ... ).copy('HEAD', force=True) >>> 'error' in result.lower() or result == '' True