pub struct WorktreeHandle {
pub path: PathBuf,
pub driver_name: String,
/* private fields */
}Expand description
Handle to a created worktree
Provides access to the worktree and handles cleanup on drop. Implements git repository operations and worktree management.
Fields§
§path: PathBufPath to the worktree
driver_name: StringDriver that created this worktree
Implementations§
Source§impl WorktreeHandle
impl WorktreeHandle
Sourcepub fn with_cleanup<F, Fut>(
path: PathBuf,
driver_name: String,
cleanup: F,
) -> Self
pub fn with_cleanup<F, Fut>( path: PathBuf, driver_name: String, cleanup: F, ) -> Self
Create with async cleanup function
Sourcepub fn open_repository(&self) -> Git2DBResult<Repository>
pub fn open_repository(&self) -> Git2DBResult<Repository>
Open the worktree as a git repository
Sourcepub fn driver_name(&self) -> &str
pub fn driver_name(&self) -> &str
Get the driver name
Sourcepub fn fs(&self) -> Result<&Arc<dyn ContainedFs>, FsError>
pub fn fs(&self) -> Result<&Arc<dyn ContainedFs>, FsError>
Get a contained filesystem for this worktree (lazy-initialized).
Returns a kernel-enforced (Linux) or canonicalize-based (other) filesystem rooted at this worktree’s path.
Sourcepub fn get_repository(&mut self) -> Git2DBResult<&mut Repository>
pub fn get_repository(&mut self) -> Git2DBResult<&mut Repository>
Get the git repository with lazy loading and caching
Sourcepub fn head(&mut self) -> Git2DBResult<Reference<'_>>
pub fn head(&mut self) -> Git2DBResult<Reference<'_>>
Get the current HEAD reference
Sourcepub fn head_commit(&mut self) -> Git2DBResult<Commit<'_>>
pub fn head_commit(&mut self) -> Git2DBResult<Commit<'_>>
Get the current commit
Sourcepub fn is_dirty(&mut self) -> Git2DBResult<bool>
pub fn is_dirty(&mut self) -> Git2DBResult<bool>
Check if the worktree has uncommitted changes
Sourcepub async fn cleanup(&mut self) -> Git2DBResult<()>
pub async fn cleanup(&mut self) -> Git2DBResult<()>
Async cleanup method
Sourcepub async fn commit(&mut self, message: &str) -> Git2DBResult<Oid>
pub async fn commit(&mut self, message: &str) -> Git2DBResult<Oid>
Sourcepub async fn commit_as(
&mut self,
signature: &Signature<'_>,
message: &str,
) -> Git2DBResult<Oid>
pub async fn commit_as( &mut self, signature: &Signature<'_>, message: &str, ) -> Git2DBResult<Oid>
Commit staged changes with a specific author/committer
Similar to git commit -m "<message>" --author="<name> <email>"
§Examples
use git2::Signature;
// Stage changes
worktree.staging().add("README.md")?;
// Create custom signature
let sig = Signature::now("Alice", "alice@example.com")?;
// Commit as specific user
let oid = worktree.commit_as(&sig, "Update docs").await?;Sourcepub async fn merge(
&mut self,
branch: &str,
ff_only: bool,
no_ff: bool,
) -> Git2DBResult<Oid>
pub async fn merge( &mut self, branch: &str, ff_only: bool, no_ff: bool, ) -> Git2DBResult<Oid>
Sourcepub async fn status(&mut self) -> Git2DBResult<RepositoryStatus>
pub async fn status(&mut self) -> Git2DBResult<RepositoryStatus>
Get the current status of the worktree
Returns branch information, modified files, repository state, and ahead/behind counts compared to the upstream tracking branch (if configured).
The ahead and behind fields indicate how many commits the local branch is ahead
or behind its upstream tracking branch. If no upstream is configured, both will be 0.
§Examples
let status = worktree.status().await?;
println!("Current branch: {:?}", status.branch);
println!("Modified files: {:?}", status.modified_files);
println!("Is clean: {}", status.is_clean);
println!("Ahead: {} commits", status.ahead);
println!("Behind: {} commits", status.behind);Sourcepub async fn checkout(&mut self, reference: impl IntoGitRef) -> Git2DBResult<()>
pub async fn checkout(&mut self, reference: impl IntoGitRef) -> Git2DBResult<()>
Checkout a specific reference (branch, tag, or commit)
Accepts strings, GitRef enums, or direct Oids for type safety.
§Examples
// String reference
worktree.checkout("main").await?;
// Explicit GitRef
worktree.checkout(git2db::GitRef::Branch("develop".into())).await?;
// Direct Oid (type-safe)
let oid = git2::Oid::from_str("abc123...")?;
worktree.checkout(oid).await?;Sourcepub async fn update(&mut self) -> Git2DBResult<()>
pub async fn update(&mut self) -> Git2DBResult<()>
Sourcepub async fn update_with_remote(&mut self, remote: &str) -> Git2DBResult<()>
pub async fn update_with_remote(&mut self, remote: &str) -> Git2DBResult<()>
Update from a specific remote
Trait Implementations§
Source§impl Debug for WorktreeHandle
impl Debug for WorktreeHandle
Source§impl Drop for WorktreeHandle
impl Drop for WorktreeHandle
Auto Trait Implementations§
impl !Freeze for WorktreeHandle
impl !RefUnwindSafe for WorktreeHandle
impl Send for WorktreeHandle
impl !Sync for WorktreeHandle
impl Unpin for WorktreeHandle
impl UnsafeUnpin for WorktreeHandle
impl !UnwindSafe for WorktreeHandle
Blanket Implementations§
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
§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>
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>
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