merge-ort: turn submodule conflict suggestions into an advice

Add a new advice type 'submoduleMergeConflict' for the error message shown when a non-trivial submodule conflict is encountered, which was added in 4057523a40 (submodule merge: update conflict error message, 2022-08-04). That commit mentions making this message an advice as possible future work. The message can now be disabled with the advice mechanism. Update the tests as the expected message now appears on stderr instead of stdout. Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Philippe Blain committed Feb 26, 2024 at 13:27 UTC b9e55be7401a5413722299279fc867eb931f4c3b
6 files changed +15 -9
Documentation/config/advice.txt
+3
@@ -129,6 +129,9 @@ advice.*::
129 submoduleAlternateErrorStrategyDie::
130 Advice shown when a submodule.alternateErrorStrategy option
131 configured to "die" causes a fatal error.
132 + submoduleMergeConflict::
133 + Advice shown when a non-trivial submodule merge conflict is
134 + encountered.
135 submodulesNotUpdated::
136 Advice shown when a user runs a submodule command that fails
137 because `git submodule update --init` was not run.
advice.c
+1
@@ -79,6 +79,7 @@ static struct {
79 [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
80 [ADVICE_SUBMODULES_NOT_UPDATED] = { "submodulesNotUpdated" },
81 [ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE] = { "submoduleAlternateErrorStrategyDie" },
82 + [ADVICE_SUBMODULE_MERGE_CONFLICT] = { "submoduleMergeConflict" },
83 [ADVICE_SUGGEST_DETACHING_HEAD] = { "suggestDetachingHead" },
84 [ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath" },
85 [ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor" },
advice.h
+1
@@ -47,6 +47,7 @@ enum advice_type {
47 ADVICE_STATUS_U_OPTION,
48 ADVICE_SUBMODULES_NOT_UPDATED,
49 ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE,
50 + ADVICE_SUBMODULE_MERGE_CONFLICT,
51 ADVICE_SUGGEST_DETACHING_HEAD,
52 ADVICE_UPDATE_SPARSE_PATH,
53 ADVICE_WAITING_FOR_EDITOR,
merge-ort.c
+2 -1
@@ -18,6 +18,7 @@
18 #include "merge-ort.h"
19
20 #include "alloc.h"
21 +#include "advice.h"
22 #include "attr.h"
23 #include "cache-tree.h"
24 #include "commit.h"
@@ -4556,7 +4557,7 @@ static void print_submodule_conflict_suggestion(struct string_list *csub) {
4557 " - commit the resulting index in the superproject\n"),
4558 tmp.buf, subs.buf);
4559
4559 - printf("%s", msg.buf);
4560 + advise_if_enabled(ADVICE_SUBMODULE_MERGE_CONFLICT, "%s", msg.buf);
4561
4562 strbuf_release(&subs);
4563 strbuf_release(&tmp);
t/t6437-submodule-merge.sh
+7 -7
@@ -113,7 +113,7 @@ test_expect_success 'merging should conflict for non fast-forward' '
113 git checkout -b test-nonforward-a b &&
114 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
115 then
116 - test_must_fail git merge c >actual &&
116 + test_must_fail git merge c 2>actual &&
117 sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
118 grep "$sub_expect" actual
119 else
@@ -154,9 +154,9 @@ test_expect_success 'merging should conflict for non fast-forward (resolution ex
154 git rev-parse --short sub-d > ../expect) &&
155 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
156 then
157 - test_must_fail git merge c >actual &&
157 + test_must_fail git merge c >actual 2>sub-actual &&
158 sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
159 - grep "$sub_expect" actual
159 + grep "$sub_expect" sub-actual
160 else
161 test_must_fail git merge c 2> actual
162 fi &&
@@ -181,9 +181,9 @@ test_expect_success 'merging should fail for ambiguous common parent' '
181 ) &&
182 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
183 then
184 - test_must_fail git merge c >actual &&
184 + test_must_fail git merge c >actual 2>sub-actual &&
185 sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
186 - grep "$sub_expect" actual
186 + grep "$sub_expect" sub-actual
187 else
188 test_must_fail git merge c 2> actual
189 fi &&
@@ -227,7 +227,7 @@ test_expect_success 'merging should fail for changes that are backwards' '
227 git commit -a -m "f" &&
228
229 git checkout -b test-backward e &&
230 - test_must_fail git merge f >actual &&
230 + test_must_fail git merge f 2>actual &&
231 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
232 then
233 sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-d)" &&
@@ -535,7 +535,7 @@ test_expect_success 'merging should fail with no merge base' '
535 git checkout -b b init &&
536 git add sub &&
537 git commit -m "b" &&
538 - test_must_fail git merge a >actual &&
538 + test_must_fail git merge a 2>actual &&
539 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
540 then
541 sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short HEAD^1)" &&
t/t7402-submodule-rebase.sh
+1 -1
@@ -116,7 +116,7 @@ test_expect_success 'rebasing submodule that should conflict' '
116 test_tick &&
117 git commit -m fourth &&
118
119 - test_must_fail git rebase --onto HEAD^^ HEAD^ HEAD^0 >actual_output &&
119 + test_must_fail git rebase --onto HEAD^^ HEAD^ HEAD^0 2>actual_output &&
120 git ls-files -s submodule >actual &&
121 (
122 cd submodule &&