summaryrefslogtreecommitdiff
path: root/sequencer.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2021-11-30 03:58:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-11-30 06:53:26 (GMT)
commitcc9dcdee6142d39cdd42d23b81d2a256f591d289 (patch)
tree99591cc293f15dd391f557c2c2216e9f2600b367 /sequencer.c
parente9d7761bb94f20acc98824275e317fa82436c25d (diff)
downloadgit-cc9dcdee6142d39cdd42d23b81d2a256f591d289.zip
git-cc9dcdee6142d39cdd42d23b81d2a256f591d289.tar.gz
git-cc9dcdee6142d39cdd42d23b81d2a256f591d289.tar.bz2
sequencer: avoid adding exec commands for non-commit creating commands
The `--exec <cmd>` is documented as Append "exec <cmd>" after each line creating a commit in the final history. ... If --autosquash is used, "exec" lines will not be appended for the intermediate commits, and will only appear at the end of each squash/fixup series. Unfortunately, it would also add exec commands after non-pick operations, such as 'no-op', which could be seen for example with git rebase -i --exec true HEAD todo_list_add_exec_commands() intent was to insert exec commands after each logical pick, while trying to consider a chains of fixup and squash commits to be part of the pick before it. So it would keep an 'insert' boolean tracking if it had seen a pick or merge, but not write the exec command until it saw the next non-fixup/squash command. Since that would make it miss the final exec command, it had some code that would check whether it still needed to insert one at the end, but instead of a simple if (insert) it had a if (insert || <condition that is always true>) That's buggy; as per the docs, we should only add exec commands for lines that create commits, i.e. only if insert is true. Fix the conditional. There was one testcase in the testsuite that we tweak for this change; it was introduced in 54fd3243da ("rebase -i: reread the todo list if `exec` touched it", 2017-04-26), and was merely testing that after an exec had fired that the todo list would be re-read. The test at the time would have worked given any revision at all, though it would only work with 'HEAD' as a side-effect of this bug. Since we're fixing this bug, choose something other than 'HEAD' for that test. Finally, add a testcase that verifies when we have no commits to pick, that we get no exec lines in the generated todo list. Reported-by: Nikita Bobko <nikitabobko@gmail.com> Signed-off-by: Elijah Newren <newren@gmail.com> Acked-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/sequencer.c b/sequencer.c
index ea96837..aa790f0 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -5496,7 +5496,7 @@ static void todo_list_add_exec_commands(struct todo_list *todo_list,
}
/* insert or append final <commands> */
- if (insert || nr == todo_list->nr) {
+ if (insert) {
ALLOC_GROW(items, nr + commands->nr, alloc);
COPY_ARRAY(items + nr, base_items, commands->nr);
nr += commands->nr;