diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-10-18 09:24:14 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-10-18 11:30:13 +0200 |
commit | d8233feb78d10ade39fd64b85044fea84f2fc293 (patch) | |
tree | d66ddab59619060290d1a89b06bdac524ad5aa3c /tests/stash | |
parent | 284816093ee733490d2129031cb2634b0ac61f6d (diff) | |
download | libgit2-d8233feb78d10ade39fd64b85044fea84f2fc293.tar.gz |
reflog: allow adding entries with newlines in their message
Currently, the reflog disallows any entries that have a message with
newlines, as that would effectively break the reflog format, which may
contain a single line per entry, only. Upstream git behaves a bit
differently, though, especially when considering stashes: instead of
rejecting any reflog entry with newlines, git will simply replace
newlines with spaces. E.g. executing 'git stash push -m "foo\nbar"' will
create a reflog entry with "foo bar" as entry message.
This commit adjusts our own logic to stop rejecting commit messages with
newlines. Previously, this logic was part of `git_reflog_append`, only.
There is a second place though where we add reflog entries, which is the
serialization code in the filesystem refdb. As it didn't contain any
sanity checks whatsoever, the refdb would have been perfectly happy to
write malformatted reflog entries to the disk. This is being fixed with
the same logic as for the reflog itself.
Diffstat (limited to 'tests/stash')
-rw-r--r-- | tests/stash/save.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/stash/save.c b/tests/stash/save.c index 362c704ea..d568567d5 100644 --- a/tests/stash/save.c +++ b/tests/stash/save.c @@ -283,6 +283,26 @@ void test_stash_save__stashing_updates_the_reflog(void) assert_object_oid("refs/stash@{1}", NULL, GIT_OBJECT_COMMIT); } +void test_stash_save__multiline_message(void) +{ + const char *msg = "This\n\nis a multiline message\n"; + const git_reflog_entry *entry; + git_reflog *reflog; + + assert_object_oid("refs/stash@{0}", NULL, GIT_OBJECT_COMMIT); + + cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, msg, GIT_STASH_DEFAULT)); + + cl_git_pass(git_reflog_read(&reflog, repo, "refs/stash")); + cl_assert(entry = git_reflog_entry_byindex(reflog, 0)); + cl_assert_equal_s(git_reflog_entry_message(entry), "On master: This is a multiline message"); + + assert_object_oid("refs/stash@{0}", git_oid_tostr_s(&stash_tip_oid), GIT_OBJECT_COMMIT); + assert_commit_message_contains("refs/stash@{0}", msg); + + git_reflog_free(reflog); +} + void test_stash_save__cannot_stash_when_there_are_no_local_change(void) { git_index *index; |