Skip to content

Commit b9e55be

Browse files
phil-blaingitster
authored andcommitted
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 4057523 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c2a3fd commit b9e55be

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

Documentation/config/advice.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ advice.*::
129129
submoduleAlternateErrorStrategyDie::
130130
Advice shown when a submodule.alternateErrorStrategy option
131131
configured to "die" causes a fatal error.
132+
submoduleMergeConflict::
133+
Advice shown when a non-trivial submodule merge conflict is
134+
encountered.
132135
submodulesNotUpdated::
133136
Advice shown when a user runs a submodule command that fails
134137
because `git submodule update --init` was not run.

advice.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static struct {
7979
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },
8080
[ADVICE_SUBMODULES_NOT_UPDATED] = { "submodulesNotUpdated" },
8181
[ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE] = { "submoduleAlternateErrorStrategyDie" },
82+
[ADVICE_SUBMODULE_MERGE_CONFLICT] = { "submoduleMergeConflict" },
8283
[ADVICE_SUGGEST_DETACHING_HEAD] = { "suggestDetachingHead" },
8384
[ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath" },
8485
[ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor" },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum advice_type {
4747
ADVICE_STATUS_U_OPTION,
4848
ADVICE_SUBMODULES_NOT_UPDATED,
4949
ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE,
50+
ADVICE_SUBMODULE_MERGE_CONFLICT,
5051
ADVICE_SUGGEST_DETACHING_HEAD,
5152
ADVICE_UPDATE_SPARSE_PATH,
5253
ADVICE_WAITING_FOR_EDITOR,

merge-ort.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "merge-ort.h"
1919

2020
#include "alloc.h"
21+
#include "advice.h"
2122
#include "attr.h"
2223
#include "cache-tree.h"
2324
#include "commit.h"
@@ -4556,7 +4557,7 @@ static void print_submodule_conflict_suggestion(struct string_list *csub) {
45564557
" - commit the resulting index in the superproject\n"),
45574558
tmp.buf, subs.buf);
45584559

4559-
printf("%s", msg.buf);
4560+
advise_if_enabled(ADVICE_SUBMODULE_MERGE_CONFLICT, "%s", msg.buf);
45604561

45614562
strbuf_release(&subs);
45624563
strbuf_release(&tmp);

t/t6437-submodule-merge.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ test_expect_success 'merging should conflict for non fast-forward' '
113113
git checkout -b test-nonforward-a b &&
114114
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
115115
then
116-
test_must_fail git merge c >actual &&
116+
test_must_fail git merge c 2>actual &&
117117
sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
118118
grep "$sub_expect" actual
119119
else
@@ -154,9 +154,9 @@ test_expect_success 'merging should conflict for non fast-forward (resolution ex
154154
git rev-parse --short sub-d > ../expect) &&
155155
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
156156
then
157-
test_must_fail git merge c >actual &&
157+
test_must_fail git merge c >actual 2>sub-actual &&
158158
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
160160
else
161161
test_must_fail git merge c 2> actual
162162
fi &&
@@ -181,9 +181,9 @@ test_expect_success 'merging should fail for ambiguous common parent' '
181181
) &&
182182
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
183183
then
184-
test_must_fail git merge c >actual &&
184+
test_must_fail git merge c >actual 2>sub-actual &&
185185
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
187187
else
188188
test_must_fail git merge c 2> actual
189189
fi &&
@@ -227,7 +227,7 @@ test_expect_success 'merging should fail for changes that are backwards' '
227227
git commit -a -m "f" &&
228228
229229
git checkout -b test-backward e &&
230-
test_must_fail git merge f >actual &&
230+
test_must_fail git merge f 2>actual &&
231231
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
232232
then
233233
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' '
535535
git checkout -b b init &&
536536
git add sub &&
537537
git commit -m "b" &&
538-
test_must_fail git merge a >actual &&
538+
test_must_fail git merge a 2>actual &&
539539
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
540540
then
541541
sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short HEAD^1)" &&

t/t7402-submodule-rebase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ test_expect_success 'rebasing submodule that should conflict' '
116116
test_tick &&
117117
git commit -m fourth &&
118118
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 &&
120120
git ls-files -s submodule >actual &&
121121
(
122122
cd submodule &&

0 commit comments

Comments
 (0)