|
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 |
|
@@ -303,7 +365,7 @@ mod from_new_merge_with_metadata { |
303 | 365 | This is a merge commit of the virtual branches in your workspace. |
304 | 366 |
|
305 | 367 | 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. |
307 | 369 |
|
308 | 370 | If you switch to another branch, GitButler will need to be reinitialized. |
309 | 371 | If you commit on this branch, GitButler will throw it away. |
@@ -366,7 +428,7 @@ mod from_new_merge_with_metadata { |
366 | 428 | This is a merge commit of the virtual branches in your workspace. |
367 | 429 |
|
368 | 430 | 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. |
370 | 432 |
|
371 | 433 | If you switch to another branch, GitButler will need to be reinitialized. |
372 | 434 | If you commit on this branch, GitButler will throw it away. |
|
0 commit comments