git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] [GSOC] cherry-pick: fix bug when used with GIT_CHERRY_PICK_HELP
@ 2021-07-22 14:06 ZheNing Hu via GitGitGadget
  2021-07-22 21:25 ` Junio C Hamano
  2021-07-24 14:01 ` [PATCH v2] " ZheNing Hu via GitGitGadget
  0 siblings, 2 replies; 17+ messages in thread
From: ZheNing Hu via GitGitGadget @ 2021-07-22 14:06 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Christian Couder, Hariom Verma,
	Ævar Arnfjörð Bjarmason, Han-Wen Nienhuys,
	Ramkumar Ramachandra, ZheNing Hu, ZheNing Hu

From: ZheNing Hu <adlternative@gmail.com>

If we set the value of the environment variable GIT_CHERRY_PICK_HELP
when using `git cherry-pick`, CHERRY_PICK_HEAD will be deleted, then
we will get an error when we try to use `git cherry-pick --continue`
or other cherr-pick command.

So add option action check in print_advice(), we will not remove
CHERRY_PICK_HEAD if we are indeed cherry-picking instead of rebasing.

Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
    [GSOC] cherry-pick: fix bug when used with GIT_CHERRY_PICK_HELP
    
    E.g. We are now in the branch main, we want to cherry-pick commit
    ac346df, then we want to use GIT_CHERRY_PICK_HELP to use customized
    advice:
    
    GIT_CHERRY_PICK_HELP="you should use git cherry-pick --continue after
    resloving the conflict!" git cherry-pick ac346df
    
    then we can see the correct advice message, but after that, if we want
    to use "git cherry-pick --continue" or other cherry-pick commands, an
    error will appear.
    
    So this patch fixes this bug when git cherry-pick is used with
    environment variable GIT_CHERRY_PICK_HELP.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1001%2Fadlternative%2Fcherry-pick-help-fix-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1001/adlternative/cherry-pick-help-fix-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1001

 sequencer.c                     |  5 +++--
 t/t3507-cherry-pick-conflict.sh | 25 ++++++++++++++++++++-----
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 0bec01cf38e..c01b0b9e9c9 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -409,8 +409,9 @@ static void print_advice(struct repository *r, int show_hint,
 		 * (typically rebase --interactive) wants to take care
 		 * of the commit itself so remove CHERRY_PICK_HEAD
 		 */
-		refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
-				NULL, 0);
+		if (opts->action != REPLAY_PICK)
+			refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
+					NULL, 0);
 		return;
 	}
 
diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh
index 014001b8f32..70becaf27aa 100755
--- a/t/t3507-cherry-pick-conflict.sh
+++ b/t/t3507-cherry-pick-conflict.sh
@@ -109,14 +109,29 @@ test_expect_success \
 	test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
 '
 
-test_expect_success 'GIT_CHERRY_PICK_HELP suppresses CHERRY_PICK_HEAD' '
-	pristine_detach initial &&
+test_expect_success 'GIT_CHERRY_PICK_HELP respects CHERRY_PICK_HEAD' '
+	git init repo &&
 	(
+		cd repo &&
+		git branch -M main &&
+		echo 1 >file &&
+		git add file &&
+		git commit -m 1 &&
+		echo 2 >file &&
+		git add file &&
+		git commit -m 2 &&
+		git checkout HEAD~ &&
+		echo 3 >file &&
+		git add file &&
+		git commit -m 3 &&
 		GIT_CHERRY_PICK_HELP="and then do something else" &&
 		export GIT_CHERRY_PICK_HELP &&
-		test_must_fail git cherry-pick picked
-	) &&
-	test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
+		test_must_fail git cherry-pick main &&
+		git rev-parse --verify CHERRY_PICK_HEAD >actual &&
+		git rev-parse --verify main >expect &&
+		test_cmp expect actual &&
+		git cherry-pick --abort
+	)
 '
 
 test_expect_success 'git reset clears CHERRY_PICK_HEAD' '

base-commit: daab8a564f8bbac55f70f8bf86c070e001a9b006
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-07-28 17:26 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22 14:06 [PATCH] [GSOC] cherry-pick: fix bug when used with GIT_CHERRY_PICK_HELP ZheNing Hu via GitGitGadget
2021-07-22 21:25 ` Junio C Hamano
2021-07-23  9:37   ` ZheNing Hu
2021-07-23 17:01     ` Felipe Contreras
2021-07-24 14:01 ` [PATCH v2] " ZheNing Hu via GitGitGadget
2021-07-27 19:43   ` Phillip Wood
2021-07-27 20:44     ` Junio C Hamano
2021-07-27 21:00       ` Junio C Hamano
2021-07-28  9:56         ` Phillip Wood
2021-07-28 10:56         ` ZheNing Hu
2021-07-28 17:24           ` Junio C Hamano
2021-07-28 11:34         ` ZheNing Hu
2021-07-28 17:26           ` Junio C Hamano
2021-07-28  7:39     ` ZheNing Hu
2021-07-28  9:46       ` Phillip Wood
2021-07-28 11:01         ` ZheNing Hu
2021-07-28 16:52           ` Phillip Wood

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).