Skip to content

Commit 2242956

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 29a0d93 commit 2242956

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
@@ -298,6 +298,14 @@ mkdir ws
298298
create_workspace_commit_once main
299299
)
300300

301+
git init just-init-with-two-branches
302+
(cd just-init-with-two-branches
303+
commit init
304+
git branch A
305+
git branch B
306+
git checkout -b gitbutler/workspace
307+
)
308+
301309
git init just-init-with-branches
302310
(cd just-init-with-branches
303311
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
@@ -681,6 +681,58 @@ fn minimal_merge() -> anyhow::Result<()> {
681681
Ok(())
682682
}
683683

684+
#[test]
685+
fn stack_configuration_is_respected_if_one_of_them_is_an_entrypoint() -> anyhow::Result<()> {
686+
let (repo, mut meta) = read_only_in_memory_scenario("ws/just-init-with-two-branches")?;
687+
insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @"* fafd9d0 (HEAD -> gitbutler/workspace, main, B, A) init");
688+
689+
add_stack_with_segments(&mut meta, 1, "A", StackState::InWorkspace, &[]);
690+
add_stack_with_segments(&mut meta, 2, "B", StackState::InWorkspace, &[]);
691+
692+
let graph = Graph::from_head(
693+
&repo,
694+
&*meta,
695+
standard_options_with_extra_target(&repo, "main"),
696+
)?
697+
.validated()?;
698+
insta::assert_snapshot!(graph_tree(&graph), @r"
699+
└── 👉📕►►►:0[0]:gitbutler/workspace
700+
├── 📙►:2[1]:A
701+
│ └── ►:1[2]:anon:
702+
│ └── ·fafd9d0 (⌂|🏘️|1) ►main
703+
└── 📙►:3[1]:B
704+
└── →:1:
705+
");
706+
insta::assert_snapshot!(graph_workspace(&graph.to_workspace()?), @r"
707+
📕🏘️⚠️:0:gitbutler/workspace <> ✓! on fafd9d0
708+
├── ≡📙:3:B on fafd9d0
709+
│ └── 📙:3:B
710+
└── ≡📙:2:A on fafd9d0
711+
└── 📙:2:A
712+
");
713+
714+
let (id, ref_name) = id_at(&repo, "B");
715+
let graph = Graph::from_commit_traversal(id, ref_name.clone(), &*meta, standard_options())?
716+
.validated()?;
717+
// TODO: it shouldn't create a dependent branch here, but instead see A as a stack.
718+
// problem is that for stack creation, there is no candidate.
719+
insta::assert_snapshot!(graph_tree(&graph), @r"
720+
└── 📕►►►:1[0]:gitbutler/workspace
721+
└── 👉📙►:0[1]:B
722+
└── 📙►:2[2]:A
723+
└── ·fafd9d0 (⌂|🏘️|1) ►main
724+
");
725+
insta::assert_snapshot!(graph_workspace(&graph.to_workspace()?), @r"
726+
📕🏘️⚠️:1:gitbutler/workspace <> ✓!
727+
└── ≡👉📙:0:B
728+
├── 👉📙:0:B
729+
└── 📙:2:A
730+
└── ·fafd9d0 (🏘️) ►main
731+
");
732+
733+
Ok(())
734+
}
735+
684736
#[test]
685737
fn just_init_with_branches() -> anyhow::Result<()> {
686738
let (repo, mut meta) = read_only_in_memory_scenario("ws/just-init-with-branches")?;

0 commit comments

Comments
 (0)