rebase -i: fix rewording with --committer-date-is-author-date

baf8ec8d3a (rebase -r: don't write .git/MERGE_MSG when fast-forwarding, 2021-08-20) stopped reading the author script in run_git_commit() when rewording a commit. This is normally safe because "git commit --amend" preserves the authorship. However if the user passes "--committer-date-is-author-date" then we need to read the author date from the author script when rewording. Fix this regression by tightening the check for when it is safe to skip reading the author script. Reported-by: Jonas Kittner <jonas.kittner@ruhr-uni-bochum.de> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Nov 2, 2021 at 21:30 UTC 9d6b9df128f842d2945e20e0760489ec6f3d2c0c
2 files changed +32 -1
sequencer.c
+3 -1
@@ -983,7 +983,9 @@ static int run_git_commit(const char *defmsg,
983
984 cmd.git_cmd = 1;
985
986 - if (is_rebase_i(opts) && !(!defmsg && (flags & AMEND_MSG)) &&
986 + if (is_rebase_i(opts) &&
987 + ((opts->committer_date_is_author_date && !opts->ignore_date) ||
988 + !(!defmsg && (flags & AMEND_MSG))) &&
989 read_env_script(&cmd.env_array)) {
990 const char *gpg_opt = gpg_sign_opt_quoted(opts);
991
t/t3436-rebase-more-options.sh
+29
@@ -82,6 +82,20 @@ test_expect_success '--committer-date-is-author-date works with merge backend' '
82 test_ctime_is_atime -1
83 '
84
85 +test_expect_success '--committer-date-is-author-date works when rewording' '
86 + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
87 + (
88 + set_fake_editor &&
89 + FAKE_COMMIT_MESSAGE=edited \
90 + FAKE_LINES="reword 1" \
91 + git rebase -i --committer-date-is-author-date HEAD^
92 + ) &&
93 + test_write_lines edited "" >expect &&
94 + git log --format="%B" -1 >actual &&
95 + test_cmp expect actual &&
96 + test_ctime_is_atime -1
97 +'
98 +
99 test_expect_success '--committer-date-is-author-date works with rebase -r' '
100 git checkout side &&
101 GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
@@ -155,6 +169,21 @@ test_expect_success '--reset-author-date with --committer-date-is-author-date wo
169 test_atime_is_ignored -2
170 '
171
172 +test_expect_success 'reset-author-date with --committer-date-is-author-date works when rewording' '
173 + GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
174 + (
175 + set_fake_editor &&
176 + FAKE_COMMIT_MESSAGE=edited \
177 + FAKE_LINES="reword 1" \
178 + git rebase -i --committer-date-is-author-date \
179 + --reset-author-date HEAD^
180 + ) &&
181 + test_write_lines edited "" >expect &&
182 + git log --format="%B" -1 >actual &&
183 + test_cmp expect actual &&
184 + test_atime_is_ignored -1
185 +'
186 +
187 test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' '
188 GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
189 PATH="./test-bin:$PATH" git rebase -i --strategy=test \