forked from libgit2/libgit2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
5 changed files
with
60 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", "[email protected]")); | ||
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) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters