pub struct WorktreeDescriptor { /* private fields */ }Expand description
A handle to a git worktree with rich metadata access.
Wraps a git2::Worktree and exposes branch state, remote tracking info,
commit history, and status checks used by the CLI commands.
Implementations§
Source§impl WorktreeDescriptor
impl WorktreeDescriptor
Sourcepub fn new(repo: &Repository, name: &str) -> Result<Self>
pub fn new(repo: &Repository, name: &str) -> Result<Self>
Open a worktree by name within the given repository.
Sourcepub fn of(worktree: Worktree) -> Self
pub fn of(worktree: Worktree) -> Self
Wrap an existing git2::Worktree without a repository lookup.
Sourcepub fn name(&self) -> Option<&str>
pub fn name(&self) -> Option<&str>
Returns the name of the worktree, or None if the name is invalid UTF-8.
Sourcepub fn branch(&self) -> Result<Option<String>>
pub fn branch(&self) -> Result<Option<String>>
Returns the branch name if the worktree is on a branch, or None if detached.
This reads the HEAD file from the worktree’s git directory to determine if HEAD points to a branch reference or directly to a commit SHA.
Sourcepub fn is_detached(&self) -> Result<bool>
pub fn is_detached(&self) -> Result<bool>
Returns true if the worktree has a detached HEAD (not on a branch).
Sourcepub fn is_dirty(&self) -> Result<bool>
pub fn is_dirty(&self) -> Result<bool>
Returns true if the worktree has uncommitted changes (dirty working tree).
This includes:
- Modified files (staged or unstaged)
- New untracked files
- Deleted files
Sourcepub fn has_tracked_changes(&self) -> Result<bool>
pub fn has_tracked_changes(&self) -> Result<bool>
Returns true if the worktree has uncommitted changes to tracked files.
Unlike is_dirty(), this excludes untracked files. Use this when
untracked files should not block an operation (e.g. pruning a worktree
whose remote branch is gone).
Sourcepub fn has_unpushed_commits(&self) -> Result<bool>
pub fn has_unpushed_commits(&self) -> Result<bool>
Returns true if the worktree’s branch has unpushed commits (ahead of upstream).
Returns false if:
- The worktree is detached (no branch)
- The branch has no upstream configured
- The branch is up to date with upstream
Returns true if:
- The branch has commits ahead of its upstream
- The upstream is configured but the remote reference is gone (conservative)
Sourcepub fn is_behind_upstream(&self) -> Result<bool>
pub fn is_behind_upstream(&self) -> Result<bool>
Returns true if the worktree’s branch is behind its upstream.
Returns false if:
- The worktree is detached (no branch)
- The branch has no upstream configured
- The branch is up to date with upstream
- The upstream is configured but the remote reference is gone
Returns true if:
- The branch has commits behind its upstream
Sourcepub fn has_gone_upstream(&self) -> Result<bool>
pub fn has_gone_upstream(&self) -> Result<bool>
Returns true if the worktree’s upstream branch reference is gone (deleted on remote).
Returns false if:
- The worktree is detached (no branch)
- The branch has no upstream configured
- The upstream branch reference exists
Returns true if:
- Upstream is configured (branch.{name}.remote exists in config)
- But the upstream branch reference cannot be found
Sourcepub fn is_merged_into(&self, target_branch: &str) -> Result<bool>
pub fn is_merged_into(&self, target_branch: &str) -> Result<bool>
Returns true if the worktree’s branch has been merged into the target branch.
A branch is considered merged if its HEAD commit is reachable from the target branch, meaning all commits in this branch exist in the target branch’s history.
Returns false if:
- The worktree is detached (no branch)
- The target branch doesn’t exist
- The branch has commits not in the target branch
Returns true if:
- All commits in this branch are reachable from the target branch
Sourcepub fn head_commit(&self) -> Result<Option<String>>
pub fn head_commit(&self) -> Result<Option<String>>
Returns the commit hash (SHA) of the worktree’s current HEAD.
Returns None if HEAD cannot be resolved (e.g., empty repository).
Sourcepub fn last_activity(&self) -> Result<Option<i64>>
pub fn last_activity(&self) -> Result<Option<i64>>
Returns the timestamp of the HEAD commit as the last activity time.
Returns None if:
- HEAD cannot be resolved (empty/unborn repository)
- HEAD cannot be peeled to a commit
Sourcepub fn is_stale(&self, days: u32) -> Result<bool>
pub fn is_stale(&self, days: u32) -> Result<bool>
Returns true if the worktree’s last activity is older than days days.
Returns false if:
- Last activity cannot be determined
- The worktree has recent activity within the threshold
Sourcepub fn remote(&self) -> Result<Option<String>>
pub fn remote(&self) -> Result<Option<String>>
Returns the name of the remote that the worktree’s branch tracks (e.g., “origin”).
Returns None if:
- The worktree is detached (no branch)
- The branch has no upstream configured
Sourcepub fn remote_branch(&self) -> Result<Option<String>>
pub fn remote_branch(&self) -> Result<Option<String>>
Returns the full name of the upstream remote branch (e.g., “refs/remotes/origin/main”).
Returns None if:
- The worktree is detached (no branch)
- The branch has no upstream configured
Sourcepub fn remote_url(&self) -> Result<Option<String>>
pub fn remote_url(&self) -> Result<Option<String>>
Returns the default URL for the remote (usually the fetch URL).
Returns None if:
- The worktree is detached (no branch)
- The branch has no upstream configured
- The remote has no URL configured
Sourcepub fn remote_fetch_url(&self) -> Result<Option<String>>
pub fn remote_fetch_url(&self) -> Result<Option<String>>
Returns the fetch URL for the remote.
Returns None if:
- The worktree is detached (no branch)
- The branch has no upstream configured
- The remote has no fetch URL configured
Sourcepub fn remote_push_url(&self) -> Result<Option<String>>
pub fn remote_push_url(&self) -> Result<Option<String>>
Returns the push URL for the remote.
Returns None if:
- The worktree is detached (no branch)
- The branch has no upstream configured
- The remote has no push URL configured (falls back to fetch URL)
Trait Implementations§
Source§impl Debug for WorktreeDescriptor
impl Debug for WorktreeDescriptor
Auto Trait Implementations§
impl Freeze for WorktreeDescriptor
impl RefUnwindSafe for WorktreeDescriptor
impl !Send for WorktreeDescriptor
impl !Sync for WorktreeDescriptor
impl Unpin for WorktreeDescriptor
impl UnsafeUnpin for WorktreeDescriptor
impl UnwindSafe for WorktreeDescriptor
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
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more