diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c --- a/usr.bin/diff3/diff3.c +++ b/usr.bin/diff3/diff3.c @@ -335,7 +335,8 @@ change(2, &d2->old, false); } else if (Aflag || mflag) { // XXX-THJ: What does it mean for the second file to differ? - j = edit(d2, dup, j, DIFF_TYPE2); + if (eflag == EFLAG_UNMERGED) + j = edit(d2, dup, j, DIFF_TYPE2); } d2++; continue; @@ -861,7 +862,7 @@ eflag = EFLAG_UNMERGED; break; case 'E': - eflag = EFLAG_UNMERGED; + eflag = EFLAG_OVERLAP; oflag = 1; break; case 'i': @@ -907,7 +908,8 @@ argv += optind; if (Aflag) { - eflag = EFLAG_UNMERGED; + if (eflag == EFLAG_NONE) + eflag = EFLAG_UNMERGED; oflag = 1; } diff --git a/usr.bin/diff3/tests/Makefile b/usr.bin/diff3/tests/Makefile --- a/usr.bin/diff3/tests/Makefile +++ b/usr.bin/diff3/tests/Makefile @@ -23,5 +23,7 @@ long-ed.out \ long-A.out \ long-merge.out \ + fbsdid1.txt \ + fbsdid2.txt .include diff --git a/usr.bin/diff3/tests/diff3_test.sh b/usr.bin/diff3/tests/diff3_test.sh --- a/usr.bin/diff3/tests/diff3_test.sh +++ b/usr.bin/diff3/tests/diff3_test.sh @@ -4,6 +4,7 @@ atf_test_case diff3_ed atf_test_case diff3_A atf_test_case diff3_merge +atf_test_case diff3_E_merge diff3_body() { @@ -66,6 +67,36 @@ diff3 -m -L long-m.txt -L long-o.txt -L long-y.txt $(atf_get_srcdir)/long-m.txt $(atf_get_srcdir)/long-o.txt $(atf_get_srcdir)/long-y.txt } +diff3_E_merge_body() +{ + +expected="<<<<<<< 2 +# \$FreeBSD: head/local 12000 jhb \$ +======= +# \$FreeBSD: head/local 12345 jhb \$ +>>>>>>> 3 +# \$FreeBSD: head/local 12345 jhb \$ + +this is a file + +these are some local mods to the file +" + # first test the regular test + cp $(atf_get_srcdir)/fbsdid2.txt out.txt + atf_check -s exit:1 -o inline:"${expected}" \ + diff3 -m -L 1 -L 2 -L 3 out.txt $(atf_get_srcdir)/fbsdid1.txt $(atf_get_srcdir)/fbsdid2.txt + +merged="# \$FreeBSD: head/local 12345 jhb \$ + +this is a file + +these are some local mods to the file +" + atf_check -s exit:0 -o inline:"${merged}" \ + diff3 -E -m out.txt $(atf_get_srcdir)/fbsdid1.txt $(atf_get_srcdir)/fbsdid2.txt +} + + atf_init_test_cases() { atf_add_test_case diff3 @@ -73,4 +104,5 @@ atf_add_test_case diff3_ed atf_add_test_case diff3_A atf_add_test_case diff3_merge + atf_add_test_case diff3_E_merge } diff --git a/usr.bin/diff3/tests/fbsdid1.txt b/usr.bin/diff3/tests/fbsdid1.txt new file mode 100644 --- /dev/null +++ b/usr.bin/diff3/tests/fbsdid1.txt @@ -0,0 +1,5 @@ +# $FreeBSD: head/local 12000 jhb $ + +this is a file + +these are some local mods to the file diff --git a/usr.bin/diff3/tests/fbsdid2.txt b/usr.bin/diff3/tests/fbsdid2.txt new file mode 100644 --- /dev/null +++ b/usr.bin/diff3/tests/fbsdid2.txt @@ -0,0 +1,5 @@ +# $FreeBSD: head/local 12345 jhb $ + +this is a file + +these are some local mods to the file