Crate git2[][src]

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

Builder-pattern objects for configuration various git operations.

Certificate types which are passed to CertificateCheck in RemoteCallbacks.

Bindings to libgit2’s raw git_oidarray type

Bindings to libgit2’s git_libgit2_opts function.

Bindings to libgit2’s raw git_strarray type

Interfaces for adding custom transports to libgit2

Structs

A structure to represent an annotated commit, the input to merge and rebase.

Options to specify when applying a diff

Opaque structure to hold blame results.

Structure that represents a blame hunk.

An iterator over the hunks in a blame.

Blame options

A structure to represent a git blob

A structure to represent a git writestream for blobs

A structure to represent a git branch

An iterator over the branches inside of a repository.

A structure to wrap an intermediate buffer used by libgit2.

Types of notifications emitted from checkouts.

Options to specify when cherry picking

A structure to represent a git commit

A structure representing a git configuration key/value store

An iterator over the ConfigEntry values of a Config structure.

A struct representing a certain entry owned by a Config instance.

A structure to represent git credentials in libgit2.

Management of the gitcredentials(7) interface.

Types of credentials that can be requested by a credential callback.

An iterator over the diffs in a delta

The result of a describe operation on either an Describe or a Repository.

Options which can be used to customize how a description is formatted.

Options which indicate how a Describe is created.

The diff object that contains all individual file deltas.

Structure describing the binary contents of a diff.

The contents of one of the files in a binary diff.

Description of changes to one entry.

Description of one side of a delta.

Control behavior of rename and copy detection

Structure describing a hunk of a diff.

Structure describing a line (or data span) of a diff.

Structure describing options about how the diff should be executed.

Structure describing a hunk of a diff.

Formatting options for diff stats

A structure to represent errors coming out of libgit2.

Options which can be specified to various fetch operations.

A structure to represent a git index

Flags for APIs that add files matching pathspec

A structure to represent the information returned when a conflict is detected in an index entry

An iterator over the conflicting entries in an index

An iterator over the entries in an index

A structure to represent an entry or a file inside of an index.

Flags for the extended_flags field of an IndexEntry.

Flags for the flags field of an IndexEntry.

Time structure used in a git index entry.

A structure to represent a repository’s .mailmap file.

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.

The results of merge_analysis indicating the merge opportunities.

Options to specify when merging.

The user’s stated preference for merges.

Collection of unencoded (bytes) trailers.

Borrowed iterator over the raw (bytes) trailers.

Collection of UTF-8-encoded trailers.

Borrowed iterator over the UTF-8-encoded trailers.

A structure representing a note in git.

An iterator over all of the notes within a repository.

A structure to represent a git object

A structure to represent a git object database

An object from the Object Database.

A stream to write a packfile to the ODB

A structure to represent a git ODB rstream

A structure to represent a git ODB wstream

Unique identity of any object (commit, tree, blob, tag).

A builder for creating a packfile

An iterator over the parent commits of a commit.

A structure representing the text changes in a single diff delta.

Structure representing a compiled pathspec used for matching against various structures.

Iterator over the matching diff deltas.

Iterator over the matched paths in a pathspec.

Iterator over the failed list of pathspec items that did not match.

List of filenames matching a pathspec.

Struct representing the progress by an in-flight transfer.

Options which can be specified to various fetch operations.

Options to control the behavior of a git push.

Representation of a rebase

A rebase operation

Rebase options

A structure to represent a git reference.

An iterator over the names of references in a repository.

An iterator over the references in a repository.

A reference log of a git repository.

An entry inside the reflog of a repository

An iterator over the entries inside of a reflog.

A structure to represent a git refspec.

An iterator over the refspecs that a remote contains.

A structure representing a remote of a git repository.

A structure to contain the callbacks which are invoked when a repository is being updated or downloaded.

Holds callbacks for a connection to a Remote. Disconnects when dropped

Description of a reference advertised by a remote server, given out on calls to list.

An owned git repository, representing all state associated with the underlying filesystem.

Mode options for RepositoryInitOptions

Options which can be used to configure how a repository is initialized

Flags for Repository::open_ext

Options to specify when reverting

Flags for the return value of Repository::revparse

A revspec represents a range of revisions within a repository.

A revwalk allows traversal of the commit graph defined by including one or more leaves and excluding one or more roots.

A Signature is used to indicate authorship of various actions throughout the library.

Orderings that may be specified for Revwalk iteration.

Stash application options structure

Status flags for a single file

A structure representing an entry in the Statuses structure.

An iterator over the statuses in a Statuses instance.

Options that can be provided to repo.statuses() to control how the status information is gathered.

A container for a list of status information about a repository.

A structure to represent a git submodule

Return codes for submodule status.

Options to update a submodule.

A structure to represent a git tag

Time in a signature

A structure representing a transactional update of a repository’s references.

A structure to represent a git tree

Constructor for in-memory trees

A structure representing an entry inside of a tree. An entry is borrowed from a tree.

An iterator over the entries in a tree.

Version information about libgit2 and the capabilities it supports.

An owned git worktree

Options which can be used to configure how a worktree is initialized

Options to configure how worktree pruning is performed

Enums

Possible application locations for git_apply see https://libgit2.org/libgit2/#HEAD/type/git_apply_options

All possible states of an attribute.

Automatic tag following options.

An enumeration for the possible types of branches

An enumeration of the possible priority levels of a config file.

What type of change is described by a DiffDelta?

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).

Possible output formats for diff data

Line origin constants.

An enumeration of the possible directions for a remote.

An enumeration of possible categories of things that can have errors when working with a git repository.

An enumeration of possible errors that can happen when working with a git repository.

Configuration for how pruning is done on a fetch

Merge file favor options for MergeOptions instruct the file-level merging functionality how to deal with conflicting regions of the files.

Valid modes for index and tree entries.

An enumeration all possible kinds objects may have.

Stages that are reported by the PackBuilder progress callback.

A rebase operation

An enumeration of all possile kinds of references.

A listing of the possible states that a repository can be in.

An enumeration of the operations that can be performed for the reset method on a Repository.

Enumeration of possible methods of what can be shown through a status operation.

Submodule ignore values

Submodule update values

Available tracing levels. When tracing is set to a particular level, callers will be provided tracing at the given level and all lower levels.

A binary indicator of whether a tree walk should be performed in pre-order or post-order.

Possible return codes for tree walking callback functions.

Lock Status of a worktree

Constants

The default comment character for message_prettify (‘#’)

Traits

A class of types that can be converted to C strings.

Functions

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.

Get the trailers for the given message.

Get the trailers for the given message.

Type Definitions

Callback used to acquire credentials for when a remote is fetched.

A callback function to filter index matches.

Callback to be invoked while indexing is in progress.

Stash application progress notification function.

This is a callback function you can provide to iterate over all the stashed states that will be invoked per entry.

Callback for receiving messages delivered by the transport.

Callback for whenever a reference is updated locally.