Skip to content

Commit 37ce973

Browse files
phil-blaingitster
authored andcommitted
builtin/am: allow disabling conflict advice
When 'git am' or 'git rebase --apply' encounter a conflict, they show a message instructing the user how to continue the operation. This message can't be disabled. Use ADVICE_MERGE_CONFLICT introduced in the previous commit to allow disabling it. Update the tests accordingly, as the advice output is now on stderr instead of stdout. In t4150, redirect stdout to 'out' and stderr to 'err', since this is less confusing. In t4254, as we are testing a specific failure mode of 'git am', simply disable the advice. Note that we are not testing that this advice is shown in 'git rebase' for the apply backend since 2ac0d62 (rebase: change the default backend from "am" to "merge", 2020-02-15). Helped-by: Phillip Wood <[email protected]> Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Philippe Blain <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec03009 commit 37ce973

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

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);

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)