pub struct BranchManager<'a> { /* private fields */ }Expand description
Manager for repository branches
Provides operations similar to git branch commands.
§Examples
ⓘ
let repo = registry.repo(repo_id)?;
let branch_mgr = repo.branch();
// List branches
for branch in branch_mgr.list().await? {
let marker = if branch.is_head { "*" } else { " " };
println!("{} {}", marker, branch.name);
}
// Get current branch
if let Some(current) = branch_mgr.current().await? {
println!("On branch: {}", current.name);
}
// Create new branch
branch_mgr.create("feature", Some("main")).await?;
// Checkout branch
branch_mgr.checkout("feature").await?;
// Remove branch
branch_mgr.remove("old-feature", false).await?;Implementations§
Source§impl<'a> BranchManager<'a>
impl<'a> BranchManager<'a>
Sourcepub async fn list(&self) -> Git2DBResult<Vec<Branch>>
pub async fn list(&self) -> Git2DBResult<Vec<Branch>>
List all branches (local and remote)
Similar to git branch -a
Sourcepub async fn current(&self) -> Git2DBResult<Option<Branch>>
pub async fn current(&self) -> Git2DBResult<Option<Branch>>
Get the current branch (HEAD)
Returns None if HEAD is detached
Sourcepub async fn create<R: IntoGitRef>(
&self,
name: &str,
from: Option<R>,
) -> Git2DBResult<()>
pub async fn create<R: IntoGitRef>( &self, name: &str, from: Option<R>, ) -> Git2DBResult<()>
Create a new branch
Similar to git branch <name> [from]
Accepts strings, GitRef enums, or direct Oids for the base reference.
If from is None, creates from HEAD.
§Examples
ⓘ
// Create from HEAD
repo.branch().create("feature", None).await?;
// Create from string reference
repo.branch().create("feature", Some("main")).await?;
// Create from explicit GitRef
repo.branch().create("hotfix", Some(git2db::GitRef::Tag("v1.0.0".into()))).await?;
// Create from specific commit (type-safe)
let oid = git2::Oid::from_str("abc123...")?;
repo.branch().create("from-commit", Some(oid)).await?;Sourcepub async fn checkout(&self, name: &str) -> Git2DBResult<()>
pub async fn checkout(&self, name: &str) -> Git2DBResult<()>
Checkout a branch
Similar to git checkout <name>
Trait Implementations§
Source§impl<'a> RepositoryAccessor for BranchManager<'a>
impl<'a> RepositoryAccessor for BranchManager<'a>
Source§fn repo_path(&self) -> Git2DBResult<PathBuf>
fn repo_path(&self) -> Git2DBResult<PathBuf>
Get the repository worktree path
Source§fn open_repo(
&self,
) -> impl Future<Output = Git2DBResult<Repository>> + Send + '_where
Self: Sync,
fn open_repo(
&self,
) -> impl Future<Output = Git2DBResult<Repository>> + Send + '_where
Self: Sync,
Open the git repository (async, uses spawn_blocking) Read more
Auto Trait Implementations§
impl<'a> Freeze for BranchManager<'a>
impl<'a> !RefUnwindSafe for BranchManager<'a>
impl<'a> Send for BranchManager<'a>
impl<'a> Sync for BranchManager<'a>
impl<'a> Unpin for BranchManager<'a>
impl<'a> UnsafeUnpin for BranchManager<'a>
impl<'a> !UnwindSafe for BranchManager<'a>
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ServiceExt for T
impl<T> ServiceExt for T
§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Apply a transformation to the response body. Read more
§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using HTTP status codes. Read more
§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using gRPC headers. Read more