Simple wrapper that provides porcelain-like functions on top of Dulwich.
- Currently implemented:
- am
- apply_patch
- archive
- add
- bisect{_start,_bad,_good,_skip,_reset,_log,_replay}
- branch{_create,_delete,_list}
- check_ignore
- checkout
- checkout_branch
- clone
- cone mode{_init, _set, _add}
- commit
- commit_tree
- daemon
- describe
- diff_tree
- fetch
- filter_branch
- for_each_ref
- grep
- init
- interpret_trailers
- ls_files
- ls_remote
- ls_tree
- mailsplit
- merge
- merge_tree
- mv/move
- prune
- pull
- push
- rm
- remote{_add}
- receive_pack
- replace{_create,_delete,_list}
- rerere{_status,_diff,_forget,_clear,_gc}
- reset
- revert
- sparse_checkout
- submodule_add
- submodule_init
- submodule_list
- rev_list
- tag{_create,_delete,_list}
- upload_pack
- update_server_info
- var
- write_commit_graph
- status
- shortlog
- symbolic_ref
- worktree{_add,_list,_remove,_prune,_lock,_unlock,_move}
These functions are meant to behave similarly to the git subcommands. Differences in behaviour are considered bugs.
Note: one of the consequences of this is that paths tend to be interpreted relative to the current working directory rather than relative to the repository root.
Functions should generally accept both unicode strings and bytestrings
| Module | lfs |
Porcelain functions for Git LFS support. |
| Module | notes |
Porcelain-like interface for Git notes. |
| Module | submodule |
Porcelain functions for working with submodules. |
| Module | subtree |
Porcelain for git subtree operations. |
| Module | tag |
Porcelain-like tag functions for Dulwich. |
| Module | worktree |
Porcelain-like interface for Git worktrees. |
From __init__.py:
| Class | |
Result of counting objects in a repository. |
| Class | |
Fallback if stdout or stderr are unavailable, does nothing. |
| Class | |
Keyword arguments accepted by get_transport_and_path. |
| Exception | |
Indicates that a checkout cannot be performed. |
| Exception | |
Branches have diverged and fast-forward is not possible. |
| Exception | |
Porcelain-based error. |
| Exception | |
Raised when the remote already exists. |
| Exception | |
Raised when the timezone cannot be determined from a given string. |
| Function | active |
Return the active branch in the repository, if any. |
| Function | add |
Add files to the staging area. |
| Function | am |
Apply patches from mailbox-style email messages, creating commits. |
| Function | am |
Abort the current am and restore the original state. |
| Function | am |
Continue applying patches after resolving a conflict. |
| Function | am |
Quit the current am without reverting changes. |
| Function | am |
Skip the current patch and continue with remaining patches. |
| Function | annotate |
Annotate the history of a file. |
| Function | apply |
Apply a patch to the working tree and/or index. |
| Function | archive |
Create an archive. |
| Function | bisect |
Mark a commit as bad. |
| Function | bisect |
Mark a commit as good. |
| Function | bisect |
Get the bisect log. |
| Function | bisect |
Replay a bisect log. |
| Function | bisect |
Reset bisect state and return to original branch/commit. |
| Function | bisect |
Skip one or more commits. |
| Function | bisect |
Start a new bisect session. |
| Function | branch |
Create a branch. |
| Function | branch |
Delete a branch. |
| Function | branch |
List all branches. |
| Function | branch |
List the short names of all remote branches. |
| Function | branches |
List branches that contain the specified commit. |
| Function | cat |
Get the raw content of a Git object. |
| Function | cat |
Get the size of a Git object. |
| Function | cat |
Get the type of a Git object. |
| Function | check |
Check if updating to a sha can be done with fast forwarding. |
| Function | check |
Debug gitignore files. |
| Function | check |
Check canonical name and email of contact. |
| Function | checkout |
Switch to a branch or commit, updating both HEAD and the working tree. |
| Function | cherry |
Find commits not merged upstream. |
| Function | cherry |
Cherry-pick a commit onto the current branch. |
| Function | clean |
Remove any untracked files from the target directory recursively. |
| Function | clone |
Clone a local or remote git repository. |
| Function | commit |
Create a new commit. |
| Function | commit |
Decode commit contents using the commit's encoding or default. |
| Function | commit |
Encode commit contents using the commit's encoding or default. |
| Function | commit |
Create a new commit object. |
| Function | cone |
Add new directories to the existing 'cone-mode' sparse-checkout patterns. |
| Function | cone |
Disable sparse checkout and restore all files. |
| Function | cone |
Initialize a repository to use sparse checkout in 'cone' mode. |
| Function | cone |
List current sparse-checkout patterns. |
| Function | cone |
Overwrite the existing 'cone-mode' sparse patterns with a new set of directories. |
| Function | count |
Count unpacked objects and their disk usage. |
| Function | daemon |
Run a daemon serving Git requests over TCP/IP. |
| Function | describe |
Describe the repository version. |
| Function | diff |
Show diff. |
| Function | diff |
Compares the content and mode of blobs found via two tree objects. |
| Function | fetch |
Fetch objects from a remote server. |
| Function | filter |
Rewrite branch history by creating new commits with filtered properties. |
| Function | filter |
Filter branches by fnmatch pattern. |
| Function | find |
Find the shortest unique abbreviation for an object ID. |
| Function | for |
Iterate over all refs that match the (optional) pattern. |
| Function | format |
Generate patches suitable for git am. |
| Function | fsck |
Check a repository. |
| Function | gc |
Run garbage collection on a repository. |
| Function | get |
Return the branch's merge reference (upstream branch), if any. |
| Function | get |
Return the active branch's remote name, if any. |
| Function | get |
Get an object by path. |
| Function | get |
Get the remote repository information. |
| Function | get |
Return add/delete/modify changes to tree by comparing index to HEAD. |
| Function | get |
Get untracked paths. |
| Function | get |
Retrieve local timezone as described in git documentation. |
| Function | grep |
Search for a pattern in tracked files. |
| Function | hash |
Compute object ID and optionally write to object store. |
| Function | independent |
Filter commits to only those that are not reachable from others. |
| Function | init |
Create a new git repository. |
| Function | interpret |
Parse and manipulate trailers in a commit message. |
| Function | is |
Check if one commit is an ancestor of another. |
| Function | is |
Check if an interactive rebase is in progress. |
| Function | lfs |
Clean a file by converting it to an LFS pointer. |
| Function | lfs |
Fetch LFS objects from remote. |
| Function | lfs |
Initialize Git LFS in a repository. |
| Function | lfs |
List files tracked by Git LFS. |
| Function | lfs |
Migrate files to Git LFS. |
| Function | lfs |
Check if files are valid LFS pointers. |
| Function | lfs |
Pull LFS objects for current checkout. |
| Function | lfs |
Push LFS objects to remote. |
| Function | lfs |
Smudge an LFS pointer by retrieving the actual content. |
| Function | lfs |
Show status of LFS files. |
| Function | lfs |
Track file patterns with Git LFS. |
| Function | lfs |
Untrack file patterns from Git LFS. |
| Function | log |
Write commit logs. |
| Function | ls |
List all files in an index. |
| Function | ls |
List the refs in a remote. |
| Function | ls |
List contents of a tree. |
| Function | mailinfo |
Extract patch information from an email message. |
| Function | mailsplit |
Split an mbox file or Maildir into individual message files. |
| Function | maintenance |
Register a repository for background maintenance. |
| Function | maintenance |
Run maintenance tasks on a repository. |
| Function | maintenance |
Unregister a repository from background maintenance. |
| Function | merge |
Merge one or more commits into the current branch. |
| Function | merge |
Find the best common ancestor(s) between commits. |
| Function | merge |
Perform a three-way tree merge without touching the working directory. |
| Function | merged |
List branches that have been merged into the current branch. |
| Function | mktag |
Create a tag object from raw tag data. |
| Function | mv |
Move or rename a file, directory, or symlink. |
| Function | no |
List branches that have been merged into the current branch. |
| Function | notes |
Add or update a note for an object. |
| Function | notes |
List all notes in a notes ref. |
| Function | notes |
Remove a note for an object. |
| Function | notes |
Show the note for an object. |
| Function | open |
Open an argument that can be a repository or a path for a repository. |
| Function | open |
Open an argument that can be a repository or a path for a repository. |
| Function | pack |
Pack objects into a file. |
| Function | pack |
Pack loose references into packed-refs file. |
| Function | parse |
Parse given string and attempt to return a timezone offset. |
| Function | path |
Convert a path to a path usable in an index, e.g. bytes and relative to the repository root. |
| Function | print |
Write a human-readable commit log entry. |
| Function | print |
Print only the names of changed files. |
| Function | print |
Print a simple status summary, listing changed files. |
| Function | print |
Write a single-line commit log entry. |
| Function | print |
Write a diffstat summary for a commit. |
| Function | print |
Write a human-readable tag. |
| Function | prune |
Prune/clean up a repository's object store. |
| Function | pull |
Pull from remote via dulwich.client. |
| Function | push |
Remote push with dulwich via dulwich.client. |
| Function | rebase |
Rebase commits onto another branch. |
| Function | receive |
Receive a pack file after negotiating its contents using smart protocol. |
| Function | reflog |
Show reflog entries for a reference or all references. |
| Function | reflog |
Delete a specific reflog entry. |
| Function | reflog |
Expire reflog entries based on age and reachability. |
| Function | remote |
Add a remote. |
| Function | remote |
Remove a remote. |
| Function | remove |
Remove files from the staging area. |
| Function | repack |
Repack loose files in a repository. |
| Function | replace |
Create a replacement ref to replace one object with another. |
| Function | replace |
Delete a replacement ref. |
| Function | replace |
List all replacement refs. |
| Function | rerere |
Record current conflict resolutions and apply known resolutions. |
| Function | rerere |
Clear all recorded rerere resolutions. |
| Function | rerere |
Show differences for recorded rerere conflicts. |
| Function | rerere |
Forget recorded rerere resolutions for a pathspec. |
| Function | rerere |
Garbage collect old rerere resolutions. |
| Function | rerere |
Get the status of all conflicts in the rerere cache. |
| Function | reset |
Reset current HEAD to the specified state. |
| Function | reset |
Reset the file to specific commit or branch. |
| Function | restore |
Restore working tree files. |
| Function | rev |
Lists commit objects in reverse chronological order. |
| Function | rev |
Parse a revision string and return the object SHA. |
| Function | revert |
Revert one or more commits. |
| Function | set |
Set up branch tracking configuration. |
| Function | shortlog |
Summarize commits by author, like git shortlog. |
| Function | show |
Print the changes in a commit. |
| Function | show |
Write a blob to a stream. |
| Function | show |
Display branches and their commits. |
| Function | show |
Show a commit to a stream. |
| Function | show |
Show the contents of a pack index file. |
| Function | show |
Show details of a git object. |
| Function | show |
List references in a local repository. |
| Function | show |
Print a tag to a stream. |
| Function | show |
Print a tree to a stream. |
| Function | sparse |
Perform a sparse checkout in the repository (either 'full' or 'cone mode'). |
| Function | stash |
Drop a stash from the stack. |
| Function | stash |
List all stashes in a repository. |
| Function | stash |
Pop a stash from the stack. |
| Function | stash |
Push a new stash onto the stack. |
| Function | status |
Returns staged, unstaged, and untracked changes relative to the HEAD. |
| Function | stripspace |
Strip unnecessary whitespace from text. |
| Function | submodule |
Add a new submodule. |
| Function | submodule |
Initialize submodules. |
| Function | submodule |
List submodules. |
| Function | submodule |
Update submodules. |
| Function | switch |
Switch branches. |
| Function | symbolic |
Set git symbolic ref into HEAD. |
| Function | tag |
Creates a tag in git via dulwich calls. |
| Function | tag |
Remove a tag. |
| Function | tag |
List all tags. |
| Function | tree |
Convert a git tree path to a filesystem path (relative). |
| Function | unpack |
Unpack objects from a pack file into the repository. |
| Function | update |
Update HEAD to point at a new branch/commit. |
| Function | update |
Update the object name stored in a ref safely. |
| Function | update |
Update server info files for a repository. |
| Function | upload |
Upload a pack file after negotiating its contents using smart protocol. |
| Function | var |
Get the value of a specific Git logical variable. |
| Function | var |
List all Git logical variables. |
| Function | verify |
Verify signature on a commit. |
| Function | verify |
Verify signature on a tag. |
| Function | web |
Run a daemon serving Git requests over HTTP. |
| Function | worktree |
Add a new worktree. |
| Function | worktree |
List all worktrees for a repository. |
| Function | worktree |
Lock a worktree to prevent it from being pruned. |
| Function | worktree |
Move a worktree to a new location. |
| Function | worktree |
Prune worktree administrative files. |
| Function | worktree |
Remove a worktree. |
| Function | worktree |
Repair worktree administrative files. |
| Function | worktree |
Unlock a worktree. |
| Function | write |
Write a commit graph file for a repository. |
| Function | write |
Write a tree object from the index. |
| Constant | DEFAULT |
Undocumented |
| Constant | INFINITE |
Undocumented |
| Type Variable | T |
Undocumented |
| Variable | default |
Undocumented |
| Variable | default |
Undocumented |
| Variable | |
Undocumented |
| Variable | |
Undocumented |
| Function | _canonical |
Undocumented |
| Function | _check |
Check for uncommitted changes that would conflict with a checkout/switch. |
| Function | _do |
Internal merge implementation that operates on an open repository. |
| Function | _do |
Internal octopus merge implementation that operates on an open repository. |
| Function | _filter |
Filter kwargs to only include parameters accepted by get_transport_and_path. |
| Function | _find |
Yield annotated tags whose targets are reachable from pushed commits. |
| Function | _get |
Get merge status for all branches relative to current HEAD. |
| Function | _get |
Get the current HEAD tree ID. |
| Function | _get |
Get reflog message, checking GIT_REFLOG_ACTION environment variable. |
| Function | _get |
Internal function to get all Git logical variables. |
| Function | _get |
Get configuration for working tree updates. |
| Function | _is |
Check whether subdir is parentdir or a subdir of parentdir. |
| Function | _make |
Undocumented |
| Function | _make |
Undocumented |
| Function | _noop |
Context manager that has the same api as closing but does nothing. |
| Function | _perform |
Perform the actual working tree switch. |
| Function | _precompose |
Normalize a filesystem path to NFC (precomposed) Unicode form. |
| Function | _quote |
Quote a path using C-style quoting similar to git's core.quotePath. |
| Function | _select |
Select which refs to push based on mode flags or user refspecs. |
| Function | _walk |
Get path, is_dir for files in working dir from frompath. |
Return the active branch in the repository, if any.
| Parameters | |
repo:RepoPath | Repository to open |
| Returns | |
bytes | branch name |
| Raises | |
KeyError | if the repository does not have a working tree |
IndexError | if HEAD is floating |
str | os.PathLike[ str] | Repo = '.', paths: Sequence[ str | bytes | os.PathLike[ str]] | str | bytes | os.PathLike[ str] | None = None) -> tuple[ list[ str], set[ str]]:
¶
Add files to the staging area.
Returns: Tuple with set of added files and ignored files
If the repository contains ignored directories, the returned set will contain the path to an ignored directory (with trailing slash). Individual files within ignored directories will not be returned.
Note: When paths=None, this function adds all untracked and modified files from the entire repository, mimicking 'git add -A' behavior.
| Parameters | |
repo:str | os.PathLike[ | Repository for the files |
paths:Sequence[ | Paths to add. If None, stages all untracked and modified files from the current working directory (mimicking 'git add .' behavior). |
| Returns | |
tuple[ | Undocumented |
RepoPath = '.', patches: str | bytes | BinaryIO | list[ str | bytes | BinaryIO] | None = None, three_way: bool = False, keep_subject: bool = False, keep_non_patch: bool = False, scissors: bool = False, message_id: bool = False, strip: int = 1, committer: bytes | None = None, commit_timestamp: float | None = None, commit_timezone: int | None = None) -> list[ ObjectID]:
¶
Apply patches from mailbox-style email messages, creating commits.
| Parameters | |
repo:RepoPath | Path to the repository |
patches:str | bytes | BinaryIO | list[ | Patch input(s) - file path(s), file-like object(s), or None for stdin. Can be a single mbox file containing multiple messages. |
threebool | Fall back to 3-way merge if patch does not apply cleanly |
keepbool | If True, keep subject intact without munging |
keepbool | If True, only strip [PATCH] from brackets |
scissors:bool | If True, remove everything before scissors line |
messagebool | If True, include Message-ID in commit message |
strip:int | Number of leading path components to strip (default: 1) |
committer:bytes | None | Optional committer identity (bytes) |
commitfloat | None | Optional committer timestamp |
commitint | None | Optional committer timezone offset |
| Returns | |
list[ | List of commit SHAs (bytes) created |
Abort the current am and restore the original state.
Resets HEAD, index, and working tree to the state before am started.
| Parameters | |
repo:RepoPath | Path to the repository |
RepoPath = '.', committer: bytes | None = None, commit_timestamp: float | None = None, commit_timezone: int | None = None) -> list[ ObjectID]:
¶
Continue applying patches after resolving a conflict.
The user should have resolved conflicts and staged the result.
| Parameters | |
repo:RepoPath | Path to the repository |
committer:bytes | None | Optional committer identity |
commitfloat | None | Optional committer timestamp |
commitint | None | Optional committer timezone offset |
| Returns | |
list[ | List of commit SHAs created |
Quit the current am without reverting changes.
Removes am state but keeps HEAD, index, and working tree as-is.
| Parameters | |
repo:RepoPath | Path to the repository |
RepoPath = '.', committer: bytes | None = None, commit_timestamp: float | None = None, commit_timezone: int | None = None) -> list[ ObjectID]:
¶
Skip the current patch and continue with remaining patches.
| Parameters | |
repo:RepoPath | Path to the repository |
committer:bytes | None | Optional committer identity |
commitfloat | None | Optional committer timestamp |
commitint | None | Optional committer timezone offset |
| Returns | |
list[ | List of commit SHAs created |
RepoPath = '.', patch_file: str | bytes | BinaryIO | None = None, cached: bool = False, reverse: bool = False, check: bool = False, strip: int = 1, three_way: bool = False):
¶
Apply a patch to the working tree and/or index.
| Parameters | |
repo:RepoPath | Path to the repository |
patchstr | bytes | BinaryIO | None | Path to patch file or file-like object (stdin if None) |
cached:bool | Apply patch to index only, not working tree |
reverse:bool | Apply patch in reverse |
check:bool | Only check if patch can be applied, don't apply |
strip:int | Number of leading path components to strip (default: 1) |
threebool | Fall back to 3-way merge if patch does not apply cleanly |
| Raises | |
ValueError | If patch cannot be applied |
Get the bisect log.
| Parameters | |
repo:str | os.PathLike[ | Path to repository or a Repo object |
| Returns | |
str | The bisect log as a string |
str | os.PathLike[ str] | Repo, log_file: str | os.PathLike[ str] | BinaryIO):
¶
Replay a bisect log.
| Parameters | |
repo:str | os.PathLike[ | Path to repository or a Repo object |
logstr | os.PathLike[ | Path to the log file or file-like object |
str | os.PathLike[ str] | Repo = '.', revs: str | bytes | Commit | Tag | Sequence[ str | bytes | Commit | Tag] | None = None) -> bytes | None:
¶
Skip one or more commits.
| Parameters | |
repo:str | os.PathLike[ | Path to repository or a Repo object |
revs:str | bytes | Commit | Tag | Sequence[ | List of commits to skip (defaults to [HEAD]) |
| Returns | |
bytes | None | The SHA of the next commit to test, or None if bisect is complete |
str | os.PathLike[ str] | Repo = '.', bad: str | bytes | Commit | Tag | None = None, good: str | bytes | Commit | Tag | Sequence[ str | bytes | Commit | Tag] | None = None, paths: Sequence[ bytes] | None = None, no_checkout: bool = False, term_bad: str = 'bad', term_good: str = 'good') -> bytes | None:
¶
Start a new bisect session.
| Parameters | |
repo:str | os.PathLike[ | Path to repository or a Repo object |
bad:str | bytes | Commit | Tag | None | The bad commit (defaults to HEAD) |
good:str | bytes | Commit | Tag | Sequence[ | List of good commits or a single good commit |
paths:Sequence[ | Optional paths to limit bisect to |
nobool | If True, don't checkout commits during bisect |
termstr | Term to use for bad commits (default: "bad") |
termstr | Term to use for good commits (default: "good") |
| Returns | |
bytes | None | Undocumented |
List branches that contain the specified commit.
| Parameters | |
repo:RepoPath | Path to the repository |
commit:str | Commit-ish string (SHA, branch name, tag, etc.) |
| Returns | |
Iterator[ | Undocumented |
| Yields | |
| Branch names (without refs/heads/ prefix) that contain the commit |
| Raises | |
ValueError | If the commit reference is malformed |
KeyError | If the commit reference does not exist |
RepoPath, paths: Sequence[ str | bytes | os.PathLike[ str]], no_index: bool = False, quote_path: bool = True) -> Iterator[ str]:
¶
Debug gitignore files.
Returns: List of ignored files
| Parameters | |
repo:RepoPath | Path to the repository |
paths:Sequence[ | List of paths to check for |
nobool | Don't check index |
quotebool | If True, quote non-ASCII characters in returned paths using C-style octal escapes (e.g. "тест.txt" becomes "\321\202\320\265\321\201\321\202.txt"). If False, return raw unicode paths. |
| Returns | |
Iterator[ | Undocumented |
str | os.PathLike[ str] | Repo, target: str | bytes | Commit | Tag | None = None, force: bool = False, new_branch: bytes | str | None = None, paths: list[ bytes | str] | None = None):
¶
Switch to a branch or commit, updating both HEAD and the working tree.
This is similar to 'git checkout', allowing you to switch to a branch, tag, or specific commit. Unlike update_head, this function also updates the working tree to match the target.
| Parameters | |
repo:str | os.PathLike[ | Path to repository or repository object |
target:str | bytes | Commit | Tag | None | Branch name, tag, or commit SHA to checkout. If None and paths is specified, restores files from HEAD |
force:bool | Force checkout even if there are local changes |
newbytes | str | None | Create a new branch at target (like git checkout -b) |
paths:list[ | List of specific paths to checkout. If specified, only these paths are updated and HEAD is not changed |
| Raises | |
CheckoutError | If checkout cannot be performed due to conflicts |
KeyError | If the target reference cannot be found |
str | os.PathLike[ str] | Repo, upstream: str | bytes | None = None, head: str | bytes | None = None, limit: str | bytes | None = None, verbose: bool = False) -> list[ tuple[ str, bytes, bytes | None]]:
¶
Find commits not merged upstream.
| Parameters | |
repo:str | os.PathLike[ | Repository path or object |
upstream:str | bytes | None | Upstream branch (default: tracking branch or @{upstream}) |
head:str | bytes | None | Head branch (default: HEAD) |
limit:str | bytes | None | Limit commits to those after this ref |
verbose:bool | Include commit messages in output |
| Returns | |
list[ | List of tuples (status, commit_sha, message) where status is '+' or '-' '+' means commit is not in upstream, '-' means equivalent patch exists upstream message is None unless verbose=True |
str | os.PathLike[ str] | Repo, committish: str | bytes | Commit | Tag | None, no_commit: bool = False, continue_: bool = False, abort: bool = False) -> bytes | None:
¶
Cherry-pick a commit onto the current branch.
| Parameters | |
repo:str | os.PathLike[ | Repository to cherry-pick into |
committish:str | bytes | Commit | Tag | None | Commit to cherry-pick (can be None only when resuming or aborting) |
nobool | If True, do not create a commit after applying changes |
continue_:bool | Resume an in-progress cherry-pick after resolving conflicts if True |
abort:bool | Abort an in-progress cherry-pick |
| Returns | |
bytes | None | The SHA of the newly created commit, or None if no_commit=True or there were conflicts |
| Raises | |
Error | If there is no HEAD reference, commit cannot be found, or operation fails |
str | os.PathLike[ str] | Repo = '.', target_dir: str | os.PathLike[ str] | None = None):
¶
Remove any untracked files from the target directory recursively.
Equivalent to running git clean -fd in target_dir.
| Parameters | |
repo:str | os.PathLike[ | Repository where the files may be tracked |
targetstr | os.PathLike[ | Directory to clean - current directory if None |
str | bytes | Repo, target: str | os.PathLike[ str] | None = None, bare: bool = False, checkout: bool | None = None, errstream: BinaryIO | RawIOBase = default_bytes_err_stream, outstream: BinaryIO | None = None, origin: str | None = 'origin', depth: int | None = None, branch: str | bytes | None = None, config: Config | None = None, filter_spec: str | None = None, protocol_version: int | None = None, recurse_submodules: bool = False, ssh_command: str | None = None, **kwargs: str | bytes | Sequence[ str | bytes]) -> Repo:
¶
Clone a local or remote git repository.
Returns: The new repository
| Parameters | |
source:str | bytes | Repo | Path or URL for source repository |
target:str | os.PathLike[ | Path to target repository (optional) |
bare:bool | Whether or not to create a bare repository |
checkout:bool | None | Whether or not to check-out HEAD after cloning |
errstream:BinaryIO | RawIOBase | Optional stream to write progress to |
outstream:BinaryIO | None | Optional stream to write progress to (deprecated) |
origin:str | None | Name of remote from the repository used to clone |
depth:int | None | Depth to fetch at |
branch:str | bytes | None | Optional branch or tag to be used as HEAD in the new repository instead of the cloned repository's HEAD. |
config:Config | None | Configuration to use |
filterstr | None | A git-rev-list-style object filter spec, as an ASCII string. Only used if the server supports the Git protocol-v2 'filter' feature, and ignored otherwise. |
protocolint | None | desired Git protocol version. By default the highest mutually supported protocol version will be used. |
recursebool | Whether to initialize and clone submodules |
sshstr | None | Optional custom SSH command |
**kwargs:str | bytes | Sequence[ | Additional keyword arguments including refspecs to fetch. Can be a bytestring, a string, or a list of bytestring/string. |
| Returns | |
Repo | Undocumented |
RepoPath = '.', message: str | bytes | Callable[ [ Any, Commit], bytes] | None = None, author: bytes | None = None, author_timestamp: float | None = None, author_timezone: int | None = None, committer: bytes | None = None, commit_timestamp: float | None = None, commit_timezone: int | None = None, encoding: bytes | None = None, no_verify: bool = False, signoff: bool | None = None, all: bool = False, amend: bool = False, sign: bool | None = None) -> bytes:
¶
Create a new commit.
Returns: SHA1 of the new commit
| Parameters | |
repo:RepoPath | Path to repository |
message:str | bytes | Callable[ | Optional commit message (string/bytes or callable that takes (repo, commit) and returns bytes) |
author:bytes | None | Optional author name and email |
authorfloat | None | Author timestamp (defaults to commit timestamp) |
authorint | None | Author timestamp timezone |
committer:bytes | None | Optional committer name and email |
commitfloat | None | Commit timestamp (defaults to now) |
commitint | None | Commit timestamp timezone |
encoding:bytes | None | Encoding to use for commit message |
nobool | Skip pre-commit and commit-msg hooks |
signoff:bool | None | Add Signed-off-by line to commit message. If None, uses format.signoff config. |
all:bool | Automatically stage all tracked files that have been modified |
amend:bool | Replace the tip of the current branch by creating a new commit |
sign:bool | None | GPG sign the commit. If None, uses commit.gpgsign config. If True, signs with default GPG key. If False, does not sign. |
| Returns | |
bytes | Undocumented |
Commit, contents: bytes, default_encoding: str = DEFAULT_ENCODING) -> str:
¶
Decode commit contents using the commit's encoding or default.
Commit, contents: str, default_encoding: str = DEFAULT_ENCODING) -> bytes:
¶
Encode commit contents using the commit's encoding or default.
Add new directories to the existing 'cone-mode' sparse-checkout patterns.
Reads the current patterns from .git/info/sparse-checkout, adds pattern lines to include the specified directories, and then performs a sparse checkout to update the working tree accordingly.
| Parameters | |
repo:str | os.PathLike[ | Path to the repository or a Repo object. |
dirs:Sequence[ | List of directory names to add to the sparse-checkout. |
force:bool | Whether to forcibly discard local modifications (default False). |
| Returns | |
| None |
Disable sparse checkout and restore all files.
This function: 1. Unsets core.sparseCheckout and core.sparseCheckoutCone config 2. Removes the .git/info/sparse-checkout file 3. Restores all files to the working tree
| Parameters | |
repo:str | os.PathLike[ | Path to the repository or a Repo object. |
force:bool | Whether to forcibly discard local modifications (default False). |
| Returns | |
| None |
Initialize a repository to use sparse checkout in 'cone' mode.
Sets core.sparseCheckout and core.sparseCheckoutCone in the config. Writes an initial .git/info/sparse-checkout file that includes only top-level files (and excludes all subdirectories), e.g. ["/*", "!/*/"]. Then performs a sparse checkout to update the working tree accordingly.
If no directories are specified, then only top-level files are included: https://git-scm.com/docs/git-sparse-checkout#_internalscone_mode_handling
| Parameters | |
repo:str | os.PathLike[ | Path to the repository or a Repo object. |
| Returns | |
| None |
Overwrite the existing 'cone-mode' sparse patterns with a new set of directories.
Ensures core.sparseCheckout and core.sparseCheckoutCone are enabled. Writes new patterns so that only the specified directories (and top-level files) remain in the working tree, and applies the sparse checkout update.
| Parameters | |
repo:str | os.PathLike[ | Path to the repository or a Repo object. |
dirs:Sequence[ | List of directory names to include. |
force:bool | Whether to forcibly discard local modifications (default False). |
| Returns | |
| None |
Count unpacked objects and their disk usage.
| Parameters | |
repo:RepoPath | Path to repository or repository object |
verbose:bool | Whether to return verbose information |
| Returns | |
CountObjectsResult | CountObjectsResult object with detailed statistics |
RepoPath = '.', commit: str | bytes | Commit | None = None, commit2: str | bytes | Commit | None = None, staged: bool = False, paths: Sequence[ str | bytes] | None = None, outstream: BinaryIO = default_bytes_out_stream, diff_algorithm: str | None = None):
¶
Show diff.
| Parameters | |
repo:RepoPath | Path to repository |
commit:str | bytes | Commit | None | First commit to compare. If staged is True, compare index to this commit. If staged is False, compare working tree to this commit. If None, defaults to HEAD for staged and index for unstaged. |
commit2:str | bytes | Commit | None | Second commit to compare against first commit. If provided, show diff between commit and commit2 (ignoring staged flag). |
staged:bool | If True, show staged changes (index vs commit). If False, show unstaged changes (working tree vs commit/index). Ignored if commit2 is provided. |
paths:Sequence[ | Optional list of paths to limit diff |
outstream:BinaryIO | Stream to write to |
diffstr | None | Algorithm to use for diffing ("myers" or "patience"), defaults to the underlying function's default if None |
RepoPath, remote_location: str | bytes | None = None, outstream: TextIO = sys.stdout, errstream: BinaryIO | RawIOBase = default_bytes_err_stream, message: bytes | None = None, depth: int | None = None, prune: bool = False, prune_tags: bool = False, force: bool = False, operation: str | None = None, thin_packs: bool = True, report_activity: Callable[ [ int, str], None] | None = None, quiet: bool = False, include_tags: bool = False, username: str | None = None, password: str | None = None, key_filename: str | None = None, ssh_command: str | None = None, shallow_since: str | None = None, shallow_exclude: list[ str] | None = None, unshallow: bool = False) -> FetchPackResult:
¶
Fetch objects from a remote server.
| Parameters | |
repo:RepoPath | Path to the repository |
remotestr | bytes | None | String identifying a remote server |
outstream:TextIO | Output stream (defaults to stdout) |
errstream:BinaryIO | RawIOBase | Error stream (defaults to stderr) |
message:bytes | None | Reflog message (defaults to b"fetch: from <remote_name>") |
depth:int | None | Depth to fetch at |
prune:bool | Prune remote removed refs |
prunebool | Prune remote removed tags |
force:bool | Force fetching even if it would overwrite local changes |
operation:str | None | Git operation for authentication (e.g., "fetch") |
thinbool | Whether to use thin packs |
reportCallable[ | Optional callback for reporting transport activity |
quiet:bool | Whether to suppress progress output |
includebool | Whether to include tags |
username:str | None | Username for authentication |
password:str | None | Password for authentication |
keystr | None | SSH key filename |
sshstr | None | SSH command to use |
shallowstr | None | Deepen or shorten the history to include commits after this date |
shallowlist[ | Deepen or shorten the history to exclude commits reachable from these refs |
unshallow:bool | Convert a shallow repository to a complete one |
| Returns | |
FetchPackResult | Dictionary with refs on the remote |
RepoPath = '.', branch: str | bytes = 'HEAD', *, filter_fn: Callable[ [ Commit], CommitData | None] | None = None, filter_author: Callable[ [ bytes], bytes | None] | None = None, filter_committer: Callable[ [ bytes], bytes | None] | None = None, filter_message: Callable[ [ bytes], bytes | None] | None = None, tree_filter: Callable[ [ ObjectID, str], ObjectID | None] | None = None, index_filter: Callable[ [ ObjectID, str], ObjectID | None] | None = None, parent_filter: Callable[ [ Sequence[ ObjectID]], list[ ObjectID]] | None = None, commit_filter: Callable[ [ Commit, ObjectID], ObjectID | None] | None = None, subdirectory_filter: str | bytes | None = None, prune_empty: bool = False, tag_name_filter: Callable[ [ bytes], bytes | None] | None = None, force: bool = False, keep_original: bool = True, refs: list[ bytes] | None = None) -> dict[ ObjectID, ObjectID]:
¶
Rewrite branch history by creating new commits with filtered properties.
This is similar to git filter-branch, allowing you to rewrite commit history by modifying trees, parents, author, committer, or commit messages.
| Parameters | |
repo:RepoPath | Path to repository |
branch:str | bytes | Branch to rewrite (defaults to HEAD) |
filterCallable[ | Optional callable that takes a Commit object and returns a dict of updated fields (author, committer, message, etc.) |
filterCallable[ | Optional callable that takes author bytes and returns updated author bytes or None to keep unchanged |
filterCallable[ | Optional callable that takes committer bytes and returns updated committer bytes or None to keep unchanged |
filterCallable[ | Optional callable that takes commit message bytes and returns updated message bytes |
treeCallable[ | Optional callable that takes (tree_sha, temp_dir) and returns new tree SHA after modifying working directory |
indexCallable[ | Optional callable that takes (tree_sha, temp_index_path) and returns new tree SHA after modifying index |
parentCallable[ | Optional callable that takes parent list and returns modified parent list |
commitCallable[ | Optional callable that takes (Commit, tree_sha) and returns new commit SHA or None to skip commit |
subdirectorystr | bytes | None | Optional subdirectory path to extract as new root |
prunebool | Whether to prune commits that become empty |
tagCallable[ | Optional callable to rename tags |
force:bool | Force operation even if branch has been filtered before |
keepbool | Keep original refs under refs/original/ |
refs:list[ | List of refs to rewrite (defaults to [branch]) |
| Returns | |
dict[ | Dict mapping old commit SHAs to new commit SHAs |
| Raises | |
Error | If branch is already filtered and force is False |
BaseObjectStore, object_id: str | bytes, min_length: int = 7) -> str:
¶
Find the shortest unique abbreviation for an object ID.
| Parameters | |
objectBaseObjectStore | Object store to search in |
objectstr | bytes | The full object ID to abbreviate |
minint | Minimum length of abbreviation (default 7) |
| Returns | |
str | The shortest unique prefix of the object ID (at least min_length chars) |
RepoPath = '.', committish: ObjectID | tuple[ ObjectID, ObjectID] | None = None, outstream: TextIO = sys.stdout, outdir: str | os.PathLike[ str] | None = None, n: int = 1, stdout: bool = False, version: str | None = None) -> list[ str]:
¶
Generate patches suitable for git am.
| Parameters | |
repo:RepoPath | Path to repository |
committish:ObjectID | tuple[ | Commit-ish or commit range to generate patches for. Can be a single commit id, or a tuple of (start, end) commit ids for a range. If None, formats the last n commits from HEAD. |
outstream:TextIO | Stream to write to if stdout=True |
outdir:str | os.PathLike[ | Directory to write patch files to (default: current directory) |
n:int | Number of patches to generate if committish is None |
stdout:bool | Write patches to stdout instead of files |
version:str | None | Version string to include in patches (default: Dulwich version) |
| Returns | |
list[ | List of patch filenames that were created (empty if stdout=True) |
RepoPath, auto: bool = False, aggressive: bool = False, prune: bool = True, grace_period: int | None = None, dry_run: bool = False, progress: Callable[ [ str], None] | None = None) -> GCStats:
¶
Run garbage collection on a repository.
| Parameters | |
repo:RepoPath | Path to the repository or a Repo object |
auto:bool | If True, only run gc if needed |
aggressive:bool | If True, use more aggressive settings |
prune:bool | If True, prune unreachable objects |
graceint | None | Grace period in seconds for pruning. If None, reads gc.pruneExpire from config (default 2 weeks). |
drybool | If True, only report what would be done |
progress:Callable[ | Optional progress callback |
| Returns | |
GCStats | GCStats object with garbage collection statistics |
Repo, remote_location: str | bytes | None = None) -> tuple[ str | None, str]:
¶
Get the remote repository information.
| Parameters | |
repo:Repo | Local repository object |
remotestr | bytes | None | Optional remote name or URL; defaults to branch remote |
| Returns | |
tuple[ | Tuple of (remote_name, remote_url) where remote_name may be None if remote_location is a URL rather than a configured remote |
str | bytes | os.PathLike[ str], basepath: str | bytes | os.PathLike[ str], index: Index, exclude_ignored: bool = False, untracked_files: str = 'all', precompose_unicode: bool = False) -> Iterator[ str]:
¶
Get untracked paths.
- Note: ignored directories will never be walked for performance reasons.
- If exclude_ignored is False, only the path to an ignored directory will be yielded, no files inside the directory will be returned
| Parameters | |
frompath:str | bytes | os.PathLike[ | Path to walk |
basepath:str | bytes | os.PathLike[ | Path to compare to |
index:Index | Index to check against |
excludebool | Whether to exclude ignored paths |
untrackedstr | How to handle untracked files: - "no": return an empty list - "all": return all files in untracked directories - "normal": return untracked directories without listing their contents |
precomposebool | If True, normalize filesystem paths to NFC Unicode form. This is needed on macOS where the filesystem returns NFD paths. |
| Returns | |
Iterator[ | Undocumented |
Retrieve local timezone as described in git documentation.
https://raw.githubusercontent.com/git/git/v2.3.0/Documentation/date-formats.txt Returns: A tuple containing author timezone, committer timezone.
RepoPath, pattern: str | bytes, *, outstream: TextIO = sys.stdout, rev: str | bytes | None = None, pathspecs: Sequence[ str | bytes] | None = None, ignore_case: bool = False, line_number: bool = False, max_depth: int | None = None, respect_ignores: bool = True):
¶
Search for a pattern in tracked files.
| Parameters | |
repo:RepoPath | Path to repository or Repo object |
pattern:str | bytes | Regular expression pattern to search for |
outstream:TextIO | Stream to write results to |
rev:str | bytes | None | Revision to search in (defaults to HEAD) |
pathspecs:Sequence[ | Optional list of path patterns to limit search |
ignorebool | Whether to perform case-insensitive matching |
linebool | Whether to output line numbers |
maxint | None | Maximum directory depth to search |
respectbool | Whether to respect .gitignore patterns |
str | os.PathLike[ str] | Repo | None, path: str | os.PathLike[ str] | None = None, data: bytes | None = None, object_type: bytes = b'blob', write: bool = False) -> bytes:
¶
Compute object ID and optionally write to object store.
| Parameters | |
repo:str | os.PathLike[ | Path to the repository or a Repo object (required if write=True) |
path:str | os.PathLike[ | Path to file to hash (mutually exclusive with data) |
data:bytes | None | Data to hash (mutually exclusive with path) |
objectbytes | Type of object (default: b'blob') |
write:bool | Whether to write the object to the object store (default: False) |
| Returns | |
bytes | Object SHA as bytes |
| Raises | |
ValueError | If neither path nor data is provided, or both are provided |
ValueError | If write=True but repo is None |
str | os.PathLike[ str] = '.', *, bare: bool = False, symlinks: bool | None = None, object_format: str | None = None) -> Repo:
¶
Create a new git repository.
Returns: A Repo instance
| Parameters | |
path:str | os.PathLike[ | Path to repository. |
bare:bool | Whether to create a bare repository. |
symlinks:bool | None | Whether to create actual symlinks (defaults to autodetect) |
objectstr | None | Object format to use ("sha1" or "sha256", defaults to "sha1") |
| Returns | |
Repo | Undocumented |
str | bytes, *, trailers: list[ tuple[ str, str]] | None = None, trim_empty: bool = False, only_trailers: bool = False, only_input: bool = False, unfold: bool = False, parse: bool = False, where: str = 'end', if_exists: str = 'addIfDifferentNeighbor', if_missing: str = 'add', separators: str = ':') -> bytes:
¶
Parse and manipulate trailers in a commit message.
This function implements the functionality of git interpret-trailers, allowing parsing and manipulation of structured metadata (trailers) in commit messages.
- Trailers are key-value pairs at the end of commit messages, formatted like:
- Signed-off-by: Alice <[email protected]> Reviewed-by: Bob <[email protected]>
Examples
>>> msg = b"Subject\\n\\nBody text\\n" >>> interpret_trailers(msg, trailers=[("Signed-off-by", "Alice <[email protected]>")]) b'Subject\\n\\nBody text\\n\\nSigned-off-by: Alice <[email protected]>\\n'
>>> msg = b"Subject\\n\\nSigned-off-by: Alice\\n" >>> interpret_trailers(msg, only_trailers=True) b'Signed-off-by: Alice\\n'
| Parameters | |
message:str | bytes | The commit message (string or bytes) |
trailers:list[ | List of (key, value) tuples to add as new trailers |
trimbool | Remove trailers with empty values |
onlybool | Output only the trailers, not the message body |
onlybool | Don't add new trailers, only parse existing ones |
unfold:bool | Join multiline trailer values into a single line |
parse:bool | Shorthand for --only-trailers --only-input --unfold |
where:str | Where to add new trailers ('end', 'start', 'after', 'before') |
ifstr | How to handle duplicate keys - 'add': Always add - 'replace': Replace all existing - 'addIfDifferent': Add only if value differs from all existing - 'addIfDifferentNeighbor': Add only if value differs from neighbors - 'doNothing': Don't add if key exists |
ifstr | What to do if key doesn't exist ('add' or 'doNothing') |
separators:str | Valid separator characters (default ':') |
| Returns | |
bytes | The processed message as bytes |
str | os.PathLike[ str] | Repo = '.', path: str | os.PathLike[ str] | None = None) -> bytes:
¶
Clean a file by converting it to an LFS pointer.
| Parameters | |
repo:str | os.PathLike[ | Path to repository |
path:str | os.PathLike[ | Path to file to clean (relative to repo root) |
| Returns | |
bytes | LFS pointer content as bytes |
Initialize Git LFS in a repository.
| Parameters | |
repo:str | os.PathLike[ | Path to repository |
| Returns | |
| None |
RepoPath = '.', paths: Sequence[ str | bytes] | None = None, outstream: TextIO = sys.stdout, max_entries: int | None = None, reverse: bool = False, name_status: bool = False, name_only: bool = False, author: str | None = None, committer: str | None = None, grep: str | None = None, since: str | int | None = None, until: str | int | None = None, no_merges: bool = False, merges: bool = False, oneline: bool = False, abbrev_commit: bool = False, stat: bool = False, patch: bool = False, follow: bool = False):
¶
Write commit logs.
| Parameters | |
repo:RepoPath | Path to repository |
paths:Sequence[ | Optional set of specific paths to print entries for |
outstream:TextIO | Stream to write log output to |
maxint | None | Optional maximum number of entries to display |
reverse:bool | Reverse order in which entries are printed |
namebool | Print name/status for each changed file |
namebool | Print only names of changed files |
author:str | None | Filter commits by author pattern |
committer:str | None | Filter commits by committer pattern |
grep:str | None | Filter commits by message pattern |
since:str | int | None | Show commits after this date (timestamp or date string) |
until:str | int | None | Show commits before this date (timestamp or date string) |
nobool | Exclude merge commits |
merges:bool | Only show merge commits |
oneline:bool | Show each commit on a single line |
abbrevbool | Abbreviate commit hashes |
stat:bool | Show diffstat for each commit |
patch:bool | Show patch (diff) for each commit |
follow:bool | Follow file renames |
str | bytes, config: Config | None = None, operation: str | None = None, thin_packs: bool = True, report_activity: Callable[ [ int, str], None] | None = None, quiet: bool = False, include_tags: bool = False, username: str | None = None, password: str | None = None, key_filename: str | None = None, ssh_command: str | None = None) -> LsRemoteResult:
¶
List the refs in a remote.
| Parameters | |
remote:str | bytes | Remote repository location |
config:Config | None | Configuration to use |
operation:str | None | Operation type |
thinbool | Whether to use thin packs |
reportCallable[ | Function to report activity |
quiet:bool | Whether to suppress output |
includebool | Whether to include tags |
username:str | None | Username for authentication |
password:str | None | Password for authentication |
keystr | None | SSH key filename |
sshstr | None | SSH command to use |
| Returns | |
LsRemoteResult | LsRemoteResult object with refs and symrefs |
str | os.PathLike[ str] | IO[ bytes] | IO[ str] | None = None, msg_file: str | os.PathLike[ str] | None = None, patch_file: str | os.PathLike[ str] | None = None, keep_subject: bool = False, keep_non_patch: bool = False, encoding: str | None = None, scissors: bool = False, message_id: bool = False) -> MailinfoResult:
¶
Extract patch information from an email message.
This is similar to git mailinfo.
Example
>>> result = mailinfo("patch.eml", "msg", "patch") >>> print(f"Author: {result.author_name} <{result.author_email}>") >>> print(f"Subject: {result.subject}")
| Parameters | |
inputstr | os.PathLike[ | Path to email file or file-like object. If None, reads from stdin. |
msgstr | os.PathLike[ | Path to write commit message. If None, message not written to file. |
patchstr | os.PathLike[ | Path to write patch content. If None, patch not written to file. |
keepbool | If True, keep subject intact without munging (-k) |
keepbool | If True, only strip [PATCH] from brackets (-b) |
encoding:str | None | Character encoding to use (default: detect from message) |
scissors:bool | If True, remove everything before scissors line |
messagebool | If True, include Message-ID in commit message (-m) |
| Returns | |
MailinfoResult | MailinfoResult with parsed information |
| Raises | |
ValueError | If message is malformed or missing required fields |
OSError | If there are issues reading/writing files |
str | os.PathLike[ str] | IO[ bytes] | None = None, output_dir: str | os.PathLike[ str] = '.', start_number: int = 1, precision: int = 4, keep_cr: bool = False, mboxrd: bool = False, is_maildir: bool = False) -> list[ str]:
¶
Split an mbox file or Maildir into individual message files.
This is similar to git mailsplit.
| Parameters | |
inputstr | os.PathLike[ | Path to mbox file, Maildir, or file-like object. If None, reads from stdin. |
outputstr | os.PathLike[ | Directory where individual messages will be written |
startint | Starting number for output files (default: 1) |
precision:int | Number of digits for output filenames (default: 4) |
keepbool | If True, preserve r in lines ending with rn (default: False) |
mboxrd:bool | If True, treat input as mboxrd format and reverse escaping (default: False) |
isbool | If True, treat input_path as a Maildir (default: False) |
| Returns | |
list[ | List of output file paths that were created |
| Raises | |
ValueError | If output_dir doesn't exist or input is invalid |
OSError | If there are issues reading/writing files |
Register a repository for background maintenance.
This adds the repository to the global maintenance.repo config and sets up recommended configuration for scheduled maintenance.
| Parameters | |
repo:RepoPath | Path to the repository or repository object |
RepoPath, tasks: list[ str] | None = None, auto: bool = False, progress: Callable[ [ str], None] | None = None) -> MaintenanceResult:
¶
Run maintenance tasks on a repository.
| Parameters | |
repo:RepoPath | Path to the repository or a Repo object |
tasks:list[ | Optional list of specific task names to run (e.g., ['gc', 'commit-graph', 'pack-refs']) |
auto:bool | If True, only run tasks if needed |
progress:Callable[ | Optional progress callback |
| Returns | |
MaintenanceResult | MaintenanceResult object with task execution results |
str | os.PathLike[ str] | Repo, committish: str | bytes | Commit | Tag | Sequence[ str | bytes | Commit | Tag], no_commit: bool = False, no_ff: bool = False, message: bytes | None = None, author: bytes | None = None, committer: bytes | None = None) -> tuple[ bytes | None, list[ bytes]]:
¶
Merge one or more commits into the current branch.
| Parameters | |
repo:str | os.PathLike[ | Repository to merge into |
committish:str | bytes | Commit | Tag | Sequence[ | Commit(s) to merge. Can be a single commit or a sequence of commits. When merging more than two heads, the octopus merge strategy is used. |
nobool | If True, do not create a merge commit |
nobool | If True, force creation of a merge commit |
message:bytes | None | Optional merge commit message |
author:bytes | None | Optional author for merge commit |
committer:bytes | None | Optional committer for merge commit |
| Returns | |
tuple[ | Tuple of (merge_commit_sha, conflicts) where merge_commit_sha is None if no_commit=True or there were conflicts |
| Raises | |
Error | If there is no HEAD reference or commit cannot be found |
RepoPath = '.', committishes: Sequence[ str | bytes] | None = None, all: bool = False, octopus: bool = False) -> list[ ObjectID]:
¶
Find the best common ancestor(s) between commits.
| Parameters | |
repo:RepoPath | Path to repository |
committishes:Sequence[ | List of commit references (branches, tags, commit IDs) |
all:bool | If True, return all merge bases, not just one |
octopus:bool | If True, find merge base of all commits (n-way merge) |
| Returns | |
list[ | List of commit IDs that are merge bases |
RepoPath, base_tree: str | bytes | Tree | Commit | Tag | None, our_tree: str | bytes | Tree | Commit | Tag, their_tree: str | bytes | Tree | Commit | Tag) -> tuple[ bytes, list[ bytes]]:
¶
Perform a three-way tree merge without touching the working directory.
This is similar to git merge-tree, performing a merge at the tree level without creating commits or updating any references.
| Parameters | |
repo:RepoPath | Repository containing the trees |
basestr | bytes | Tree | Commit | Tag | None | Tree-ish of the common ancestor (or None for no common ancestor) |
ourstr | bytes | Tree | Commit | Tag | Tree-ish of our side of the merge |
theirstr | bytes | Tree | Commit | Tag | Tree-ish of their side of the merge |
| Returns | |
tuple |
|
| Raises | |
KeyError | If any of the tree-ish arguments cannot be resolved |
str | os.PathLike[ str] | Repo, source: str | bytes | os.PathLike[ str], destination: str | bytes | os.PathLike[ str], force: bool = False):
¶
Move or rename a file, directory, or symlink.
| Parameters | |
repo:str | os.PathLike[ | Path to the repository |
source:str | bytes | os.PathLike[ | Path to move from |
destination:str | bytes | os.PathLike[ | Path to move to |
force:bool | Force move even if destination exists |
| Raises | |
Error | If source doesn't exist, is not tracked, or destination already exists (without force) |
RepoPath, object_sha: bytes, note: bytes, ref: bytes = b'commits', author: bytes | None = None, committer: bytes | None = None, message: bytes | None = None) -> bytes:
¶
Add or update a note for an object.
| Parameters | |
repo:RepoPath | Path to repository |
objectbytes | SHA of the object to annotate |
note:bytes | Note content |
ref:bytes | Notes ref to use (defaults to "commits" for refs/notes/commits) |
author:bytes | None | Author identity (defaults to committer) |
committer:bytes | None | Committer identity (defaults to config) |
message:bytes | None | Commit message for the notes update |
| Returns | |
bytes | SHA of the new notes commit |
RepoPath, object_sha: bytes, ref: bytes = b'commits', author: bytes | None = None, committer: bytes | None = None, message: bytes | None = None) -> bytes | None:
¶
Remove a note for an object.
| Parameters | |
repo:RepoPath | Path to repository |
objectbytes | SHA of the object to remove notes from |
ref:bytes | Notes ref to use (defaults to "commits" for refs/notes/commits) |
author:bytes | None | Author identity (defaults to committer) |
committer:bytes | None | Committer identity (defaults to config) |
message:bytes | None | Commit message for the notes removal |
| Returns | |
bytes | None | SHA of the new notes commit, or None if no note existed |
str | bytes | os.PathLike[ str]) -> AbstractContextManager[ Repo]:Open an argument that can be a repository or a path for a repository.
returns a context manager that will close the repo on exit if the argument is a path, else does nothing if the argument is a repo.
RepoPath, object_ids: Sequence[ ObjectID], packf: BinaryIO, idxf: BinaryIO | None, delta_window_size: int | None = None, deltify: bool | None = None, reuse_deltas: bool = True, pack_index_version: int | None = None):
¶
Pack objects into a file.
| Parameters | |
repo:RepoPath | Path to the repository |
objectSequence[ | List of object ids to write |
packf:BinaryIO | File-like object to write to |
idxf:BinaryIO | None | File-like object to write to (can be None) |
deltaint | None | Sliding window size for searching for deltas; Set to None for default window size. |
deltify:bool | None | Whether to deltify objects |
reusebool | Allow reuse of existing deltas while deltifying |
packint | None | Pack index version to use (1, 2, or 3). If None, uses default version. |
Parse given string and attempt to return a timezone offset.
Different formats are considered in the following order:
- Git internal format: <unix timestamp> <timezone offset>
- RFC 2822: e.g. Mon, 20 Nov 1995 19:12:08 -0500
- ISO 8601: e.g. 1995-11-20T19:12:08-0500
Returns: Timezone offset as integer
| Parameters | |
tzstr | datetime string |
| Returns | |
int | Undocumented |
| Raises | |
TimezoneFormatError | if timezone information cannot be extracted |
str | bytes | os.PathLike[ str], path: str | bytes | os.PathLike[ str], tree_encoding: str = DEFAULT_ENCODING) -> bytes:
¶
Convert a path to a path usable in an index, e.g. bytes and relative to the repository root.
Returns: A path formatted for use in e.g. an index
| Parameters | |
repopath:str | bytes | os.PathLike[ | Repository path, absolute or relative to the cwd |
path:str | bytes | os.PathLike[ | A path, absolute or relative to the cwd |
treestr | Encoding to use for tree paths |
| Returns | |
bytes | Undocumented |
Print only the names of changed files.
| Parameters | |
changes:Iterator[ | Iterator of TreeChange objects |
| Returns | |
Iterator[ | Undocumented |
| Yields | |
| Formatted name-only strings for each change |
Write a diffstat summary for a commit.
| Parameters | |
store:BaseObjectStore | ObjectStore for looking up objects |
commit:Commit | A Commit object |
outstream:TextIO | A stream file to write to |
RepoPath, grace_period: int | None = None, dry_run: bool = False, progress: Callable[ [ str], None] | None = None):
¶
Prune/clean up a repository's object store.
This removes temporary files that were left behind by interrupted pack operations.
| Parameters | |
repo:RepoPath | Path to the repository or a Repo object |
graceint | None | Grace period in seconds for removing temporary files (default 2 weeks) |
drybool | If True, only report what would be done |
progress:Callable[ | Optional progress callback |
RepoPath, remote_location: str | bytes | None = None, refspecs: str | bytes | Sequence[ str | bytes] | None = None, outstream: BinaryIO = default_bytes_out_stream, errstream: BinaryIO | RawIOBase = default_bytes_err_stream, fast_forward: bool = True, ff_only: bool = False, force: bool = False, filter_spec: str | None = None, protocol_version: int | None = None, **kwargs: object):
¶
Pull from remote via dulwich.client.
| Parameters | |
repo:RepoPath | Path to repository |
remotestr | bytes | None | Location of the remote |
refspecs:str | bytes | Sequence[ | refspecs to fetch. Can be a bytestring, a string, or a list of bytestring/string. |
outstream:BinaryIO | A stream file to write to output |
errstream:BinaryIO | RawIOBase | A stream file to write to errors |
fastbool | If True, raise an exception when fast-forward is not possible |
ffbool | If True, only allow fast-forward merges. Raises DivergedBranches when branches have diverged rather than performing a merge. |
force:bool | If True, allow overwriting local changes in the working tree. If False, pull will abort if it would overwrite uncommitted changes. |
filterstr | None | A git-rev-list-style object filter spec, as an ASCII string. Only used if the server supports the Git protocol-v2 'filter' feature, and ignored otherwise. |
protocolint | None | desired Git protocol version. By default the highest mutually supported protocol version will be used |
**kwargs:object | Additional keyword arguments for the client |
RepoPath, remote_location: str | bytes | None = None, refspecs: str | bytes | Sequence[ str | bytes] | None = None, outstream: BinaryIO = default_bytes_out_stream, errstream: BinaryIO | RawIOBase = default_bytes_err_stream, force: bool = False, push_options: list[ str] | None = None, atomic: bool = False, all: bool = False, tags: bool = False, delete: bool = False, dry_run: bool = False, prune: bool = False, set_upstream: bool = False, follow_tags: bool = False, mirror: bool = False, **kwargs: object) -> SendPackResult:
¶
Remote push with dulwich via dulwich.client.
| Parameters | |
repo:RepoPath | Path to repository |
remotestr | bytes | None | Location of the remote |
refspecs:str | bytes | Sequence[ | Refs to push to remote |
outstream:BinaryIO | A stream file to write output |
errstream:BinaryIO | RawIOBase | A stream file to write errors |
force:bool | Force overwriting refs |
pushlist[ | Optional list of push options to send to the server (e.g. for AGit flow: ["topic=my-branch", "title=My PR"]) |
atomic:bool | If True, request atomic push (all refs update or none do) |
all:bool | If True, push all branches |
tags:bool | If True, push all tags |
delete:bool | If True, delete the specified remote refs |
drybool | If True, do everything except actually send the updates |
prune:bool | If True, remove remote refs that don't exist locally |
setbool | If True, set upstream tracking info for pushed branches |
followbool | If True, push annotated tags reachable from pushed commits |
mirror:bool | If True, mirror all refs (implies force, push all refs and delete remote refs not present locally) |
**kwargs:object | Additional keyword arguments for the client |
| Returns | |
SendPackResult | Undocumented |
Repo | str, upstream: bytes | str, onto: bytes | str | None = None, branch: bytes | str | None = None, abort: bool = False, continue_rebase: bool = False, skip: bool = False, interactive: bool = False, edit_todo: bool = False) -> list[ bytes]:
¶
Rebase commits onto another branch.
| Parameters | |
repo:Repo | str | Repository to rebase in |
upstream:bytes | str | Upstream branch/commit to rebase onto |
onto:bytes | str | None | Specific commit to rebase onto (defaults to upstream) |
branch:bytes | str | None | Branch to rebase (defaults to current branch) |
abort:bool | Abort an in-progress rebase |
continuebool | Continue an in-progress rebase |
skip:bool | Skip current commit and continue rebase |
interactive:bool | Start an interactive rebase |
editbool | Edit the todo list of an interactive rebase |
| Returns | |
list[ | List of new commit SHAs created by rebase |
| Raises | |
Error | If rebase fails or conflicts occur |
RepoPath = '.', ref: str | bytes = b'HEAD', all: bool = False) -> Iterator[ Any | tuple[ bytes, Any]]:
¶
Show reflog entries for a reference or all references.
| Parameters | |
repo:RepoPath | Path to repository or a Repo object |
ref:str | bytes | Reference name (defaults to HEAD) |
all:bool | If True, show reflogs for all refs (ignores ref parameter) |
| Returns | |
Iterator[ | Undocumented |
| Yields | |
If all=False | ReflogEntry objects If all=True: Tuples of (ref_name, ReflogEntry) for all refs with reflogs |
RepoPath = '.', ref: str | bytes | None = None, all: bool = False, expire_time: int | None = None, expire_unreachable_time: int | None = None, dry_run: bool = False) -> dict[ bytes, int]:
¶
Expire reflog entries based on age and reachability.
| Parameters | |
repo:RepoPath | Path to repository or a Repo object |
ref:str | bytes | None | Reference name (if not using --all) |
all:bool | If True, expire reflogs for all refs |
expireint | None | Expire entries older than this timestamp (seconds since epoch) |
expireint | None | Expire unreachable entries older than this timestamp |
drybool | If True, show what would be expired without making changes |
| Returns | |
dict[ | Dictionary mapping ref names to number of expired entries |
str | os.PathLike[ str] | Repo = '.', paths: Sequence[ str | bytes | os.PathLike[ str]] = [], cached: bool = False):
¶
Remove files from the staging area.
| Parameters | |
repo:str | os.PathLike[ | Repository for the files |
paths:Sequence[ | Paths to remove. Can be absolute or relative to the repository root. |
cached:bool | Only remove from index, not from working directory |
Record current conflict resolutions and apply known resolutions.
This reads conflicted files from the working tree and records them in the rerere cache. If rerere.autoupdate is enabled and a known resolution exists, it will be automatically applied.
| Parameters | |
repo:RepoPath | Path to the repository |
| Returns | |
Tuple of |
|
Repo, file_path: str, target: str | bytes | Commit | Tree | Tag = b'HEAD', symlink_fn: Callable[ [ (str | bytes | os.PathLike[ str]), (str | bytes | os.PathLike[ str])], None] | None = None):
¶
Reset the file to specific commit or branch.
| Parameters | |
repo:Repo | dulwich Repo object |
filestr | file to reset, relative to the repository path |
target:str | bytes | Commit | Tree | Tag | branch or commit or b'HEAD' to reset |
symlinkCallable[ | Function to use for creating symlinks |
str | os.PathLike[ str] | Repo, paths: list[ bytes | str], source: str | bytes | Commit | Tag | None = None, staged: bool = False, worktree: bool = True):
¶
Restore working tree files.
This is similar to 'git restore', allowing you to restore specific files from a commit or the index without changing HEAD.
| Parameters | |
repo:str | os.PathLike[ | Path to repository or repository object |
paths:list[ | List of specific paths to restore |
source:str | bytes | Commit | Tag | None | Branch name, tag, or commit SHA to restore from. If None, restores staged files from HEAD, or worktree files from index |
staged:bool | Restore files in the index (--staged) |
worktree:bool | Restore files in the working tree (default: True) |
| Raises | |
CheckoutError | If restore cannot be performed |
ValueError | If neither staged nor worktree is specified |
KeyError | If the source reference cannot be found |
str | os.PathLike[ str] | Repo, commits: str | bytes | Commit | Tag | Sequence[ str | bytes | Commit | Tag], no_commit: bool = False, message: str | bytes | None = None, author: bytes | None = None, committer: bytes | None = None) -> bytes | None:
¶
Revert one or more commits.
This creates a new commit that undoes the changes introduced by the specified commits. Unlike reset, revert creates a new commit that preserves history.
| Parameters | |
repo:str | os.PathLike[ | Path to repository or repository object |
commits:str | bytes | Commit | Tag | Sequence[ | List of commit-ish (SHA, ref, etc.) to revert, or a single commit-ish |
nobool | If True, apply changes to index/working tree but don't commit |
message:str | bytes | None | Optional commit message (default: "Revert <original subject>") |
author:bytes | None | Optional author for revert commit |
committer:bytes | None | Optional committer for revert commit |
| Returns | |
bytes | None | SHA1 of the new revert commit, or None if no_commit=True |
| Raises | |
Error | If revert fails due to conflicts or other issues |
str | os.PathLike[ str] | Repo, summary_only: bool = False, sort_by_commits: bool = False) -> list[ dict[ str, str]]:
¶
Summarize commits by author, like git shortlog.
| Parameters | |
repo:str | os.PathLike[ | Path to repository or Repo object. |
summarybool | If True, only show counts per author. |
sortbool | If True, sort authors by number of commits. |
| Returns | |
A list where each item is a dict containing |
|
Repo | str = '.', branches: list[ str | bytes] | None = None, all_branches: bool = False, remotes: bool = False, current: bool = False, topo_order: bool = False, more: int | None = None, list_branches: bool = False, independent_branches: bool = False, merge_base: bool = False) -> list[ str]:
¶
Display branches and their commits.
| Parameters | |
repo:Repo | str | Path to the repository |
branches:list[ | List of specific branches to show (default: all local branches) |
allbool | Show both local and remote branches |
remotes:bool | Show only remote branches |
current:bool | Include current branch if not specified |
topobool | Show in topological order instead of chronological |
more:int | None | Show N more commits beyond common ancestor (negative to show only headers) |
listbool | Synonym for more=-1 (show only branch headers) |
independentbool | Show only branches not reachable from others |
mergebool | Show merge bases instead of commit list |
| Returns | |
list[ | List of output lines |
str | os.PathLike[ str], repo: str | os.PathLike[ str] | Repo = '.') -> list[ tuple[ int, RawObjectID, int | None]]:
¶
Show the contents of a pack index file.
| Parameters | |
indexstr | os.PathLike[ | Path to the pack index file |
repo:str | os.PathLike[ | Path to the repository or a Repo object (for object format) |
| Returns | |
list[ | List of tuples (offset, sha, crc32) for each entry |
| Raises | |
FileNotFoundError | If the index file doesn't exist |
RepoPath, obj: Tree | Blob | Commit | Tag, decode: Callable[ [ bytes], str], outstream: TextIO):
¶
Show details of a git object.
Repo | str = '.', patterns: list[ str | bytes] | None = None, head: bool = False, branches: bool = False, tags: bool = False, dereference: bool = False, verify: bool = False) -> list[ tuple[ bytes, bytes]]:
¶
List references in a local repository.
Returns: List of tuples with (sha, ref_name) or (sha, ref_name^{}) for dereferenced tags
| Parameters | |
repo:Repo | str | Path to the repository |
patterns:list[ | Optional list of patterns to filter refs (matched from the end) |
head:bool | Show the HEAD reference |
branches:bool | Limit to local branches (refs/heads/) |
tags:bool | Limit to local tags (refs/tags/) |
dereference:bool | Dereference tags into object IDs |
verify:bool | Enable stricter reference checking (exact path match) |
| Returns | |
list[ | Undocumented |
str | os.PathLike[ str] | Repo, patterns: list[ str] | None = None, force: bool = False, cone: bool | None = None):
¶
Perform a sparse checkout in the repository (either 'full' or 'cone mode').
Perform sparse checkout in either 'cone' (directory-based) mode or 'full pattern' (.gitignore) mode, depending on the cone parameter.
If cone is None, the mode is inferred from the repository's core.sparseCheckoutCone config setting.
- Steps:
- If patterns is provided, write them to .git/info/sparse-checkout.
- Determine which paths in the index are included vs. excluded. - If cone=True, use "cone-compatible" directory-based logic. - If cone=False, use standard .gitignore-style matching.
- Update the index's skip-worktree bits and add/remove files in the working tree accordingly.
- If force=False, refuse to remove files that have local modifications.
| Parameters | |
repo:str | os.PathLike[ | Path to the repository or a Repo object. |
patterns:list[ | Optional list of sparse-checkout patterns to write. |
force:bool | Whether to force removal of locally modified files (default False). |
cone:bool | None | Boolean indicating cone mode (True/False). If None, read from config. |
| Returns | |
| None |
str | os.PathLike[ str] | Repo = '.', ignored: bool = False, untracked_files: str = 'normal') -> GitStatus:
¶
Returns staged, unstaged, and untracked changes relative to the HEAD.
- Returns: GitStatus tuple,
- staged - dict with lists of staged paths (filesystem paths as bytes) unstaged - list of unstaged paths (filesystem paths as bytes) untracked - list of untracked paths (filesystem paths as bytes)
| Parameters | |
repo:str | os.PathLike[ | Path to repository or repository object |
ignored:bool | Whether to include ignored files in untracked |
untrackedstr |
|
| Returns | |
GitStatus | Undocumented |
str | bytes, *, strip_comments: bool = False, comment_char: str = '#', comment_lines: bool = False) -> bytes:
¶
Strip unnecessary whitespace from text.
This function implements the functionality of git stripspace, commonly used to clean up commit messages and other text content.
- The function performs the following operations:
- If comment_lines is True, prepend comment_char + space to each line
- Strip trailing whitespace from each line
- If strip_comments is True, remove lines starting with comment_char
- Collapse multiple consecutive blank lines into a single blank line
- Remove leading blank lines
- Remove trailing blank lines
- Ensure the text ends with a newline (unless empty)
Examples
>>> stripspace(b" hello \\n\\n\\nworld \\n\\n") b'hello\\n\\nworld\\n'
>>> stripspace(b"# comment\\ntext\\n", strip_comments=True) b'text\\n'
>>> stripspace(b"line\\n", comment_lines=True) b'# line\\n'
| Parameters | |
text:str | bytes | The text to process (string or bytes) |
stripbool | If True, remove lines that begin with comment_char |
commentstr | The comment character to use (default: "#") |
commentbool | If True, prepend comment_char to each line |
| Returns | |
bytes | The processed text as bytes |
str | os.PathLike[ str] | Repo, paths: Sequence[ str | bytes | os.PathLike[ str]] | None = None, init: bool = False, force: bool = False, recursive: bool = False, errstream: BinaryIO | None = None):
¶
Update submodules.
| Parameters | |
repo:str | os.PathLike[ | Path to repository |
paths:Sequence[ | Optional list of specific submodule paths to update. If None, updates all. |
init:bool | If True, initialize submodules first |
force:bool | Force update even if local changes exist |
recursive:bool | If True, recursively update nested submodules |
errstream:BinaryIO | None | Error stream for error messages |
str | os.PathLike[ str] | Repo, target: str | bytes | Commit | Tag, create: str | bytes | None = None, force: bool = False, detach: bool = False):
¶
Switch branches.
This is similar to 'git switch', allowing you to switch to a different branch or commit, updating both HEAD and the working tree.
| Parameters | |
repo:str | os.PathLike[ | Path to repository or repository object |
target:str | bytes | Commit | Tag | Branch name, tag, or commit SHA to switch to |
create:str | bytes | None | Create a new branch at target before switching (like git switch -c) |
force:bool | Force switch even if there are local changes |
detach:bool | Switch to a commit in detached HEAD state (like git switch --detach) |
| Raises | |
CheckoutError | If switch cannot be performed due to conflicts |
KeyError | If the target reference cannot be found |
ValueError | If both create and detach are specified |
RepoPath, tag: str | bytes, author: str | bytes | None = None, message: str | bytes | None = None, annotated: bool = False, objectish: str | bytes = 'HEAD', tag_time: int | None = None, tag_timezone: int | None = None, sign: bool | None = None, encoding: str | None = None):
¶
Creates a tag in git via dulwich calls.
| Parameters | |
repo:RepoPath | Path to repository |
tag:str | bytes | tag string |
author:str | bytes | None | tag author (optional, if annotated is set) |
message:str | bytes | None | tag message (optional) |
annotated:bool | whether to create an annotated tag |
objectish:str | bytes | object the tag should point at, defaults to HEAD |
tagint | None | Optional time for annotated tag |
tagint | None | Optional timezone for annotated tag |
sign:bool | None | GPG Sign the tag (bool, defaults to False, pass True to use default GPG key, pass a str containing Key ID to use a specific GPG key) |
encoding:str | None | Encoding to use for tag messages |
str | os.PathLike[ str], target: str | os.PathLike[ str] = '.') -> int:
¶
Unpack objects from a pack file into the repository.
| Parameters | |
packstr | os.PathLike[ | Path to the pack file to unpack |
target:str | os.PathLike[ | Path to the repository to unpack into |
| Returns | |
int | Number of objects unpacked |
str | os.PathLike[ str] | Repo, ref: str | bytes, new_value: str | bytes | None, old_value: str | bytes | None = None, message: str | bytes | None = None):
¶
Update the object name stored in a ref safely.
| Parameters | |
repo:str | os.PathLike[ | Path to the repository or a Repo object |
ref:str | bytes | Name of the ref to update (e.g., 'refs/heads/main', 'HEAD') |
newstr | bytes | None | New object SHA to set the ref to (None to delete) |
oldstr | bytes | None | Optional old value to verify before updating (for atomic updates) |
message:str | bytes | None | Optional message for the reflog |
| Raises | |
ValueError | If the old value doesn't match |
RepoPath, committish: str | bytes = 'HEAD', keyids: list[ str] | None = None):
¶
Verify signature on a commit.
| Parameters | |
repo:RepoPath | Path to repository |
committish:str | bytes | Commit to verify (defaults to HEAD) |
keyids:list[ | Optional list of trusted key IDs. If provided, the commit must be signed by one of these keys. If not provided, just verifies that the commit has a valid signature. |
| Raises | |
gpg.errors.BadSignatures | if GPG signature verification fails |
gpg.errors.MissingSignatures | if commit was not signed by a key specified in keyids |
Verify signature on a tag.
| Parameters | |
repo:RepoPath | Path to repository |
tagname:str | bytes | Name of tag to verify |
keyids:list[ | Optional list of trusted key IDs. If provided, the tag must be signed by one of these keys. If not provided, just verifies that the tag has a valid signature. |
| Raises | |
gpg.errors.BadSignatures | if GPG signature verification fails |
gpg.errors.MissingSignatures | if tag was not signed by a key specified in keyids |
RepoPath = '.', path: str | os.PathLike[ str] | None = None, branch: str | bytes | None = None, commit: str | bytes | None = None, detach: bool = False, force: bool = False) -> str:
¶
Add a new worktree.
| Parameters | |
repo:RepoPath | Path to repository |
path:str | os.PathLike[ | Path for new worktree |
branch:str | bytes | None | Branch to checkout (creates if doesn't exist) |
commit:str | bytes | None | Specific commit to checkout |
detach:bool | Create with detached HEAD |
force:bool | Force creation even if branch is already checked out |
| Returns | |
str | Path to the newly created worktree |
RepoPath = '.', old_path: str | os.PathLike[ str] | None = None, new_path: str | os.PathLike[ str] | None = None):
¶
Move a worktree to a new location.
| Parameters | |
repo:RepoPath | Path to repository |
oldstr | os.PathLike[ | Current path of worktree |
newstr | os.PathLike[ | New path for worktree |
Unlock a worktree.
| Parameters | |
repo:RepoPath | Path to repository |
path:str | os.PathLike[ | Path to worktree to unlock |
Check for uncommitted changes that would conflict with a checkout/switch.
| Parameters | |
repo:Repo | Repository object |
targetObjectID | Tree ID to check conflicts against |
force:bool | If True, skip the check |
| Raises | |
CheckoutError | If there are conflicting local changes |
Repo, merge_commit_id: ObjectID, no_commit: bool = False, no_ff: bool = False, message: bytes | None = None, author: bytes | None = None, committer: bytes | None = None) -> tuple[ ObjectID | None, list[ bytes]]:
¶
Internal merge implementation that operates on an open repository.
| Parameters | |
r:Repo | Open repository object |
mergeObjectID | SHA of commit to merge |
nobool | If True, do not create a merge commit |
nobool | If True, force creation of a merge commit |
message:bytes | None | Optional merge commit message |
author:bytes | None | Optional author for merge commit |
committer:bytes | None | Optional committer for merge commit |
| Returns | |
tuple[ | Tuple of (merge_commit_sha, conflicts) where merge_commit_sha is None if no_commit=True or there were conflicts |
Repo, merge_commit_ids: list[ ObjectID], no_commit: bool = False, no_ff: bool = False, message: bytes | None = None, author: bytes | None = None, committer: bytes | None = None) -> tuple[ ObjectID | None, list[ bytes]]:
¶
Internal octopus merge implementation that operates on an open repository.
| Parameters | |
r:Repo | Open repository object |
mergelist[ | List of commit SHAs to merge |
nobool | If True, do not create a merge commit |
nobool | If True, force creation of a merge commit (ignored for octopus) |
message:bytes | None | Optional merge commit message |
author:bytes | None | Optional author for merge commit |
committer:bytes | None | Optional committer for merge commit |
| Returns | |
tuple[ | Tuple of (merge_commit_sha, conflicts) where merge_commit_sha is None if no_commit=True or there were conflicts |
Filter kwargs to only include parameters accepted by get_transport_and_path.
| Parameters | |
**kwargs:object | Arbitrary keyword arguments |
| Returns | |
TransportKwargs | Dictionary containing only the kwargs that get_transport_and_path accepts |
BaseRepo, pushed_shas: set[ ObjectID], already_included: set[ Ref], remote_refs: dict[ Ref, ObjectID]) -> Iterator[ tuple[ Ref, ObjectID]]:
¶
Yield annotated tags whose targets are reachable from pushed commits.
| Parameters | |
r:BaseRepo | Local repository |
pushedset[ | SHAs being pushed (non-deletion) |
alreadyset[ | Refs already being pushed |
remotedict[ | Current remote refs |
| Returns | |
Iterator[ | Undocumented |
Get merge status for all branches relative to current HEAD.
| Parameters | |
repo:RepoPath | Path to the repository |
| Returns | |
Iterator[ | Undocumented |
| Yields | |
tuple of (branch_name, is_merged) where |
|
Get reflog message, checking GIT_REFLOG_ACTION environment variable.
| Parameters | |
defaultbytes | Default message to use if no explicit message or env var |
explicitbytes | None | Explicit message passed as argument (takes precedence) |
| Returns | |
The reflog message with priority |
|
Check whether subdir is parentdir or a subdir of parentdir.
If parentdir or subdir is a relative path, it will be disamgibuated relative to the pwd.
Normalize a filesystem path to NFC (precomposed) Unicode form.
On macOS, HFS+/APFS filesystems return filenames in NFD (decomposed) form. This function normalizes them to NFC so they match the paths stored in the git index.
BaseRepo, remote_refs: dict[ Ref, ObjectID], refspecs: str | bytes | Sequence[ str | bytes] | None, *, force: bool = False, mirror_mode: bool = False, all: bool = False, tags: bool = False, delete: bool = False) -> list[ tuple[ Ref | None, Ref | None, bool]]:
¶
Select which refs to push based on mode flags or user refspecs.
Returns a list of (local_ref, remote_ref, force) tuples. local_ref is None for deletions.
| Parameters | |
r:BaseRepo | Local repository |
remotedict[ | Current remote refs dict |
refspecs:str | bytes | Sequence[ | User-provided refspecs (may be None) |
force:bool | Force overwriting refs |
mirrorbool | Push all refs |
all:bool | Push all branches |
tags:bool | Push all tags |
delete:bool | Delete the specified remote refs |
| Returns | |
list[ | Undocumented |
str | bytes | os.PathLike[ str], basepath: str | bytes | os.PathLike[ str], prune_dirnames: Callable[ [ str, list[ str]], list[ str]] | None = None, precompose_unicode: bool = False) -> Iterator[ tuple[ str | bytes, bool]]:
¶
Get path, is_dir for files in working dir from frompath.
| Parameters | |
frompath:str | bytes | os.PathLike[ | Path to begin walk |
basepath:str | bytes | os.PathLike[ | Path to compare to |
pruneCallable[ | Optional callback to prune dirnames during os.walk dirnames will be set to result of prune_dirnames(dirpath, dirnames) |
precomposebool | If True, normalize paths to NFC Unicode form |
| Returns | |
Iterator[ | Undocumented |