pub struct RepoBuilder<'cb> { /* private fields */ }
Expand description

A builder struct which is used to build configuration for cloning a new git repository.

Example

Cloning using SSH:

use git2::{Cred, Error, RemoteCallbacks};
use std::env;
use std::path::Path;

  // Prepare callbacks.
  let mut callbacks = RemoteCallbacks::new();
  callbacks.credentials(|_url, username_from_url, _allowed_types| {
    Cred::ssh_key(
      username_from_url.unwrap(),
      None,
      std::path::Path::new(&format!("{}/.ssh/id_rsa", env::var("HOME").unwrap())),
      None,
    )
  });

  // Prepare fetch options.
  let mut fo = git2::FetchOptions::new();
  fo.remote_callbacks(callbacks);

  // Prepare builder.
  let mut builder = git2::build::RepoBuilder::new();
  builder.fetch_options(fo);

  // Clone the project.
  builder.clone(
    "git@github.com:rust-lang/git2-rs.git",
    Path::new("/tmp/git2-rs"),
  );

Implementations

Creates a new repository builder with all of the default configuration.

When ready, the clone() method can be used to clone a new repository using this configuration.

Indicate whether the repository will be cloned as a bare repository or not.

Specify the name of the branch to check out after the clone.

If not specified, the remote’s default branch will be used.

Configures options for bypassing the git-aware transport on clone.

Bypassing it means that instead of a fetch libgit2 will copy the object database directory instead of figuring out what it needs, which is faster. If possible, it will hardlink the files to save space.

Configure the checkout which will be performed by consuming a checkout builder.

Options which control the fetch, including callbacks.

The callbacks are used for reporting fetch progress, and for acquiring credentials in the event they are needed.

Configures a callback used to create the git remote, prior to its being used to perform the clone operation.

Clone a remote repository.

This will use the options configured so far to clone the specified url into the specified local path.

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.