1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-13 05:16:09 +02:00

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>
This commit is contained in:
Philippe Blain 2024-02-26 13:27:28 +00:00 committed by Junio C Hamano
parent 3c2a3fdc38
commit b9e55be740
6 changed files with 15 additions and 9 deletions

View File

@ -129,6 +129,9 @@ advice.*::
submoduleAlternateErrorStrategyDie:: submoduleAlternateErrorStrategyDie::
Advice shown when a submodule.alternateErrorStrategy option Advice shown when a submodule.alternateErrorStrategy option
configured to "die" causes a fatal error. configured to "die" causes a fatal error.
submoduleMergeConflict::
Advice shown when a non-trivial submodule merge conflict is
encountered.
submodulesNotUpdated:: submodulesNotUpdated::
Advice shown when a user runs a submodule command that fails Advice shown when a user runs a submodule command that fails
because `git submodule update --init` was not run. because `git submodule update --init` was not run.

View File

@ -79,6 +79,7 @@ static struct {
[ADVICE_STATUS_U_OPTION] = { "statusUoption" }, [ADVICE_STATUS_U_OPTION] = { "statusUoption" },
[ADVICE_SUBMODULES_NOT_UPDATED] = { "submodulesNotUpdated" }, [ADVICE_SUBMODULES_NOT_UPDATED] = { "submodulesNotUpdated" },
[ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE] = { "submoduleAlternateErrorStrategyDie" }, [ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE] = { "submoduleAlternateErrorStrategyDie" },
[ADVICE_SUBMODULE_MERGE_CONFLICT] = { "submoduleMergeConflict" },
[ADVICE_SUGGEST_DETACHING_HEAD] = { "suggestDetachingHead" }, [ADVICE_SUGGEST_DETACHING_HEAD] = { "suggestDetachingHead" },
[ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath" }, [ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath" },
[ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor" }, [ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor" },

View File

@ -47,6 +47,7 @@ enum advice_type {
ADVICE_STATUS_U_OPTION, ADVICE_STATUS_U_OPTION,
ADVICE_SUBMODULES_NOT_UPDATED, ADVICE_SUBMODULES_NOT_UPDATED,
ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE, ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE,
ADVICE_SUBMODULE_MERGE_CONFLICT,
ADVICE_SUGGEST_DETACHING_HEAD, ADVICE_SUGGEST_DETACHING_HEAD,
ADVICE_UPDATE_SPARSE_PATH, ADVICE_UPDATE_SPARSE_PATH,
ADVICE_WAITING_FOR_EDITOR, ADVICE_WAITING_FOR_EDITOR,

View File

@ -18,6 +18,7 @@
#include "merge-ort.h" #include "merge-ort.h"
#include "alloc.h" #include "alloc.h"
#include "advice.h"
#include "attr.h" #include "attr.h"
#include "cache-tree.h" #include "cache-tree.h"
#include "commit.h" #include "commit.h"
@ -4556,7 +4557,7 @@ static void print_submodule_conflict_suggestion(struct string_list *csub) {
" - commit the resulting index in the superproject\n"), " - commit the resulting index in the superproject\n"),
tmp.buf, subs.buf); tmp.buf, subs.buf);
printf("%s", msg.buf); advise_if_enabled(ADVICE_SUBMODULE_MERGE_CONFLICT, "%s", msg.buf);
strbuf_release(&subs); strbuf_release(&subs);
strbuf_release(&tmp); strbuf_release(&tmp);

View File

@ -113,7 +113,7 @@ test_expect_success 'merging should conflict for non fast-forward' '
git checkout -b test-nonforward-a b && git checkout -b test-nonforward-a b &&
if test "$GIT_TEST_MERGE_ALGORITHM" = ort if test "$GIT_TEST_MERGE_ALGORITHM" = ort
then then
test_must_fail git merge c >actual && test_must_fail git merge c 2>actual &&
sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" && sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
grep "$sub_expect" actual grep "$sub_expect" actual
else else
@ -154,9 +154,9 @@ test_expect_success 'merging should conflict for non fast-forward (resolution ex
git rev-parse --short sub-d > ../expect) && git rev-parse --short sub-d > ../expect) &&
if test "$GIT_TEST_MERGE_ALGORITHM" = ort if test "$GIT_TEST_MERGE_ALGORITHM" = ort
then then
test_must_fail git merge c >actual && test_must_fail git merge c >actual 2>sub-actual &&
sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" && sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
grep "$sub_expect" actual grep "$sub_expect" sub-actual
else else
test_must_fail git merge c 2> actual test_must_fail git merge c 2> actual
fi && fi &&
@ -181,9 +181,9 @@ test_expect_success 'merging should fail for ambiguous common parent' '
) && ) &&
if test "$GIT_TEST_MERGE_ALGORITHM" = ort if test "$GIT_TEST_MERGE_ALGORITHM" = ort
then then
test_must_fail git merge c >actual && test_must_fail git merge c >actual 2>sub-actual &&
sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" && sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
grep "$sub_expect" actual grep "$sub_expect" sub-actual
else else
test_must_fail git merge c 2> actual test_must_fail git merge c 2> actual
fi && fi &&
@ -227,7 +227,7 @@ test_expect_success 'merging should fail for changes that are backwards' '
git commit -a -m "f" && git commit -a -m "f" &&
git checkout -b test-backward e && git checkout -b test-backward e &&
test_must_fail git merge f >actual && test_must_fail git merge f 2>actual &&
if test "$GIT_TEST_MERGE_ALGORITHM" = ort if test "$GIT_TEST_MERGE_ALGORITHM" = ort
then then
sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-d)" && 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' '
git checkout -b b init && git checkout -b b init &&
git add sub && git add sub &&
git commit -m "b" && git commit -m "b" &&
test_must_fail git merge a >actual && test_must_fail git merge a 2>actual &&
if test "$GIT_TEST_MERGE_ALGORITHM" = ort if test "$GIT_TEST_MERGE_ALGORITHM" = ort
then then
sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short HEAD^1)" && sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short HEAD^1)" &&

View File

@ -116,7 +116,7 @@ test_expect_success 'rebasing submodule that should conflict' '
test_tick && test_tick &&
git commit -m fourth && git commit -m fourth &&
test_must_fail git rebase --onto HEAD^^ HEAD^ HEAD^0 >actual_output && test_must_fail git rebase --onto HEAD^^ HEAD^ HEAD^0 2>actual_output &&
git ls-files -s submodule >actual && git ls-files -s submodule >actual &&
( (
cd submodule && cd submodule &&