Expand description
§libgit2 bindings for Rust
This library contains bindings to the libgit2 C library which is used to manage git repositories. The library itself is a work in progress and is likely lacking some bindings here and there, so be warned.
The git2-rs library strives to be as close to libgit2 as possible, but also
strives to make using libgit2 as safe as possible. All resource management
is automatic as well as adding strong types to all interfaces (including
Result
)
§Creating a Repository
The Repository
is the source from which almost all other objects in git-rs
are spawned. A repository can be created through opening, initializing, or
cloning.
§Initializing a new repository
The init
method will create a new repository, assuming one does not
already exist.
use git2::Repository;
let repo = match Repository::init("/path/to/a/repo") {
Ok(repo) => repo,
Err(e) => panic!("failed to init: {}", e),
};
§Opening an existing repository
use git2::Repository;
let repo = match Repository::open("/path/to/a/repo") {
Ok(repo) => repo,
Err(e) => panic!("failed to open: {}", e),
};
§Cloning an existing repository
use git2::Repository;
let url = "https://github.com/alexcrichton/git2-rs";
let repo = match Repository::clone(url, "/path/to/a/repo") {
Ok(repo) => repo,
Err(e) => panic!("failed to clone: {}", e),
};
To clone using SSH, refer to RepoBuilder.
§Working with a Repository
All derivative objects, references, etc are attached to the lifetime of the
source Repository
, to ensure that they do not outlive the repository
itself.
Modules§
- build
- Builder-pattern objects for configuration various git operations.
- cert
- Certificate types which are passed to
CertificateCheck
inRemoteCallbacks
. - oid_
array - Bindings to libgit2’s raw
git_oidarray
type - opts
- Bindings to libgit2’s git_libgit2_opts function.
- string_
array - Bindings to libgit2’s raw
git_strarray
type - transport
- Interfaces for adding custom transports to libgit2
Structs§
- Annotated
Commit - A structure to represent an annotated commit, the input to merge and rebase.
- Apply
Options - Options to specify when applying a diff
- Attr
Check Flags - Blame
- Opaque structure to hold blame results.
- Blame
Hunk - Structure that represents a blame hunk.
- Blame
Iter - An iterator over the hunks in a blame.
- Blame
Options - Blame options
- Blob
- A structure to represent a git blob
- Blob
Writer - A structure to represent a git writestream for blobs
- Branch
- A structure to represent a git branch
- Branches
- An iterator over the branches inside of a repository.
- Buf
- A structure to wrap an intermediate buffer used by libgit2.
- Checkout
Notification Type - Types of notifications emitted from checkouts.
- Cherrypick
Options - Options to specify when cherry picking
- Commit
- A structure to represent a git commit
- Config
- A structure representing a git configuration key/value store
- Config
Entries - An iterator over the
ConfigEntry
values of aConfig
structure. - Config
Entry - A struct representing a certain entry owned by a
Config
instance. - Cred
- A structure to represent git credentials in libgit2.
- Credential
Helper - Management of the gitcredentials(7) interface.
- Credential
Type - Types of credentials that can be requested by a credential callback.
- Deltas
- An iterator over the diffs in a delta
- Describe
- The result of a
describe
operation on either anDescribe
or aRepository
. - Describe
Format Options - Options which can be used to customize how a description is formatted.
- Describe
Options - Options which indicate how a
Describe
is created. - Diff
- The diff object that contains all individual file deltas.
- Diff
Binary - Structure describing the binary contents of a diff.
- Diff
Binary File - The contents of one of the files in a binary diff.
- Diff
Delta - Description of changes to one entry.
- Diff
File - Description of one side of a delta.
- Diff
Find Options - Control behavior of rename and copy detection
- Diff
Flags - Diff
Hunk - Structure describing a hunk of a diff.
- Diff
Line - Structure describing a line (or data span) of a diff.
- Diff
Options - Structure describing options about how the diff should be executed.
- Diff
Patchid Options - Control behavior of formatting emails
- Diff
Stats - Structure describing a hunk of a diff.
- Diff
Stats Format - Formatting options for diff stats
- A structure to represent patch in mbox format for sending via email
- Email
Create Options - Options for controlling the formatting of the generated e-mail.
- Error
- A structure to represent errors coming out of libgit2.
- Fetch
Options - Options which can be specified to various fetch operations.
- Index
- A structure to represent a git index
- Index
AddOption - Flags for APIs that add files matching pathspec
- Index
Conflict - A structure to represent the information returned when a conflict is detected in an index entry
- Index
Conflicts - An iterator over the conflicting entries in an index
- Index
Entries - An iterator over the entries in an index
- Index
Entry - A structure to represent an entry or a file inside of an index.
- Index
Entry Extended Flag - Flags for the
extended_flags
field of an IndexEntry. - Index
Entry Flag - Flags for the
flags
field of an IndexEntry. - Index
Time - Time structure used in a git index entry.
- Indexer
- A stream to write and index a packfile
- Mailmap
- A structure to represent a repository’s .mailmap file.
- Mempack
- A structure to represent a mempack backend for the object database. The Mempack is bound to the Odb that it was created from, and cannot outlive that Odb.
- Merge
Analysis - The results of
merge_analysis
indicating the merge opportunities. - Merge
File Options - Options for merging a file.
- Merge
File Result - Information about file-level merging.
- Merge
Options - Options to specify when merging.
- Merge
Preference - The user’s stated preference for merges.
- Message
Trailers Bytes - Collection of unencoded (bytes) trailers.
- Message
Trailers Bytes Iterator - Borrowed iterator over the raw (bytes) trailers.
- Message
Trailers Strs - Collection of UTF-8-encoded trailers.
- Message
Trailers Strs Iterator - Borrowed iterator over the UTF-8-encoded trailers.
- Note
- A structure representing a note in git.
- Notes
- An iterator over all of the notes within a repository.
- Object
- A structure to represent a git object
- Odb
- A structure to represent a git object database
- OdbLookup
Flags - Flags controlling the behavior of ODB lookup operations
- OdbObject
- An object from the Object Database.
- OdbPackwriter
- A stream to write a packfile to the ODB
- OdbReader
- A structure to represent a git ODB rstream
- OdbWriter
- A structure to represent a git ODB wstream
- Oid
- Unique identity of any object (commit, tree, blob, tag).
- Pack
Builder - A builder for creating a packfile
- Parents
- An iterator over the parent commits of a commit.
- Patch
- A structure representing the text changes in a single diff delta.
- Pathspec
- Structure representing a compiled pathspec used for matching against various structures.
- Pathspec
Diff Entries - Iterator over the matching diff deltas.
- Pathspec
Entries - Iterator over the matched paths in a pathspec.
- Pathspec
Failed Entries - Iterator over the failed list of pathspec items that did not match.
- Pathspec
Flags - …
- Pathspec
Match List - List of filenames matching a pathspec.
- Progress
- Struct representing the progress by an in-flight transfer.
- Proxy
Options - Options which can be specified to various fetch operations.
- Push
Options - Options to control the behavior of a git push.
- Push
Update - Represents an update which will be performed on the remote during push.
- Rebase
- Representation of a rebase
- Rebase
Operation - A rebase operation
- Rebase
Options - Rebase options
- Reference
- A structure to represent a git reference.
- Reference
Format - Options for
Reference::normalize_name
. - Reference
Names - An iterator over the names of references in a repository.
- References
- An iterator over the references in a repository.
- Reflog
- A reference log of a git repository.
- Reflog
Entry - An entry inside the reflog of a repository
- Reflog
Iter - An iterator over the entries inside of a reflog.
- Refspec
- A structure to represent a git refspec.
- Refspecs
- An iterator over the refspecs that a remote contains.
- Remote
- A structure representing a remote of a git repository.
- Remote
Callbacks - A structure to contain the callbacks which are invoked when a repository is being updated or downloaded.
- Remote
Connection - Holds callbacks for a connection to a
Remote
. Disconnects when dropped - Remote
Head - Description of a reference advertised by a remote server, given out on calls
to
list
. - Remote
Update Flags - How to handle reference updates.
- Repository
- An owned git repository, representing all state associated with the underlying filesystem.
- Repository
Init Mode - Mode options for RepositoryInitOptions
- Repository
Init Options - Options which can be used to configure how a repository is initialized
- Repository
Open Flags - Flags for
Repository::open_ext
- Revert
Options - Options to specify when reverting
- Revparse
Mode - Flags for the return value of
Repository::revparse
- Revspec
- A revspec represents a range of revisions within a repository.
- Revwalk
- A revwalk allows traversal of the commit graph defined by including one or more leaves and excluding one or more roots.
- Signature
- A Signature is used to indicate authorship of various actions throughout the library.
- Sort
- Orderings that may be specified for Revwalk iteration.
- Stash
Apply Flags - Stash
Apply Options - Stash application options structure
- Stash
Flags - Stash
Save Options - Stash application options structure
- Status
- Status flags for a single file
- Status
Entry - A structure representing an entry in the
Statuses
structure. - Status
Iter - An iterator over the statuses in a
Statuses
instance. - Status
Options - Options that can be provided to
repo.statuses()
to control how the status information is gathered. - Statuses
- A container for a list of status information about a repository.
- Submodule
- A structure to represent a git submodule
- Submodule
Status - Return codes for submodule status.
- Submodule
Update Options - Options to update a submodule.
- Tag
- A structure to represent a git tag
- Time
- Time in a signature
- Transaction
- A structure representing a transactional update of a repository’s references.
- Tree
- A structure to represent a git tree
- Tree
Builder - Constructor for in-memory trees (low-level)
- Tree
Entry - A structure representing an entry inside of a tree. An entry is borrowed from a tree.
- Tree
Iter - An iterator over the entries in a tree.
- Version
- Version information about libgit2 and the capabilities it supports.
- Worktree
- An owned git worktree
- Worktree
AddOptions - Options which can be used to configure how a worktree is initialized
- Worktree
Prune Options - Options to configure how worktree pruning is performed
Enums§
- Apply
Location - Possible application locations for git_apply see https://libgit2.org/libgit2/#HEAD/type/git_apply_options
- Attr
Value - All possible states of an attribute.
- Autotag
Option - Automatic tag following options.
- Branch
Type - An enumeration for the possible types of branches
- Certificate
Check Status - The return value for the
RemoteCallbacks::certificate_check
callback. - Config
Level - An enumeration of the possible priority levels of a config file.
- Delta
- What type of change is described by a
DiffDelta
? - Diff
Binary Kind - When producing a binary diff, the binary data returned will be either the deflated full (“literal”) contents of the file, or the deflated binary delta between the two sides (whichever is smaller).
- Diff
Format - Possible output formats for diff data
- Diff
Line Type - Line origin constants.
- Direction
- An enumeration of the possible directions for a remote.
- Error
Class - An enumeration of possible categories of things that can have errors when working with a git repository.
- Error
Code - An enumeration of possible errors that can happen when working with a git repository.
- Fetch
Prune - Configuration for how pruning is done on a fetch
- File
Favor - Merge file favor options for
MergeOptions
instruct the file-level merging functionality how to deal with conflicting regions of the files. - File
Mode - Valid modes for index and tree entries.
- Object
Type - An enumeration all possible kinds objects may have.
- Pack
Builder Stage - Stages that are reported by the
PackBuilder
progress callback. - Rebase
Operation Type - A rebase operation
- Reference
Type - An enumeration of all possible kinds of references.
- Remote
Redirect - Remote redirection settings; whether redirects to another host are permitted.
- Repository
State - A listing of the possible states that a repository can be in.
- Reset
Type - An enumeration of the operations that can be performed for the
reset
method on aRepository
. - Stash
Apply Progress - Status
Show - Enumeration of possible methods of what can be shown through a status operation.
- Submodule
Ignore - Submodule ignore values
- Submodule
Update - Submodule update values
- Trace
Level - Available tracing levels. When tracing is set to a particular level, callers will be provided tracing at the given level and all lower levels.
- Tree
Walk Mode - A binary indicator of whether a tree walk should be performed in pre-order or post-order.
- Tree
Walk Result - Possible return codes for tree walking callback functions.
- Worktree
Lock Status - Lock Status of a worktree
Constants§
- DEFAULT_
COMMENT_ CHAR - The default comment character for
message_prettify
(‘#’)
Traits§
- IntoC
String - A class of types that can be converted to C strings.
Functions§
- message_
prettify - Clean up a message, removing extraneous whitespace, and ensure that the
message ends with a newline. If
comment_char
isSome
, also remove comment lines starting with that character. - message_
trailers_ bytes - Get the trailers for the given message.
- message_
trailers_ strs - Get the trailers for the given message.
- trace_
set - Set the global subscriber called when libgit2 produces a tracing message.
Type Aliases§
- Credentials
- Callback used to acquire credentials for when a remote is fetched.
- Index
Matched Path - A callback function to filter index matches.
- Indexer
Progress - Callback to be invoked while indexing is in progress.
- Stash
Apply Progress Cb - Stash application progress notification function.
- StashCb
- This is a callback function you can provide to iterate over all the stashed states that will be invoked per entry.
- Transport
Message - Callback for receiving messages delivered by the transport.
- Update
Tips - Callback for whenever a reference is updated locally.