Skip to content

Commit 9153a1d

Browse files
committed
Assure that an entrypoint doesn't alter the stack setup.
I.e. if stacks are separate when looking at the workspace, they should remain separtate when one of these is checked out directly.
1 parent e09cc01 commit 9153a1d

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ mkdir ws
281281
create_workspace_commit_once main
282282
)
283283

284+
git init just-init-with-two-branches
285+
(cd just-init-with-two-branches
286+
commit init
287+
git branch A
288+
git branch B
289+
git checkout -b gitbutler/workspace
290+
)
291+
284292
git init just-init-with-branches
285293
(cd just-init-with-branches
286294
commit init && setup_target_to_match_main

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,58 @@ fn minimal_merge() -> anyhow::Result<()> {
634634
Ok(())
635635
}
636636

637+
#[test]
638+
fn stack_configuration_is_respected_if_one_of_them_is_an_entrypoint() -> anyhow::Result<()> {
639+
let (repo, mut meta) = read_only_in_memory_scenario("ws/just-init-with-two-branches")?;
640+
insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @"* fafd9d0 (HEAD -> gitbutler/workspace, main, B, A) init");
641+
642+
add_stack_with_segments(&mut meta, 1, "A", StackState::InWorkspace, &[]);
643+
add_stack_with_segments(&mut meta, 2, "B", StackState::InWorkspace, &[]);
644+
645+
let graph = Graph::from_head(
646+
&repo,
647+
&*meta,
648+
standard_options_with_extra_target(&repo, "main"),
649+
)?
650+
.validated()?;
651+
insta::assert_snapshot!(graph_tree(&graph), @r"
652+
└── 👉📕►►►:0[0]:gitbutler/workspace
653+
├── 📙►:2[1]:A
654+
│ └── ►:1[2]:anon:
655+
│ └── ·fafd9d0 (⌂|🏘️|1) ►main
656+
└── 📙►:3[1]:B
657+
└── →:1:
658+
");
659+
insta::assert_snapshot!(graph_workspace(&graph.to_workspace()?), @r"
660+
📕🏘️⚠️:0:gitbutler/workspace <> ✓! on fafd9d0
661+
├── ≡📙:3:B on fafd9d0
662+
│ └── 📙:3:B
663+
└── ≡📙:2:A on fafd9d0
664+
└── 📙:2:A
665+
");
666+
667+
let (id, ref_name) = id_at(&repo, "B");
668+
let graph = Graph::from_commit_traversal(id, ref_name.clone(), &*meta, standard_options())?
669+
.validated()?;
670+
// TODO: it shouldn't create a dependent branch here, but instead see A as a stack.
671+
// problem is that for stack creation, there is no candidate.
672+
insta::assert_snapshot!(graph_tree(&graph), @r"
673+
└── 📕►►►:1[0]:gitbutler/workspace
674+
└── 👉📙►:0[1]:B
675+
└── 📙►:2[2]:A
676+
└── ·fafd9d0 (⌂|🏘️|1) ►main
677+
");
678+
insta::assert_snapshot!(graph_workspace(&graph.to_workspace()?), @r"
679+
📕🏘️⚠️:1:gitbutler/workspace <> ✓!
680+
└── ≡👉📙:0:B
681+
├── 👉📙:0:B
682+
└── 📙:2:A
683+
└── ·fafd9d0 (🏘️) ►main
684+
");
685+
686+
Ok(())
687+
}
688+
637689
#[test]
638690
fn just_init_with_branches() -> anyhow::Result<()> {
639691
let (repo, mut meta) = read_only_in_memory_scenario("ws/just-init-with-branches")?;

0 commit comments

Comments
 (0)