merge-ort: capture and print ll-merge warnings in our preferred fashion

Instead of immediately printing ll-merge warnings to stderr, we save them in our output strbuf. Besides allowing us to move these warnings to a special file for --remerge-diff, this has two other benefits for regular merges done by merge-ort: * The deferral of messages ensures we can print all messages about any given path together (merge-recursive was known to sometimes intersperse messages about other paths, particularly when renames were involved). * The deferral of messages means we can avoid printing spurious conflict messages when we just end up aborting due to local user modifications in the way. (In contrast to merge-recursive.c which prematurely checks for local modifications in the way via unpack_trees() and gets the check wrong both in terms of false positives and false negatives relative to renames, merge-ort does not perform the local modifications in the way check until the checkout() step after the full merge has been computed.) Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Feb 2, 2022 at 02:37 UTC 24dbdab50ddaadf6a7abaf5537e0dad36d91e49a
3 files changed +17 -6
merge-ort.c
+3 -2
@@ -1788,8 +1788,9 @@ static int merge_3way(struct merge_options *opt,
1788 &src1, name1, &src2, name2,
1789 &opt->priv->attr_index, &ll_opts);
1790 if (merge_status == LL_MERGE_BINARY_CONFLICT)
1791 - warning("Cannot merge binary files: %s (%s vs. %s)",
1792 - path, name1, name2);
1791 + path_msg(opt, path, 0,
1792 + "warning: Cannot merge binary files: %s (%s vs. %s)",
1793 + path, name1, name2);
1794
1795 free(base);
1796 free(name1);
t/t6404-recursive-merge.sh
+7 -2
@@ -108,8 +108,13 @@ test_expect_success 'refuse to merge binary files' '
108 printf "\0\0" >binary-file &&
109 git add binary-file &&
110 git commit -m binary2 &&
111 - test_must_fail git merge F >merge.out 2>merge.err &&
112 - grep "Cannot merge binary files: binary-file (HEAD vs. F)" merge.err
111 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
112 + then
113 + test_must_fail git merge F >merge_output
114 + else
115 + test_must_fail git merge F 2>merge_output
116 + fi &&
117 + grep "Cannot merge binary files: binary-file (HEAD vs. F)" merge_output
118 '
119
120 test_expect_success 'mark rename/delete as unmerged' '
t/t6406-merge-attr.sh
+7 -2
@@ -221,8 +221,13 @@ test_expect_success 'binary files with union attribute' '
221 printf "two\0" >bin.txt &&
222 git commit -am two &&
223
224 - test_must_fail git merge bin-main 2>stderr &&
225 - grep -i "warning.*cannot merge.*HEAD vs. bin-main" stderr
224 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
225 + then
226 + test_must_fail git merge bin-main >output
227 + else
228 + test_must_fail git merge bin-main 2>output
229 + fi &&
230 + grep -i "warning.*cannot merge.*HEAD vs. bin-main" output
231 '
232
233 test_done