Skip to content

Commit 8969250

Browse files
committed
Implement snapshot::create_tree() with worktree snapshot supports
1 parent f44ea3c commit 8969250

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

crates/but-workspace/src/snapshot.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
///
44
pub mod create_tree {
55
use bstr::BString;
6+
use but_graph::VirtualBranchesTomlMetadata;
67

78
/// A way to determine what should be included in the snapshot when calling [create_tree()](function::create_tree).
8-
pub struct State<'a> {
9+
pub struct State {
910
/// The result of a previous worktree changes call.
1011
///
1112
/// It contains detailed information about the complete set of possible changes to become part of the worktree.
12-
pub changes: &'a but_core::WorktreeChanges,
13+
pub changes: but_core::WorktreeChanges,
1314
/// Repository-relative and slash-separated paths that match any change in the [`changes`](State::changes) field.
1415
/// **It's an error if there is no match.** as there is not supposed to be a snapshot without a change to the working tree.
1516
pub selection: Vec<BString>,
@@ -40,6 +41,14 @@ pub mod create_tree {
4041
pub metadata: Option<gix::ObjectId>,
4142
}
4243

44+
/// A utility to more easily use *no* workspace or metadata.
45+
pub fn no_workspace_and_meta() -> Option<(
46+
&'static but_graph::projection::Workspace<'static>,
47+
&'static VirtualBranchesTomlMetadata,
48+
)> {
49+
None
50+
}
51+
4352
pub(super) mod function {
4453
use super::{Outcome, State};
4554
use but_core::RefMetadata;

crates/but-workspace/tests/workspace/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod branch_details;
55
mod commit_engine;
66
mod flatten_diff_specs;
77
mod ref_info;
8+
mod snapshot;
89
mod tree_manipulation;
910
mod ui;
1011

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
mod create_tree {
2+
use crate::utils::read_only_in_memory_scenario;
3+
use but_graph::VirtualBranchesTomlMetadata;
4+
use but_workspace::snapshot;
5+
6+
#[test]
7+
fn worktree_all_filetypes() -> anyhow::Result<()> {
8+
let repo = read_only_in_memory_scenario("all-file-types-changed")?;
9+
let (head_tree_id, state, no_workspace_and_meta) = args_for_worktree_changes(&repo)?;
10+
snapshot::create_tree(head_tree_id, state, no_workspace_and_meta)?;
11+
Ok(())
12+
}
13+
14+
fn args_for_worktree_changes(
15+
repo: &gix::Repository,
16+
) -> anyhow::Result<(
17+
gix::Id<'_>,
18+
snapshot::create_tree::State,
19+
Option<(
20+
&'static but_graph::projection::Workspace<'static>,
21+
&'static VirtualBranchesTomlMetadata,
22+
)>,
23+
)> {
24+
todo!()
25+
}
26+
}

0 commit comments

Comments
 (0)