iterator: workdir tests with submodules Ensure that when specifying start/end paths, or pathlists, that we deal correctly with submodules.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
diff --git a/tests/repo/iterator.c b/tests/repo/iterator.c
index a8e668d..c498679 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;