Struct git2::build::RepoBuilder

source ·
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,
      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§

source§

impl<'cb> RepoBuilder<'cb>

source

pub fn new() -> RepoBuilder<'cb>

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.

source

pub fn bare(&mut self, bare: bool) -> &mut RepoBuilder<'cb>

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

source

pub fn branch(&mut self, branch: &str) -> &mut RepoBuilder<'cb>

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

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

source

pub fn clone_local(&mut self, clone_local: CloneLocal) -> &mut RepoBuilder<'cb>

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.

source

pub fn with_checkout( &mut self, checkout: CheckoutBuilder<'cb> ) -> &mut RepoBuilder<'cb>

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

source

pub fn fetch_options( &mut self, fetch_opts: FetchOptions<'cb> ) -> &mut RepoBuilder<'cb>

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.

source

pub fn remote_create<F>(&mut self, f: F) -> &mut RepoBuilder<'cb>
where F: for<'a> FnMut(&'a Repository, &str, &str) -> Result<Remote<'a>, Error> + 'cb,

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

source

pub fn clone(&mut self, url: &str, into: &Path) -> Result<Repository, Error>

Clone a remote repository.

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

Trait Implementations§

source§

impl<'cb> Default for RepoBuilder<'cb>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'cb> !RefUnwindSafe for RepoBuilder<'cb>

§

impl<'cb> !Send for RepoBuilder<'cb>

§

impl<'cb> !Sync for RepoBuilder<'cb>

§

impl<'cb> Unpin for RepoBuilder<'cb>

§

impl<'cb> !UnwindSafe for RepoBuilder<'cb>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.