diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-03-01 17:03:32 +0100 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-05-07 12:16:04 +0200 |
commit | 458b94503d023a07247153f44d34bcc65e6f8103 (patch) | |
tree | 02a14a37ebde58cdcf7164f0f362c705e510b201 /src/commit.c | |
parent | 9b62e40ecdb92ab7493eac514e1399d791fa6f62 (diff) | |
download | libgit2-458b94503d023a07247153f44d34bcc65e6f8103.tar.gz |
commit/tag: ensure the message is cleaned up
'git commit' and 'git tag -a' enforce some conventions, like cleaning up excess whitespace and making sure that the last line ends with a '\n'. This fix replicates this behavior.
Fix libgit2/libgit2sharp#117
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/commit.c b/src/commit.c index 04f37fe1..2bf12f3a 100644 --- a/src/commit.c +++ b/src/commit.c @@ -14,6 +14,7 @@ #include "odb.h" #include "commit.h" #include "signature.h" +#include "message.h" #include <stdarg.h> @@ -161,7 +162,7 @@ int git_commit_create( int parent_count, const git_commit *parents[]) { - git_buf commit = GIT_BUF_INIT; + git_buf commit = GIT_BUF_INIT, cleaned_message = GIT_BUF_INIT; int i; git_odb *odb; @@ -181,11 +182,16 @@ int git_commit_create( git_buf_printf(&commit, "encoding %s\n", message_encoding); git_buf_putc(&commit, '\n'); - git_buf_puts(&commit, message); - if (git_buf_oom(&commit)) + /* Remove comments by default */ + if (git_message_prettify(&cleaned_message, message, 1) < 0) goto on_error; + if (git_buf_puts(&commit, git_buf_cstr(&cleaned_message)) < 0) + goto on_error; + + git_buf_free(&cleaned_message); + if (git_repository_odb__weakptr(&odb, repo) < 0) goto on_error; @@ -201,6 +207,8 @@ int git_commit_create( on_error: git_buf_free(&commit); + git_buf_free(&cleaned_message); + giterr_set(GITERR_OBJECT, "Failed to create commit."); return -1; } |