notes¶
For git-notes(1).
Overview¶
Manage git notes using GitNotesManager (collection-level)
and GitNoteCmd (per-note operations).
Examples¶
Add a note to the current commit (object_sha defaults to HEAD), then list
notes:
>>> from libvcs.cmd.git import Git
>>> git = Git(path=example_git_repo.path)
>>> git.notes.add(message='This is a note')
''
>>> notes = git.notes.ls()
>>> len(notes) >= 1
True
Operate on a note through its Cmd object — show it, append to it, remove it:
>>> from libvcs.cmd.git import Git
>>> git = Git(path=example_git_repo.path)
>>> git.notes.add(message='Reviewed by Alice')
''
>>> note = git.notes.ls()[0]
>>> note.show()
'Reviewed by Alice\n'
>>> note.append(message='Additional info')
''
>>> note.remove()
'...'
Prune notes attached to objects that no longer exist:
>>> from libvcs.cmd.git import Git
>>> git = Git(path=example_git_repo.path)
>>> 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', trim=True) 'fatal: not a git repository (or any of the parent directories): .git'
>>> 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(trim=True) '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>
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