Skip to main content

WorktreeHandle

Struct WorktreeHandle 

Source
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: PathBuf

Path to the worktree

§driver_name: String

Driver that created this worktree

Implementations§

Source§

impl WorktreeHandle

Source

pub fn new(path: PathBuf, driver_name: String) -> Self

Create a new worktree handle

Source

pub fn with_cleanup<F, Fut>( path: PathBuf, driver_name: String, cleanup: F, ) -> Self
where F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Git2DBResult<()>> + Send + 'static,

Create with async cleanup function

Source

pub fn open_repository(&self) -> Git2DBResult<Repository>

Open the worktree as a git repository

Source

pub fn driver_name(&self) -> &str

Get the driver name

Source

pub fn path(&self) -> &Path

Get the worktree path

Source

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.

Source

pub fn get_repository(&mut self) -> Git2DBResult<&mut Repository>

Get the git repository with lazy loading and caching

Source

pub fn head(&mut self) -> Git2DBResult<Reference<'_>>

Get the current HEAD reference

Source

pub fn head_commit(&mut self) -> Git2DBResult<Commit<'_>>

Get the current commit

Source

pub fn is_valid(&self) -> bool

Check if the worktree is valid and accessible

Source

pub fn is_dirty(&mut self) -> Git2DBResult<bool>

Check if the worktree has uncommitted changes

Source

pub fn metadata(&mut self) -> WorktreeMetadata

Get basic worktree metadata

Source

pub async fn cleanup(&mut self) -> Git2DBResult<()>

Async cleanup method

Source

pub async fn commit(&mut self, message: &str) -> Git2DBResult<Oid>

Commit staged changes with default signature

Similar to git commit -m "<message>" This operation is performed on the worktree’s checked-out files.

§Examples
ⓘ
// Stage changes
worktree.staging().add("README.md")?;

// Commit changes
let oid = worktree.commit("Update docs").await?;
Source

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?;
Source

pub async fn amend(&mut self, message: Option<&str>) -> Git2DBResult<Oid>

Amend the last commit

Similar to git commit --amend

§Examples
ⓘ
// Stage additional changes
worktree.staging().add("forgotten_file.rs")?;

// Amend previous commit
let oid = worktree.amend(Some("Updated commit message")).await?;
Source

pub async fn merge( &mut self, branch: &str, ff_only: bool, no_ff: bool, ) -> Git2DBResult<Oid>

Merge a branch into the current worktree

Similar to git merge <branch> with various merge options

§Examples
ⓘ
// Merge a feature branch
let merge_oid = worktree.merge("feature-branch", false, false).await?;
println!("Merged commit: {}", merge_oid);
Source

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);
Source

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?;
Source

pub async fn fetch(&mut self, remote: Option<&str>) -> Git2DBResult<()>

Fetch from a remote

§Examples
ⓘ
// Fetch from default remote (origin)
worktree.fetch(None).await?;

// Fetch from specific remote
worktree.fetch(Some("upstream")).await?;
Source

pub async fn pull(&mut self, remote: Option<&str>) -> Git2DBResult<()>

Pull updates from remote (fetch + merge)

Updates the current branch with changes from the remote tracking branch.

§Examples
ⓘ
// Pull from default remote (origin)
worktree.pull(None).await?;

// Pull from specific remote
worktree.pull(Some("upstream")).await?;
Source

pub async fn push(&mut self, remote: Option<&str>) -> Git2DBResult<()>

Push changes to remote

§Examples
ⓘ
// Push to default remote (origin)
worktree.push(None).await?;

// Push to specific remote
worktree.push(Some("upstream")).await?;
Source

pub async fn update(&mut self) -> Git2DBResult<()>

Update to latest from tracking remote

Equivalent to git pull --ff-only - only fast-forwards, no merges

§Examples
ⓘ
// Update from default remote (origin)
worktree.update().await?;

// Update from specific remote
worktree.update_with_remote("upstream").await?;
Source

pub async fn update_with_remote(&mut self, remote: &str) -> Git2DBResult<()>

Update from a specific remote

Trait Implementations§

Source§

impl Debug for WorktreeHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for WorktreeHandle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

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.

§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

impl<T> Identity for T
where T: ?Sized,

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

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,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSend for T
where T: Send,