Skip to content

Commit f7d42ce

Browse files
dschogitster
authored andcommitted
rebase -i: do leave commit message intact in fixup! chains
In 6e98de7 (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 <[email protected]> Helped-by: Martin Ågren <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 71ca53e commit f7d42ce

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

sequencer.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ N_("you have staged changes in your working tree\n"
943943
#define CLEANUP_MSG (1<<3)
944944
#define VERIFY_MSG (1<<4)
945945
#define CREATE_ROOT_COMMIT (1<<5)
946+
#define VERBATIM_MSG (1<<6)
946947

947948
static int run_command_silent_on_success(struct child_process *cmd)
948949
{
@@ -979,6 +980,9 @@ static int run_git_commit(const char *defmsg,
979980
{
980981
struct child_process cmd = CHILD_PROCESS_INIT;
981982

983+
if ((flags & CLEANUP_MSG) && (flags & VERBATIM_MSG))
984+
BUG("CLEANUP_MSG and VERBATIM_MSG are mutually exclusive");
985+
982986
cmd.git_cmd = 1;
983987

984988
if (is_rebase_i(opts) && read_env_script(&cmd.env_array)) {
@@ -1012,6 +1016,8 @@ static int run_git_commit(const char *defmsg,
10121016
strvec_pushl(&cmd.args, "-C", "HEAD", NULL);
10131017
if ((flags & CLEANUP_MSG))
10141018
strvec_push(&cmd.args, "--cleanup=strip");
1019+
if ((flags & VERBATIM_MSG))
1020+
strvec_push(&cmd.args, "--cleanup=verbatim");
10151021
if ((flags & EDIT_MSG))
10161022
strvec_push(&cmd.args, "-e");
10171023
else if (!(flags & CLEANUP_MSG) &&
@@ -1380,6 +1386,9 @@ static int try_to_commit(struct repository *r,
13801386
enum commit_msg_cleanup_mode cleanup;
13811387
int res = 0;
13821388

1389+
if ((flags & CLEANUP_MSG) && (flags & VERBATIM_MSG))
1390+
BUG("CLEANUP_MSG and VERBATIM_MSG are mutually exclusive");
1391+
13831392
if (parse_head(r, &current_head))
13841393
return -1;
13851394

@@ -1454,6 +1463,8 @@ static int try_to_commit(struct repository *r,
14541463

14551464
if (flags & CLEANUP_MSG)
14561465
cleanup = COMMIT_MSG_CLEANUP_ALL;
1466+
else if (flags & VERBATIM_MSG)
1467+
cleanup = COMMIT_MSG_CLEANUP_NONE;
14571468
else if ((opts->signoff || opts->record_origin) &&
14581469
!opts->explicit_cleanup)
14591470
cleanup = COMMIT_MSG_CLEANUP_SPACE;
@@ -2002,7 +2013,7 @@ static int do_pick_commit(struct repository *r,
20022013
if (!final_fixup)
20032014
msg_file = rebase_path_squash_msg();
20042015
else if (file_exists(rebase_path_fixup_msg())) {
2005-
flags |= CLEANUP_MSG;
2016+
flags |= VERBATIM_MSG;
20062017
msg_file = rebase_path_fixup_msg();
20072018
} else {
20082019
const char *dest = git_path_squash_msg(r);

t/t3415-rebase-autosquash.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,12 @@ test_expect_success 'fixup a fixup' '
440440
test XZWY = $(git show | tr -cd W-Z)
441441
'
442442

443+
test_expect_success 'fixup does not clean up commit message' '
444+
oneline="#818" &&
445+
git commit --allow-empty -m "$oneline" &&
446+
git commit --fixup HEAD --allow-empty &&
447+
git -c commit.cleanup=strip rebase -ki --autosquash HEAD~2 &&
448+
test "$oneline" = "$(git show -s --format=%s)"
449+
'
450+
443451
test_done

0 commit comments

Comments
 (0)