@matheusbsbs / matheus-bagliano / commits / 21b11c6d1d
Fork 0

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 <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Dec 6, 2019 at 16:06 UTC 21b11c6d1de3840dcaf3fa82dae14ca3924f689f
2 files changed +56 -1
sequencer.c
+3 -1
@@ -1916,7 +1916,9 @@ static int do_pick_commit(struct repository *r,
1916 * However, if the merge did not even start, then we don't want to
1917 * write it at all.
1918 */
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) &&
1922 update_ref(NULL, "CHERRY_PICK_HEAD", &commit->object.oid, NULL,
1923 REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR))
1924 res = -1;
t/t3403-rebase-skip.sh
+53
@@ -29,6 +29,13 @@ test_expect_success setup '
29 test_tick &&
30 git commit -m reverted-goodbye &&
31 git tag reverted-goodbye &&
32 + git checkout goodbye &&
33 + test_tick &&
34 + GIT_AUTHOR_NAME="Another Author" \
35 + GIT_AUTHOR_EMAIL="another.author@example.com" \
36 + git commit --amend --no-edit -m amended-goodbye &&
37 + test_tick &&
38 + git tag amended-goodbye &&
39
40 git checkout -f skip-reference &&
41 echo moo > hello &&
@@ -85,6 +92,52 @@ test_expect_success 'moved back to branch correctly' '
92
93 test_debug 'gitk --all & sleep 1'
94
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 +
141 test_expect_success 'fixup that empties commit fails' '
142 test_when_finished "git rebase --abort" &&
143 (