git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Christian Couder" <christian.couder@gmail.com>,
	"Hariom Verma" <hariom18599@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Han-Wen Nienhuys" <hanwen@google.com>,
	"Ramkumar Ramachandra" <artagnon@gmail.com>,
	"Felipe Contreras" <felipe.contreras@gmail.com>,
	"Phillip Wood" <phillip.wood123@gmail.com>,
	"ZheNing Hu" <adlternative@gmail.com>,
	"ZheNing Hu" <adlternative@gmail.com>
Subject: [PATCH 2/2] [GSOC] cherry-pick: use better advice message
Date: Thu, 29 Jul 2021 12:27:44 +0000	[thread overview]
Message-ID: <5f08f4dc1180ffd6f7fae7419a4c7214fe770b0a.1627561665.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1007.git.1627561665.gitgitgadget@gmail.com>

From: ZheNing Hu <adlternative@gmail.com>

In the past, git cherry-pick would print such advice when
there was a conflict:

hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

But in fact, when we want to cherry-pick multiple commits,
we should not use "git commit" after resolving conflicts, which
will make Git generate some errors. We should recommend users to
use `git cherry-pick --continue`, `git cherry-pick --abort`, just
like git rebase does.

This is the improved advice:

hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git cherry-pick \
--continue".
hint: You can instead skip this commit: run "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by Hariom Verma <hariom18599@gmail.com>:
Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Hepled-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
 sequencer.c                     | 19 ++++++++++++++-----
 t/t3507-cherry-pick-conflict.sh | 23 +++++++++++++++--------
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index ceaf73a34df..b9adeb7e5f5 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -39,6 +39,16 @@
 
 static const char sign_off_header[] = "Signed-off-by: ";
 static const char cherry_picked_prefix[] = "(cherry picked from commit ";
+static const char *no_commit_advice = N_("after resolving the conflicts, mark the corrected paths\n"
+				"with 'git add <paths>' or 'git rm <paths>'");
+static const char *commit_advice = N_("after resolving the conflicts, mark the corrected paths\n"
+			    "with 'git add <paths>' or 'git rm <paths>'\n"
+			    "and commit the result with 'git commit'");
+static const char *cherry_pick_advice = N_("Resolve all conflicts manually, mark them as resolved with\n"
+					"\"git add/rm <conflicted_files>\", then run \"git cherry-pick --continue\".\n"
+					"You can instead skip this commit: run \"git cherry-pick --skip\".\n"
+					"To abort and get back to the state before \"git cherry-pick\",\n"
+					"run \"git cherry-pick --abort\".");
 
 GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
 
@@ -419,12 +429,9 @@ static void print_advice(struct replay_opts *opts, const char *help_msgs)
 	if (help_msgs)
 		advise("%s\n", help_msgs);
 	else if (opts->no_commit)
-		advise(_("after resolving the conflicts, mark the corrected paths\n"
-			 "with 'git add <paths>' or 'git rm <paths>'"));
+		advise("%s\n", _(no_commit_advice));
 	else
-		advise(_("after resolving the conflicts, mark the corrected paths\n"
-			 "with 'git add <paths>' or 'git rm <paths>'\n"
-			 "and commit the result with 'git commit'"));
+		advise("%s\n", _(commit_advice));
 }
 
 static int write_message(const void *buf, size_t len, const char *filename,
@@ -2269,6 +2276,8 @@ static int do_pick_commit(struct repository *r,
 		      ? _("could not revert %s... %s")
 		      : _("could not apply %s... %s"),
 		      short_commit_name(commit), msg.subject);
+		if (opts->action == REPLAY_PICK)
+			help_msgs = _(cherry_pick_advice);
 		if (((opts->action == REPLAY_PICK &&
 		      !opts->rebase_preserve_merges_mode) ||
 		      (help_msgs = check_need_delete_cherry_pick_head(r))) &&
diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh
index 6f8035399d9..bf77bb0bd50 100755
--- a/t/t3507-cherry-pick-conflict.sh
+++ b/t/t3507-cherry-pick-conflict.sh
@@ -53,9 +53,11 @@ test_expect_success 'advice from failed cherry-pick' "
 	picked=\$(git rev-parse --short picked) &&
 	cat <<-EOF >expected &&
 	error: could not apply \$picked... picked
-	hint: after resolving the conflicts, mark the corrected paths
-	hint: with 'git add <paths>' or 'git rm <paths>'
-	hint: and commit the result with 'git commit'
+	hint: Resolve all conflicts manually, mark them as resolved with
+	hint: \"git add/rm <conflicted_files>\", then run \"git cherry-pick --continue\".
+	hint: You can instead skip this commit: run \"git cherry-pick --skip\".
+	hint: To abort and get back to the state before \"git cherry-pick\",
+	hint: run \"git cherry-pick --abort\".
 	EOF
 	test_must_fail git cherry-pick picked 2>actual &&
 
@@ -68,8 +70,11 @@ test_expect_success 'advice from failed cherry-pick --no-commit' "
 	picked=\$(git rev-parse --short picked) &&
 	cat <<-EOF >expected &&
 	error: could not apply \$picked... picked
-	hint: after resolving the conflicts, mark the corrected paths
-	hint: with 'git add <paths>' or 'git rm <paths>'
+	hint: Resolve all conflicts manually, mark them as resolved with
+	hint: \"git add/rm <conflicted_files>\", then run \"git cherry-pick --continue\".
+	hint: You can instead skip this commit: run \"git cherry-pick --skip\".
+	hint: To abort and get back to the state before \"git cherry-pick\",
+	hint: run \"git cherry-pick --abort\".
 	EOF
 	test_must_fail git cherry-pick --no-commit picked 2>actual &&
 
@@ -82,9 +87,11 @@ test_expect_success 'advice from failed cherry-pick with GIT_CHERRY_PICK_HELP' "
 		picked=\$(git rev-parse --short picked) &&
 		cat <<-EOF >expected &&
 		error: could not apply \$picked... picked
-		hint: after resolving the conflicts, mark the corrected paths
-		hint: with 'git add <paths>' or 'git rm <paths>'
-		hint: and commit the result with 'git commit'
+		hint: Resolve all conflicts manually, mark them as resolved with
+		hint: \"git add/rm <conflicted_files>\", then run \"git cherry-pick --continue\".
+		hint: You can instead skip this commit: run \"git cherry-pick --skip\".
+		hint: To abort and get back to the state before \"git cherry-pick\",
+		hint: run \"git cherry-pick --abort\".
 		EOF
 		GIT_CHERRY_PICK_HELP='and then do something else' &&
 		export GIT_CHERRY_PICK_HELP &&
-- 
gitgitgadget

  parent reply	other threads:[~2021-07-29 12:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-29 12:27 [PATCH 0/2] [GSOC] cherry-pick: fix bug when used with GIT_CHERRY_PICK_HELP ZheNing Hu via GitGitGadget
2021-07-29 12:27 ` [PATCH 1/2] " ZheNing Hu via GitGitGadget
2021-07-29 20:56   ` Junio C Hamano
2021-07-30 14:15     ` ZheNing Hu
2021-07-29 12:27 ` ZheNing Hu via GitGitGadget [this message]
2021-07-31  7:01 [PATCH 0/2] " ZheNing Hu via GitGitGadget
2021-07-31  7:01 ` [PATCH 2/2] [GSOC] cherry-pick: use better advice message ZheNing Hu via GitGitGadget
2021-08-01 10:14   ` Phillip Wood
2021-08-02 13:35     ` ZheNing Hu

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=5f08f4dc1180ffd6f7fae7419a4c7214fe770b0a.1627561665.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=adlternative@gmail.com \
    --cc=artagnon@gmail.com \
    --cc=avarab@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hanwen@google.com \
    --cc=hariom18599@gmail.com \
    --cc=phillip.wood123@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).