11mod 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+ } ;
25 use bstr:: ByteSlice ;
3- use but_graph:: init:: Options ;
6+ use but_graph:: init:: { Options , Overlay } ;
47 use but_testsupport:: { visualize_commit_graph_all, visualize_tree} ;
58 use but_workspace:: WorkspaceCommit ;
69 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 ;
911
1012 #[ test]
1113 fn without_conflict_journey ( ) -> anyhow:: Result < ( ) > {
@@ -240,9 +242,69 @@ mod from_new_merge_with_metadata {
240242
241243 #[ test]
242244 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+
246308 Ok ( ( ) )
247309 }
248310
@@ -253,11 +315,11 @@ mod from_new_merge_with_metadata {
253315 insta:: assert_snapshot!( visualize_commit_graph_all( & repo) ?, @r"
254316 * d3cce74 (clean-A) add A
255317 | * 115e41b (clean-B) add B
256- |/
318+ |/
257319 | * 6777bd8 (conflict-C1) add C1
258- |/
320+ |/
259321 | * f8392d2 (HEAD -> conflict-C2) add C2
260- |/
322+ |/
261323 * 85efbe4 (main, gitbutler/workspace) M
262324 " ) ;
263325
@@ -303,7 +365,7 @@ mod from_new_merge_with_metadata {
303365 This is a merge commit of the virtual branches in your workspace.
304366
305367 Due to GitButler managing multiple virtual branches, you cannot switch back and
306- forth between git branches and virtual branches easily.
368+ forth between git branches and virtual branches easily.
307369
308370 If you switch to another branch, GitButler will need to be reinitialized.
309371 If you commit on this branch, GitButler will throw it away.
@@ -366,7 +428,7 @@ mod from_new_merge_with_metadata {
366428 This is a merge commit of the virtual branches in your workspace.
367429
368430 Due to GitButler managing multiple virtual branches, you cannot switch back and
369- forth between git branches and virtual branches easily.
431+ forth between git branches and virtual branches easily.
370432
371433 If you switch to another branch, GitButler will need to be reinitialized.
372434 If you commit on this branch, GitButler will throw it away.
0 commit comments