summaryrefslogtreecommitdiff
path: root/tests-clar/diff/iterator.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-11-19 16:34:44 -0800
committerRussell Belfer <rb@github.com>2012-11-19 16:34:44 -0800
commitd46b0a04c7733e430a50a9d2df195bec87d5dae6 (patch)
tree3a5afaf7c85f51141f64edf50a6def788e762e81 /tests-clar/diff/iterator.c
parent02df42ddbf87820011aa4ccba9adfde52670e5e2 (diff)
downloadlibgit2-d46b0a04c7733e430a50a9d2df195bec87d5dae6.tar.gz
Improve iterator ignoring .git file
The workdir iterator has always tried to ignore .git files, but it turns out there were some bugs. This makes it more robust at ignoring .git files. This also makes iterators always check ".git" case insensitively regardless of the properties of the system. This will make libgit2 skip ".GIT" and the like. This is different from core git, but on systems with case insensitive but case preserving file systems, allowing ".GIT" to be added is problematic.
Diffstat (limited to 'tests-clar/diff/iterator.c')
-rw-r--r--tests-clar/diff/iterator.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c
index 368903200..1d8396099 100644
--- a/tests-clar/diff/iterator.c
+++ b/tests-clar/diff/iterator.c
@@ -668,3 +668,59 @@ void test_diff_iterator__workdir_1_ranged_empty_2(void)
"status", NULL, "aaaa_empty_before",
0, 0, NULL, NULL);
}
+
+void test_diff_iterator__workdir_builtin_ignores(void)
+{
+ git_repository *repo = cl_git_sandbox_init("attr");
+ git_iterator *i;
+ const git_index_entry *entry;
+ int idx;
+ static struct {
+ const char *path;
+ bool ignored;
+ } expected[] = {
+ { "dir/", true },
+ { "file", false },
+ { "ign", true },
+ { "macro_bad", false },
+ { "macro_test", false },
+ { "root_test1", false },
+ { "root_test2", false },
+ { "root_test3", false },
+ { "root_test4.txt", false },
+ { "sub/", false },
+ { "sub/.gitattributes", false },
+ { "sub/abc", false },
+ { "sub/dir/", true },
+ { "sub/file", false },
+ { "sub/ign/", true },
+ { "sub/sub/", false },
+ { "sub/sub/.gitattributes", false },
+ { "sub/sub/dir", false }, /* file is not actually a dir */
+ { "sub/sub/file", false },
+ { NULL, false }
+ };
+
+ cl_git_pass(p_mkdir("attr/sub/sub/.git", 0777));
+ cl_git_mkfile("attr/sub/.git", "whatever");
+
+ cl_git_pass(
+ git_iterator_for_workdir_range(&i, repo, "dir", "sub/sub/file"));
+ cl_git_pass(git_iterator_current(i, &entry));
+
+ for (idx = 0; entry != NULL; ++idx) {
+ int ignored = git_iterator_current_is_ignored(i);
+
+ cl_assert_equal_s(expected[idx].path, entry->path);
+ cl_assert_(ignored == expected[idx].ignored, expected[idx].path);
+
+ if (!ignored && S_ISDIR(entry->mode))
+ cl_git_pass(git_iterator_advance_into_directory(i, &entry));
+ else
+ cl_git_pass(git_iterator_advance(i, &entry));
+ }
+
+ cl_assert(expected[idx].path == NULL);
+
+ git_iterator_free(i);
+}