diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-10-04 17:13:43 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-10-27 00:11:09 +0400 |
commit | 233884131d123432d2e1ad7236ad3c6ef7b2b518 (patch) | |
tree | 7badf8a263468f8cba00a1568b4fc06cf25b17c1 /tests-clar/stash | |
parent | 590fb68be087ed8a60323026dc2501c456ede945 (diff) |
stash: add git_stash_foreach()
Diffstat (limited to 'tests-clar/stash')
-rw-r--r-- | tests-clar/stash/foreach.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/tests-clar/stash/foreach.c b/tests-clar/stash/foreach.c new file mode 100644 index 000000000..808650786 --- /dev/null +++ b/tests-clar/stash/foreach.c @@ -0,0 +1,119 @@ +#include "clar_libgit2.h" +#include "fileops.h" +#include "stash_helpers.h" + +struct callback_data +{ + char **oids; + int invokes; +}; + +static git_repository *repo; +static git_signature *signature; +static git_oid stash_tip_oid; +struct callback_data data; + +#define REPO_NAME "stash" + +void test_stash_foreach__initialize(void) +{ + cl_git_pass(git_signature_new( + &signature, + "nulltoken", + "emeric.fermas@gmail.com", + 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */ + + memset(&data, 0, sizeof(struct callback_data)); +} + +void test_stash_foreach__cleanup(void) +{ + git_signature_free(signature); + git_repository_free(repo); + cl_git_pass(git_futils_rmdir_r(REPO_NAME, NULL, GIT_DIRREMOVAL_FILES_AND_DIRS)); +} + +static int callback_cb( + size_t index, + const char* message, + const git_oid *stash_oid, + void *payload) +{ + int i = 0; + bool found = false; + struct callback_data *data = (struct callback_data *)payload; + + cl_assert_equal_i(0, git_oid_streq(stash_oid, data->oids[data->invokes++])); + + return 0; +} + +void test_stash_foreach__enumerating_a_empty_repository_doesnt_fail(void) +{ + char *oids[] = { NULL }; + + data.oids = oids; + + cl_git_pass(git_repository_init(&repo, REPO_NAME, 0)); + + cl_git_pass(git_stash_foreach(repo, callback_cb, &data)); + + cl_assert_equal_i(0, data.invokes); +} + +void test_stash_foreach__can_enumerate_a_repository(void) +{ + char *oids_default[] = { + "1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL }; + + char *oids_untracked[] = { + "7f89a8b15c878809c5c54d1ff8f8c9674154017b", + "1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL }; + + char *oids_ignored[] = { + "c95599a8fef20a7e57582c6727b1a0d02e0a5828", + "7f89a8b15c878809c5c54d1ff8f8c9674154017b", + "1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL }; + + cl_git_pass(git_repository_init(&repo, REPO_NAME, 0)); + + setup_stash(repo, signature); + + cl_git_pass(git_stash_save( + &stash_tip_oid, + repo, + signature, + NULL, + GIT_STASH_DEFAULT)); + + data.oids = oids_default; + + cl_git_pass(git_stash_foreach(repo, callback_cb, &data)); + cl_assert_equal_i(1, data.invokes); + + data.oids = oids_untracked; + data.invokes = 0; + + cl_git_pass(git_stash_save( + &stash_tip_oid, + repo, + signature, + NULL, + GIT_STASH_INCLUDE_UNTRACKED)); + + cl_git_pass(git_stash_foreach(repo, callback_cb, &data)); + cl_assert_equal_i(2, data.invokes); + + data.oids = oids_ignored; + data.invokes = 0; + + cl_git_pass(git_stash_save( + &stash_tip_oid, + repo, + signature, + NULL, + GIT_STASH_INCLUDE_IGNORED)); + + cl_git_pass(git_stash_foreach(repo, callback_cb, &data)); + cl_assert_equal_i(3, data.invokes); +} |