int git_diff_driver_lookup( git_diff_driver **out, git_repository *repo, const char *path) { int error = 0; const char *value; assert(out); *out = NULL; if (!repo || !path || !strlen(path)) /* just use the auto value */; else if ((error = git_attr_get(&value, repo, 0, path, "diff")) < 0) /* return error below */; else if (GIT_ATTR_UNSPECIFIED(value)) /* just use the auto value */; else if (GIT_ATTR_FALSE(value)) *out = &global_drivers[DIFF_DRIVER_BINARY]; else if (GIT_ATTR_TRUE(value)) *out = &global_drivers[DIFF_DRIVER_TEXT]; /* otherwise look for driver information in config and build driver */ else if ((error = git_diff_driver_load(out, repo, value)) < 0) { if (error == GIT_ENOTFOUND) { error = 0; giterr_clear(); } } if (!*out) *out = &global_drivers[DIFF_DRIVER_AUTO]; return error; }
void test_attr_repo__manpage_example(void) { const char *value; cl_git_pass(git_attr_get(g_repo, "sub/abc", "foo", &value)); cl_assert(value == GIT_ATTR_TRUE); cl_git_pass(git_attr_get(g_repo, "sub/abc", "bar", &value)); cl_assert(value == NULL); cl_git_pass(git_attr_get(g_repo, "sub/abc", "baz", &value)); cl_assert(value == GIT_ATTR_FALSE); cl_git_pass(git_attr_get(g_repo, "sub/abc", "merge", &value)); cl_assert_strequal("filfre", value); cl_git_pass(git_attr_get(g_repo, "sub/abc", "frotz", &value)); cl_assert(value == NULL); }
void test_attr_repo__manpage_example(void) { const char *value; cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "foo")); cl_assert(GIT_ATTR_TRUE(value)); cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "bar")); cl_assert(GIT_ATTR_UNSPECIFIED(value)); cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "baz")); cl_assert(GIT_ATTR_FALSE(value)); cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "merge")); cl_assert_equal_s("filfre", value); cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "frotz")); cl_assert(GIT_ATTR_UNSPECIFIED(value)); }
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_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")); }