Skip to main content

Branch

Struct Branch 

Source
pub struct Branch;
Expand description

Branch operations — checkout, create, delete.

Uses the git CLI.

Implementations§

Source§

impl Branch

Source

pub fn checkout(repo: &Repository, name: &str) -> Result<()>

Check out an existing branch by name.

Equivalent to git checkout <name>.

Source

pub fn create( repo: &Repository, name: &str, checkout: bool, from: Option<&str>, ) -> Result<()>

Create a new branch and optionally check it out.

If checkout is true, equivalent to git checkout -b <name> [<from>]. Otherwise equivalent to git branch <name> [<from>]. from is the base ref to branch off of; None uses git’s own default (HEAD).

Source

pub fn delete(repo: &Repository, name: &str) -> Result<()>

Delete a branch by name.

Uses -D (force-delete). Callers should confirm with the user before calling this on unmerged branches.

Source

pub fn rename(repo: &Repository, old: &str, new: &str) -> Result<()>

Rename a branch.

Equivalent to git branch -m <old> <new>. Deliberately not -M: the lowercase form refuses when new already names a branch, and the uppercase one overwrites it. Overwriting here destroys whatever new pointed at, silently, so the refusal is the behaviour we want and the error is propagated rather than swallowed.

Renaming the checked-out branch carries HEAD with it (git’s own behaviour); it does not detach.

Source

pub fn list(repo: &Repository) -> Result<Vec<String>>

List all local branches.

Equivalent to git branch --format=%(refname:short).

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.