@@ -521,6 +521,79 @@ fn detached_head_journey() -> anyhow::Result<()> {
521
521
Ok ( ( ) )
522
522
}
523
523
524
+ #[ test]
525
+ fn apply_two_ambiguous_stacks_with_target ( ) -> anyhow:: Result < ( ) > {
526
+ let ( _tmp, graph, repo, mut meta, _description) =
527
+ named_writable_scenario_with_description_and_graph (
528
+ "no-ws-ref-stack-and-dependent-branch" ,
529
+ |_meta| { } ,
530
+ ) ?;
531
+ insta:: assert_snapshot!( visualize_commit_graph_all( & repo) ?, @r"
532
+ * f084d61 (C, B, A) A2
533
+ * 7076dee (E, D) A1
534
+ * 85efbe4 (HEAD -> main, origin/main) M
535
+ " ) ;
536
+
537
+ let ws = graph. to_workspace ( ) ?;
538
+ insta:: assert_snapshot!( graph_workspace( & ws) , @r"
539
+ ⌂:0:main <> ✓!
540
+ └── ≡:0:main
541
+ └── :0:main
542
+ └── ·85efbe4
543
+ " ) ;
544
+
545
+ // Apply `A` first.
546
+ let out =
547
+ but_workspace:: branch:: apply ( r ( "refs/heads/A" ) , & ws, & repo, & mut meta, default_options ( ) ) ?;
548
+ insta:: assert_debug_snapshot!( out, @r"
549
+ Outcome {
550
+ workspace_changed: true,
551
+ workspace_ref_created: true,
552
+ }
553
+ " ) ;
554
+ let graph = out. graph ;
555
+ let ws = graph. to_workspace ( ) ?;
556
+ insta:: assert_snapshot!( graph_workspace( & ws) , @r"
557
+ 📕🏘️:0:gitbutler/workspace <> ✓refs/remotes/origin/main on 85efbe4
558
+ └── ≡📙:3:A on 85efbe4
559
+ └── 📙:3:A
560
+ ├── ·f084d61 (🏘️) ►B, ►C
561
+ └── ·7076dee (🏘️) ►D, ►E
562
+ " ) ;
563
+ insta:: assert_snapshot!( visualize_commit_graph_all( & repo) ?, @r"
564
+ * 6a706b7 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
565
+ * f084d61 (C, B, A) A2
566
+ * 7076dee (E, D) A1
567
+ * 85efbe4 (origin/main, main) M
568
+ " ) ;
569
+
570
+ // Apply `B` - the only sane way is to make it its own stack, but allow it to diverge.
571
+ let out =
572
+ but_workspace:: branch:: apply ( r ( "refs/heads/B" ) , & ws, & repo, & mut meta, default_options ( ) )
573
+ . expect ( "apply actually works" ) ;
574
+ insta:: assert_debug_snapshot!( out, @r"
575
+ Outcome {
576
+ workspace_changed: true,
577
+ workspace_ref_created: false,
578
+ }
579
+ " ) ;
580
+
581
+ // TODO: Make it work as dependent branch
582
+ let graph = out. graph ;
583
+ let ws = graph. to_workspace ( ) ?;
584
+ insta:: assert_snapshot!( graph_workspace( & ws) , @r"" ) ;
585
+ insta:: assert_snapshot!( visualize_commit_graph_all( & repo) ?, @r"
586
+ * ccbee14 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
587
+ |\
588
+ | * 6a706b7 (main) GitButler Workspace Commit
589
+ |/
590
+ * f084d61 (B, A) A2
591
+ * 7076dee A1
592
+ * 85efbe4 (origin/main) M
593
+ " ) ;
594
+ Ok ( ( ) )
595
+ }
596
+
524
597
#[ test]
525
598
fn auto_checkout_of_enclosing_workspace_flat ( ) -> anyhow:: Result < ( ) > {
526
599
let ( _tmp, graph, repo, mut meta, _description) =
0 commit comments