All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Victor Gambier <vgambier@excilys.com>,
	Elijah Newren <newren@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Phillip Wood <phillip.wood@dunelm.org.uk>,
	Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: [PATCH 3/3] rebase --continue: remove .git/MERGE_MSG
Date: Tue, 10 Aug 2021 09:31:57 +0000	[thread overview]
Message-ID: <6a63b657f1313ea6d4141c37a7c24bca691ce107.1628587917.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1013.git.1628587917.gitgitgadget@gmail.com>

From: Phillip Wood <phillip.wood@dunelm.org.uk>

If the user skips the final commit by removing all the changes from
the index and worktree with 'git restore' (or read-tree) and then runs
'git rebase --continue' .git/MERGE_MSG is left behind. This will seed
the commit message the next time the user commits which is not what we
want to happen.

Reported-by: Victor Gambier <vgambier@excilys.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 sequencer.c                |  3 +++
 t/t3403-rebase-skip.sh     |  8 ++++++++
 t/t3418-rebase-continue.sh | 10 ++++++++++
 3 files changed, 21 insertions(+)

diff --git a/sequencer.c b/sequencer.c
index 7f07cd00f3f..52c7b461179 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4716,6 +4716,9 @@ static int commit_staged_changes(struct repository *r,
 		    refs_delete_ref(get_main_ref_store(r), "",
 				    "CHERRY_PICK_HEAD", NULL, 0))
 			return error(_("could not remove CHERRY_PICK_HEAD"));
+		if (unlink(git_path_merge_msg(r)) && errno != ENOENT)
+			return error_errno(_("could not remove '%s'"),
+					   git_path_merge_msg(r));
 		if (!final_fixup)
 			return 0;
 	}
diff --git a/t/t3403-rebase-skip.sh b/t/t3403-rebase-skip.sh
index a44e68d0ffb..f6e48644978 100755
--- a/t/t3403-rebase-skip.sh
+++ b/t/t3403-rebase-skip.sh
@@ -20,6 +20,7 @@ test_expect_success setup '
 	git add hello &&
 	git commit -m "hello" &&
 	git branch skip-reference &&
+	git tag hello &&
 
 	echo world >> hello &&
 	git commit -a -m "hello world" &&
@@ -96,6 +97,13 @@ test_expect_success 'moved back to branch correctly' '
 
 test_debug 'gitk --all & sleep 1'
 
+test_expect_success 'skipping final pick removes .git/MERGE_MSG' '
+	test_must_fail git rebase --onto hello reverted-goodbye^ \
+		reverted-goodbye &&
+	git rebase --skip &&
+	test_path_is_missing .git/MERGE_MSG
+'
+
 test_expect_success 'correct advice upon picking empty commit' '
 	test_when_finished "git rebase --abort" &&
 	test_must_fail git rebase -i --onto goodbye \
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
index e4cb8be0418..f23996c9be0 100755
--- a/t/t3418-rebase-continue.sh
+++ b/t/t3418-rebase-continue.sh
@@ -31,6 +31,16 @@ test_expect_success 'interactive rebase --continue works with touched file' '
 	git rebase --continue
 '
 
+test_expect_success 'rebase --continue removes .git/MERGE_MSG' '
+	git checkout -f --detach topic &&
+
+	test_must_fail git rebase --onto main HEAD^ &&
+	git read-tree --reset -u HEAD &&
+	test_path_is_file .git/MERGE_MSG &&
+	git rebase --continue &&
+	test_path_is_missing .git/MERGE_MSG
+'
+
 test_expect_success 'non-interactive rebase --continue works with touched file' '
 	rm -fr .git/rebase-* &&
 	git reset --hard &&
-- 
gitgitgadget

  parent reply	other threads:[~2021-08-10  9:32 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10  9:31 [PATCH 0/3] rebase --continue: remove .git/MERGE_MSG Phillip Wood via GitGitGadget
2021-08-10  9:31 ` [PATCH 1/3] t3403: fix commit authorship Phillip Wood via GitGitGadget
2021-08-10 17:01   ` Elijah Newren
2021-08-10 18:43     ` Junio C Hamano
2021-08-12 10:04       ` Phillip Wood
2021-08-14 21:53         ` Johannes Schindelin
2021-08-15 17:36           ` Junio C Hamano
2021-08-15 20:04             ` Phillip Wood
2021-08-16 16:36               ` Junio C Hamano
2021-08-17 10:05                 ` Phillip Wood
2021-08-10  9:31 ` [PATCH 2/3] rebase --apply: restore some tests Phillip Wood via GitGitGadget
2021-08-10 16:58   ` Elijah Newren
2021-08-12 10:03     ` Phillip Wood
2021-08-10  9:31 ` Phillip Wood via GitGitGadget [this message]
2021-08-10 17:03 ` [PATCH 0/3] rebase --continue: remove .git/MERGE_MSG Elijah Newren
2021-08-12 13:42 ` [PATCH v2 " Phillip Wood via GitGitGadget
2021-08-12 13:42   ` [PATCH v2 1/3] t3403: fix commit authorship Phillip Wood via GitGitGadget
2021-08-12 13:42   ` [PATCH v2 2/3] rebase --apply: restore some tests Phillip Wood via GitGitGadget
2021-08-12 13:42   ` [PATCH v2 3/3] rebase --continue: remove .git/MERGE_MSG Phillip Wood via GitGitGadget
2021-08-13 23:01     ` Junio C Hamano
2021-08-14 20:01       ` Phillip Wood
2021-08-13  0:46   ` [PATCH v2 0/3] " Elijah Newren
2021-08-13 15:31     ` Junio C Hamano
2021-08-13 17:21       ` Elijah Newren
2021-08-14 20:02         ` Phillip Wood

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=6a63b657f1313ea6d4141c37a7c24bca691ce107.1628587917.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=vgambier@excilys.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.