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/refs | |
| 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/refs')
| -rw-r--r-- | tests/refs/reflog/messages.c | 21 | ||||
| -rw-r--r-- | tests/refs/reflog/reflog.c | 4 |
2 files changed, 22 insertions, 3 deletions
diff --git a/tests/refs/reflog/messages.c b/tests/refs/reflog/messages.c index f8acd23d2..43f59a84b 100644 --- a/tests/refs/reflog/messages.c +++ b/tests/refs/reflog/messages.c @@ -281,6 +281,27 @@ void test_refs_reflog_messages__creating_a_direct_reference(void) git_reference_free(reference); } +void test_refs_reflog_messages__newline_gets_replaced(void) +{ + const git_reflog_entry *entry; + git_signature *signature; + git_reflog *reflog; + git_oid oid; + + cl_git_pass(git_signature_now(&signature, "me", "foo@example.com")); + cl_git_pass(git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); + + cl_git_pass(git_reflog_read(&reflog, g_repo, "HEAD")); + cl_assert_equal_sz(7, git_reflog_entrycount(reflog)); + cl_git_pass(git_reflog_append(reflog, &oid, signature, "inner\nnewline")); + cl_assert_equal_sz(8, git_reflog_entrycount(reflog)); + + cl_assert(entry = git_reflog_entry_byindex(reflog, 0)); + cl_assert_equal_s(git_reflog_entry_message(entry), "inner newline"); + + git_signature_free(signature); + git_reflog_free(reflog); +} void test_refs_reflog_messages__renaming_ref(void) { diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c index 7e4b1ef4a..9bd1af463 100644 --- a/tests/refs/reflog/reflog.c +++ b/tests/refs/reflog/reflog.c @@ -87,15 +87,13 @@ void test_refs_reflog_reflog__append_then_read(void) cl_git_pass(git_signature_now(&committer, "foo", "foo@bar")); cl_git_pass(git_reflog_read(&reflog, g_repo, new_ref)); - - cl_git_fail(git_reflog_append(reflog, &oid, committer, "no inner\nnewline")); cl_git_pass(git_reflog_append(reflog, &oid, committer, NULL)); cl_git_pass(git_reflog_append(reflog, &oid, committer, commit_msg "\n")); cl_git_pass(git_reflog_write(reflog)); - git_reflog_free(reflog); assert_appends(committer, &oid); + git_reflog_free(reflog); git_signature_free(committer); } |
