summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sequencer.c11
-rwxr-xr-xt/t3511-cherry-pick-x.sh44
2 files changed, 48 insertions, 7 deletions
diff --git a/sequencer.c b/sequencer.c
index d64c97397b..5df080dada 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -698,6 +698,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
strbuf_addstr(&msgbuf, skip_blank_lines(p + 2));
if (opts->record_origin) {
+ strbuf_complete_line(&msgbuf);
if (!has_conforming_footer(&msgbuf, NULL, 0))
strbuf_addch(&msgbuf, '\n');
strbuf_addstr(&msgbuf, cherry_picked_prefix);
@@ -1362,6 +1363,9 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
getenv("GIT_COMMITTER_EMAIL")));
strbuf_addch(&sob, '\n');
+ if (!ignore_footer)
+ strbuf_complete_line(msgbuf);
+
/*
* If the whole message buffer is equal to the sob, pretend that we
* found a conforming footer with a matching sob
@@ -1382,13 +1386,6 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
* the title and body to be filled in by the user.
*/
append_newlines = "\n\n";
- } else if (msgbuf->buf[len - 1] != '\n') {
- /*
- * Incomplete line. Complete the line and add a
- * blank one so that there is an empty line between
- * the message body and the sob.
- */
- append_newlines = "\n\n";
} else if (len == 1) {
/*
* Buffer contains a single newline. Add another
diff --git a/t/t3511-cherry-pick-x.sh b/t/t3511-cherry-pick-x.sh
index bf0a5c9887..9888bf34b9 100755
--- a/t/t3511-cherry-pick-x.sh
+++ b/t/t3511-cherry-pick-x.sh
@@ -208,6 +208,50 @@ test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists fo
test_cmp expect actual
'
+test_expect_success 'cherry-pick -x handles commits with no NL at end of message' '
+ pristine_detach initial &&
+ printf "title\n\nSigned-off-by: A <a@example.com>" >msg &&
+ sha1=$(git commit-tree -p initial mesg-with-footer^{tree} <msg) &&
+ git cherry-pick -x $sha1 &&
+ git log -1 --pretty=format:%B >actual &&
+
+ printf "\n(cherry picked from commit %s)\n" $sha1 >>msg &&
+ test_cmp msg actual
+'
+
+test_expect_success 'cherry-pick -x handles commits with no footer and no NL at end of message' '
+ pristine_detach initial &&
+ printf "title\n\nnot a footer" >msg &&
+ sha1=$(git commit-tree -p initial mesg-with-footer^{tree} <msg) &&
+ git cherry-pick -x $sha1 &&
+ git log -1 --pretty=format:%B >actual &&
+
+ printf "\n\n(cherry picked from commit %s)\n" $sha1 >>msg &&
+ test_cmp msg actual
+'
+
+test_expect_success 'cherry-pick -s handles commits with no NL at end of message' '
+ pristine_detach initial &&
+ printf "title\n\nSigned-off-by: A <a@example.com>" >msg &&
+ sha1=$(git commit-tree -p initial mesg-with-footer^{tree} <msg) &&
+ git cherry-pick -s $sha1 &&
+ git log -1 --pretty=format:%B >actual &&
+
+ printf "\nSigned-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>\n" >>msg &&
+ test_cmp msg actual
+'
+
+test_expect_success 'cherry-pick -s handles commits with no footer and no NL at end of message' '
+ pristine_detach initial &&
+ printf "title\n\nnot a footer" >msg &&
+ sha1=$(git commit-tree -p initial mesg-with-footer^{tree} <msg) &&
+ git cherry-pick -s $sha1 &&
+ git log -1 --pretty=format:%B >actual &&
+
+ printf "\n\nSigned-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>\n" >>msg &&
+ test_cmp msg actual
+'
+
test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
pristine_detach initial &&
sha1=$(git rev-parse mesg-with-cherry-footer^0) &&