Ref handling.
| Class | |
RefsContainer backed by a simple dict. |
| Class | |
Refs container that reads refs from disk. |
| Class | locked |
Lock a ref while making modifications. |
| Class | |
Wrapper that adds namespace prefix to all ref operations. |
| Class | |
A container for refs. |
| Exception | |
There is a loop between one or more symrefs. |
| Function | check |
Check if a refname is correctly formatted. |
| Function | extract |
Extract branch name from a full branch ref. |
| Function | extract |
Extract tag name from a full tag ref. |
| Function | filter |
Filter refs to only include those with a given prefix. |
| Function | is |
Check if a ref name is a local branch. |
| Function | is |
Returns whether a reference is stored per worktree or not. |
| Function | local |
Build a full branch ref from a short name. |
| Function | local |
Build a full replace ref from a short name. |
| Function | local |
Build a full tag ref from a short name. |
| Function | parse |
Parse a remote ref into remote name and branch name. |
| Function | parse |
Parse a symref value. |
| Function | read |
Read info/refs file. |
| Function | read |
Read a packed refs file. |
| Function | read |
Read a packed refs file including peeled refs. |
| Function | set |
Set a reference from a raw ref value. |
| Function | shorten |
Convert a full ref name to its short form. |
| Function | write |
Write a packed refs file. |
| Constant | BAD |
Undocumented |
| Constant | HEADREF |
Undocumented |
| Constant | LOCAL |
Undocumented |
| Constant | LOCAL |
Undocumented |
| Constant | LOCAL |
Undocumented |
| Constant | LOCAL |
Undocumented |
| Constant | LOCAL |
Undocumented |
| Constant | SYMREF |
Undocumented |
| Type Variable | T |
Undocumented |
| Variable | |
Undocumented |
| Function | _import |
Undocumented |
| Function | _set |
Set the default branch. |
| Function | _set |
Undocumented |
| Function | _set |
Undocumented |
| Function | _split |
Split a single ref line into a tuple of SHA1 and name. |
Check if a refname is correctly formatted.
Implements all the same rules as git-check-ref-format[1].
[1] http://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
Returns: True if refname is valid, False otherwise
| Parameters | |
refname:Ref | The refname to check |
| Returns | |
bool | Undocumented |
Extract branch name from a full branch ref.
Examples
>>> extract_branch_name(b"refs/heads/master") b'master' >>> extract_branch_name(b"refs/heads/feature/foo") b'feature/foo'
| Parameters | |
ref:bytes | Full branch ref (e.g., b"refs/heads/master") |
| Returns | |
bytes | Short branch name (e.g., b"master") |
| Raises | |
ValueError | If ref is not a local branch |
Extract tag name from a full tag ref.
Examples
>>> extract_tag_name(b"refs/tags/v1.0") b'v1.0'
| Parameters | |
ref:bytes | Full tag ref (e.g., b"refs/tags/v1.0") |
| Returns | |
bytes | Short tag name (e.g., b"v1.0") |
| Raises | |
ValueError | If ref is not a local tag |
Returns whether a reference is stored per worktree or not.
Per-worktree references are: - all pseudorefs, e.g. HEAD - all references stored inside "refs/bisect/", "refs/worktree/" and "refs/rewritten/"
All refs starting with "refs/" are shared, except for the ones listed above.
Build a full replace ref from a short name.
Examples
>>> local_replace_name(b"abc123") b'refs/replace/abc123' >>> local_replace_name(b"refs/replace/abc123") b'refs/replace/abc123'
| Parameters | |
name:bytes | Short replace name (object SHA) or full ref |
| Returns | |
Ref | Full replace ref name (e.g., b"refs/replace/<sha>") |
Parse a remote ref into remote name and branch name.
| Parameters | |
ref:bytes | Remote ref like b"refs/remotes/origin/main" |
| Returns | |
tuple[ | Tuple of (remote_name, branch_name) |
| Raises | |
ValueError | If ref is not a valid remote ref |
IO[ bytes]) -> Iterator[ tuple[ ObjectID, Ref, ObjectID | None]]:
¶
Read a packed refs file including peeled refs.
Assumes the "# pack-refs with: peeled" line was already read. Yields tuples with ref names, SHA1s, and peeled SHA1s (or None).
| Parameters | |
f:IO[ | file-like object to read from, seek'ed to the second line |
| Returns | |
Iterator[ | Undocumented |
Set a reference from a raw ref value.
This handles both symbolic refs (starting with 'ref: ') and direct ObjectID refs.
| Parameters | |
refs:RefsContainer | The RefsContainer to set the ref in |
name:Ref | The ref name to set |
rawbytes | The raw ref value (either a symbolic ref or an ObjectID) |
Convert a full ref name to its short form.
Examples
>>> shorten_ref_name(b"refs/heads/master") b'master' >>> shorten_ref_name(b"refs/remotes/origin/main") b'origin/main' >>> shorten_ref_name(b"refs/tags/v1.0") b'v1.0' >>> shorten_ref_name(b"HEAD") b'HEAD'
| Parameters | |
ref:bytes | Full ref name (e.g., b"refs/heads/master") |
| Returns | |
bytes | Short ref name (e.g., b"master") |
RefsContainer, remote_name: str, refs: Mapping[ Ref, ObjectID | None], message: bytes | None = None, prune: bool = False, prune_tags: bool = False):
¶
Undocumented
RefsContainer, origin: bytes, origin_head: bytes | None, branch: bytes | None, ref_message: bytes | None) -> bytes:
¶
Set the default branch.