diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2018-03-19 19:45:11 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2018-11-03 16:42:53 +0000 |
commit | 2b12dcf6d6971a622abe9730472dc373c0856d98 (patch) | |
tree | 38a8ae6e9f23aee52c97972428910dfa436ba931 /tests/iterator/workdir.c | |
parent | b5ae83bfac53fa3a17435ebf2fc3b79db8055dae (diff) | |
download | libgit2-2b12dcf6d6971a622abe9730472dc373c0856d98.tar.gz |
iterator: optionally hash filesystem iterators
Optionally hash the contents of files encountered in the filesystem or
working directory iterators. This is not expected to be used in
production code paths, but may allow us to simplify some test contexts.
For working directory iterators, apply filters as appropriate, since we
have the context able to do it.
Diffstat (limited to 'tests/iterator/workdir.c')
-rw-r--r-- | tests/iterator/workdir.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c index a16acd722..889fcd6c0 100644 --- a/tests/iterator/workdir.c +++ b/tests/iterator/workdir.c @@ -3,6 +3,7 @@ #include "repository.h" #include "fileops.h" #include "../submodule/submodule_helpers.h" +#include "../merge/merge_helpers.h" #include "iterator_helpers.h" #include <stdarg.h> @@ -1474,3 +1475,48 @@ void test_iterator_workdir__pathlist_with_directory_include_trees(void) git_vector_free(&filelist); } +void test_iterator_workdir__hash_when_requested(void) +{ + git_iterator *iter; + const git_index_entry *entry; + git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; + git_oid expected_id = {{0}}; + size_t i; + + struct merge_index_entry expected[] = { + { 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" }, + { 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" }, + { 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" }, + { 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" }, + { 0100644, "7c7e08f9559d9e1551b91e1cf68f1d0066109add", 0, "oyster.txt" }, + { 0100644, "898d12687fb35be271c27c795a6b32c8b51da79e", 0, "veal.txt" }, + }; + + g_repo = cl_git_sandbox_init("merge-recursive"); + + /* do the iteration normally, ensure there are no hashes */ + cl_git_pass(git_iterator_for_workdir(&iter, g_repo, NULL, NULL, &iter_opts)); + + for (i = 0; i < sizeof(expected) / sizeof(struct merge_index_entry); i++) { + cl_git_pass(git_iterator_advance(&entry, iter)); + + cl_assert_equal_oid(&expected_id, &entry->id); + cl_assert_equal_s(expected[i].path, entry->path); + } + cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&entry, iter)); + git_iterator_free(iter); + + /* do the iteration requesting hashes */ + iter_opts.flags |= GIT_ITERATOR_INCLUDE_HASH; + cl_git_pass(git_iterator_for_workdir(&iter, g_repo, NULL, NULL, &iter_opts)); + + for (i = 0; i < sizeof(expected) / sizeof(struct merge_index_entry); i++) { + cl_git_pass(git_iterator_advance(&entry, iter)); + + cl_git_pass(git_oid_fromstr(&expected_id, expected[i].oid_str)); + cl_assert_equal_oid(&expected_id, &entry->id); + cl_assert_equal_s(expected[i].path, entry->path); + } + cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&entry, iter)); + git_iterator_free(iter); +} |