Skip to main content

Module branches

Module branches 

Source
Available on crate feature workflow only.
Expand description

Typed listing and bulk operations on local branches.

Reached through Repository::branches, which returns a BranchOps handle:

use git_spawn::Repository;

let repo = Repository::open("/path/to/repo")?;

// All local branches with upstream / ahead-behind info.
for b in repo.branches().list().await? {
    println!("{}{}  {}  ({})",
        if b.current { "* " } else { "  " },
        b.name,
        b.subject.as_deref().unwrap_or(""),
        b.upstream.as_deref().unwrap_or("no upstream"),
    );
}

// Delete branches merged into main.
let deleted = repo.branches().delete_merged("main").await?;
println!("removed {} merged branch(es)", deleted.len());

Listing is implemented with git for-each-ref refs/heads/ and a fixed, NUL-delimited format string, so the parser is deterministic across git versions and locales.

Structsยง

Branch
One local branch with tracking info.
BranchOps
Operations on local branches, scoped to a Repository.