|
| 1 | +/// Tests for gix blob-merge behaviour. |
| 2 | +/// |
| 3 | +/// Some tests in this module are expected to **fail** until an upstream gix bug |
| 4 | +/// is resolved. Those tests are marked `#[should_panic]` so the test suite |
| 5 | +/// stays green in the interim; once gix is fixed the annotation must be removed. |
| 6 | +use gix::merge::blob::{ |
| 7 | + Resolution, |
| 8 | + builtin_driver::text::{Conflict, ConflictStyle, Labels, Options}, |
| 9 | +}; |
| 10 | + |
| 11 | +fn fixtures() -> std::path::PathBuf { |
| 12 | + let dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/merge"); |
| 13 | + assert!(dir.exists(), "fixtures directory missing: {dir:?}"); |
| 14 | + dir |
| 15 | +} |
| 16 | + |
| 17 | +/// gix's Myers blob merge produces a false conflict on certain inputs where |
| 18 | +/// `git merge-file` (also Myers-based) resolves cleanly. |
| 19 | +/// |
| 20 | +/// Scenario (minimal reproduction – 5/4/4 lines) |
| 21 | +/// ----------------------------------------------- |
| 22 | +/// * **base** – `alpha_x`, blank, `bravo_x`, `charlie_x`, blank |
| 23 | +/// * **ours** – blank, blank, `bravo_x`, `charlie_x` |
| 24 | +/// (i.e. `alpha_x` deleted, one blank added, trailing blank removed) |
| 25 | +/// * **theirs** – `alpha_x`, blank, `charlie_x`, blank |
| 26 | +/// (i.e. `bravo_x` deleted) |
| 27 | +/// |
| 28 | +/// `git merge-file -p ours base theirs` exits 0 (clean merge). |
| 29 | +/// imara-diff's Myers implementation chooses different hunk boundaries when |
| 30 | +/// blank lines create alignment ambiguity, causing the 3-way merge to see |
| 31 | +/// the `bravo_x` deletion as overlapping with the `alpha_x` area changes. |
| 32 | +/// |
| 33 | +/// Upstream issue: https://github.com/GitoxideLabs/gitoxide/issues/2475 |
| 34 | +/// |
| 35 | +/// Remove `#[should_panic]` once the upstream fix lands. |
| 36 | +#[test] |
| 37 | +#[should_panic(expected = "https://github.com/GitoxideLabs/gitoxide/issues/2475")] |
| 38 | +fn myers_blob_merge_false_conflict_with_large_insertion_and_adjacent_deletion() { |
| 39 | + let dir = fixtures(); |
| 40 | + let base = std::fs::read(dir.join("base.txt")).unwrap(); |
| 41 | + let ours = std::fs::read(dir.join("ours.txt")).unwrap(); |
| 42 | + let theirs = std::fs::read(dir.join("theirs.txt")).unwrap(); |
| 43 | + |
| 44 | + let labels = Labels { |
| 45 | + ancestor: Some("base".into()), |
| 46 | + current: Some("ours".into()), |
| 47 | + other: Some("theirs".into()), |
| 48 | + }; |
| 49 | + let options = Options { |
| 50 | + diff_algorithm: gix::diff::blob::Algorithm::Myers, |
| 51 | + conflict: Conflict::Keep { |
| 52 | + style: ConflictStyle::Merge, |
| 53 | + marker_size: std::num::NonZeroU8::new(7).unwrap(), |
| 54 | + }, |
| 55 | + }; |
| 56 | + |
| 57 | + let mut out = Vec::new(); |
| 58 | + let mut input = gix::diff::blob::intern::InternedInput::new(&[][..], &[][..]); |
| 59 | + let resolution = gix::merge::blob::builtin_driver::text( |
| 60 | + &mut out, &mut input, labels, &ours, &base, &theirs, options, |
| 61 | + ); |
| 62 | + |
| 63 | + assert_eq!( |
| 64 | + resolution, |
| 65 | + Resolution::Complete, |
| 66 | + "gix Myers blob merge should resolve cleanly (upstream bug: \ |
| 67 | + https://github.com/GitoxideLabs/gitoxide/issues/2475)" |
| 68 | + ); |
| 69 | +} |
| 70 | + |
| 71 | +/// Sanity check: the Histogram algorithm already resolves the same input |
| 72 | +/// without conflicts. This test must always pass. |
| 73 | +#[test] |
| 74 | +fn histogram_blob_merge_resolves_large_insertion_and_adjacent_deletion() { |
| 75 | + let dir = fixtures(); |
| 76 | + let base = std::fs::read(dir.join("base.txt")).unwrap(); |
| 77 | + let ours = std::fs::read(dir.join("ours.txt")).unwrap(); |
| 78 | + let theirs = std::fs::read(dir.join("theirs.txt")).unwrap(); |
| 79 | + |
| 80 | + let labels = Labels { |
| 81 | + ancestor: Some("base".into()), |
| 82 | + current: Some("ours".into()), |
| 83 | + other: Some("theirs".into()), |
| 84 | + }; |
| 85 | + let options = Options { |
| 86 | + diff_algorithm: gix::diff::blob::Algorithm::Histogram, |
| 87 | + conflict: Conflict::Keep { |
| 88 | + style: ConflictStyle::Merge, |
| 89 | + marker_size: std::num::NonZeroU8::new(7).unwrap(), |
| 90 | + }, |
| 91 | + }; |
| 92 | + |
| 93 | + let mut out = Vec::new(); |
| 94 | + let mut input = gix::diff::blob::intern::InternedInput::new(&[][..], &[][..]); |
| 95 | + let resolution = gix::merge::blob::builtin_driver::text( |
| 96 | + &mut out, &mut input, labels, &ours, &base, &theirs, options, |
| 97 | + ); |
| 98 | + |
| 99 | + assert_eq!( |
| 100 | + resolution, |
| 101 | + Resolution::Complete, |
| 102 | + "Histogram should merge without conflicts" |
| 103 | + ); |
| 104 | + assert!( |
| 105 | + !String::from_utf8_lossy(&out).contains("<<<<<<<"), |
| 106 | + "Histogram merge output should contain no conflict markers" |
| 107 | + ); |
| 108 | +} |
0 commit comments