All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Elijah Newren" <newren@gmail.com>,
	"Phillip Wood" <phillip.wood@dunelm.org.uk>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"ZheNing Hu" <adlternative@gmail.com>,
	"Kristoffer Haugsbakk" <code@khaugsbakk.name>,
	"Rubén Justo" <rjusto@gmail.com>,
	"Philippe Blain" <levraiphilippeblain@gmail.com>,
	"Philippe Blain" <levraiphilippeblain@gmail.com>
Subject: [PATCH v3 2/2] builtin/am: allow disabling conflict advice
Date: Sat, 16 Mar 2024 21:16:30 +0000	[thread overview]
Message-ID: <73d07c8b6a7fc56510798e7e146cb8b14ad558f7.1710623790.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1682.v3.git.1710623790.gitgitgadget@gmail.com>

From: Philippe Blain <levraiphilippeblain@gmail.com>

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 2ac0d6273f (rebase: change the default
backend from "am" to "merge", 2020-02-15).

Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
 builtin/am.c          | 14 +++++++++-----
 t/t4150-am.sh         |  8 ++++----
 t/t4254-am-corrupt.sh |  2 +-
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index d1990d7edcb..d87847205c7 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1150,19 +1150,23 @@ static const char *msgnum(const struct am_state *state)
 static void NORETURN die_user_resolve(const struct am_state *state)
 {
 	if (state->resolvemsg) {
-		printf_ln("%s", state->resolvemsg);
+		advise_if_enabled(ADVICE_MERGE_CONFLICT, "%s", state->resolvemsg);
 	} else {
 		const char *cmdline = state->interactive ? "git am -i" : "git am";
+		struct strbuf sb = STRBUF_INIT;
 
-		printf_ln(_("When you have resolved this problem, run \"%s --continue\"."), cmdline);
-		printf_ln(_("If you prefer to skip this patch, run \"%s --skip\" instead."), cmdline);
+		strbuf_addf(&sb, _("When you have resolved this problem, run \"%s --continue\".\n"), cmdline);
+		strbuf_addf(&sb, _("If you prefer to skip this patch, run \"%s --skip\" instead.\n"), cmdline);
 
 		if (advice_enabled(ADVICE_AM_WORK_DIR) &&
 		    is_empty_or_missing_file(am_path(state, "patch")) &&
 		    !repo_index_has_changes(the_repository, NULL, NULL))
-			printf_ln(_("To record the empty patch as an empty commit, run \"%s --allow-empty\"."), cmdline);
+			strbuf_addf(&sb, _("To record the empty patch as an empty commit, run \"%s --allow-empty\".\n"), cmdline);
 
-		printf_ln(_("To restore the original branch and stop patching, run \"%s --abort\"."), cmdline);
+		strbuf_addf(&sb, _("To restore the original branch and stop patching, run \"%s --abort\"."), cmdline);
+
+		advise_if_enabled(ADVICE_MERGE_CONFLICT, "%s", sb.buf);
+		strbuf_release(&sb);
 	}
 
 	exit(128);
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 3b125762694..5e2b6c80eae 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -1224,8 +1224,8 @@ test_expect_success 'record as an empty commit when meeting e-mail message that
 
 test_expect_success 'skip an empty patch in the middle of an am session' '
 	git checkout empty-commit^ &&
-	test_must_fail git am empty-commit.patch >err &&
-	grep "Patch is empty." err &&
+	test_must_fail git am empty-commit.patch >out 2>err &&
+	grep "Patch is empty." out &&
 	grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
 	git am --skip &&
 	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' '
 
 test_expect_success 'record an empty patch as an empty commit in the middle of an am session' '
 	git checkout empty-commit^ &&
-	test_must_fail git am empty-commit.patch >err &&
-	grep "Patch is empty." err &&
+	test_must_fail git am empty-commit.patch >out 2>err &&
+	grep "Patch is empty." out &&
 	grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
 	git am --allow-empty >output &&
 	grep "No changes - recorded it as an empty commit." output &&
diff --git a/t/t4254-am-corrupt.sh b/t/t4254-am-corrupt.sh
index 45f1d4f95e5..661feb60709 100755
--- a/t/t4254-am-corrupt.sh
+++ b/t/t4254-am-corrupt.sh
@@ -59,7 +59,7 @@ test_expect_success setup '
 # Also, it had the unwanted side-effect of deleting f.
 test_expect_success 'try to apply corrupted patch' '
 	test_when_finished "git am --abort" &&
-	test_must_fail git -c advice.amWorkDir=false am bad-patch.diff 2>actual &&
+	test_must_fail git -c advice.amWorkDir=false -c advice.mergeConflict=false am bad-patch.diff 2>actual &&
 	echo "error: git diff header lacks filename information (line 4)" >expected &&
 	test_path_is_file f &&
 	test_cmp expected actual
-- 
gitgitgadget

  parent reply	other threads:[~2024-03-16 21:16 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-02 16:18 [PATCH] sequencer: allow disabling conflict advice Philippe Blain via GitGitGadget
2024-03-02 16:32 ` Philippe Blain
2024-03-03 22:57 ` Junio C Hamano
2024-03-09 17:22   ` Philippe Blain
2024-03-09 18:58     ` Philippe Blain
2024-03-09 19:55       ` Junio C Hamano
2024-03-09 23:19         ` Junio C Hamano
2024-03-04 10:12 ` Phillip Wood
2024-03-04 10:27   ` Phillip Wood
2024-03-04 17:56     ` Junio C Hamano
2024-03-09 17:53       ` Philippe Blain
2024-03-09 19:15         ` Phillip Wood
2024-03-09 19:56           ` Junio C Hamano
2024-03-09 18:01   ` Philippe Blain
2024-03-10 19:50 ` [PATCH v2 0/2] Allow disabling advice shown after merge conflicts Philippe Blain via GitGitGadget
2024-03-10 19:51   ` [PATCH v2 1/2] sequencer: allow disabling conflict advice Philippe Blain via GitGitGadget
2024-03-11 10:29     ` Kristoffer Haugsbakk
2024-03-16 19:33       ` Philippe Blain
2024-03-10 19:51   ` [PATCH v2 2/2] builtin/am: " Philippe Blain via GitGitGadget
2024-03-11 10:54     ` phillip.wood123
2024-03-11 17:12       ` Junio C Hamano
2024-03-11 17:49         ` Junio C Hamano
2024-03-16 19:44           ` Philippe Blain
2024-03-16 20:01         ` Philippe Blain
2024-03-11 20:58   ` [PATCH v2 0/2] Allow disabling advice shown after merge conflicts Rubén Justo
2024-03-16 20:33     ` Philippe Blain
2024-03-16 21:16   ` [PATCH v3 " Philippe Blain via GitGitGadget
2024-03-16 21:16     ` [PATCH v3 1/2] sequencer: allow disabling conflict advice Philippe Blain via GitGitGadget
2024-03-16 21:16     ` Philippe Blain via GitGitGadget [this message]
2024-03-18 16:31     ` [PATCH v3 0/2] Allow disabling advice shown after merge conflicts Junio C Hamano
2024-03-25 10:48     ` Phillip Wood
2024-03-25 16:57       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=73d07c8b6a7fc56510798e7e146cb8b14ad558f7.1710623790.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=adlternative@gmail.com \
    --cc=code@khaugsbakk.name \
    --cc=git@vger.kernel.org \
    --cc=levraiphilippeblain@gmail.com \
    --cc=newren@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=rjusto@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.