Skip to content

Commit ec03009

Browse files
phil-blaingitster
authored andcommitted
sequencer: allow disabling conflict advice
Allow disabling the advice shown when a squencer operation results in a merge conflict through a new config 'advice.mergeConflict', which is named generically such that it can be used by other commands eventually. Remove that final '\n' in the first hunk in sequencer.c to avoid an otherwise empty 'hint: ' line before the line 'hint: Disable this message with "git config advice.mergeConflict false"' which is automatically added by 'advise_if_enabled'. Note that we use 'advise_if_enabled' for each message in the second hunk in sequencer.c, instead of using 'if (show_hints && advice_enabled(...)', because the former instructs the user how to disable the advice, which is more user-friendly. Update the tests accordingly. Note that the body of the second test in t3507-cherry-pick-conflict.sh is enclosed in double quotes, so we must escape them in the added line. Note that t5520-pull.sh, which checks that we display the advice for 'git rebase' (via 'git pull --rebase') does not have to be updated because it only greps for a specific line in the advice message. Signed-off-by: Philippe Blain <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2953d95 commit ec03009

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

Documentation/config/advice.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ advice.*::
5656
Shown when the user's information is guessed from the
5757
system username and domain name, to tell the user how to
5858
set their identity configuration.
59+
mergeConflict::
60+
Shown when various commands stop because of conflicts.
5961
nestedTag::
6062
Shown when a user attempts to recursively tag a tag object.
6163
pushAlreadyExists::

advice.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static struct {
5757
[ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated" },
5858
[ADVICE_IGNORED_HOOK] = { "ignoredHook" },
5959
[ADVICE_IMPLICIT_IDENTITY] = { "implicitIdentity" },
60+
[ADVICE_MERGE_CONFLICT] = { "mergeConflict" },
6061
[ADVICE_NESTED_TAG] = { "nestedTag" },
6162
[ADVICE_OBJECT_NAME_WARNING] = { "objectNameWarning" },
6263
[ADVICE_PUSH_ALREADY_EXISTS] = { "pushAlreadyExists" },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum advice_type {
2525
ADVICE_GRAFT_FILE_DEPRECATED,
2626
ADVICE_IGNORED_HOOK,
2727
ADVICE_IMPLICIT_IDENTITY,
28+
ADVICE_MERGE_CONFLICT,
2829
ADVICE_NESTED_TAG,
2930
ADVICE_OBJECT_NAME_WARNING,
3031
ADVICE_PUSH_ALREADY_EXISTS,

sequencer.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ static void print_advice(struct repository *r, int show_hint,
467467
char *msg = getenv("GIT_CHERRY_PICK_HELP");
468468

469469
if (msg) {
470-
advise("%s\n", msg);
470+
advise_if_enabled(ADVICE_MERGE_CONFLICT, "%s", msg);
471471
/*
472472
* A conflict has occurred but the porcelain
473473
* (typically rebase --interactive) wants to take care
@@ -480,22 +480,25 @@ static void print_advice(struct repository *r, int show_hint,
480480

481481
if (show_hint) {
482482
if (opts->no_commit)
483-
advise(_("after resolving the conflicts, mark the corrected paths\n"
484-
"with 'git add <paths>' or 'git rm <paths>'"));
483+
advise_if_enabled(ADVICE_MERGE_CONFLICT,
484+
_("after resolving the conflicts, mark the corrected paths\n"
485+
"with 'git add <paths>' or 'git rm <paths>'"));
485486
else if (opts->action == REPLAY_PICK)
486-
advise(_("After resolving the conflicts, mark them with\n"
487-
"\"git add/rm <pathspec>\", then run\n"
488-
"\"git cherry-pick --continue\".\n"
489-
"You can instead skip this commit with \"git cherry-pick --skip\".\n"
490-
"To abort and get back to the state before \"git cherry-pick\",\n"
491-
"run \"git cherry-pick --abort\"."));
487+
advise_if_enabled(ADVICE_MERGE_CONFLICT,
488+
_("After resolving the conflicts, mark them with\n"
489+
"\"git add/rm <pathspec>\", then run\n"
490+
"\"git cherry-pick --continue\".\n"
491+
"You can instead skip this commit with \"git cherry-pick --skip\".\n"
492+
"To abort and get back to the state before \"git cherry-pick\",\n"
493+
"run \"git cherry-pick --abort\"."));
492494
else if (opts->action == REPLAY_REVERT)
493-
advise(_("After resolving the conflicts, mark them with\n"
494-
"\"git add/rm <pathspec>\", then run\n"
495-
"\"git revert --continue\".\n"
496-
"You can instead skip this commit with \"git revert --skip\".\n"
497-
"To abort and get back to the state before \"git revert\",\n"
498-
"run \"git revert --abort\"."));
495+
advise_if_enabled(ADVICE_MERGE_CONFLICT,
496+
_("After resolving the conflicts, mark them with\n"
497+
"\"git add/rm <pathspec>\", then run\n"
498+
"\"git revert --continue\".\n"
499+
"You can instead skip this commit with \"git revert --skip\".\n"
500+
"To abort and get back to the state before \"git revert\",\n"
501+
"run \"git revert --abort\"."));
499502
else
500503
BUG("unexpected pick action in print_advice()");
501504
}

t/t3501-revert-cherry-pick.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ test_expect_success 'advice from failed revert' '
170170
hint: You can instead skip this commit with "git revert --skip".
171171
hint: To abort and get back to the state before "git revert",
172172
hint: run "git revert --abort".
173+
hint: Disable this message with "git config advice.mergeConflict false"
173174
EOF
174175
test_commit --append --no-tag "double-add dream" dream dream &&
175176
test_must_fail git revert HEAD^ 2>actual &&

t/t3507-cherry-pick-conflict.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ test_expect_success 'advice from failed cherry-pick' '
6060
hint: You can instead skip this commit with "git cherry-pick --skip".
6161
hint: To abort and get back to the state before "git cherry-pick",
6262
hint: run "git cherry-pick --abort".
63+
hint: Disable this message with "git config advice.mergeConflict false"
6364
EOF
6465
test_must_fail git cherry-pick picked 2>actual &&
6566
@@ -74,6 +75,7 @@ test_expect_success 'advice from failed cherry-pick --no-commit' "
7475
error: could not apply \$picked... picked
7576
hint: after resolving the conflicts, mark the corrected paths
7677
hint: with 'git add <paths>' or 'git rm <paths>'
78+
hint: Disable this message with \"git config advice.mergeConflict false\"
7779
EOF
7880
test_must_fail git cherry-pick --no-commit picked 2>actual &&
7981

0 commit comments

Comments
 (0)