Skip to content

Commit 4943b54

Browse files
committed
Store index data in the snapshot, and resolve it as well.
1 parent ce73858 commit 4943b54

File tree

4 files changed

+118
-29
lines changed

4 files changed

+118
-29
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
### Description
4+
# A newly initialized git repository with an executable, a normal file, a symlink and a fifo, added to the index.
5+
set -eu -o pipefail
6+
7+
git init
8+
echo content > untracked
9+
echo exe > untracked-exe && chmod +x untracked-exe
10+
ln -s untracked link
11+
mkdir dir
12+
mkfifo dir/fifo-should-be-ignored
13+
14+
git add .
15+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use crate::snapshot::args_for_worktree_changes;
2+
use crate::utils::{read_only_in_memory_scenario, visualize_index};
3+
use but_testsupport::visualize_tree;
4+
use but_workspace::snapshot;
5+
use gix::prelude::ObjectIdExt;
6+
7+
#[test]
8+
fn unborn_added_to_index() -> anyhow::Result<()> {
9+
let repo = read_only_in_memory_scenario("unborn-all-file-types-added-to-index")?;
10+
let (head_tree_id, state, no_workspace_and_meta) = args_for_worktree_changes(&repo)?;
11+
12+
let out = snapshot::create_tree(head_tree_id, state, no_workspace_and_meta)?;
13+
insta::assert_snapshot!(visualize_tree(out.snapshot_tree.attach(&repo)), @r#""#);
14+
insta::assert_debug_snapshot!(out, @r"");
15+
16+
let res_out = snapshot::resolve_tree(
17+
out.snapshot_tree.attach(&repo),
18+
out.head_tree,
19+
snapshot::resolve_tree::Options::default(),
20+
)?;
21+
let mut cherry_pick = res_out
22+
.worktree_cherry_pick
23+
.expect("a worktree change was applied");
24+
assert_eq!(cherry_pick.tree.write()?, out.worktree.unwrap());
25+
let index = res_out
26+
.index
27+
.expect("the index was altered with many added files");
28+
insta::assert_snapshot!(visualize_index(&index), @r"");
29+
30+
assert!(res_out.metadata.is_none());
31+
assert!(
32+
res_out.workspace_references.is_none(),
33+
"didn't ask to store this"
34+
);
35+
Ok(())
36+
}
37+
38+
#[test]
39+
fn with_conflicts() -> anyhow::Result<()> {
40+
let repo = read_only_in_memory_scenario("merge-with-two-branches-conflict")?;
41+
let (head_tree_id, state, no_workspace_and_meta) = args_for_worktree_changes(&repo)?;
42+
43+
let out = snapshot::create_tree(head_tree_id, state, no_workspace_and_meta)?;
44+
insta::assert_snapshot!(visualize_tree(out.snapshot_tree.attach(&repo)), @r#""#);
45+
insta::assert_debug_snapshot!(out, @r"");
46+
47+
let res_out = snapshot::resolve_tree(
48+
out.snapshot_tree.attach(&repo),
49+
out.head_tree,
50+
snapshot::resolve_tree::Options::default(),
51+
)?;
52+
let mut cherry_pick = res_out
53+
.worktree_cherry_pick
54+
.expect("a worktree change was applied");
55+
assert_eq!(cherry_pick.tree.write()?, out.worktree.unwrap());
56+
let index = res_out
57+
.index
58+
.expect("the index was altered with many added files");
59+
insta::assert_snapshot!(visualize_index(&index), @r"");
60+
61+
assert!(res_out.metadata.is_none());
62+
assert!(
63+
res_out.workspace_references.is_none(),
64+
"didn't ask to store this"
65+
);
66+
Ok(())
67+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,36 @@
1+
mod index_create_and_resolve;
12
mod worktree_create_and_resolve;
3+
4+
mod utils {
5+
use but_graph::VirtualBranchesTomlMetadata;
6+
use but_workspace::snapshot;
7+
8+
/// Produce all args needed for creating a snapshot tree, and assure everything is selected.
9+
#[allow(clippy::type_complexity)]
10+
pub fn args_for_worktree_changes(
11+
repo: &gix::Repository,
12+
) -> anyhow::Result<(
13+
gix::Id<'_>,
14+
snapshot::create_tree::State,
15+
Option<(
16+
&'static but_graph::projection::Workspace<'static>,
17+
&'static VirtualBranchesTomlMetadata,
18+
)>,
19+
)> {
20+
let changes = but_core::diff::worktree_changes(repo)?;
21+
let state = snapshot::create_tree::State {
22+
selection: changes
23+
.changes
24+
.iter()
25+
.map(|c| c.path.clone())
26+
.chain(changes.ignored_changes.iter().map(|c| c.path.clone()))
27+
.collect(),
28+
changes,
29+
head: false,
30+
};
31+
let head_tree_id = repo.head_tree_id_or_empty()?;
32+
33+
Ok((head_tree_id, state, None))
34+
}
35+
}
36+
pub use utils::args_for_worktree_changes;

crates/but-workspace/tests/workspace/snapshot/worktree_create_and_resolve.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use crate::snapshot::args_for_worktree_changes;
12
use crate::utils::read_only_in_memory_scenario;
2-
use but_graph::VirtualBranchesTomlMetadata;
33
use but_testsupport::visualize_tree;
44
use but_workspace::snapshot;
55
use gix::prelude::ObjectIdExt;
@@ -154,31 +154,3 @@ fn worktree_all_filetypes() -> anyhow::Result<()> {
154154
);
155155
Ok(())
156156
}
157-
158-
/// Produce all args needed for creating a snapshot tree, and assure everything is selected.
159-
#[allow(clippy::type_complexity)]
160-
fn args_for_worktree_changes(
161-
repo: &gix::Repository,
162-
) -> anyhow::Result<(
163-
gix::Id<'_>,
164-
snapshot::create_tree::State,
165-
Option<(
166-
&'static but_graph::projection::Workspace<'static>,
167-
&'static VirtualBranchesTomlMetadata,
168-
)>,
169-
)> {
170-
let changes = but_core::diff::worktree_changes(repo)?;
171-
let state = snapshot::create_tree::State {
172-
selection: changes
173-
.changes
174-
.iter()
175-
.map(|c| c.path.clone())
176-
.chain(changes.ignored_changes.iter().map(|c| c.path.clone()))
177-
.collect(),
178-
changes,
179-
head: false,
180-
};
181-
let head_tree_id = repo.head_tree_id_or_empty()?;
182-
183-
Ok((head_tree_id, state, None))
184-
}

0 commit comments

Comments
 (0)