void test_attr_repo__get_one(void) { struct attr_expected test_cases[] = { { "root_test1", "repoattr", EXPECT_TRUE, NULL }, { "root_test1", "rootattr", EXPECT_TRUE, NULL }, { "root_test1", "missingattr", EXPECT_UNDEFINED, NULL }, { "root_test1", "subattr", EXPECT_UNDEFINED, NULL }, { "root_test1", "negattr", EXPECT_UNDEFINED, NULL }, { "root_test2", "repoattr", EXPECT_TRUE, NULL }, { "root_test2", "rootattr", EXPECT_FALSE, NULL }, { "root_test2", "missingattr", EXPECT_UNDEFINED, NULL }, { "root_test2", "multiattr", EXPECT_FALSE, NULL }, { "root_test3", "repoattr", EXPECT_TRUE, NULL }, { "root_test3", "rootattr", EXPECT_UNDEFINED, NULL }, { "root_test3", "multiattr", EXPECT_STRING, "3" }, { "root_test3", "multi2", EXPECT_UNDEFINED, NULL }, { "sub/subdir_test1", "repoattr", EXPECT_TRUE, NULL }, { "sub/subdir_test1", "rootattr", EXPECT_TRUE, NULL }, { "sub/subdir_test1", "missingattr", EXPECT_UNDEFINED, NULL }, { "sub/subdir_test1", "subattr", EXPECT_STRING, "yes" }, { "sub/subdir_test1", "negattr", EXPECT_FALSE, NULL }, { "sub/subdir_test1", "another", EXPECT_UNDEFINED, NULL }, { "sub/subdir_test2.txt", "repoattr", EXPECT_TRUE, NULL }, { "sub/subdir_test2.txt", "rootattr", EXPECT_TRUE, NULL }, { "sub/subdir_test2.txt", "missingattr", EXPECT_UNDEFINED, NULL }, { "sub/subdir_test2.txt", "subattr", EXPECT_STRING, "yes" }, { "sub/subdir_test2.txt", "negattr", EXPECT_FALSE, NULL }, { "sub/subdir_test2.txt", "another", EXPECT_STRING, "zero" }, { "sub/subdir_test2.txt", "reposub", EXPECT_TRUE, NULL }, { "sub/sub/subdir.txt", "another", EXPECT_STRING, "one" }, { "sub/sub/subdir.txt", "reposubsub", EXPECT_TRUE, NULL }, { "sub/sub/subdir.txt", "reposub", EXPECT_UNDEFINED, NULL }, { "does-not-exist", "foo", EXPECT_STRING, "yes" }, { "sub/deep/file", "deepdeep", EXPECT_TRUE, NULL }, { "sub/sub/d/no", "test", EXPECT_STRING, "a/b/d/*" }, { "sub/sub/d/yes", "test", EXPECT_UNDEFINED, NULL }, { NULL, NULL, 0, NULL } }, *scan; for (scan = test_cases; scan->path != NULL; scan++) { const char *value; cl_git_pass(git_attr_get(&value, g_repo, 0, scan->path, scan->attr)); attr_check_expected(scan->expected, scan->expected_str, scan->attr, value); } cl_assert(git_attr_cache__is_cached(g_repo, 0, ".git/info/attributes")); cl_assert(git_attr_cache__is_cached(g_repo, 0, ".gitattributes")); cl_assert(git_attr_cache__is_cached(g_repo, 0, "sub/.gitattributes")); }
void test_status_ignore__0(void) { struct { const char *path; int expected; } test_cases[] = { /* pattern "ign" from .gitignore */ { "file", 0 }, { "ign", 1 }, { "sub", 0 }, { "sub/file", 0 }, { "sub/ign", 1 }, { "sub/ign/file", 1 }, { "sub/ign/sub", 1 }, { "sub/ign/sub/file", 1 }, { "sub/sub", 0 }, { "sub/sub/file", 0 }, { "sub/sub/ign", 1 }, { "sub/sub/sub", 0 }, /* pattern "dir/" from .gitignore */ { "dir", 1 }, { "dir/", 1 }, { "sub/dir", 1 }, { "sub/dir/", 1 }, { "sub/dir/file", 1 }, /* contained in ignored parent */ { "sub/sub/dir", 0 }, /* dir is not actually a dir, but a file */ { NULL, 0 } }, *one_test; g_repo = cl_git_sandbox_init("attr"); for (one_test = test_cases; one_test->path != NULL; one_test++) { int ignored; cl_git_pass(git_status_should_ignore(&ignored, g_repo, one_test->path)); cl_assert_(ignored == one_test->expected, one_test->path); } /* confirm that ignore files were cached */ cl_assert(git_attr_cache__is_cached(g_repo, 0, ".git/info/exclude")); cl_assert(git_attr_cache__is_cached(g_repo, 0, ".gitignore")); }
void test_attr_repo__get_one(void) { const char *value; struct { const char *file; const char *attr; const char *expected; } test_cases[] = { { "root_test1", "repoattr", GIT_ATTR_TRUE }, { "root_test1", "rootattr", GIT_ATTR_TRUE }, { "root_test1", "missingattr", NULL }, { "root_test1", "subattr", NULL }, { "root_test1", "negattr", NULL }, { "root_test2", "repoattr", GIT_ATTR_TRUE }, { "root_test2", "rootattr", GIT_ATTR_FALSE }, { "root_test2", "missingattr", NULL }, { "root_test2", "multiattr", GIT_ATTR_FALSE }, { "root_test3", "repoattr", GIT_ATTR_TRUE }, { "root_test3", "rootattr", NULL }, { "root_test3", "multiattr", "3" }, { "root_test3", "multi2", NULL }, { "sub/subdir_test1", "repoattr", GIT_ATTR_TRUE }, { "sub/subdir_test1", "rootattr", GIT_ATTR_TRUE }, { "sub/subdir_test1", "missingattr", NULL }, { "sub/subdir_test1", "subattr", "yes" }, { "sub/subdir_test1", "negattr", GIT_ATTR_FALSE }, { "sub/subdir_test1", "another", NULL }, { "sub/subdir_test2.txt", "repoattr", GIT_ATTR_TRUE }, { "sub/subdir_test2.txt", "rootattr", GIT_ATTR_TRUE }, { "sub/subdir_test2.txt", "missingattr", NULL }, { "sub/subdir_test2.txt", "subattr", "yes" }, { "sub/subdir_test2.txt", "negattr", GIT_ATTR_FALSE }, { "sub/subdir_test2.txt", "another", "zero" }, { "sub/subdir_test2.txt", "reposub", GIT_ATTR_TRUE }, { "sub/sub/subdir.txt", "another", "one" }, { "sub/sub/subdir.txt", "reposubsub", GIT_ATTR_TRUE }, { "sub/sub/subdir.txt", "reposub", NULL }, { "does-not-exist", "foo", "yes" }, { "sub/deep/file", "deepdeep", GIT_ATTR_TRUE }, { NULL, NULL, NULL } }, *scan; for (scan = test_cases; scan->file != NULL; scan++) { git_buf b = GIT_BUF_INIT; git_buf_printf(&b, "%s:%s == expect %s", scan->file, scan->attr, scan->expected); cl_must_pass_( git_attr_get(g_repo, scan->file, scan->attr, &value) == GIT_SUCCESS, b.ptr); git_buf_printf(&b, ", got %s", value); if (scan->expected == NULL || scan->expected == GIT_ATTR_TRUE || scan->expected == GIT_ATTR_FALSE) { cl_assert_(scan->expected == value, b.ptr); } else { cl_assert_strequal(scan->expected, value); } git_buf_free(&b); } cl_git_pass(git_attr_cache__is_cached(g_repo, ".git/info/attributes")); cl_git_pass(git_attr_cache__is_cached(g_repo, ".gitattributes")); cl_git_pass(git_attr_cache__is_cached(g_repo, "sub/.gitattributes")); }