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
- submodule_add
- submodule_init
- submodule_list
- 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.
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
Class |
|
Fallback if stdout or stderr are unavailable, does nothing. |
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 | archive |
Create an archive. |
Function | branch |
Create a branch. |
Function | branch |
Delete a branch. |
Function | branch |
List all branches. |
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 | 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 |
Undocumented |
Function | commit |
Undocumented |
Function | commit |
Create a new commit object. |
Function | daemon |
Run a daemon serving Git requests over TCP/IP. |
Function | describe |
Describe the repository version. |
Function | diff |
Compares the content and mode of blobs found via two tree objects. |
Function | fetch |
Fetch objects from a remote server. |
Function | find |
For now, just return 7 characters. |
Function | fsck |
Check a repository. |
Function | get |
Return the active branch's remote name, if any. |
Function | get |
Get an object by path. |
Function | get |
Undocumented |
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 https://raw.githubusercontent.com/git/git/v2.3.0/Documentation/date-formats.txt Returns: A tuple containing author timezone, committer timezone |
Function | init |
Create a new git repository. |
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 | 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. 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 | pack |
Pack objects into a 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 a simple status summary, listing changed files. |
Function | print |
Write a human-readable tag. |
Function | pull |
Pull from remote via dulwich.client |
Function | push |
Remote push with dulwich via dulwich.client |
Function | receive |
Receive a pack file after negotiating its contents using smart protocol. |
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 | reset |
Reset current HEAD to the specified state. |
Function | reset |
Reset the file to specific commit or branch. |
Function | rev |
Lists commit objects in reverse chronological order. |
Function | show |
Print the changes in a commit. |
Function | show |
Write a blob to a stream. |
Function | show |
Show a commit to a stream. |
Function | show |
Undocumented |
Function | show |
Print a tag to a stream. |
Function | show |
Print a tree to a stream. |
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 | submodule |
Add a new submodule. |
Function | submodule |
Initialize submodules. |
Function | submodule |
List submodules. |
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 | update |
Update HEAD to point at a new branch/commit. |
Function | update |
Update server info files for a repository. |
Function | upload |
Upload a pack file after negotiating its contents using smart protocol. |
Function | web |
Run a daemon serving Git requests over HTTP. |
Function | write |
Write a tree object from the index. |
Constant | DEFAULT |
Undocumented |
Variable | default |
Undocumented |
Variable | default |
Undocumented |
Variable |
|
Undocumented |
Function | _canonical |
Undocumented |
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 | _walk |
Get path, is_dir for files in working dir from frompath |
Return the active branch in the repository, if any.
Parameters | |
repo | Repository to open |
Returns | |
branch name | |
Raises | |
KeyError | if the repository does not have a working tree |
IndexError | if HEAD is floating |
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.
Parameters | |
repo | Repository for the files |
paths | Paths to add. No value passed stages all modified files. |
Create an archive.
Parameters | |
repo | Path of repository for which to generate an archive. |
committish | Commit SHA1 or ref to use |
outstream | Output stream (defaults to stdout) |
errstream | Error stream (defaults to stderr) |
Create a branch.
Parameters | |
repo | Path to the repository |
name | Name of the new branch |
objectish | Target object to point new branch at (defaults to HEAD) |
force | Force creation of branch, even if it already exists |
Check if updating to a sha can be done with fast forwarding.
Parameters | |
repo | Repository object |
current | Current head sha |
new | New head sha |
Debug gitignore files.
Returns: List of ignored files
Parameters | |
repo | Path to the repository |
paths | List of paths to check for |
no | Don't check index |
Check canonical name and email of contact.
Returns: Canonical contact data
Parameters | |
repo | Path to the repository |
contact | Contact name and/or email |
Remove any untracked files from the target directory recursively
Equivalent to running git clean -fd in target_dir.
Parameters | |
repo | Repository where the files may be tracked |
target | Directory to clean - current directory if None |
Clone a local or remote git repository.
Returns: The new repository
Parameters | |
source | Path or URL for source repository |
target | Path to target repository (optional) |
bare | Whether or not to create a bare repository |
checkout | Whether or not to check-out HEAD after cloning |
errstream | Optional stream to write progress to |
outstream | Optional stream to write progress to (deprecated) |
origin:Optional[ | Name of remote from the repository used to clone |
depth:Optional[ | Depth to fetch at |
branch:Optional[ | Optional branch or tag to be used as HEAD in the new repository instead of the cloned repository's HEAD. |
config:Optional[ | Configuration to use |
**kwargs | Undocumented |
Create a new commit.
Returns: SHA1 of the new commit
Parameters | |
repo | Path to repository |
message | Optional commit message |
author | Optional author name and email |
author | Author timestamp timezone |
committer | Optional committer name and email |
commit | Commit timestamp timezone |
encoding | Undocumented |
no | Skip pre-commit and commit-msg hooks |
signoff | GPG Sign the commit (bool, defaults to False, pass True to use default GPG key, pass a str containing Key ID to use a specific GPG key) |
Create a new commit object.
Parameters | |
repo | Path to repository |
tree | An existing tree object |
message | Undocumented |
author | Optional author name and email |
committer | Optional committer name and email |
Run a daemon serving Git requests over TCP/IP.
Parameters | |
path | Path to the directory to serve. |
address | Optional address to listen on (defaults to ::) |
port | Optional port to listen on (defaults to TCP_GIT_PORT) |
Describe the repository version.
Returns: a string description of the current git revision
Examples: "gabcdefh", "v0.1" or "v0.1-5-gabcdefh".
Parameters | |
repo | git repository |
abbrev | number of characters of commit to take, default is 7 |
Compares the content and mode of blobs found via two tree objects.
Parameters | |
repo | Path to repository |
old | Id of old tree |
new | Id of new tree |
outstream | Stream to write to |
Fetch objects from a remote server.
Parameters | |
repo | Path to the repository |
remote | String identifying a remote server |
outstream | Output stream (defaults to stdout) |
errstream | Error stream (defaults to stderr) |
message | Reflog message (defaults to b"fetch: from <remote_name>") |
depth | Depth to fetch at |
prune | Prune remote removed refs |
prune | Prune reomte removed tags |
force | Undocumented |
**kwargs | Undocumented |
Returns | |
Dictionary with refs on the remote |
Return the active branch's remote name, if any.
Parameters | |
repo | Repository to open |
Returns | |
remote name | |
Raises | |
KeyError | if the repository does not have a working tree |
Get an object by path.
Returns: A ShaFile
object
Parameters | |
repo | A path to the repository |
path | Path to look up |
committish | Commit to look up path in |
Return add/delete/modify changes to tree by comparing index to HEAD.
Returns: dict with lists for each type of change
Parameters | |
repo | repo path or object |
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 | Path to walk |
basepath | Path to compare to |
index | Index to check against |
exclude | Whether to exclude ignored paths |
untracked | How to handle untracked files: - "no": return an empty list - "all": return all files in untracked directories - "normal": Not implemented |
Retrieve local timezone as described in https://raw.githubusercontent.com/git/git/v2.3.0/Documentation/date-formats.txt Returns: A tuple containing author timezone, committer timezone
Create a new git repository.
Returns: A Repo instance
Parameters | |
path | Path to repository. |
bare | Whether to create a bare repository. |
Write commit logs.
Parameters | |
repo | Path to repository |
paths | Optional set of specific paths to print entries for |
outstream | Stream to write log output to |
max | Optional maximum number of entries to display |
reverse | Reverse order in which entries are printed |
name | Print name status |
List contents of a tree.
Parameters | |
repo | Path to the repository |
treeish | Tree id to list |
outstream | Output stream (defaults to stdout) |
recursive | Whether to recursively list files |
name | Only print item name |
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.
Pack objects into a file.
Parameters | |
repo | Path to the repository |
object | List of object ids to write |
packf | File-like object to write to |
idxf | File-like object to write to (can be None) |
delta | Undocumented |
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 | |
tz | datetime string |
Raises | |
TimezoneFormatError | if timezone information cannot be extracted |
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 | Repository path, absolute or relative to the cwd |
path | A path, absolute or relative to the cwd |
tree | Undocumented |
Write a human-readable commit log entry.
Parameters | |
commit | A Commit object |
decode | Undocumented |
outstream | A stream file to write to |
Write a human-readable tag.
Parameters | |
tag | A Tag object |
decode | Function for decoding bytes to unicode string |
outstream | A stream to write to |
Pull from remote via dulwich.client
Parameters | |
repo | Path to repository |
remote | Location of the remote |
refspecs | refspecs to fetch |
outstream | A stream file to write to output |
errstream | A stream file to write to errors |
fast | Undocumented |
force | Undocumented |
**kwargs | Undocumented |
Remote push with dulwich via dulwich.client
Parameters | |
repo | Path to repository |
remote | Location of the remote |
refspecs | Refs to push to remote |
outstream | A stream file to write output |
errstream | A stream file to write errors |
force | Force overwriting refs |
**kwargs | Undocumented |
Receive a pack file after negotiating its contents using smart protocol.
Parameters | |
path | Path to the repository |
inf | Input stream to communicate with client |
outf | Output stream to communicate with client |
Remove files from the staging area.
Parameters | |
repo | Repository for the files |
paths | Paths to remove |
cached | Undocumented |
Repack loose files in a repository.
Currently this only packs loose objects.
Parameters | |
repo | Path to the repository |
Reset current HEAD to the specified state.
Parameters | |
repo | Path to repository |
mode | Mode ("hard", "soft", "mixed") |
treeish | Treeish to reset to |
Lists commit objects in reverse chronological order.
Parameters | |
repo | Path to repository |
commits | Commits over which to iterate |
outstream | Stream to write to |
Print the changes in a commit.
Parameters | |
repo | Path to repository |
objects | Objects to show (defaults to [HEAD]) |
outstream | Stream to write to |
default | Default encoding to use if none is set in the commit |
Returns staged, unstaged, and untracked changes relative to the HEAD.
Note: untracked_files="normal" (git's default) is not implemented.
- Returns: GitStatus tuple,
- staged - dict with lists of staged paths (diff index/HEAD) unstaged - list of unstaged paths (diff index/working-tree) untracked - list of untracked, un-ignored & non-.git paths
Parameters | |
repo | Path to repository or repository object |
ignored | Whether to include ignored files in untracked |
untracked |
|
Add a new submodule.
Parameters | |
repo | Path to repository |
url | URL of repository to add as submodule |
path | Path where submodule should live |
name | Undocumented |
Set git symbolic ref into HEAD.
Parameters | |
repo | path to the repository |
ref | short name of the new ref |
force | force settings without checking if it exists in refs/heads |
Creates a tag in git via dulwich calls:
Parameters | |
repo | Path to repository |
tag | tag string |
author | tag author (optional, if annotated is set) |
message | tag message (optional) |
annotated | whether to create an annotated tag |
objectish | object the tag should point at, defaults to HEAD |
tag | Optional time for annotated tag |
tag | Optional timezone for annotated tag |
sign | 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 | Undocumented |
Update HEAD to point at a new branch/commit.
Note that this does not actually update the working tree.
Parameters | |
repo | Path to the repository |
target | Branch or committish to switch to |
detached | Create a detached head |
new | New branch to create |
Upload a pack file after negotiating its contents using smart protocol.
Parameters | |
path | Path to the repository |
inf | Input stream to communicate with client |
outf | Output stream to communicate with client |
Run a daemon serving Git requests over HTTP.
Parameters | |
path | Path to the directory to serve |
address | Optional address to listen on (defaults to ::) |
port | Optional port to listen on (defaults to 80) |
Write a tree object from the index.
Returns: tree id for the tree that was written
Parameters | |
repo | Repository for which to write tree |
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.