Skip to content

Commit

Permalink
Resolve unique worktree names (#34)
Browse files Browse the repository at this point in the history
For #21
  • Loading branch information
9999years authored Oct 17, 2024
1 parent 8de7be1 commit 3fd1dfd
Show file tree
Hide file tree
Showing 4 changed files with 407 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub use status::StatusCode;
pub use status::StatusEntry;
pub use worktree::AddWorktreeOpts;
pub use worktree::GitWorktree;
pub use worktree::RenamedWorktree;
pub use worktree::ResolveUniqueNameOpts;
pub use worktree::Worktree;
pub use worktree::WorktreeHead;
pub use worktree::Worktrees;
Expand Down
15 changes: 15 additions & 0 deletions src/git/worktree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use command_error::CommandExt;
use command_error::OutputContext;
use miette::miette;
use miette::IntoDiagnostic;
use rustc_hash::FxHashMap as HashMap;
use tap::Tap;
use tracing::instrument;
use utf8_command::Utf8Output;
Expand All @@ -15,10 +16,15 @@ use winnow::Parser;
use super::Git;
use super::LocalBranchRef;

mod resolve_unique_names;

mod parse;

pub use parse::Worktree;
pub use parse::WorktreeHead;
pub use parse::Worktrees;
pub use resolve_unique_names::RenamedWorktree;
pub use resolve_unique_names::ResolveUniqueNameOpts;

/// Git methods for dealing with worktrees.
#[repr(transparent)]
Expand Down Expand Up @@ -177,6 +183,15 @@ impl<'a> GitWorktree<'a> {
.container()?
.tap_mut(|p| p.push(self.dirname_for(branch))))
}

/// Resolves a set of worktrees into a map from worktree paths to unique names.
#[instrument(level = "trace")]
pub fn resolve_unique_names(
&self,
opts: ResolveUniqueNameOpts<'_>,
) -> miette::Result<HashMap<Utf8PathBuf, RenamedWorktree>> {
resolve_unique_names::resolve_unique_worktree_names(self.0, opts)
}
}

/// Options for `git worktree add`.
Expand Down
Loading

0 comments on commit 3fd1dfd

Please sign in to comment.