Docs.rs
  • git2-0.16.1
    • git2 0.16.1
    • Docs.rs crate page
    • MIT OR Apache-2.0
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • alexcrichton
    • joshtriplett
    • ehuss
    • rust-lang-owner
    • Dependencies
      • bitflags ^1.1.0 normal
      • libc ^0.2 normal
      • libgit2-sys ^0.14.2 normal
      • log ^0.4.8 normal
      • url ^2.0 normal
      • paste ^1 dev
      • structopt ^0.3 dev
      • tempfile ^3.1.0 dev
      • time ^0.1.39 dev
      • openssl-probe ^0.1 normal
      • openssl-sys ^0.9.0 normal
    • Versions
    • 100% of the crate is documented
  • Go to latest version
  • Platform
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation
logo

Crate git2

logo

Crate git2

  • Version 0.16.1
  • All Items
  • Modules
  • Structs
  • Enums
  • Constants
  • Traits
  • Functions
  • Type Definitions

Crates

  • git2
?
Change settings

Crate git2

source ·
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 in RemoteCallbacks.
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

AnnotatedCommit
A structure to represent an annotated commit, the input to merge and rebase.
ApplyOptions
Options to specify when applying a diff
AttrCheckFlags
Blame
Opaque structure to hold blame results.
BlameHunk
Structure that represents a blame hunk.
BlameIter
An iterator over the hunks in a blame.
BlameOptions
Blame options
Blob
A structure to represent a git blob
BlobWriter
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.
CheckoutNotificationType
Types of notifications emitted from checkouts.
CherrypickOptions
Options to specify when cherry picking
Commit
A structure to represent a git commit
Config
A structure representing a git configuration key/value store
ConfigEntries
An iterator over the ConfigEntry values of a Config structure.
ConfigEntry
A struct representing a certain entry owned by a Config instance.
Cred
A structure to represent git credentials in libgit2.
CredentialHelper
Management of the gitcredentials(7) interface.
CredentialType
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 an Describe or a Repository.
DescribeFormatOptions
Options which can be used to customize how a description is formatted.
DescribeOptions
Options which indicate how a Describe is created.
Diff
The diff object that contains all individual file deltas.
DiffBinary
Structure describing the binary contents of a diff.
DiffBinaryFile
The contents of one of the files in a binary diff.
DiffDelta
Description of changes to one entry.
DiffFile
Description of one side of a delta.
DiffFindOptions
Control behavior of rename and copy detection
DiffFlags
DiffHunk
Structure describing a hunk of a diff.
DiffLine
Structure describing a line (or data span) of a diff.
DiffOptions
Structure describing options about how the diff should be executed.
DiffStats
Structure describing a hunk of a diff.
DiffStatsFormat
Formatting options for diff stats
Email
A structure to represent patch in mbox format for sending via email
EmailCreateOptions
Options for controlling the formatting of the generated e-mail.
Error
A structure to represent errors coming out of libgit2.
FetchOptions
Options which can be specified to various fetch operations.
Index
A structure to represent a git index
IndexAddOption
Flags for APIs that add files matching pathspec
IndexConflict
A structure to represent the information returned when a conflict is detected in an index entry
IndexConflicts
An iterator over the conflicting entries in an index
IndexEntries
An iterator over the entries in an index
IndexEntry
A structure to represent an entry or a file inside of an index.
IndexEntryExtendedFlag
Flags for the extended_flags field of an IndexEntry.
IndexEntryFlag
Flags for the flags field of an IndexEntry.
IndexTime
Time structure used in a git index entry.
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.
MergeAnalysis
The results of merge_analysis indicating the merge opportunities.
MergeOptions
Options to specify when merging.
MergePreference
The user’s stated preference for merges.
MessageTrailersBytes
Collection of unencoded (bytes) trailers.
MessageTrailersBytesIterator
Borrowed iterator over the raw (bytes) trailers.
MessageTrailersStrs
Collection of UTF-8-encoded trailers.
MessageTrailersStrsIterator
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
OdbLookupFlags
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).
PackBuilder
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.
PathspecDiffEntries
Iterator over the matching diff deltas.
PathspecEntries
Iterator over the matched paths in a pathspec.
PathspecFailedEntries
Iterator over the failed list of pathspec items that did not match.
PathspecFlags
…
PathspecMatchList
List of filenames matching a pathspec.
Progress
Struct representing the progress by an in-flight transfer.
ProxyOptions
Options which can be specified to various fetch operations.
PushOptions
Options to control the behavior of a git push.
Rebase
Representation of a rebase
RebaseOperation
A rebase operation
RebaseOptions
Rebase options
Reference
A structure to represent a git reference.
ReferenceFormat
Options for Reference::normalize_name.
ReferenceNames
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.
ReflogEntry
An entry inside the reflog of a repository
ReflogIter
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.
RemoteCallbacks
A structure to contain the callbacks which are invoked when a repository is being updated or downloaded.
RemoteConnection
Holds callbacks for a connection to a Remote. Disconnects when dropped
RemoteHead
Description of a reference advertised by a remote server, given out on calls to list.
Repository
An owned git repository, representing all state associated with the underlying filesystem.
RepositoryInitMode
Mode options for RepositoryInitOptions
RepositoryInitOptions
Options which can be used to configure how a repository is initialized
RepositoryOpenFlags
Flags for Repository::open_ext
RevertOptions
Options to specify when reverting
RevparseMode
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.
StashApplyFlags
StashApplyOptions
Stash application options structure
StashFlags
Status
Status flags for a single file
StatusEntry
A structure representing an entry in the Statuses structure.
StatusIter
An iterator over the statuses in a Statuses instance.
StatusOptions
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
SubmoduleStatus
Return codes for submodule status.
SubmoduleUpdateOptions
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
TreeBuilder
Constructor for in-memory trees
TreeEntry
A structure representing an entry inside of a tree. An entry is borrowed from a tree.
TreeIter
An iterator over the entries in a tree.
Version
Version information about libgit2 and the capabilities it supports.
Worktree
An owned git worktree
WorktreeAddOptions
Options which can be used to configure how a worktree is initialized
WorktreePruneOptions
Options to configure how worktree pruning is performed

Enums

ApplyLocation
Possible application locations for git_apply see https://libgit2.org/libgit2/#HEAD/type/git_apply_options
AttrValue
All possible states of an attribute.
AutotagOption
Automatic tag following options.
BranchType
An enumeration for the possible types of branches
CertificateCheckStatus
The return value for the [CertificateCheck] callback.
ConfigLevel
An enumeration of the possible priority levels of a config file.
Delta
What type of change is described by a DiffDelta?
DiffBinaryKind
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).
DiffFormat
Possible output formats for diff data
DiffLineType
Line origin constants.
Direction
An enumeration of the possible directions for a remote.
ErrorClass
An enumeration of possible categories of things that can have errors when working with a git repository.
ErrorCode
An enumeration of possible errors that can happen when working with a git repository.
FetchPrune
Configuration for how pruning is done on a fetch
FileFavor
Merge file favor options for MergeOptions instruct the file-level merging functionality how to deal with conflicting regions of the files.
FileMode
Valid modes for index and tree entries.
ObjectType
An enumeration all possible kinds objects may have.
PackBuilderStage
Stages that are reported by the PackBuilder progress callback.
RebaseOperationType
A rebase operation
ReferenceType
An enumeration of all possile kinds of references.
RemoteRedirect
Remote redirection settings; whether redirects to another host are permitted.
RepositoryState
A listing of the possible states that a repository can be in.
ResetType
An enumeration of the operations that can be performed for the reset method on a Repository.
StashApplyProgress
StatusShow
Enumeration of possible methods of what can be shown through a status operation.
SubmoduleIgnore
Submodule ignore values
SubmoduleUpdate
Submodule update values
TraceLevel
Available tracing levels. When tracing is set to a particular level, callers will be provided tracing at the given level and all lower levels.
TreeWalkMode
A binary indicator of whether a tree walk should be performed in pre-order or post-order.
TreeWalkResult
Possible return codes for tree walking callback functions.
WorktreeLockStatus
Lock Status of a worktree

Constants

DEFAULT_COMMENT_CHAR
The default comment character for message_prettify (‘#’)

Traits

IntoCString
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 is Some, 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

Type Definitions

Credentials
Callback used to acquire credentials for when a remote is fetched.
IndexMatchedPath
A callback function to filter index matches.
IndexerProgress
Callback to be invoked while indexing is in progress.
StashApplyProgressCb
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.
TransportMessage
Callback for receiving messages delivered by the transport.
UpdateTips
Callback for whenever a reference is updated locally.

Results

git2::Commit
A structure to represent a git commit
git2::BlobWriter::commit
Finalize blob writing stream and write the blob to the …
git2::OdbPackwriter::commit
Finish writing the packfile
git2::Rebase::commit
Commits the current patch. You must have resolved any …
git2::Repository::commit
Create new commit in the repository
git2::Transaction::commit
Commit the changes from the transaction.
git2::ObjectType::Commit
An object which corresponds to a git commit
git2::FileMode::Commit
Commit
git2::Commit::committer
Get the committer of this commit.
git2::Note::committer
Get the note committer
git2::ReflogEntry::committer
Get the committer of this entry
git2::Repository::commit_signed
Create a commit object from the given buffer and signature
git2::Repository::commit_create_buffer
Create a commit object and return that as a Buf.
git2::Commit::committer_with_mailmap
Get the committer of this commit, using the mailmap to map …
git2::Object::as_commit
Attempt to view this object as a commit.
git2::ErrorCode::Uncommitted
Uncommitted changes in index prevented operation
git2::Repository::find_commit
Lookup a reference to one of the commits in a repository.
git2::Email::from_commit
Create a diff for a commit in mbox format for sending via …
git2::Object::into_commit
Attempt to consume this object and return a commit.
git2::BlameHunk::orig_commit_id
Returns the OID of the commit where this hunk was found.
git2::DescribeOptions::show_commit_oid_as_fallback
If no matching tag or reference is found whether a …
git2::Repository::merge_commits
Merge two commits, producing an index that reflects the …
git2::BlameHunk::final_commit_id
Returns OID of the commit where this line was last changed
git2::PackBuilder::insert_commit
Insert a commit object. This will add a commit as well as …
git2::BlameOptions::newest_commit
Setter for the id of the newest commit to consider.
git2::BlameOptions::oldest_commit
Setter for the id of the oldest commit to consider.
git2::Repository::revert_commit
Reverts the given commit against the given “our” …
git2::Object::peel_to_commit
Recursively peel an object until a commit is found
git2::Reference::peel_to_commit
Peel a reference to a commit
git2::AnnotatedCommit
A structure to represent an annotated commit, the input to …
git2::Repository::annotated_commit_from_fetchhead
Creates a git_annotated_commit from FETCH_HEAD.
git2::Repository::cherrypick_commit
Create an index of uncommitted changes, representing the …
git2::Repository::find_annotated_commit
Creates an AnnotatedCommit from the given commit id.
git2::BlameOptions::track_copies_any_commit_copies
Track lines that have been copied from another file that …
git2::BlameOptions::track_copies_same_commit_moves
Track lines that have moved across files in the same …
git2::BlameOptions::track_copies_same_commit_copies
Track lines that have been copied from another file that …
git2::Repository::branch_from_annotated_commit
Create a new branch pointing at a target commit
git2::Repository::reference_to_annotated_commit
Creates a git_annotated_commit from the given reference.
git2::Config
A structure representing a git configuration key/value …
git2::CredentialHelper::config
Query the specified configuration object to discover …
git2::Repository::config
Get the configuration file for this repository.
git2::ErrorClass::Config
Bad configuration
git2::Describe::format
Prints this describe result, returning the result as a …
git2::Commit::id
Get the id (SHA1) of a repository commit
git2::Commit::fmt
git2::Commit::raw
Get access to the underlying raw pointer.
git2::Commit::body
Get the long “body” of the git commit message.
git2::Commit::drop
git2::Commit::time
Get the commit time (i.e. committer time) of a commit.
git2::Commit::tree
Get the tree pointed to by a commit.
git2::Commit::amend
Amend this existing commit with all non-None values
git2::Commit::clone
git2::Commit::author
Get the author of this commit.
git2::Repository::branch
Create a new branch pointing at a target commit
git2::Commit::parent
Get the specified parent of the commit.
git2::Repository::revert
Reverts the given commit, producing changes in the index …
git2::Commit::message
Get the full message of a commit.
git2::Commit::parents
Creates a new iterator over the parents of this commit.
git2::Commit::summary
Get the short “summary” of the git commit message.
git2::Commit::tree_id
Get the id of the tree pointed to by this commit.
git2::Commit::as_object
Casts this Commit to be usable as an Object
git2::Commit::committer
Get the committer of this commit.
git2::Commit::parent_id
Get the specified parent id of the commit.
git2::Commit::body_bytes
Get the long “body” of the git commit message.
git2::Repository::cherrypick
Perform a cherrypick
git2::Commit::raw_header
Get the full raw text of the commit header.
git2::Email::from_commit
Create a diff for a commit in mbox format for sending via …
git2::Commit::into_object
Consumes Commit to be returned as an Object
git2::Commit::message_raw
Get the full raw message of a commit.
git2::Commit::parent_count
Get the number of parents of this commit.
git2::Repository::merge_commits
Merge two commits, producing an index that reflects the …
git2::Commit::message_bytes
Get the full message of a commit as a byte slice.
git2::Repository::revert_commit
Reverts the given commit against the given “our” …
git2::Commit::summary_bytes
Get the short “summary” of the git commit message.
git2::Commit::message_encoding
Get the encoding for the message of a commit, as a string …
git2::Commit::raw_header_bytes
Get the full raw text of the commit header.
git2::Repository::cherrypick_commit
Create an index of uncommitted changes, representing the …
git2::Commit::message_raw_bytes
Get the full raw message of a commit.
git2::Commit::header_field_bytes
Get an arbitrary header field.
git2::Commit::author_with_mailmap
Get the author of this commit, using the mailmap to map …
git2::Commit::committer_with_mailmap
Get the committer of this commit, using the mailmap to map …
git2::Config::drop
git2::CredentialHelper::config
Query the specified configuration object to discover …
git2::Config::remove
Delete a config variable from the config file with the …
git2::Config::entries
Iterate over all the config variables
git2::Config::get_i32
Get the value of an integer config variable.
git2::Config::get_i64
Get the value of an integer config variable.
git2::Config::get_str
Get the value of a string config variable.
git2::Config::set_i32
Set the value of an integer config variable in the config …
git2::Config::set_i64
Set the value of an integer config variable in the config …
git2::Config::set_str
Set the value of a string config variable in the config …
git2::Config::add_file
Add an on-disk config file instance to an existing config
git2::Config::get_bool
Get the value of a boolean config variable.
git2::Config::get_path
Get the value of a path config variable as an owned PathBuf…
git2::Config::multivar
Iterate over the values of a multivar
git2::Config::set_bool
Set the value of a boolean config variable in the config …
git2::Config::snapshot
Create a snapshot of the configuration
git2::Config::get_bytes
Get the value of a string config variable as a byte slice.
git2::Config::get_entry
Get the ConfigEntry for a config variable.
git2::Config::get_string
Get the value of a string config variable as an owned …
git2::Config::open_level
Build a single-level focused config object from a …
git2::Config::open_global
Open the global/XDG configuration file according to git’…
git2::Config::set_multivar
Set the value of an multivar config variable in the config …
git2::Config::remove_multivar
Remove multivar config variables in the config file with …
git2::Cred::credential_helper
Attempt to read credential.helper according to …
git2::Commit::clone
git2::Parents::next
git2::Commit::parent
Get the specified parent of the commit.
git2::Object::as_commit
Attempt to view this object as a commit.
git2::Parents::next_back
git2::Repository::find_commit
Lookup a reference to one of the commits in a repository.
git2::Object::into_commit
Attempt to consume this object and return a commit.
git2::Object::peel_to_commit
Recursively peel an object until a commit is found
git2::Reference::peel_to_commit
Peel a reference to a commit