const char *p = ctx->current_fixups.buf;
ctx->current_fixup_count = 1;
while ((p = strchr(p, '\n'))) {
- ctx->current_fixup_count++;
+ /*
+ * Older versions of git accidentally
+ * inserted blank lines when a fixup
+ * was skipped.
+ */
+ if (p[1] && p[1] != '\n')
+ ctx->current_fixup_count++;
p++;
}
}
BUG("Incorrect current_fixups:\n%s", p);
while (len && p[len - 1] != '\n')
len--;
+ /* Remove trailing newline */
+ if (len)
+ len--;
strbuf_setlen(&ctx->current_fixups, len);
if (write_message(p, len, rebase_path_current_fixups(),
0) < 0) {
EOF
: skip and continue &&
+ test_config commit.status false &&
echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
(test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
: now, let us ensure that "squash" is handled correctly &&
git reset --hard wants-fixup-3 &&
- test_must_fail env FAKE_LINES="1 squash 2 squash 1 squash 3 squash 1" \
+ test_must_fail env \
+ FAKE_LINES="1 squash 2 squash 1 squash 3 squash 1 squash 4 squash 1" \
git rebase -i HEAD~4 &&
: the second squash failed, but there are two more in the chain &&
fixup 2
EOF
+ (test_set_editor "$PWD/copy-editor.sh" &&
+ test_must_fail git rebase --skip) &&
+ : not the final squash, no need to edit the commit message &&
+ test_path_is_missing .git/copy.txt &&
+
+ : The first, third and fifth squashes succeeded, therefore: &&
+ cat >expect <<-\EOF &&
+ # This is a combination of 4 commits.
+ # This is the 1st commit message:
+
+ wants-fixup
+
+ # This is the commit message #2:
+
+ fixup 1
+
+ # This is the commit message #3:
+
+ fixup 2
+
+ # This is the commit message #4:
+
+ fixup 3
+ EOF
+ test_commit_message HEAD expect &&
+
(test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
test_commit_message HEAD <<-\EOF &&
wants-fixup
fixup 1
fixup 2
+
+ fixup 3
EOF
: Final squash failed, but there was still a squash &&
- head -n1 .git/copy.txt >first-line &&
- test_grep "# This is a combination of 3 commits" first-line &&
- test_grep "# This is the commit message #3:" .git/copy.txt
+ test_cmp expect .git/copy.txt
'
test_expect_success 'setup rerere database' '