diff options
author | Edward Thomson <ethomson@github.com> | 2016-03-16 12:15:55 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2016-03-23 17:16:37 -0400 |
commit | 908d8de8c31bc1be909da5825c4bcc16057141a4 (patch) | |
tree | 466720ef5314f5c3cececb1e3e9ec0c4da100473 /tests/repo | |
parent | c3d195f1d9a9ddbf6ac01ce40320ad122426da1f (diff) | |
download | libgit2-908d8de8c31bc1be909da5825c4bcc16057141a4.tar.gz |
iterator: workdir tests with submodules
Ensure that when specifying start/end paths, or pathlists, that we
deal correctly with submodules.
Diffstat (limited to 'tests/repo')
-rw-r--r-- | tests/repo/iterator.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/repo/iterator.c b/tests/repo/iterator.c index a8e668d17..c49867925 100644 --- a/tests/repo/iterator.c +++ b/tests/repo/iterator.c @@ -2,6 +2,7 @@ #include "iterator.h" #include "repository.h" #include "fileops.h" +#include "../submodule/submodule_helpers.h" #include <stdarg.h> static git_repository *g_repo; @@ -1640,6 +1641,85 @@ void test_repo_iterator__workdir_pathlist_with_dirs(void) git_vector_free(&filelist); } +void test_repo_iterator__workdir_bounded_submodules(void) +{ + git_iterator *i; + git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT; + git_vector filelist; + git_index *index; + git_tree *head; + + cl_git_pass(git_vector_init(&filelist, 5, NULL)); + + g_repo = setup_fixture_submod2(); + cl_git_pass(git_repository_index(&index, g_repo)); + cl_git_pass(git_repository_head_tree(&head, g_repo)); + + /* Test that a submodule matches */ + { + const char *expected[] = { "sm_changed_head" }; + size_t expected_len = 1; + + git_vector_clear(&filelist); + cl_git_pass(git_vector_insert(&filelist, "sm_changed_head")); + + i_opts.pathlist.strings = (char **)filelist.contents; + i_opts.pathlist.count = filelist.length; + i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE; + + cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts)); + expect_iterator_items(i, expected_len, expected, expected_len, expected); + git_iterator_free(i); + } + + /* Test that a submodule never matches when suffixed with a '/' */ + { + git_vector_clear(&filelist); + cl_git_pass(git_vector_insert(&filelist, "sm_changed_head/")); + + i_opts.pathlist.strings = (char **)filelist.contents; + i_opts.pathlist.count = filelist.length; + i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE; + + cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts)); + cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i)); + git_iterator_free(i); + } + + /* Test that start/end work with a submodule */ + { + const char *expected[] = { "sm_changed_head", "sm_changed_index" }; + size_t expected_len = 2; + + i_opts.start = "sm_changed_head"; + i_opts.end = "sm_changed_index"; + i_opts.pathlist.strings = NULL; + i_opts.pathlist.count = 0; + i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE; + + cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts)); + expect_iterator_items(i, expected_len, expected, expected_len, expected); + git_iterator_free(i); + } + + /* Test that start and end do not allow '/' suffixes of submodules */ + { + i_opts.start = "sm_changed_head/"; + i_opts.end = "sm_changed_head/"; + i_opts.pathlist.strings = NULL; + i_opts.pathlist.count = 0; + i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE; + + cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts)); + cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i)); + git_iterator_free(i); + } + + git_vector_free(&filelist); + git_index_free(index); + git_tree_free(head); +} + void test_repo_iterator__treefilelist(void) { git_iterator *i; |