iterator: test pathlist handling for directories tree_iterator was only working properly for a pathlist containing file paths. In case of directory paths, it didn't match children which contradicts GIT_DIFF_DISABLE_PATHSPEC_MATCH and is different from index_iterator and fs_iterator. As a consequence head-to-index status reporting for a specific directory did not work properly -- all files have been reported as added. Include additional tests.
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
diff --git a/tests/repo/iterator.c b/tests/repo/iterator.c
index df31386..158a6e4 100644
--- a/tests/repo/iterator.c
+++ b/tests/repo/iterator.c
@@ -1371,6 +1371,31 @@ void test_repo_iterator__indexfilelist_icase(void)
git_vector_free(&filelist);
}
+void test_repo_iterator__indexfilelist_with_directory(void)
+{
+ git_iterator *i;
+ git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
+ git_vector filelist;
+ git_tree *tree;
+ git_index *index;
+
+ g_repo = cl_git_sandbox_init("testrepo2");
+ git_repository_head_tree(&tree, g_repo);
+
+ cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
+ cl_git_pass(git_vector_insert(&filelist, "subdir"));
+
+ i_opts.pathlist.strings = (char **)filelist.contents;
+ i_opts.pathlist.count = filelist.length;
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
+ expect_iterator_items(i, 4, NULL, 4, NULL);
+ git_iterator_free(i);
+ git_index_free(index);
+ git_vector_free(&filelist);
+}
+
void test_repo_iterator__workdir_pathlist(void)
{
git_iterator *i;
@@ -2016,6 +2041,27 @@ void test_repo_iterator__workdir_advance_over_with_pathlist(void)
git_vector_free(&pathlist);
}
+void test_repo_iterator__workdir_filelist_with_directory(void)
+{
+ git_iterator *i;
+ git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
+ git_vector filelist;
+
+ cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
+ cl_git_pass(git_vector_insert(&filelist, "subdir/"));
+
+ g_repo = cl_git_sandbox_init("testrepo2");
+
+ i_opts.pathlist.strings = (char **)filelist.contents;
+ i_opts.pathlist.count = filelist.length;
+
+ cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
+ expect_iterator_items(i, 4, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ git_vector_free(&filelist);
+}
+
void test_repo_iterator__treefilelist(void)
{
git_iterator *i;
@@ -2129,3 +2175,94 @@ void test_repo_iterator__treefilelist_icase(void)
git_vector_free(&filelist);
git_tree_free(tree);
}
+
+void test_repo_iterator__tree_filelist_with_directory(void)
+{
+ git_iterator *i;
+ git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
+ git_vector filelist;
+ git_tree *tree;
+
+ g_repo = cl_git_sandbox_init("testrepo2");
+ git_repository_head_tree(&tree, g_repo);
+
+ cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
+ cl_git_pass(git_vector_insert(&filelist, "subdir"));
+
+ i_opts.pathlist.strings = (char **)filelist.contents;
+ i_opts.pathlist.count = filelist.length;
+
+ cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
+ expect_iterator_items(i, 4, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ git_vector_clear(&filelist);
+ cl_git_pass(git_vector_insert(&filelist, "subdir/"));
+
+ i_opts.pathlist.strings = (char **)filelist.contents;
+ i_opts.pathlist.count = filelist.length;
+
+ cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
+ expect_iterator_items(i, 4, NULL, 4, NULL);
+ git_iterator_free(i);
+
+ git_vector_clear(&filelist);
+ cl_git_pass(git_vector_insert(&filelist, "subdir/subdir2"));
+
+ i_opts.pathlist.strings = (char **)filelist.contents;
+ i_opts.pathlist.count = filelist.length;
+
+ cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
+ expect_iterator_items(i, 2, NULL, 2, NULL);
+ git_iterator_free(i);
+
+ git_vector_free(&filelist);
+}
+
+void test_repo_iterator__tree_filelist_with_directory_include_tree_nodes(void)
+{
+ git_iterator *i;
+ git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
+ git_vector filelist;
+ git_tree *tree;
+
+ g_repo = cl_git_sandbox_init("testrepo2");
+ git_repository_head_tree(&tree, g_repo);
+
+ cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
+ cl_git_pass(git_vector_insert(&filelist, "subdir"));
+
+ i_opts.flags |= GIT_ITERATOR_INCLUDE_TREES;
+ i_opts.pathlist.strings = (char **)filelist.contents;
+ i_opts.pathlist.count = filelist.length;
+
+ cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
+ expect_iterator_items(i, 6, NULL, 6, NULL);
+ git_iterator_free(i);
+
+ git_vector_free(&filelist);
+}
+
+void test_repo_iterator__tree_filelist_no_match(void)
+{
+ git_iterator *i;
+ git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
+ git_vector filelist;
+ git_tree *tree;
+ const git_index_entry *entry;
+
+ g_repo = cl_git_sandbox_init("testrepo2");
+ git_repository_head_tree(&tree, g_repo);
+
+ cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
+ cl_git_pass(git_vector_insert(&filelist, "nonexistent/"));
+
+ i_opts.pathlist.strings = (char **)filelist.contents;
+ i_opts.pathlist.count = filelist.length;
+
+ cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
+ cl_assert_equal_i(GIT_ITEROVER, git_iterator_current(&entry, i));
+
+ git_vector_free(&filelist);
+}
+
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index 6b82378..d1117f4 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -1146,3 +1146,85 @@ void test_status_worktree__update_index_with_symlink_doesnt_change_mode(void)
git_reference_free(head);
}
+static const char *testrepo2_subdir_paths[] = {
+ "subdir/README",
+ "subdir/new.txt",
+ "subdir/subdir2/README",
+ "subdir/subdir2/new.txt",
+};
+
+static const char *testrepo2_subdir_paths_icase[] = {
+ "subdir/new.txt",
+ "subdir/README",
+ "subdir/subdir2/new.txt",
+ "subdir/subdir2/README"
+};
+
+void test_status_worktree__with_directory_in_pathlist(void)
+{
+ git_repository *repo = cl_git_sandbox_init("testrepo2");
+ git_index *index;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ git_status_list *statuslist;
+ const git_status_entry *status;
+ size_t i, entrycount;
+ bool native_ignore_case;
+
+ cl_git_pass(git_repository_index(&index, repo));
+ native_ignore_case =
+ (git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0;
+ git_index_free(index);
+
+ opts.pathspec.count = 1;
+ opts.pathspec.strings = malloc(opts.pathspec.count * sizeof(char *));
+ opts.pathspec.strings[0] = "subdir";
+ opts.flags =
+ GIT_STATUS_OPT_DEFAULTS |
+ GIT_STATUS_OPT_INCLUDE_UNMODIFIED |
+ GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH;
+
+ opts.show = GIT_STATUS_SHOW_WORKDIR_ONLY;
+ git_status_list_new(&statuslist, repo, &opts);
+
+ entrycount = git_status_list_entrycount(statuslist);
+ cl_assert_equal_i(4, entrycount);
+
+ for (i = 0; i < entrycount; i++) {
+ status = git_status_byindex(statuslist, i);
+ cl_assert_equal_i(0, status->status);
+ cl_assert_equal_s(native_ignore_case ?
+ testrepo2_subdir_paths_icase[i] :
+ testrepo2_subdir_paths[i],
+ status->index_to_workdir->old_file.path);
+ }
+
+ opts.show = GIT_STATUS_SHOW_INDEX_ONLY;
+ git_status_list_new(&statuslist, repo, &opts);
+
+ entrycount = git_status_list_entrycount(statuslist);
+ cl_assert_equal_i(4, entrycount);
+
+ for (i = 0; i < entrycount; i++) {
+ status = git_status_byindex(statuslist, i);
+ cl_assert_equal_i(0, status->status);
+ cl_assert_equal_s(native_ignore_case ?
+ testrepo2_subdir_paths_icase[i] :
+ testrepo2_subdir_paths[i],
+ status->head_to_index->old_file.path);
+ }
+
+ opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
+ git_status_list_new(&statuslist, repo, &opts);
+
+ entrycount = git_status_list_entrycount(statuslist);
+ cl_assert_equal_i(4, entrycount);
+
+ for (i = 0; i < entrycount; i++) {
+ status = git_status_byindex(statuslist, i);
+ cl_assert_equal_i(0, status->status);
+ cl_assert_equal_s(native_ignore_case ?
+ testrepo2_subdir_paths_icase[i] :
+ testrepo2_subdir_paths[i],
+ status->index_to_workdir->old_file.path);
+ }
+}