Skip to content

Commit ac16f55

Browse files
committed
Merge branch 'pb/advice-merge-conflict'
Hints that suggest what to do after resolving conflicts can now be squelched by disabling advice.mergeConflict. Acked-by: Phillip Wood <[email protected]> cf. <[email protected]> * pb/advice-merge-conflict: builtin/am: allow disabling conflict advice sequencer: allow disabling conflict advice
2 parents 521df68 + 37ce973 commit ac16f55

File tree

9 files changed

+39
-25
lines changed

9 files changed

+39
-25
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,

builtin/am.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,19 +1150,23 @@ static const char *msgnum(const struct am_state *state)
11501150
static void NORETURN die_user_resolve(const struct am_state *state)
11511151
{
11521152
if (state->resolvemsg) {
1153-
printf_ln("%s", state->resolvemsg);
1153+
advise_if_enabled(ADVICE_MERGE_CONFLICT, "%s", state->resolvemsg);
11541154
} else {
11551155
const char *cmdline = state->interactive ? "git am -i" : "git am";
1156+
struct strbuf sb = STRBUF_INIT;
11561157

1157-
printf_ln(_("When you have resolved this problem, run \"%s --continue\"."), cmdline);
1158-
printf_ln(_("If you prefer to skip this patch, run \"%s --skip\" instead."), cmdline);
1158+
strbuf_addf(&sb, _("When you have resolved this problem, run \"%s --continue\".\n"), cmdline);
1159+
strbuf_addf(&sb, _("If you prefer to skip this patch, run \"%s --skip\" instead.\n"), cmdline);
11591160

11601161
if (advice_enabled(ADVICE_AM_WORK_DIR) &&
11611162
is_empty_or_missing_file(am_path(state, "patch")) &&
11621163
!repo_index_has_changes(the_repository, NULL, NULL))
1163-
printf_ln(_("To record the empty patch as an empty commit, run \"%s --allow-empty\"."), cmdline);
1164+
strbuf_addf(&sb, _("To record the empty patch as an empty commit, run \"%s --allow-empty\".\n"), cmdline);
11641165

1165-
printf_ln(_("To restore the original branch and stop patching, run \"%s --abort\"."), cmdline);
1166+
strbuf_addf(&sb, _("To restore the original branch and stop patching, run \"%s --abort\"."), cmdline);
1167+
1168+
advise_if_enabled(ADVICE_MERGE_CONFLICT, "%s", sb.buf);
1169+
strbuf_release(&sb);
11661170
}
11671171

11681172
exit(128);

sequencer.c

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

481481
if (msg) {
482-
advise("%s\n", msg);
482+
advise_if_enabled(ADVICE_MERGE_CONFLICT, "%s", msg);
483483
/*
484484
* A conflict has occurred but the porcelain
485485
* (typically rebase --interactive) wants to take care
@@ -492,22 +492,25 @@ static void print_advice(struct repository *r, int show_hint,
492492

493493
if (show_hint) {
494494
if (opts->no_commit)
495-
advise(_("after resolving the conflicts, mark the corrected paths\n"
496-
"with 'git add <paths>' or 'git rm <paths>'"));
495+
advise_if_enabled(ADVICE_MERGE_CONFLICT,
496+
_("after resolving the conflicts, mark the corrected paths\n"
497+
"with 'git add <paths>' or 'git rm <paths>'"));
497498
else if (opts->action == REPLAY_PICK)
498-
advise(_("After resolving the conflicts, mark them with\n"
499-
"\"git add/rm <pathspec>\", then run\n"
500-
"\"git cherry-pick --continue\".\n"
501-
"You can instead skip this commit with \"git cherry-pick --skip\".\n"
502-
"To abort and get back to the state before \"git cherry-pick\",\n"
503-
"run \"git cherry-pick --abort\"."));
499+
advise_if_enabled(ADVICE_MERGE_CONFLICT,
500+
_("After resolving the conflicts, mark them with\n"
501+
"\"git add/rm <pathspec>\", then run\n"
502+
"\"git cherry-pick --continue\".\n"
503+
"You can instead skip this commit with \"git cherry-pick --skip\".\n"
504+
"To abort and get back to the state before \"git cherry-pick\",\n"
505+
"run \"git cherry-pick --abort\"."));
504506
else if (opts->action == REPLAY_REVERT)
505-
advise(_("After resolving the conflicts, mark them with\n"
506-
"\"git add/rm <pathspec>\", then run\n"
507-
"\"git revert --continue\".\n"
508-
"You can instead skip this commit with \"git revert --skip\".\n"
509-
"To abort and get back to the state before \"git revert\",\n"
510-
"run \"git revert --abort\"."));
507+
advise_if_enabled(ADVICE_MERGE_CONFLICT,
508+
_("After resolving the conflicts, mark them with\n"
509+
"\"git add/rm <pathspec>\", then run\n"
510+
"\"git revert --continue\".\n"
511+
"You can instead skip this commit with \"git revert --skip\".\n"
512+
"To abort and get back to the state before \"git revert\",\n"
513+
"run \"git revert --abort\"."));
511514
else
512515
BUG("unexpected pick action in print_advice()");
513516
}

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

t/t4150-am.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,8 @@ test_expect_success 'record as an empty commit when meeting e-mail message that
12241224

12251225
test_expect_success 'skip an empty patch in the middle of an am session' '
12261226
git checkout empty-commit^ &&
1227-
test_must_fail git am empty-commit.patch >err &&
1228-
grep "Patch is empty." err &&
1227+
test_must_fail git am empty-commit.patch >out 2>err &&
1228+
grep "Patch is empty." out &&
12291229
grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
12301230
git am --skip &&
12311231
test_path_is_missing .git/rebase-apply &&
@@ -1236,8 +1236,8 @@ test_expect_success 'skip an empty patch in the middle of an am session' '
12361236

12371237
test_expect_success 'record an empty patch as an empty commit in the middle of an am session' '
12381238
git checkout empty-commit^ &&
1239-
test_must_fail git am empty-commit.patch >err &&
1240-
grep "Patch is empty." err &&
1239+
test_must_fail git am empty-commit.patch >out 2>err &&
1240+
grep "Patch is empty." out &&
12411241
grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
12421242
git am --allow-empty >output &&
12431243
grep "No changes - recorded it as an empty commit." output &&

t/t4254-am-corrupt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test_expect_success setup '
5959
# Also, it had the unwanted side-effect of deleting f.
6060
test_expect_success 'try to apply corrupted patch' '
6161
test_when_finished "git am --abort" &&
62-
test_must_fail git -c advice.amWorkDir=false am bad-patch.diff 2>actual &&
62+
test_must_fail git -c advice.amWorkDir=false -c advice.mergeConflict=false am bad-patch.diff 2>actual &&
6363
echo "error: git diff header lacks filename information (line 4)" >expected &&
6464
test_path_is_file f &&
6565
test_cmp expected actual

0 commit comments

Comments
 (0)