Skip to content

Commit 21b11c6

Browse files
phillipwoodgitster
authored andcommitted
sequencer: write CHERRY_PICK_HEAD for reword and edit
`git commit` relies on the presence of CHERRY_PICK_HEAD to show the correct error message in the case of an empty pick. This fixes a regression introduced by the conversion from shell to C. In the shell version everything was a cherry-pick as far as the sequencer code was concerned so it always wrote CHERRY_PICK_HEAD. The conversion to C forgot to update the code that creates CHERRY_PICK_HEAD. We do not want to create CHERRY_PICK_HEAD for fixup and squash commands as that would prevent `git commit --amend` from running. Note that the error message shown by `git commit` for an empty pick during a rebase is currently wrong as it talks about running `git cherry-pick --skip` rather than `git rebase --skip`. This will be fixed in a future commit which is why the tests are in t3403-rebase-skip.sh. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f028d66 commit 21b11c6

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

sequencer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,9 @@ static int do_pick_commit(struct repository *r,
19161916
* However, if the merge did not even start, then we don't want to
19171917
* write it at all.
19181918
*/
1919-
if (command == TODO_PICK && !opts->no_commit && (res == 0 || res == 1) &&
1919+
if ((command == TODO_PICK || command == TODO_REWORD ||
1920+
command == TODO_EDIT) && !opts->no_commit &&
1921+
(res == 0 || res == 1) &&
19201922
update_ref(NULL, "CHERRY_PICK_HEAD", &commit->object.oid, NULL,
19211923
REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR))
19221924
res = -1;

t/t3403-rebase-skip.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ test_expect_success setup '
2929
test_tick &&
3030
git commit -m reverted-goodbye &&
3131
git tag reverted-goodbye &&
32+
git checkout goodbye &&
33+
test_tick &&
34+
GIT_AUTHOR_NAME="Another Author" \
35+
GIT_AUTHOR_EMAIL="[email protected]" \
36+
git commit --amend --no-edit -m amended-goodbye &&
37+
test_tick &&
38+
git tag amended-goodbye &&
3239
3340
git checkout -f skip-reference &&
3441
echo moo > hello &&
@@ -85,6 +92,52 @@ test_expect_success 'moved back to branch correctly' '
8592

8693
test_debug 'gitk --all & sleep 1'
8794

95+
test_expect_success 'correct advice upon picking empty commit' '
96+
test_when_finished "git rebase --abort" &&
97+
test_must_fail git rebase -i --onto goodbye \
98+
amended-goodbye^ amended-goodbye 2>err &&
99+
test_i18ngrep "previous cherry-pick is now empty" err &&
100+
test_i18ngrep "git cherry-pick --skip" err &&
101+
test_must_fail git commit &&
102+
test_i18ngrep "git cherry-pick --skip" err
103+
'
104+
105+
test_expect_success 'correct authorship when committing empty pick' '
106+
test_when_finished "git rebase --abort" &&
107+
test_must_fail git rebase -i --onto goodbye \
108+
amended-goodbye^ amended-goodbye &&
109+
git commit --allow-empty &&
110+
git log --pretty=format:"%an <%ae>%n%ad%B" -1 amended-goodbye >expect &&
111+
git log --pretty=format:"%an <%ae>%n%ad%B" -1 HEAD >actual &&
112+
test_cmp expect actual
113+
'
114+
115+
test_expect_success 'correct advice upon rewording empty commit' '
116+
test_when_finished "git rebase --abort" &&
117+
(
118+
set_fake_editor &&
119+
test_must_fail env FAKE_LINES="reword 1" git rebase -i \
120+
--onto goodbye amended-goodbye^ amended-goodbye 2>err
121+
) &&
122+
test_i18ngrep "previous cherry-pick is now empty" err &&
123+
test_i18ngrep "git cherry-pick --skip" err &&
124+
test_must_fail git commit &&
125+
test_i18ngrep "git cherry-pick --skip" err
126+
'
127+
128+
test_expect_success 'correct advice upon editing empty commit' '
129+
test_when_finished "git rebase --abort" &&
130+
(
131+
set_fake_editor &&
132+
test_must_fail env FAKE_LINES="edit 1" git rebase -i \
133+
--onto goodbye amended-goodbye^ amended-goodbye 2>err
134+
) &&
135+
test_i18ngrep "previous cherry-pick is now empty" err &&
136+
test_i18ngrep "git cherry-pick --skip" err &&
137+
test_must_fail git commit &&
138+
test_i18ngrep "git cherry-pick --skip" err
139+
'
140+
88141
test_expect_success 'fixup that empties commit fails' '
89142
test_when_finished "git rebase --abort" &&
90143
(

0 commit comments

Comments
 (0)