git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Vojtěch Knyttl" <vojtech@knyt.tl>,
	"SZEDER Gábor" <szeder.dev@gmail.com>,
	"Martin Ågren" <martin.agren@gmail.com>,
	"Johannes Schindelin" <johannes.schindelin@gmx.de>,
	"Johannes Schindelin" <johannes.schindelin@gmx.de>
Subject: [PATCH v2] rebase -i: do leave commit message intact in fixup! chains
Date: Fri, 08 Jan 2021 16:28:18 +0000	[thread overview]
Message-ID: <pull.818.v2.git.1610123298764.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.818.git.1608337339246.gitgitgadget@gmail.com>

From: Johannes Schindelin <johannes.schindelin@gmx.de>

In 6e98de72c03 (sequencer (rebase -i): add support for the 'fixup' and
'squash' commands, 2017-01-02), this developer introduced a change of
behavior by mistake: when encountering a `fixup!` commit (or multiple
`fixup!` commits) without any `squash!` commit thrown in, the final `git
commit` was invoked with `--cleanup=strip`. Prior to that commit, the
commit command had been called without that `--cleanup` option.

Since we explicitly read the original commit message from a file in that
case, there is really no sense in forcing that clean-up.

We actually need to actively suppress that clean-up lest a configured
`commit.cleanup` may interfere with what we want to do: leave the commit
message unchanged.

Reported-by: Vojtěch Knyttl <vojtech@knyt.tl>
Helped-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
    Fix bug in interactive rebases where fixup! cleans up the commit message
    
    Original report here:
    https://lore.kernel.org/git/CANVGpwZGbzYLMeMze64e_OU9p3bjyEgzC5thmNBr6LttBt%2BYGw%40mail.gmail.com/t
    
    Changes since v1:
    
     * The fix now works even if commit.cleanup = commit

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-818%2Fdscho%2Fautosquash-without-scissors-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-818/dscho/autosquash-without-scissors-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/818

Range-diff vs v1:

 1:  bfade3b146f ! 1:  c760d6cd203 rebase -i: do leave commit message intact in fixup! chains
     @@ Commit message
          Since we explicitly read the original commit message from a file in that
          case, there is really no sense in forcing that clean-up.
      
     +    We actually need to actively suppress that clean-up lest a configured
     +    `commit.cleanup` may interfere with what we want to do: leave the commit
     +    message unchanged.
     +
          Reported-by: Vojtěch Knyttl <vojtech@knyt.tl>
     +    Helped-by: Martin Ågren <martin.agren@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## sequencer.c ##
     +@@ sequencer.c: N_("you have staged changes in your working tree\n"
     + #define CLEANUP_MSG (1<<3)
     + #define VERIFY_MSG  (1<<4)
     + #define CREATE_ROOT_COMMIT (1<<5)
     ++#define VERBATIM_MSG (1<<6)
     + 
     + static int run_command_silent_on_success(struct child_process *cmd)
     + {
     +@@ sequencer.c: static int run_git_commit(const char *defmsg,
     + 		strvec_pushl(&cmd.args, "-C", "HEAD", NULL);
     + 	if ((flags & CLEANUP_MSG))
     + 		strvec_push(&cmd.args, "--cleanup=strip");
     ++	if ((flags & VERBATIM_MSG))
     ++		strvec_push(&cmd.args, "--cleanup=verbatim");
     + 	if ((flags & EDIT_MSG))
     + 		strvec_push(&cmd.args, "-e");
     + 	else if (!(flags & CLEANUP_MSG) &&
     +@@ sequencer.c: static int try_to_commit(struct repository *r,
     + 
     + 	if (flags & CLEANUP_MSG)
     + 		cleanup = COMMIT_MSG_CLEANUP_ALL;
     ++	else if (flags & VERBATIM_MSG)
     ++		cleanup = COMMIT_MSG_CLEANUP_NONE;
     + 	else if ((opts->signoff || opts->record_origin) &&
     + 		 !opts->explicit_cleanup)
     + 		cleanup = COMMIT_MSG_CLEANUP_SPACE;
      @@ sequencer.c: static int do_pick_commit(struct repository *r,
     - 		flags |= AMEND_MSG;
       		if (!final_fixup)
       			msg_file = rebase_path_squash_msg();
     --		else if (file_exists(rebase_path_fixup_msg())) {
     + 		else if (file_exists(rebase_path_fixup_msg())) {
      -			flags |= CLEANUP_MSG;
     -+		else if (file_exists(rebase_path_fixup_msg()))
     ++			flags |= VERBATIM_MSG;
       			msg_file = rebase_path_fixup_msg();
     --		} else {
     -+		else {
     + 		} else {
       			const char *dest = git_path_squash_msg(r);
     - 			unlink(dest);
     - 			if (copy_file(dest, rebase_path_squash_msg(), 0666))
      
       ## t/t3415-rebase-autosquash.sh ##
      @@ t/t3415-rebase-autosquash.sh: test_expect_success 'fixup a fixup' '
     @@ t/t3415-rebase-autosquash.sh: test_expect_success 'fixup a fixup' '
      +	oneline="#818" &&
      +	git commit --allow-empty -m "$oneline" &&
      +	git commit --fixup HEAD --allow-empty &&
     -+	git rebase -ki --autosquash HEAD~2 &&
     ++	git -c commit.cleanup=strip rebase -ki --autosquash HEAD~2 &&
      +	test "$oneline" = "$(git show -s --format=%s)"
      +'
      +


 sequencer.c                  | 7 ++++++-
 t/t3415-rebase-autosquash.sh | 8 ++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/sequencer.c b/sequencer.c
index 8909a467700..092e7b811f0 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -943,6 +943,7 @@ N_("you have staged changes in your working tree\n"
 #define CLEANUP_MSG (1<<3)
 #define VERIFY_MSG  (1<<4)
 #define CREATE_ROOT_COMMIT (1<<5)
+#define VERBATIM_MSG (1<<6)
 
 static int run_command_silent_on_success(struct child_process *cmd)
 {
@@ -1012,6 +1013,8 @@ static int run_git_commit(const char *defmsg,
 		strvec_pushl(&cmd.args, "-C", "HEAD", NULL);
 	if ((flags & CLEANUP_MSG))
 		strvec_push(&cmd.args, "--cleanup=strip");
+	if ((flags & VERBATIM_MSG))
+		strvec_push(&cmd.args, "--cleanup=verbatim");
 	if ((flags & EDIT_MSG))
 		strvec_push(&cmd.args, "-e");
 	else if (!(flags & CLEANUP_MSG) &&
@@ -1454,6 +1457,8 @@ static int try_to_commit(struct repository *r,
 
 	if (flags & CLEANUP_MSG)
 		cleanup = COMMIT_MSG_CLEANUP_ALL;
+	else if (flags & VERBATIM_MSG)
+		cleanup = COMMIT_MSG_CLEANUP_NONE;
 	else if ((opts->signoff || opts->record_origin) &&
 		 !opts->explicit_cleanup)
 		cleanup = COMMIT_MSG_CLEANUP_SPACE;
@@ -2002,7 +2007,7 @@ static int do_pick_commit(struct repository *r,
 		if (!final_fixup)
 			msg_file = rebase_path_squash_msg();
 		else if (file_exists(rebase_path_fixup_msg())) {
-			flags |= CLEANUP_MSG;
+			flags |= VERBATIM_MSG;
 			msg_file = rebase_path_fixup_msg();
 		} else {
 			const char *dest = git_path_squash_msg(r);
diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh
index 7bab6000dc7..88040bc4352 100755
--- a/t/t3415-rebase-autosquash.sh
+++ b/t/t3415-rebase-autosquash.sh
@@ -440,4 +440,12 @@ test_expect_success 'fixup a fixup' '
 	test XZWY = $(git show | tr -cd W-Z)
 '
 
+test_expect_success 'fixup does not clean up commit message' '
+	oneline="#818" &&
+	git commit --allow-empty -m "$oneline" &&
+	git commit --fixup HEAD --allow-empty &&
+	git -c commit.cleanup=strip rebase -ki --autosquash HEAD~2 &&
+	test "$oneline" = "$(git show -s --format=%s)"
+'
+
 test_done

base-commit: ba2aa15129e59f248d8cdd30404bc78b5178f61d
-- 
gitgitgadget

  parent reply	other threads:[~2021-01-08 16:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-19  0:22 [PATCH] rebase -i: do leave commit message intact in fixup! chains Johannes Schindelin via GitGitGadget
2020-12-19 14:47 ` Martin Ågren
2020-12-19 15:00   ` Johannes Schindelin
2021-01-08 16:28 ` Johannes Schindelin via GitGitGadget [this message]
2021-01-12 20:49   ` [PATCH v2] " Martin Ågren
2021-01-28 16:19     ` Johannes Schindelin
2021-01-12 23:12   ` Junio C Hamano
2021-01-28 16:24     ` Johannes Schindelin
2021-01-28 20:18       ` Junio C Hamano
2021-01-28 16:16   ` [PATCH v3] " Johannes Schindelin via GitGitGadget

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=pull.818.v2.git.1610123298764.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmx.de \
    --cc=martin.agren@gmail.com \
    --cc=szeder.dev@gmail.com \
    --cc=vojtech@knyt.tl \
    /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.
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).