|  | 
| 1 | 1 | mod from_new_merge_with_metadata { | 
|  | 2 | +    use crate::ref_info::with_workspace_commit::utils::{ | 
|  | 3 | +        named_read_only_in_memory_scenario, named_writable_scenario_with_description_and_graph, | 
|  | 4 | +    }; | 
| 2 | 5 |     use bstr::ByteSlice; | 
| 3 |  | -    use but_graph::init::Options; | 
|  | 6 | +    use but_graph::init::{Options, Overlay}; | 
| 4 | 7 |     use but_testsupport::{visualize_commit_graph_all, visualize_tree}; | 
| 5 | 8 |     use but_workspace::WorkspaceCommit; | 
| 6 | 9 |     use gix::prelude::ObjectIdExt; | 
| 7 |  | - | 
| 8 |  | -    use crate::ref_info::with_workspace_commit::utils::named_read_only_in_memory_scenario; | 
|  | 10 | +    use gix::refs::Target; | 
| 9 | 11 | 
 | 
| 10 | 12 |     #[test] | 
| 11 | 13 |     fn without_conflict_journey() -> anyhow::Result<()> { | 
| @@ -240,9 +242,69 @@ mod from_new_merge_with_metadata { | 
| 240 | 242 | 
 | 
| 241 | 243 |     #[test] | 
| 242 | 244 |     fn with_conflict_commits() -> anyhow::Result<()> { | 
| 243 |  | -        let (repo, mut meta) = named_read_only_in_memory_scenario("with-conflict", "")?; | 
| 244 |  | -        insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @r""); | 
| 245 |  | -        // but_testsupport::git(&repo) | 
|  | 245 | +        let (_tmp, mut graph, repo, mut meta, _description) = | 
|  | 246 | +            named_writable_scenario_with_description_and_graph("with-conflict", |_| {})?; | 
|  | 247 | +        insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @r" | 
|  | 248 | +        * 8450331 (HEAD -> main, tag: conflicted) GitButler WIP Commit | 
|  | 249 | +        * a047f81 (tag: normal) init | 
|  | 250 | +        "); | 
|  | 251 | +        but_testsupport::invoke_bash( | 
|  | 252 | +            r#" | 
|  | 253 | +            git branch tip-conflicted | 
|  | 254 | +            git reset --hard @~1 | 
|  | 255 | +            git checkout -b unrelated | 
|  | 256 | +                touch unrelated-file && git add unrelated-file && git commit -m "unrelated" | 
|  | 257 | +            "#, | 
|  | 258 | +            &repo, | 
|  | 259 | +        ); | 
|  | 260 | +        insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @r" | 
|  | 261 | +        * 8450331 (tag: conflicted, tip-conflicted) GitButler WIP Commit | 
|  | 262 | +        | * 8ab1c4d (HEAD -> unrelated) unrelated | 
|  | 263 | +        |/   | 
|  | 264 | +        * a047f81 (tag: normal, main) init | 
|  | 265 | +        "); | 
|  | 266 | + | 
|  | 267 | +        let stacks = ["tip-conflicted", "unrelated"]; | 
|  | 268 | +        add_stacks(&mut meta, stacks); | 
|  | 269 | + | 
|  | 270 | +        graph = graph.redo_traversal_with_overlay( | 
|  | 271 | +            &repo, | 
|  | 272 | +            &meta, | 
|  | 273 | +            Overlay::default().with_references_if_new([ | 
|  | 274 | +                repo.find_reference("unrelated")?.inner, | 
|  | 275 | +                // The workspace ref is needed so the workspace and its stacks are iterated as well. | 
|  | 276 | +                // Algorithms which work with simulation also have to be mindful about this. | 
|  | 277 | +                gix::refs::Reference { | 
|  | 278 | +                    name: "refs/heads/gitbutler/workspace".try_into()?, | 
|  | 279 | +                    target: Target::Object(repo.rev_parse_single("main")?.detach()), | 
|  | 280 | +                    peeled: None, | 
|  | 281 | +                }, | 
|  | 282 | +            ]), | 
|  | 283 | +        )?; | 
|  | 284 | + | 
|  | 285 | +        let out = | 
|  | 286 | +            WorkspaceCommit::from_new_merge_with_metadata(&to_stacks(stacks), &graph, &repo, None)?; | 
|  | 287 | +        insta::assert_debug_snapshot!(out, @r#" | 
|  | 288 | +        Outcome { | 
|  | 289 | +            workspace_commit_id: Sha1(ed5a3012c6a4798404f5b8586588d0ede0664683), | 
|  | 290 | +            stacks: [ | 
|  | 291 | +                Stack { tip: 8450331, name: "tip-conflicted" }, | 
|  | 292 | +                Stack { tip: 8ab1c4d, name: "unrelated" }, | 
|  | 293 | +            ], | 
|  | 294 | +            missing_stacks: [], | 
|  | 295 | +            conflicting_stacks: [], | 
|  | 296 | +        } | 
|  | 297 | +        "#); | 
|  | 298 | + | 
|  | 299 | +        // There it auto-resolves the commit to not merge the actual tree structure. | 
|  | 300 | +        insta::assert_snapshot!(visualize_tree( | 
|  | 301 | +            out.workspace_commit_id.attach(&repo).object()?.into_commit().tree_id()? | 
|  | 302 | +        ), @r#" | 
|  | 303 | +        8882acc | 
|  | 304 | +        ├── file:100644:e69de29 "" | 
|  | 305 | +        └── unrelated-file:100644:e69de29 "" | 
|  | 306 | +        "#); | 
|  | 307 | + | 
| 246 | 308 |         Ok(()) | 
| 247 | 309 |     } | 
| 248 | 310 | 
 | 
|  | 
0 commit comments