Implement TUI search and mutation workflows
This commit is contained in:
@@ -275,6 +275,36 @@ pub enum AutomaticPolicyCommitter {
|
||||
None(crate::recipient::NoGitCommitter),
|
||||
}
|
||||
|
||||
/// Storage-owned selection of pass-compatible automatic Git commits for a
|
||||
/// remove, move, or copy transaction.
|
||||
pub enum AutomaticTreeCommitter {
|
||||
Git(Box<GitRepository>),
|
||||
None(crate::mutation::NoGitTreeCommitter),
|
||||
}
|
||||
|
||||
impl AutomaticTreeCommitter {
|
||||
pub fn for_source(
|
||||
repository: &Repository,
|
||||
source: &str,
|
||||
identity: GitIdentity,
|
||||
) -> Result<Self, GitError> {
|
||||
match GitRepository::open_innermost(repository, Path::new(source), identity) {
|
||||
Ok(git) => Ok(Self::Git(Box::new(git))),
|
||||
Err(GitError::NotRepository) => Ok(Self::None(crate::mutation::NoGitTreeCommitter)),
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TreeCommitter for AutomaticTreeCommitter {
|
||||
fn commit(&mut self, change: &TreeCommit) -> Result<(), TreeCommitError> {
|
||||
match self {
|
||||
Self::Git(git) => TreeCommitter::commit(git.as_mut(), change),
|
||||
Self::None(committer) => committer.commit(change),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AutomaticPolicyCommitter {
|
||||
pub fn for_directory(
|
||||
repository: &Repository,
|
||||
|
||||
@@ -84,6 +84,7 @@ impl TreeCommitter for NoGitTreeCommitter {
|
||||
pub struct MutationOutcome {
|
||||
action: MutationAction,
|
||||
entries: Vec<EntryPath>,
|
||||
selection: Option<MutationSelection>,
|
||||
}
|
||||
|
||||
impl MutationOutcome {
|
||||
@@ -93,6 +94,35 @@ impl MutationOutcome {
|
||||
pub fn entries(&self) -> &[EntryPath] {
|
||||
&self.entries
|
||||
}
|
||||
pub fn selection(&self) -> Option<&MutationSelection> {
|
||||
self.selection.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum MutationSelection {
|
||||
Entry(EntryPath),
|
||||
Directory(DirectoryPath),
|
||||
}
|
||||
|
||||
impl MutationSelection {
|
||||
pub fn path(&self) -> &std::path::Path {
|
||||
match self {
|
||||
Self::Entry(path) => path.as_path(),
|
||||
Self::Directory(path) => path.as_path(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_directory(&self) -> bool {
|
||||
matches!(self, Self::Directory(_))
|
||||
}
|
||||
|
||||
pub fn display_path(&self) -> String {
|
||||
match self {
|
||||
Self::Entry(path) => path.to_string(),
|
||||
Self::Directory(path) => path.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TreeMutator<'a> {
|
||||
@@ -172,6 +202,7 @@ impl<'a> TreeMutator<'a> {
|
||||
Ok(MutationOutcome {
|
||||
action: MutationAction::Remove,
|
||||
entries: entries.into_iter().map(|entry| entry.source).collect(),
|
||||
selection: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -507,9 +538,14 @@ impl<'a> TreeMutator<'a> {
|
||||
if moving {
|
||||
self.repository.cleanup_empty_directories(&source_root)?;
|
||||
}
|
||||
let selection = destination_entry.map_or_else(
|
||||
|| MutationSelection::Directory(destination_root),
|
||||
MutationSelection::Entry,
|
||||
);
|
||||
Ok(MutationOutcome {
|
||||
action,
|
||||
entries: entries.into_iter().map(|entry| entry.destination).collect(),
|
||||
selection: Some(selection),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -294,6 +294,10 @@ impl GrepResults {
|
||||
self.entries.is_empty()
|
||||
}
|
||||
|
||||
pub fn includes_line_numbers(&self) -> bool {
|
||||
self.line_numbers
|
||||
}
|
||||
|
||||
/// Render matched bytes without requiring the CLI to reconstruct entry semantics.
|
||||
pub fn render_plain(&self) -> SecretBytes {
|
||||
let mut rendered = Vec::new();
|
||||
|
||||
Reference in New Issue
Block a user