pub struct Branch;Expand description
Branch operations — checkout, create, delete.
Uses the git CLI.
Implementations§
Source§impl Branch
impl Branch
Sourcepub fn checkout(repo: &Repository, name: &str) -> Result<()>
pub fn checkout(repo: &Repository, name: &str) -> Result<()>
Check out an existing branch by name.
Equivalent to git checkout <name>.
Sourcepub fn create(
repo: &Repository,
name: &str,
checkout: bool,
from: Option<&str>,
) -> Result<()>
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).
Sourcepub fn delete(repo: &Repository, name: &str) -> Result<()>
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.
Sourcepub fn rename(repo: &Repository, old: &str, new: &str) -> Result<()>
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.