Struct git2::Remote

source ·
pub struct Remote<'repo> { /* private fields */ }
Expand description

A structure representing a remote of a git repository.

The lifetime is the lifetime of the repository that it is attached to. The remote is used to manage fetches and pushes as well as refspecs.

Implementations§

source§

impl<'repo> Remote<'repo>

source

pub fn is_valid_name(remote_name: &str) -> bool

Ensure the remote name is well-formed.

source

pub fn create_detached<S: Into<Vec<u8>>>(url: S) -> Result<Remote<'repo>, Error>

Create a detached remote

Create a remote with the given URL in-memory. You can use this when you have a URL instead of a remote’s name. Contrasted with an anonymous remote, a detached remote will not consider any repo configuration values.

source

pub fn name(&self) -> Option<&str>

Get the remote’s name.

Returns None if this remote has not yet been named or if the name is not valid utf-8

source

pub fn name_bytes(&self) -> Option<&[u8]>

Get the remote’s name, in bytes.

Returns None if this remote has not yet been named

source

pub fn url(&self) -> Option<&str>

Get the remote’s URL.

Returns None if the URL is not valid utf-8

source

pub fn url_bytes(&self) -> &[u8]

Get the remote’s URL as a byte array.

source

pub fn pushurl(&self) -> Option<&str>

Get the remote’s pushurl.

Returns None if the pushurl is not valid utf-8

source

pub fn pushurl_bytes(&self) -> Option<&[u8]>

Get the remote’s pushurl as a byte array.

source

pub fn default_branch(&self) -> Result<Buf, Error>

Get the remote’s default branch.

The remote (or more exactly its transport) must have connected to the remote repository. This default branch is available as soon as the connection to the remote is initiated and it remains available after disconnecting.

source

pub fn connect(&mut self, dir: Direction) -> Result<(), Error>

Open a connection to a remote.

source

pub fn connect_auth<'connection, 'cb>( &'connection mut self, dir: Direction, cb: Option<RemoteCallbacks<'cb>>, proxy_options: Option<ProxyOptions<'cb>>, ) -> Result<RemoteConnection<'repo, 'connection, 'cb>, Error>

Open a connection to a remote with callbacks and proxy settings

Returns a RemoteConnection that will disconnect once dropped

source

pub fn connected(&mut self) -> bool

Check whether the remote is connected

source

pub fn disconnect(&mut self) -> Result<(), Error>

Disconnect from the remote

source

pub fn download<Str: AsRef<str> + IntoCString + Clone>( &mut self, specs: &[Str], opts: Option<&mut FetchOptions<'_>>, ) -> Result<(), Error>

Download and index the packfile

Connect to the remote if it hasn’t been done yet, negotiate with the remote git which objects are missing, download and index the packfile.

The .idx file will be created and both it and the packfile with be renamed to their final name.

The specs argument is a list of refspecs to use for this negotiation and download. Use an empty array to use the base refspecs.

source

pub fn stop(&mut self) -> Result<(), Error>

Cancel the operation

At certain points in its operation, the network code checks whether the operation has been canceled and if so stops the operation.

source

pub fn refspecs(&self) -> Refspecs<'_>

Get the number of refspecs for a remote

source

pub fn get_refspec(&self, i: usize) -> Option<Refspec<'repo>>

Get the nth refspec from this remote.

The refspecs iterator can be used to iterate over all refspecs.

source

pub fn fetch<Str: AsRef<str> + IntoCString + Clone>( &mut self, refspecs: &[Str], opts: Option<&mut FetchOptions<'_>>, reflog_msg: Option<&str>, ) -> Result<(), Error>

Download new data and update tips

Convenience function to connect to a remote, download the data, disconnect and update the remote-tracking branches.

§Examples

Example of functionality similar to git fetch origin main:

fn fetch_origin_main(repo: git2::Repository) -> Result<(), git2::Error> {
    repo.find_remote("origin")?.fetch(&["main"], None, None)
}

let repo = git2::Repository::discover("rust").unwrap();
fetch_origin_main(repo).unwrap();
source

pub fn update_tips( &mut self, callbacks: Option<&mut RemoteCallbacks<'_>>, update_flags: RemoteUpdateFlags, download_tags: AutotagOption, msg: Option<&str>, ) -> Result<(), Error>

Update the tips to the new state

source

pub fn push<Str: AsRef<str> + IntoCString + Clone>( &mut self, refspecs: &[Str], opts: Option<&mut PushOptions<'_>>, ) -> Result<(), Error>

Perform a push

Perform all the steps for a push. If no refspecs are passed then the configured refspecs will be used.

Note that you’ll likely want to use RemoteCallbacks and set push_update_reference to test whether all the references were pushed successfully.

source

pub fn stats(&self) -> Progress<'_>

Get the statistics structure that is filled in by the fetch operation.

source

pub fn list(&self) -> Result<&[RemoteHead<'_>], Error>

Get the remote repository’s reference advertisement list.

Get the list of references with which the server responds to a new connection.

The remote (or more exactly its transport) must have connected to the remote repository. This list is available as soon as the connection to the remote is initiated and it remains available after disconnecting.

source

pub fn prune( &mut self, callbacks: Option<RemoteCallbacks<'_>>, ) -> Result<(), Error>

Prune tracking refs that are no longer present on remote

source

pub fn fetch_refspecs(&self) -> Result<StringArray, Error>

Get the remote’s list of fetch refspecs

source

pub fn push_refspecs(&self) -> Result<StringArray, Error>

Get the remote’s list of push refspecs

Trait Implementations§

source§

impl<'repo> Clone for Remote<'repo>

source§

fn clone(&self) -> Remote<'repo>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'repo> Drop for Remote<'repo>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'repo> Freeze for Remote<'repo>

§

impl<'repo> RefUnwindSafe for Remote<'repo>

§

impl<'repo> !Send for Remote<'repo>

§

impl<'repo> !Sync for Remote<'repo>

§

impl<'repo> Unpin for Remote<'repo>

§

impl<'repo> UnwindSafe for Remote<'repo>

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T