diff options
author | Russell Belfer <rb@github.com> | 2013-05-24 22:09:04 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-05-24 22:09:04 +0400 |
commit | 7a5ee3dc923caf2b3b9b5e9b2408340f6ae32d7d (patch) | |
tree | b0bac0291ac788c6771b02e4ed59e970d2c669c7 /tests-clar/attr | |
parent | d20b044961352348855ee82dcc77615f605ac832 (diff) |
Add ~ expansion to global attributes and excludes
This adds ~/ prefix expansion for the value of core.attributesfile
and core.excludesfile, plus it fixes the fact that the attributes
cache was holding on to the string data from the config for a long
time (instead of making its own strdup) which could have caused a
problem if the config was refreshed. Adds a test for the new
expansion capability.
Diffstat (limited to 'tests-clar/attr')
-rw-r--r-- | tests-clar/attr/ignore.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tests-clar/attr/ignore.c b/tests-clar/attr/ignore.c index aa81e9249..8df0eb9de 100644 --- a/tests-clar/attr/ignore.c +++ b/tests-clar/attr/ignore.c @@ -1,6 +1,7 @@ #include "clar_libgit2.h" #include "posix.h" #include "path.h" +#include "fileops.h" static git_repository *g_repo = NULL; @@ -20,7 +21,7 @@ void assert_is_ignored(bool expected, const char *filepath) int is_ignored; cl_git_pass(git_ignore_path_is_ignored(&is_ignored, g_repo, filepath)); - cl_assert_equal_i(expected, is_ignored == 1); + cl_assert_equal_b(expected, is_ignored); } void test_attr_ignore__honor_temporary_rules(void) @@ -46,3 +47,35 @@ void test_attr_ignore__skip_gitignore_directory(void) assert_is_ignored(true, "NewFolder/NewFolder"); assert_is_ignored(true, "NewFolder/NewFolder/File.txt"); } + +void test_attr_ignore__expand_tilde_to_homedir(void) +{ + git_buf path = GIT_BUF_INIT; + git_config *cfg; + + assert_is_ignored(false, "example.global_with_tilde"); + + /* construct fake home with fake global excludes */ + + cl_must_pass(p_mkdir("home", 0777)); + cl_git_pass(git_path_prettify(&path, "home", NULL)); + cl_git_pass(git_libgit2_opts( + GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); + + cl_git_mkfile("home/globalexcludes", "# found me\n*.global_with_tilde\n"); + + cl_git_pass(git_repository_config(&cfg, g_repo)); + cl_git_pass(git_config_set_string(cfg, "core.excludesfile", "~/globalexcludes")); + git_config_free(cfg); + + git_attr_cache_flush(g_repo); /* must reset to pick up change */ + + assert_is_ignored(true, "example.global_with_tilde"); + + cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES)); + + cl_git_pass(git_libgit2_opts( + GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, NULL)); + + git_buf_free(&path); +} |