Skip to content

Commit 9d6b9df

Browse files
phillipwoodgitster
authored andcommitted
rebase -i: fix rewording with --committer-date-is-author-date
baf8ec8 (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 <[email protected]> Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f2563c9 commit 9d6b9df

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

sequencer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,9 @@ static int run_git_commit(const char *defmsg,
983983

984984
cmd.git_cmd = 1;
985985

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))) &&
987989
read_env_script(&cmd.env_array)) {
988990
const char *gpg_opt = gpg_sign_opt_quoted(opts);
989991

t/t3436-rebase-more-options.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ test_expect_success '--committer-date-is-author-date works with merge backend' '
8282
test_ctime_is_atime -1
8383
'
8484

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+
8599
test_expect_success '--committer-date-is-author-date works with rebase -r' '
86100
git checkout side &&
87101
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
155169
test_atime_is_ignored -2
156170
'
157171

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+
158187
test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' '
159188
GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
160189
PATH="./test-bin:$PATH" git rebase -i --strategy=test \

0 commit comments

Comments
 (0)