diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-08-01 17:49:19 +0200 |
---|---|---|
committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-08-01 18:39:20 +0200 |
commit | 074841ec6ae2cc70391544ea76082bc4e2c4a1bf (patch) | |
tree | a0c9b36cc08aff7074b2b2884304ba7bda4609fe /tests-clar/repo/message.c | |
parent | 2340b18102eedc73cbbfeca43f0b22e5d4119c38 (diff) | |
download | libgit2-074841ec6ae2cc70391544ea76082bc4e2c4a1bf.tar.gz |
repository: add a getter and remove function for git's prepared message
The 'git revert/cherry-pick/merge -n' commands leave .git/MERGE_MSG
behind so that git-commit can find it. As we don't yet support these
operations, users who are shelling out to let git perform these
operations haven't had a convenient way to get this message.
These functions allow the user to retrieve the message and remove it
when she's created the commit.
Diffstat (limited to 'tests-clar/repo/message.c')
-rw-r--r-- | tests-clar/repo/message.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests-clar/repo/message.c b/tests-clar/repo/message.c new file mode 100644 index 000000000..4a6f13b9d --- /dev/null +++ b/tests-clar/repo/message.c @@ -0,0 +1,47 @@ +#include "clar_libgit2.h" +#include "buffer.h" +#include "refs.h" +#include "posix.h" + +static git_repository *_repo; +static git_buf _path; +static char *_actual; + +void test_repo_message__initialize(void) +{ + _repo = cl_git_sandbox_init("testrepo.git"); +} + +void test_repo_message__cleanup(void) +{ + cl_git_sandbox_cleanup(); + git_buf_free(&_path); + git__free(_actual); + _actual = NULL; +} + +void test_repo_message__none(void) +{ + cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(NULL, 0, _repo)); +} + +void test_repo_message__message(void) +{ + const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n"; + ssize_t len; + + cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), "MERGE_MSG")); + cl_git_mkfile(git_buf_cstr(&_path), expected); + + len = git_repository_message(NULL, 0, _repo); + cl_assert(len > 0); + _actual = git__malloc(len + 1); + cl_assert(_actual != NULL); + + cl_assert(git_repository_message(_actual, len, _repo) > 0); + _actual[len] = '\0'; + cl_assert_equal_s(expected, _actual); + + cl_git_pass(p_unlink(git_buf_cstr(&_path))); + cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(NULL, 0, _repo)); +} |