]>
git.proxmox.com Git - libgit2.git/blob - tests-clar/attr/ignore.c
8df0eb9de0e82629a92b7a88ba85f2ff01466aa7
1 #include "clar_libgit2.h"
6 static git_repository
*g_repo
= NULL
;
8 void test_attr_ignore__initialize(void)
10 g_repo
= cl_git_sandbox_init("attr");
13 void test_attr_ignore__cleanup(void)
15 cl_git_sandbox_cleanup();
19 void assert_is_ignored(bool expected
, const char *filepath
)
23 cl_git_pass(git_ignore_path_is_ignored(&is_ignored
, g_repo
, filepath
));
24 cl_assert_equal_b(expected
, is_ignored
);
27 void test_attr_ignore__honor_temporary_rules(void)
29 cl_git_rewritefile("attr/.gitignore", "/NewFolder\n/NewFolder/NewFolder");
31 assert_is_ignored(false, "File.txt");
32 assert_is_ignored(true, "NewFolder");
33 assert_is_ignored(true, "NewFolder/NewFolder");
34 assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
37 void test_attr_ignore__skip_gitignore_directory(void)
39 cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder");
40 p_unlink("attr/.gitignore");
41 cl_assert(!git_path_exists("attr/.gitignore"));
42 p_mkdir("attr/.gitignore", 0777);
43 cl_git_mkfile("attr/.gitignore/garbage.txt", "new_file\n");
45 assert_is_ignored(false, "File.txt");
46 assert_is_ignored(true, "NewFolder");
47 assert_is_ignored(true, "NewFolder/NewFolder");
48 assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
51 void test_attr_ignore__expand_tilde_to_homedir(void)
53 git_buf path
= GIT_BUF_INIT
;
56 assert_is_ignored(false, "example.global_with_tilde");
58 /* construct fake home with fake global excludes */
60 cl_must_pass(p_mkdir("home", 0777));
61 cl_git_pass(git_path_prettify(&path
, "home", NULL
));
62 cl_git_pass(git_libgit2_opts(
63 GIT_OPT_SET_SEARCH_PATH
, GIT_CONFIG_LEVEL_GLOBAL
, path
.ptr
));
65 cl_git_mkfile("home/globalexcludes", "# found me\n*.global_with_tilde\n");
67 cl_git_pass(git_repository_config(&cfg
, g_repo
));
68 cl_git_pass(git_config_set_string(cfg
, "core.excludesfile", "~/globalexcludes"));
71 git_attr_cache_flush(g_repo
); /* must reset to pick up change */
73 assert_is_ignored(true, "example.global_with_tilde");
75 cl_git_pass(git_futils_rmdir_r("home", NULL
, GIT_RMDIR_REMOVE_FILES
));
77 cl_git_pass(git_libgit2_opts(
78 GIT_OPT_SET_SEARCH_PATH
, GIT_CONFIG_LEVEL_GLOBAL
, NULL
));