Simple wrapper that provides porcelain-like functions on top of Dulwich.

Currently implemented:
  • archive
  • add
  • branch{_create,_delete,_list}
  • check-ignore
  • checkout
  • clone
  • commit
  • commit-tree
  • daemon
  • describe
  • diff-tree
  • fetch
  • init
  • ls-files
  • ls-remote
  • ls-tree
  • pull
  • push
  • rm
  • remote{_add}
  • receive-pack
  • reset
  • rev-list
  • tag{_create,_delete,_list}
  • upload-pack
  • update-server-info
  • status
  • symbolic-ref

These functions are meant to behave similarly to the git subcommands. Differences in behaviour are considered bugs.

Functions should generally accept both unicode strings and bytestrings

Class NoneStream Fallback if stdout or stderr are unavailable, does nothing.
Class RemoteExists Raised when the remote already exists.
Function open_repo Open an argument that can be a repository or a path for a repository.
Function open_repo_closing 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.
Function path_to_tree_path Convert a path to a path usable in an index, e.g. bytes and relative to the repository root.
Function archive Create an archive.
Function update_server_info Update server info files for a repository.
Function symbolic_ref Set git symbolic ref into HEAD.
Function commit Create a new commit.
Function commit_tree Create a new commit object.
Function init Create a new git repository.
Function clone Clone a local or remote git repository.
Function add Add files to the staging area.
Function remove Remove files from the staging area.
Function commit_decode Undocumented
Function print_commit Write a human-readable commit log entry.
Function print_tag Write a human-readable tag.
Function show_blob Write a blob to a stream.
Function show_commit Show a commit to a stream.
Function show_tree Print a tree to a stream.
Function show_tag Print a tag to a stream.
Function show_object Undocumented
Function print_name_status Print a simple status summary, listing changed files.
Function log Write commit logs.
Function show Print the changes in a commit.
Function diff_tree Compares the content and mode of blobs found via two tree objects.
Function rev_list Lists commit objects in reverse chronological order.
Function tag Undocumented
Function tag_create Creates a tag in git via dulwich calls:
Function list_tags Undocumented
Function tag_list List all tags.
Function tag_delete Remove a tag.
Function reset Reset current HEAD to the specified state.
Function push Remote push with dulwich via dulwich.client
Function pull Pull from remote via dulwich.client
Function status Returns staged, unstaged, and untracked changes relative to the HEAD.
Function get_untracked_paths Get untracked paths.
Function get_tree_changes Return add/delete/modify changes to tree by comparing index to HEAD.
Function daemon Run a daemon serving Git requests over TCP/IP.
Function web_daemon Run a daemon serving Git requests over HTTP.
Function upload_pack Upload a pack file after negotiating its contents using smart protocol.
Function receive_pack Receive a pack file after negotiating its contents using smart protocol.
Function branch_delete Delete a branch.
Function branch_create Create a branch.
Function branch_list List all branches.
Function fetch Fetch objects from a remote server.
Function ls_remote List the refs in a remote.
Function repack Repack loose files in a repository.
Function pack_objects Pack objects into a file.
Function ls_tree List contents of a tree.
Function remote_add Add a remote.
Function check_ignore Debug gitignore files.
Function update_head Update HEAD to point at a new branch/commit.
Function check_mailmap Check canonical name and email of contact.
Function fsck Check a repository.
Function stash_list List all stashes in a repository.
Function stash_push Push a new stash onto the stack.
Function stash_pop Pop a new stash from the stack.
Function ls_files List all files in an index.
Function describe Describe the repository version.
Function get_object_by_path Get an object by path.
Function _noop_context_manager Context manager that has the same api as closing but does nothing.
Function _make_branch_ref Undocumented
Function _make_tag_ref Undocumented
def open_repo(path_or_repo):
Open an argument that can be a repository or a path for a repository.
@contextmanager
def _noop_context_manager(obj):
Context manager that has the same api as closing but does nothing.
def open_repo_closing(path_or_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.
def path_to_tree_path(repopath, path):
Convert a path to a path usable in an index, e.g. bytes and relative to the repository root.
ParametersrepopathRepository path, absolute or relative to the cwd
pathA path, absolute or relative to the cwd
ReturnsA path formatted for use in e.g. an index
def archive(repo, committish=None, outstream=default_bytes_out_stream, errstream=default_bytes_err_stream):
Create an archive.
ParametersrepoPath of repository for which to generate an archive.
committishCommit SHA1 or ref to use
outstreamOutput stream (defaults to stdout)
errstreamError stream (defaults to stderr)
def update_server_info(repo='.'):
Update server info files for a repository.
Parametersrepopath to the repository
def symbolic_ref(repo, ref_name, force=False):
Set git symbolic ref into HEAD.
Parametersrepopath to the repository
ref_nameshort name of the new ref
forceforce settings without checking if it exists in refs/heads
def commit(repo='.', message=None, author=None, committer=None, encoding=None):
Create a new commit.
ParametersrepoPath to repository
messageOptional commit message
authorOptional author name and email
committerOptional committer name and email
ReturnsSHA1 of the new commit
def commit_tree(repo, tree, message=None, author=None, committer=None):
Create a new commit object.
ParametersrepoPath to repository
treeAn existing tree object
authorOptional author name and email
committerOptional committer name and email
def init(path='.', bare=False):
Create a new git repository.
ParameterspathPath to repository.
bareWhether to create a bare repository.
ReturnsA Repo instance
def clone(source, target=None, bare=False, checkout=None, errstream=default_bytes_err_stream, outstream=None, origin='origin', depth=None, **kwargs):
Clone a local or remote git repository.
ParameterssourcePath or URL for source repository
targetPath to target repository (optional)
bareWhether or not to create a bare repository
checkoutWhether or not to check-out HEAD after cloning
errstreamOptional stream to write progress to
outstreamOptional stream to write progress to (deprecated)
originName of remote from the repository used to clone
depthDepth to fetch at
ReturnsThe new repository
def add(repo='.', paths=None):
Add files to the staging area.
ParametersrepoRepository for the files
pathsPaths to add. No value passed stages all modified files.
ReturnsTuple with set of added files and ignored files
def remove(repo='.', paths=None, cached=False):
Remove files from the staging area.
ParametersrepoRepository for the files
pathsPaths to remove
def commit_decode(commit, contents, default_encoding=DEFAULT_ENCODING):
Undocumented
def print_commit(commit, decode, outstream=sys.stdout):
Write a human-readable commit log entry.
ParameterscommitA Commit object
outstreamA stream file to write to
def print_tag(tag, decode, outstream=sys.stdout):
Write a human-readable tag.
ParameterstagA Tag object
decodeFunction for decoding bytes to unicode string
outstreamA stream to write to
def show_blob(repo, blob, decode, outstream=sys.stdout):
Write a blob to a stream.
ParametersrepoA Repo object
blobA Blob object
decodeFunction for decoding bytes to unicode string
outstreamA stream file to write to
def show_commit(repo, commit, decode, outstream=sys.stdout):
Show a commit to a stream.
ParametersrepoA Repo object
commitA Commit object
decodeFunction for decoding bytes to unicode string
outstreamStream to write to
def show_tree(repo, tree, decode, outstream=sys.stdout):
Print a tree to a stream.
ParametersrepoA Repo object
treeA Tree object
decodeFunction for decoding bytes to unicode string
outstreamStream to write to
def show_tag(repo, tag, decode, outstream=sys.stdout):
Print a tag to a stream.
ParametersrepoA Repo object
tagA Tag object
decodeFunction for decoding bytes to unicode string
outstreamStream to write to
def show_object(repo, obj, decode, outstream):
Undocumented
def print_name_status(changes):
Print a simple status summary, listing changed files.
def log(repo='.', paths=None, outstream=sys.stdout, max_entries=None, reverse=False, name_status=False):
Write commit logs.
ParametersrepoPath to repository
pathsOptional set of specific paths to print entries for
outstreamStream to write log output to
reverseReverse order in which entries are printed
name_statusPrint name status
max_entriesOptional maximum number of entries to display
def show(repo='.', objects=None, outstream=sys.stdout, default_encoding=DEFAULT_ENCODING):
Print the changes in a commit.
ParametersrepoPath to repository
objectsObjects to show (defaults to [HEAD])
outstreamStream to write to
default_encodingDefault encoding to use if none is set in the commit
def diff_tree(repo, old_tree, new_tree, outstream=sys.stdout):
Compares the content and mode of blobs found via two tree objects.
ParametersrepoPath to repository
old_treeId of old tree
new_treeId of new tree
outstreamStream to write to
def rev_list(repo, commits, outstream=sys.stdout):
Lists commit objects in reverse chronological order.
ParametersrepoPath to repository
commitsCommits over which to iterate
outstreamStream to write to
def tag(*args, **kwargs):
Undocumented
def tag_create(repo, tag, author=None, message=None, annotated=False, objectish='HEAD', tag_time=None, tag_timezone=None):
Creates a tag in git via dulwich calls:
ParametersrepoPath to repository
tagtag string
authortag author (optional, if annotated is set)
messagetag message (optional)
annotatedwhether to create an annotated tag
objectishobject the tag should point at, defaults to HEAD
tag_timeOptional time for annotated tag
tag_timezoneOptional timezone for annotated tag
def list_tags(*args, **kwargs):
Undocumented
def tag_list(repo, outstream=sys.stdout):
List all tags.
ParametersrepoPath to repository
outstreamStream to write tags to
def tag_delete(repo, name):
Remove a tag.
ParametersrepoPath to repository
nameName of tag to remove
def reset(repo, mode, treeish='HEAD'):
Reset current HEAD to the specified state.
ParametersrepoPath to repository
modeMode ("hard", "soft", "mixed")
treeishTreeish to reset to
def push(repo, remote_location, refspecs, outstream=default_bytes_out_stream, errstream=default_bytes_err_stream, **kwargs):
Remote push with dulwich via dulwich.client
ParametersrepoPath to repository
remote_locationLocation of the remote
refspecsRefs to push to remote
outstreamA stream file to write output
errstreamA stream file to write errors
def pull(repo, remote_location=None, refspecs=None, outstream=default_bytes_out_stream, errstream=default_bytes_err_stream, **kwargs):
Pull from remote via dulwich.client
ParametersrepoPath to repository
remote_locationLocation of the remote
refspecrefspecs to fetch
outstreamA stream file to write to output
errstreamA stream file to write to errors
def status(repo='.', ignored=False):
Returns staged, unstaged, and untracked changes relative to the HEAD.
ParametersrepoPath to repository or repository object
ignoredWhether to include ignored files in untracked
ReturnsGitStatus tuple, staged - list of staged paths (diff index/HEAD) unstaged - list of unstaged paths (diff index/working-tree) untracked - list of untracked, un-ignored & non-.git paths
def get_untracked_paths(frompath, basepath, index):

Get untracked paths.

;param frompath: Path to walk :param basepath: Path to compare to :param index: Index to check against

def get_tree_changes(repo):
Return add/delete/modify changes to tree by comparing index to HEAD.
Parametersreporepo path or object
Returnsdict with lists for each type of change
def daemon(path='.', address=None, port=None):
Run a daemon serving Git requests over TCP/IP.
ParameterspathPath to the directory to serve.
addressOptional address to listen on (defaults to ::)
portOptional port to listen on (defaults to TCP_GIT_PORT)
def web_daemon(path='.', address=None, port=None):
Run a daemon serving Git requests over HTTP.
ParameterspathPath to the directory to serve
addressOptional address to listen on (defaults to ::)
portOptional port to listen on (defaults to 80)
def upload_pack(path='.', inf=None, outf=None):
Upload a pack file after negotiating its contents using smart protocol.
ParameterspathPath to the repository
infInput stream to communicate with client
outfOutput stream to communicate with client
def receive_pack(path='.', inf=None, outf=None):
Receive a pack file after negotiating its contents using smart protocol.
ParameterspathPath to the repository
infInput stream to communicate with client
outfOutput stream to communicate with client
def _make_branch_ref(name):
Undocumented
def _make_tag_ref(name):
Undocumented
def branch_delete(repo, name):
Delete a branch.
ParametersrepoPath to the repository
nameName of the branch
def branch_create(repo, name, objectish=None, force=False):
Create a branch.
ParametersrepoPath to the repository
nameName of the new branch
objectishTarget object to point new branch at (defaults to HEAD)
forceForce creation of branch, even if it already exists
def branch_list(repo):
List all branches.
ParametersrepoPath to the repository
def fetch(repo, remote_location, remote_name='origin', outstream=sys.stdout, errstream=default_bytes_err_stream, message=None, depth=None, **kwargs):
Fetch objects from a remote server.
ParametersrepoPath to the repository
remote_locationString identifying a remote server
remote_nameName for remote server
outstreamOutput stream (defaults to stdout)
errstreamError stream (defaults to stderr)
messageReflog message (defaults to b"fetch: from <remote_name>")
depthDepth to fetch at
ReturnsDictionary with refs on the remote
def ls_remote(remote, config=None, **kwargs):
List the refs in a remote.
ParametersremoteRemote repository location
configConfiguration to use
ReturnsDictionary with remote refs
def repack(repo):

Repack loose files in a repository.

Currently this only packs loose objects.

ParametersrepoPath to the repository
def pack_objects(repo, object_ids, packf, idxf, delta_window_size=None):
Pack objects into a file.
ParametersrepoPath to the repository
object_idsList of object ids to write
packfFile-like object to write to
idxfFile-like object to write to (can be None)
def ls_tree(repo, treeish='HEAD', outstream=sys.stdout, recursive=False, name_only=False):
List contents of a tree.
ParametersrepoPath to the repository
tree_ishTree id to list
outstreamOutput stream (defaults to stdout)
recursiveWhether to recursively list files
name_onlyOnly print item name
def remote_add(repo, name, url):
Add a remote.
ParametersrepoPath to the repository
nameRemote name
urlRemote URL
def check_ignore(repo, paths, no_index=False):
Debug gitignore files.
ParametersrepoPath to the repository
pathsList of paths to check for
no_indexDon't check index
ReturnsList of ignored files
def update_head(repo, target, detached=False, new_branch=None):

Update HEAD to point at a new branch/commit.

Note that this does not actually update the working tree.

ParametersrepoPath to the repository
detachCreate a detached head
targetBranch or committish to switch to
new_branchNew branch to create
def check_mailmap(repo, contact):
Check canonical name and email of contact.
ParametersrepoPath to the repository
contactContact name and/or email
ReturnsCanonical contact data
def fsck(repo):
Check a repository.
ParametersrepoA path to the repository
ReturnsIterator over errors/warnings
def stash_list(repo):
List all stashes in a repository.
def stash_push(repo):
Push a new stash onto the stack.
def stash_pop(repo):
Pop a new stash from the stack.
def ls_files(repo):
List all files in an index.
def describe(repo):

Describe the repository version.

Examples: "gabcdefh", "v0.1" or "v0.1-5-gabcdefh".

Parametersprojdirgit repository root
Returnsa string description of the current git revision
def get_object_by_path(repo, path, committish=None):
Get an object by path.
ParametersrepoA path to the repository
pathPath to look up
committishCommit to look up path in
ReturnsA ShaFile object
API Documentation for Dulwich, generated by pydoctor at 2018-11-17 19:05:54.