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§

Ensure the remote name is well-formed.

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.

Get the remote’s name.

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

Get the remote’s name, in bytes.

Returns None if this remote has not yet been named

Get the remote’s url.

Returns None if the url is not valid utf-8

Get the remote’s url as a byte array.

Get the remote’s pushurl.

Returns None if the pushurl is not valid utf-8

Get the remote’s pushurl as a byte array.

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.

Open a connection to a remote.

Open a connection to a remote with callbacks and proxy settings

Returns a RemoteConnection that will disconnect once dropped

Check whether the remote is connected

Disconnect from the remote

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.

Cancel the operation

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

Get the number of refspecs for a remote

Get the nth refspec from this remote.

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

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();

Update the tips to the new state

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.

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

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.

Prune tracking refs that are no longer present on remote

Get the remote’s list of fetch refspecs

Get the remote’s list of push refspecs

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Executes the destructor for this 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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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.