summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVicent Marti <vicent@github.com>2014-04-16 10:51:25 +0200
committerVicent Marti <vicent@github.com>2014-04-16 10:51:25 +0200
commit37ab5ecc107118d5fa541cb42cc203649e549fd8 (patch)
tree5908575b2522b553cad65adf69a78a9267170c2c /tests
parent0f7aa47dbd16a9111e5dd054014d2f61b9b21211 (diff)
parenta9528b8fdd627e11b9dee099a10fa7697380b3e7 (diff)
downloadlibgit2-37ab5ecc107118d5fa541cb42cc203649e549fd8.tar.gz
Merge pull request #2269 from libgit2/rb/fix-leading-slash-ignores
Fix core.excludesfile named .gitignore
Diffstat (limited to 'tests')
-rw-r--r--tests/attr/ignore.c21
-rw-r--r--tests/clar_libgit2.c21
-rw-r--r--tests/clar_libgit2.h3
-rw-r--r--tests/status/ignore.c56
4 files changed, 89 insertions, 12 deletions
diff --git a/tests/attr/ignore.c b/tests/attr/ignore.c
index 4ed92387c..a83c5bd74 100644
--- a/tests/attr/ignore.c
+++ b/tests/attr/ignore.c
@@ -130,22 +130,18 @@ void test_attr_ignore__skip_gitignore_directory(void)
void test_attr_ignore__expand_tilde_to_homedir(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_buf cleanup = 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_fake_home(&cleanup);
- cl_git_mkfile("home/globalexcludes", "# found me\n*.global_with_tilde\n");
+ /* construct fake home with fake global excludes */
+ cl_git_mkfile("home/globalexclude", "# 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"));
+ cl_git_pass(git_config_set_string(cfg, "core.excludesfile", "~/globalexclude"));
git_config_free(cfg);
git_attr_cache_flush(g_repo); /* must reset to pick up change */
@@ -154,8 +150,9 @@ void test_attr_ignore__expand_tilde_to_homedir(void)
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));
+ cl_fake_home_cleanup(&cleanup);
- git_buf_free(&path);
+ git_attr_cache_flush(g_repo); /* must reset to pick up change */
+
+ assert_is_ignored(false, "example.global_with_tilde");
}
diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c
index 9b062ef78..90e53c5e6 100644
--- a/tests/clar_libgit2.c
+++ b/tests/clar_libgit2.c
@@ -490,3 +490,24 @@ void clar__assert_equal_file(
clar__assert_equal(file, line, "mismatched file length", 1, "%"PRIuZ,
(size_t)expected_bytes, (size_t)total_bytes);
}
+
+void cl_fake_home(git_buf *restore)
+{
+ git_buf path = GIT_BUF_INIT;
+
+ cl_git_pass(git_libgit2_opts(
+ GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, restore));
+
+ 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));
+ git_buf_free(&path);
+}
+
+void cl_fake_home_cleanup(git_buf *restore)
+{
+ cl_git_pass(git_libgit2_opts(
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, restore->ptr));
+ git_buf_free(restore);
+}
diff --git a/tests/clar_libgit2.h b/tests/clar_libgit2.h
index 3de80bfa0..c2489db38 100644
--- a/tests/clar_libgit2.h
+++ b/tests/clar_libgit2.h
@@ -120,4 +120,7 @@ int cl_repo_get_bool(git_repository *repo, const char *cfg);
void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value);
+void cl_fake_home(git_buf *restore);
+void cl_fake_home_cleanup(git_buf *restore);
+
#endif
diff --git a/tests/status/ignore.c b/tests/status/ignore.c
index 1fefcba5f..d6c26a847 100644
--- a/tests/status/ignore.c
+++ b/tests/status/ignore.c
@@ -364,6 +364,62 @@ void test_status_ignore__subdirectories_not_at_root(void)
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
+void test_status_ignore__leading_slash_ignores(void)
+{
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts;
+ git_buf home = GIT_BUF_INIT;
+ static const char *paths_2[] = {
+ "dir/.gitignore",
+ "dir/a/ignore_me",
+ "dir/b/ignore_me",
+ "dir/ignore_me",
+ "ignore_also/file",
+ "ignore_me",
+ "test/.gitignore",
+ "test/ignore_me/and_me/file",
+ "test/ignore_me/file",
+ "test/ignore_me/file2",
+ };
+ static const unsigned int statuses_2[] = {
+ GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW,
+ GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
+ GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW,
+ };
+
+ make_test_data();
+
+ cl_fake_home(&home);
+ cl_git_mkfile("home/.gitignore", "/ignore_me\n");
+ {
+ git_config *cfg;
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_config_set_string(
+ cfg, "core.excludesfile", "~/.gitignore"));
+ git_config_free(cfg);
+ }
+
+ cl_git_rewritefile("empty_standard_repo/.git/info/exclude", "/ignore_also\n");
+ cl_git_rewritefile("empty_standard_repo/dir/.gitignore", "/ignore_me\n");
+ cl_git_rewritefile("empty_standard_repo/test/.gitignore", "/and_me\n");
+
+ memset(&counts, 0x0, sizeof(status_entry_counts));
+ counts.expected_entry_count = 10;
+ counts.expected_paths = paths_2;
+ counts.expected_statuses = statuses_2;
+
+ opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
+
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__normal, &counts));
+
+ cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
+ cl_assert_equal_i(0, counts.wrong_status_flags_count);
+ cl_assert_equal_i(0, counts.wrong_sorted_path);
+
+ cl_fake_home_cleanup(&home);
+}
+
void test_status_ignore__adding_internal_ignores(void)
{
int ignored;