Skip to content

Commit b7ba15b

Browse files
committed
Incorporate worktree information into graph and workspace.
1 parent 3467de7 commit b7ba15b

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

crates/but-graph/tests/fixtures/scenarios.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ git init multi-root
120120
git checkout main && git merge --allow-unrelated-histories C
121121
)
122122

123+
git init ambiguous-worktrees
124+
(cd ambiguous-worktrees
125+
commit M
126+
git worktree add ../wt-outside-ambiguous-worktree
127+
git worktree add wt-inside-ambiguous-worktree
128+
)
129+
123130
# A single root that splits up into 4 branches and merges again
124131
git init four-diamond
125132
(cd four-diamond
@@ -205,6 +212,31 @@ git init special-branches
205212

206213
mkdir ws
207214
(cd ws
215+
git init ambiguous-worktrees
216+
(cd ambiguous-worktrees
217+
set -x
218+
commit M1
219+
commit M-base
220+
221+
git branch A
222+
git worktree add -b A-inside wt-A-inside
223+
git worktree add -b A-outside ../wt-A-outside
224+
225+
git checkout -b soon-origin-A main
226+
commit A-remote
227+
git checkout main
228+
commit M-advanced
229+
setup_target_to_match_main
230+
231+
git checkout -b B A
232+
commit B
233+
git checkout A
234+
git worktree add wt-B-inside B
235+
236+
create_workspace_commit_once A B
237+
setup_remote_tracking soon-origin-A A "move"
238+
)
239+
208240
git init remote-and-integrated-tracking-linear
209241
(cd remote-and-integrated-tracking-linear
210242
commit M1

crates/but-graph/tests/graph/init/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,27 @@ fn special_branch_names_do_not_end_up_in_segment() -> anyhow::Result<()> {
723723
Ok(())
724724
}
725725

726+
#[test]
727+
fn ambiguous_worktrees() -> anyhow::Result<()> {
728+
let (repo, meta) = read_only_in_memory_scenario("ambiguous-worktrees")?;
729+
insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @"* 85efbe4 (HEAD -> main, wt-outside-ambiguous-worktree, wt-inside-ambiguous-worktree) M");
730+
731+
let graph = Graph::from_head(&repo, &*meta, standard_options())?.validated()?;
732+
// TODO: show worktree ids at least, make main workspace clear
733+
insta::assert_snapshot!(graph_tree(&graph), @r"
734+
└── 👉►:0[0]:main
735+
└── ·85efbe4 (⌂|1) ►wt-inside-ambiguous-worktree, ►wt-outside-ambiguous-worktree
736+
");
737+
738+
insta::assert_snapshot!(graph_workspace(&graph.to_workspace()?), @r"
739+
⌂:0:main <> ✓!
740+
└── ≡:0:main
741+
└── :0:main
742+
└── ·85efbe4 ►wt-inside-ambiguous-worktree, ►wt-outside-ambiguous-worktree
743+
");
744+
Ok(())
745+
}
746+
726747
mod with_workspace;
727748

728749
mod utils;

crates/but-graph/tests/graph/init/with_workspace.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5462,6 +5462,57 @@ fn no_ws_commit_two_branches_no_target() -> anyhow::Result<()> {
54625462
Ok(())
54635463
}
54645464

5465+
#[test]
5466+
fn ambiguous_worktrees() -> anyhow::Result<()> {
5467+
let (repo, mut meta) = read_only_in_memory_scenario("ws/ambiguous-worktrees")?;
5468+
insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @r"
5469+
* a5f94a2 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
5470+
|\
5471+
| * 3e01e28 (B) B
5472+
|/
5473+
| * 8dc508f (origin/main, main) M-advanced
5474+
|/
5475+
| * 197ddce (origin/A) A-remote
5476+
|/
5477+
* 081bae9 (A-outside, A-inside, A) M-base
5478+
* 3183e43 M1
5479+
");
5480+
5481+
add_stack_with_segments(&mut meta, 0, "A", StackState::InWorkspace, &[]);
5482+
let graph = Graph::from_head(&repo, &*meta, standard_options())?.validated()?;
5483+
// TODO: Show worktrees
5484+
insta::assert_snapshot!(graph_tree(&graph), @r"
5485+
├── 👉📕►►►:0[0]:gitbutler/workspace
5486+
│ └── ·a5f94a2 (⌂|🏘|1)
5487+
│ ├── ►:5[1]:B
5488+
│ │ └── ·3e01e28 (⌂|🏘|1)
5489+
│ │ └── ►:3[2]:anon: →:6:
5490+
│ │ ├── ·081bae9 (⌂|🏘|✓|1111) ►A-inside, ►A-outside
5491+
│ │ └── ·3183e43 (⌂|🏘|✓|1111)
5492+
│ └── 📙►:6[1]:A <> origin/A →:4:
5493+
│ └── →:3:
5494+
├── ►:1[0]:origin/main →:2:
5495+
│ └── ►:2[1]:main <> origin/main →:1:
5496+
│ └── ·8dc508f (⌂|✓|10)
5497+
│ └── →:3:
5498+
└── ►:4[0]:origin/A →:6:
5499+
└── 🟣197ddce (0x0|1000)
5500+
└── →:3:
5501+
");
5502+
5503+
graph.open_as_svg();
5504+
insta::assert_snapshot!(graph_workspace(&graph.to_workspace()?), @r"
5505+
📕🏘️:0:gitbutler/workspace <> ✓refs/remotes/origin/main⇣1 on 081bae9
5506+
├── ≡📙:6:A <> origin/A →:4:⇣1 on 081bae9 {0}
5507+
│ └── 📙:6:A <> origin/A →:4:⇣1
5508+
│ └── 🟣197ddce
5509+
└── ≡:5:B on 081bae9
5510+
└── :5:B
5511+
└── ·3e01e28 (🏘️)
5512+
");
5513+
Ok(())
5514+
}
5515+
54655516
mod edit_commit {
54665517
use but_graph::Graph;
54675518
use but_testsupport::{graph_tree, graph_workspace, visualize_commit_graph_all};

0 commit comments

Comments
 (0)