void test_attr_ignore__expand_tilde_to_homedir(void) { git_config *cfg; assert_is_ignored(false, "example.global_with_tilde"); cl_fake_home(); /* 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", "~/globalexclude")); 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_fake_home_cleanup(NULL); git_attr_cache_flush(g_repo); /* must reset to pick up change */ assert_is_ignored(false, "example.global_with_tilde"); }
void test_status_ignore__1(void) { int ignored; g_repo = cl_git_sandbox_init("attr"); cl_git_rewritefile("attr/.gitignore", "/*.txt\n/dir/\n"); git_attr_cache_flush(g_repo); cl_git_pass(git_status_should_ignore(&ignored, g_repo, "root_test4.txt")); cl_assert(ignored); cl_git_pass(git_status_should_ignore(&ignored, g_repo, "sub/subdir_test2.txt")); cl_assert(!ignored); cl_git_pass(git_status_should_ignore(&ignored, g_repo, "dir")); cl_assert(ignored); cl_git_pass(git_status_should_ignore(&ignored, g_repo, "dir/")); cl_assert(ignored); cl_git_pass(git_status_should_ignore(&ignored, g_repo, "sub/dir")); cl_assert(!ignored); cl_git_pass(git_status_should_ignore(&ignored, g_repo, "sub/dir/")); cl_assert(!ignored); }
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); }
void git_repository__cleanup(git_repository *repo) { assert(repo); git_cache_clear(&repo->objects); git_attr_cache_flush(repo); git_submodule_cache_free(repo); set_config(repo, NULL); set_index(repo, NULL); set_odb(repo, NULL); set_refdb(repo, NULL); }
void test_status_ignore__1(void) { g_repo = cl_git_sandbox_init("attr"); cl_git_rewritefile("attr/.gitignore", "/*.txt\n/dir/\n"); git_attr_cache_flush(g_repo); assert_is_ignored("root_test4.txt"); refute_is_ignored("sub/subdir_test2.txt"); assert_is_ignored("dir"); assert_is_ignored("dir/"); refute_is_ignored("sub/dir"); refute_is_ignored("sub/dir/"); }
void git_repository_free(git_repository *repo) { if (repo == NULL) return; git_cache_free(&repo->objects); git_repository__refcache_free(&repo->references); git_attr_cache_flush(repo); git_submodule_config_free(repo); git__free(repo->path_repository); git__free(repo->workdir); drop_config(repo); drop_index(repo); drop_odb(repo); git__free(repo); }
void test_object_blob_filter__to_odb(void) { git_filter_list *fl = NULL; git_config *cfg; int i; git_blob *blob; git_buf out = GIT_BUF_INIT, zeroed; cl_git_pass(git_repository_config(&cfg, g_repo)); cl_assert(cfg); git_attr_cache_flush(g_repo); cl_git_append2file("empty_standard_repo/.gitattributes", "*.txt text\n"); cl_git_pass(git_filter_list_load( &fl, g_repo, NULL, "filename.txt", GIT_FILTER_TO_ODB, 0)); cl_assert(fl != NULL); for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) { cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i])); /* try once with allocated blob */ cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob)); cl_assert_equal_sz(g_crlf_filtered[i].size, out.size); cl_assert_equal_i( 0, memcmp(out.ptr, g_crlf_filtered[i].ptr, out.size)); /* try again with zeroed blob */ memset(&zeroed, 0, sizeof(zeroed)); cl_git_pass(git_filter_list_apply_to_blob(&zeroed, fl, blob)); cl_assert_equal_sz(g_crlf_filtered[i].size, zeroed.size); cl_assert_equal_i( 0, memcmp(zeroed.ptr, g_crlf_filtered[i].ptr, zeroed.size)); git_buf_free(&zeroed); git_blob_free(blob); } git_filter_list_free(fl); git_buf_free(&out); git_config_free(cfg); }