Example #1
0
/* Ensure that the .gitignore in the subdirectory only affects
 * items in the subdirectory. */
void test_attr_ignore__gitignore_in_subdir(void)
{
	cl_git_rmfile("attr/.gitignore");

	cl_must_pass(p_mkdir("attr/dir1", 0777));
	cl_must_pass(p_mkdir("attr/dir1/dir2", 0777));
	cl_must_pass(p_mkdir("attr/dir1/dir2/dir3", 0777));

	cl_git_mkfile("attr/dir1/dir2/dir3/.gitignore", "dir1/\ndir1/subdir/");

	assert_is_ignored(false, "dir1/file");
	assert_is_ignored(false, "dir1/dir2/file");
	assert_is_ignored(false, "dir1/dir2/dir3/file");
	assert_is_ignored(true,  "dir1/dir2/dir3/dir1/file");
	assert_is_ignored(true,  "dir1/dir2/dir3/dir1/subdir/foo");

	if (cl_repo_get_bool(g_repo, "core.ignorecase")) {
		cl_git_mkfile("attr/dir1/dir2/dir3/.gitignore", "DiR1/\nDiR1/subdir/\n");

		assert_is_ignored(false, "dir1/file");
		assert_is_ignored(false, "dir1/dir2/file");
		assert_is_ignored(false, "dir1/dir2/dir3/file");
		assert_is_ignored(true,  "dir1/dir2/dir3/dir1/file");
		assert_is_ignored(true,  "dir1/dir2/dir3/dir1/subdir/foo");
	}
}
Example #2
0
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");
}
Example #3
0
void test_status_ignore__subdir_ignore_everything_except_certain_files(void)
{
	static const char *test_files[] = {
		"empty_standard_repo/project/README.md",
		"empty_standard_repo/project/some_file",
		"empty_standard_repo/project/src/main.c",
		"empty_standard_repo/project/src/foo/foo.c",
		"empty_standard_repo/project/dist/foo.o",
		"empty_standard_repo/project/dist/main.o",
		NULL
	};

	make_test_data("empty_standard_repo", test_files);
	cl_git_mkfile(
		"empty_standard_repo/project/.gitignore",
		"/*\n"
		"!/src\n"
		"!README.md\n");

	assert_is_ignored("project/some_file");
	assert_is_ignored("project/dist/foo.o");
	assert_is_ignored("project/dist/main.o");

	refute_is_ignored("project/README.md");
	refute_is_ignored("project/src/foo.c");
	refute_is_ignored("project/src/foo/foo.c");
}
Example #4
0
void test_status_ignore__adding_internal_ignores(void)
{
	g_repo = cl_git_sandbox_init("empty_standard_repo");

	refute_is_ignored("one.txt");
	refute_is_ignored("two.bar");

	cl_git_pass(git_ignore_add_rule(g_repo, "*.nomatch\n"));

	refute_is_ignored("one.txt");
	refute_is_ignored("two.bar");

	cl_git_pass(git_ignore_add_rule(g_repo, "*.txt\n"));

	assert_is_ignored("one.txt");
	refute_is_ignored("two.bar");

	cl_git_pass(git_ignore_add_rule(g_repo, "*.bar\n"));

	assert_is_ignored("one.txt");
	assert_is_ignored("two.bar");

	cl_git_pass(git_ignore_clear_internal_rules(g_repo));

	refute_is_ignored("one.txt");
	refute_is_ignored("two.bar");

	cl_git_pass(git_ignore_add_rule(
		g_repo, "multiple\n*.rules\n# comment line\n*.bar\n"));

	refute_is_ignored("one.txt");
	assert_is_ignored("two.bar");
}
Example #5
0
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);
}
Example #6
0
void test_attr_ignore__ignore_root(void)
{
	cl_git_rewritefile("attr/.gitignore", "/\n\n/NewFolder\n/NewFolder/NewFolder");

	assert_is_ignored(false, "File.txt");
	assert_is_ignored(true, "NewFolder");
	assert_is_ignored(true, "NewFolder/NewFolder");
	assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
}
Example #7
0
void test_attr_ignore__honor_temporary_rules(void)
{
	cl_git_rewritefile("attr/.gitignore", "/NewFolder\n/NewFolder/NewFolder");

	assert_is_ignored(false, "File.txt");
	assert_is_ignored(true, "NewFolder");
	assert_is_ignored(true, "NewFolder/NewFolder");
	assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
}
Example #8
0
void test_attr_ignore__symlink_to_outside(void)
{
#ifdef GIT_WIN32
	cl_skip();
#endif

	cl_git_rewritefile("attr/.gitignore", "symlink\n");
	cl_git_mkfile("target", "target");
	cl_git_pass(p_symlink("../target", "attr/symlink"));
	assert_is_ignored(true, "symlink");
	assert_is_ignored(true, "lala/../symlink");
}
Example #9
0
void test_status_ignore__negative_directory_ignores(void)
{
	static const char *test_files[] = {
		"empty_standard_repo/parent/child1/bar.txt",
		"empty_standard_repo/parent/child2/bar.txt",
		"empty_standard_repo/parent/child3/foo.txt",
		"empty_standard_repo/parent/child4/bar.txt",
		"empty_standard_repo/parent/nested/child5/bar.txt",
		"empty_standard_repo/parent/nested/child6/bar.txt",
		"empty_standard_repo/parent/nested/child7/bar.txt",
		"empty_standard_repo/padded_parent/child8/bar.txt",
		NULL
	};

	make_test_data("empty_standard_repo", test_files);
	cl_git_mkfile(
		"empty_standard_repo/.gitignore",
		"foo.txt\n"
		"parent/child1\n"
		"parent/child2\n"
		"parent/child4\n"
		"parent/nested/child5\n"
		"nested/child6\n"
		"nested/child7\n"
		"padded_parent/child8\n"
		/* test simple exact match */
		"!parent/child1\n"
		/* test negating file without negating dir */
		"!parent/child2/bar.txt\n"
		/* test negative pattern on dir with its content
		 * being ignored */
		"!parent/child3\n"
		/* test with partial match at end */
		"!child4\n"
		/* test with partial match with '/' at end */
		"!nested/child5\n"
		/* test with complete match */
		"!nested/child6\n"
		/* test with trailing '/' */
		"!child7/\n"
		/* test with partial dir match */
		"!_parent/child8\n");

	refute_is_ignored("parent/child1/bar.txt");
	assert_is_ignored("parent/child2/bar.txt");
	assert_is_ignored("parent/child3/foo.txt");
	refute_is_ignored("parent/child4/bar.txt");
	assert_is_ignored("parent/nested/child5/bar.txt");
	refute_is_ignored("parent/nested/child6/bar.txt");
	refute_is_ignored("parent/nested/child7/bar.txt");
	assert_is_ignored("padded_parent/child8/bar.txt");
}
Example #10
0
void test_attr_ignore__skip_gitignore_directory(void)
{
	cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder");
	p_unlink("attr/.gitignore");
	cl_assert(!git_path_exists("attr/.gitignore"));
	p_mkdir("attr/.gitignore", 0777);
	cl_git_mkfile("attr/.gitignore/garbage.txt", "new_file\n");

	assert_is_ignored(false, "File.txt");
	assert_is_ignored(true, "NewFolder");
	assert_is_ignored(true, "NewFolder/NewFolder");
	assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
}
Example #11
0
void test_status_ignore__negative_ignores_inside_ignores(void)
{
	static const char *test_files[] = {
		"empty_standard_repo/top/mid/btm/tracked",
		"empty_standard_repo/top/mid/btm/untracked",
		"empty_standard_repo/zoo/bar",
		"empty_standard_repo/zoo/foo/bar",
		NULL
	};

	make_test_data("empty_standard_repo", test_files);
	cl_git_mkfile(
		"empty_standard_repo/.gitignore",
		"top\n"
		"!top/mid/btm\n"
		"zoo/*\n"
		"!zoo/bar\n"
		"!zoo/foo/bar\n");
	add_one_to_index("top/mid/btm/tracked");

	{
		git_status_options opts = GIT_STATUS_OPTIONS_INIT;
		status_entry_counts counts;
		static const char *files[] = {
			".gitignore", "top/mid/btm/tracked", "top/mid/btm/untracked",
			"zoo/bar", "zoo/foo/bar",
		};
		static const unsigned int statuses[] = {
			GIT_STATUS_WT_NEW, GIT_STATUS_INDEX_NEW, GIT_STATUS_IGNORED,
			GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED,
		};

		memset(&counts, 0x0, sizeof(status_entry_counts));
		counts.expected_entry_count = 5;
		counts.expected_paths = files;
		counts.expected_statuses = statuses;
		opts.flags = GIT_STATUS_OPT_DEFAULTS |
			GIT_STATUS_OPT_INCLUDE_IGNORED |
			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);
	}

	assert_is_ignored("top/mid/btm/tracked");
	assert_is_ignored("top/mid/btm/untracked");
	refute_is_ignored("foo/bar");
}
Example #12
0
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/");
}
Example #13
0
void test_status_ignore__subdirectories(void)
{
	status_entry_single st;

	g_repo = cl_git_sandbox_init("empty_standard_repo");

	cl_git_mkfile(
		"empty_standard_repo/ignore_me", "I'm going to be ignored!");

	cl_git_rewritefile("empty_standard_repo/.gitignore", "ignore_me\n");

	memset(&st, 0, sizeof(st));
	cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
	cl_assert_equal_i(2, st.count);
	cl_assert(st.status == GIT_STATUS_IGNORED);

	cl_git_pass(git_status_file(&st.status, g_repo, "ignore_me"));
	cl_assert(st.status == GIT_STATUS_IGNORED);

	assert_is_ignored("ignore_me");

	/* I've changed libgit2 so that the behavior here now differs from
	 * core git but seems to make more sense.  In core git, the following
	 * items are skipped completed, even if --ignored is passed to status.
	 * It you mirror these steps and run "git status -uall --ignored" then
	 * you will not see "test/ignore_me/" in the results.
	 *
	 * However, we had a couple reports of this as a bug, plus there is a
	 * similar circumstance where we were differing for core git when you
	 * used a rooted path for an ignore, so I changed this behavior.
	 */
	cl_git_pass(git_futils_mkdir_r(
		"empty_standard_repo/test/ignore_me", 0775));
	cl_git_mkfile(
		"empty_standard_repo/test/ignore_me/file", "I'm going to be ignored!");
	cl_git_mkfile(
		"empty_standard_repo/test/ignore_me/file2", "Me, too!");

	memset(&st, 0, sizeof(st));
	cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
	cl_assert_equal_i(3, st.count);

	cl_git_pass(git_status_file(&st.status, g_repo, "test/ignore_me/file"));
	cl_assert(st.status == GIT_STATUS_IGNORED);

	assert_is_ignored("test/ignore_me/file");
}
Example #14
0
void test_attr_ignore__subdirectory_gitignore(void)
{
	p_unlink("attr/.gitignore");
	cl_assert(!git_path_exists("attr/.gitignore"));
	cl_git_mkfile(
		"attr/.gitignore",
		"file1\n");
	p_mkdir("attr/dir", 0777);
	cl_git_mkfile(
		"attr/dir/.gitignore",
		"file2/\n");

	assert_is_ignored(true, "file1");
	assert_is_ignored(true, "dir/file1");
	assert_is_ignored(true, "dir/file2/actual_file");  /* in ignored dir */
	assert_is_ignored(false, "dir/file3");
}
Example #15
0
void test_status_ignore__trailing_slash_star(void)
{
	static const char *test_files[] = {
		"empty_standard_repo/file",
		"empty_standard_repo/subdir/file",
		"empty_standard_repo/subdir/sub2/sub3/file",
		NULL
	};

	make_test_data("empty_standard_repo", test_files);
	cl_git_mkfile(
		"empty_standard_repo/subdir/.gitignore", "/**/*\n");

	refute_is_ignored("file");
	assert_is_ignored("subdir/sub2/sub3/file");
	assert_is_ignored("subdir/file");
}
Example #16
0
void test_status_ignore__negative_ignores_without_trailing_slash_inside_ignores(void)
{
	git_status_options status_opts = GIT_STATUS_OPTIONS_INIT;
	git_status_list *list;
	int found_parent_file = 0, found_parent_child1_file = 0, found_parent_child2_file = 0;
	size_t i;
	static const char *test_files[] = {
		"empty_standard_repo/parent/file.txt",
		"empty_standard_repo/parent/force.txt",
		"empty_standard_repo/parent/child1/file.txt",
		"empty_standard_repo/parent/child2/file.txt",
		NULL
	};

	make_test_data("empty_standard_repo", test_files);
	cl_git_mkfile(
		"empty_standard_repo/.gitignore",
		"parent/*\n"
		"!parent/force.txt\n"
		"!parent/child1\n"
		"!parent/child2/\n");

	add_one_to_index("parent/force.txt");

	assert_is_ignored("parent/file.txt");
	refute_is_ignored("parent/force.txt");
	refute_is_ignored("parent/child1/file.txt");
	refute_is_ignored("parent/child2/file.txt");

	status_opts.flags = GIT_STATUS_OPT_DEFAULTS;
	cl_git_pass(git_status_list_new(&list, g_repo, &status_opts));
	for (i = 0; i < git_status_list_entrycount(list); i++) {
		const git_status_entry *entry = git_status_byindex(list, i);

		if (!entry->index_to_workdir)
			continue;

		if (!strcmp("parent/file.txt", entry->index_to_workdir->new_file.path))
			found_parent_file = 1;

		if (!strcmp("parent/force.txt", entry->index_to_workdir->new_file.path))
			found_parent_file = 1;

		if (!strcmp("parent/child1/file.txt", entry->index_to_workdir->new_file.path))
			found_parent_child1_file = 1;

		if (!strcmp("parent/child2/file.txt", entry->index_to_workdir->new_file.path))
			found_parent_child2_file = 1;
	}
	git_status_list_free(list);

	cl_assert(found_parent_file);
	cl_assert(found_parent_child1_file);
	cl_assert(found_parent_child2_file);
}
Example #17
0
void test_status_ignore__add_internal_as_first_thing(void)
{
	const char *add_me = "\n#################\n## Eclipse\n#################\n\n*.pydevproject\n.project\n.metadata\nbin/\ntmp/\n*.tmp\n\n";

	g_repo = cl_git_sandbox_init("empty_standard_repo");

	cl_git_pass(git_ignore_add_rule(g_repo, add_me));

	assert_is_ignored("one.tmp");
	refute_is_ignored("two.bar");
}
Example #18
0
void test_attr_ignore__more_starstar_cases(void)
{
	cl_must_pass(p_unlink("attr/.gitignore"));
	cl_git_mkfile(
		"attr/dir/.gitignore",
		"sub/**/*.html\n");

	assert_is_ignored(false, "aaa.html");
	assert_is_ignored(false, "dir");
	assert_is_ignored(false, "dir/sub");
	assert_is_ignored(true,  "dir/sub/sub2/aaa.html");
	assert_is_ignored(true,  "dir/sub/aaa.html");
	assert_is_ignored(false, "dir/aaa.html");
	assert_is_ignored(false, "sub");
	assert_is_ignored(false, "sub/aaa.html");
	assert_is_ignored(false, "sub/sub2/aaa.html");
}
Example #19
0
void test_status_ignore__unignore_entry_in_ignored_dir(void)
{
	static const char *test_files[] = {
		"empty_standard_repo/bar.txt",
		"empty_standard_repo/parent/bar.txt",
		"empty_standard_repo/parent/child/bar.txt",
		"empty_standard_repo/nested/parent/child/bar.txt",
		NULL
	};

	make_test_data("empty_standard_repo", test_files);
	cl_git_mkfile(
		"empty_standard_repo/.gitignore",
		"bar.txt\n"
		"!parent/child/bar.txt\n");

	assert_is_ignored("bar.txt");
	assert_is_ignored("parent/bar.txt");
	refute_is_ignored("parent/child/bar.txt");
	assert_is_ignored("nested/parent/child/bar.txt");
}
Example #20
0
void test_status_ignore__internal_ignores_inside_deep_paths(void)
{
	const char *add_me = "Debug\nthis/is/deep\npatterned*/dir\n";

	g_repo = cl_git_sandbox_init("empty_standard_repo");

	cl_git_pass(git_ignore_add_rule(g_repo, add_me));

	assert_is_ignored("Debug");
	assert_is_ignored("and/Debug");
	assert_is_ignored("really/Debug/this/file");
	assert_is_ignored("Debug/what/I/say");

	refute_is_ignored("and/NoDebug");
	refute_is_ignored("NoDebug/this");
	refute_is_ignored("please/NoDebug/this");

	assert_is_ignored("this/is/deep");
	/* pattern containing slash gets FNM_PATHNAME so all slashes must match */
	refute_is_ignored("and/this/is/deep");
	assert_is_ignored("this/is/deep/too");
	/* pattern containing slash gets FNM_PATHNAME so all slashes must match */
	refute_is_ignored("but/this/is/deep/and/ignored");

	refute_is_ignored("this/is/not/deep");
	refute_is_ignored("is/this/not/as/deep");
	refute_is_ignored("this/is/deepish");
	refute_is_ignored("xthis/is/deep");
}
Example #21
0
/* Ensure that files do not match folder cases */
void test_attr_ignore__dont_ignore_files_for_folder(void)
{
	cl_git_rmfile("attr/.gitignore");

	cl_git_mkfile("attr/dir/.gitignore", "test/\n");

	/* Create "test" as a file; ensure it is not ignored. */
	cl_git_mkfile("attr/dir/test", "This is a file.");

	assert_is_ignored(false, "dir/test");
	if (cl_repo_get_bool(g_repo, "core.ignorecase"))
		assert_is_ignored(false, "dir/TeSt");

	/* Create "test" as a directory; ensure it is ignored. */
	cl_git_rmfile("attr/dir/test");
	cl_must_pass(p_mkdir("attr/dir/test", 0777));

	assert_is_ignored(true, "dir/test");
	if (cl_repo_get_bool(g_repo, "core.ignorecase"))
		assert_is_ignored(true, "dir/TeSt");

	/* Remove "test" entirely; ensure it is not ignored.
	 * (As it doesn't exist, it is not a directory.)
	 */
	cl_must_pass(p_rmdir("attr/dir/test"));

	assert_is_ignored(false, "dir/test");
	if (cl_repo_get_bool(g_repo, "core.ignorecase"))
		assert_is_ignored(false, "dir/TeSt");
}
Example #22
0
void test_status_ignore__automatically_ignore_bad_files(void)
{
	g_repo = cl_git_sandbox_init("empty_standard_repo");

	assert_is_ignored(".git");
	assert_is_ignored("this/file/.");
	assert_is_ignored("path/../funky");
	refute_is_ignored("path/whatever.c");

	cl_git_pass(git_ignore_add_rule(g_repo, "*.c\n"));

	assert_is_ignored(".git");
	assert_is_ignored("this/file/.");
	assert_is_ignored("path/../funky");
	assert_is_ignored("path/whatever.c");

	cl_git_pass(git_ignore_clear_internal_rules(g_repo));

	assert_is_ignored(".git");
	assert_is_ignored("this/file/.");
	assert_is_ignored("path/../funky");
	refute_is_ignored("path/whatever.c");
}
Example #23
0
void test_status_ignore__subdir_ignore_all_toplevel_dirs_include_files(void)
{
	static const char *test_files[] = {
		"empty_standard_repo/project/README.md",
		"empty_standard_repo/project/src/main.c",
		"empty_standard_repo/project/src/foo/foo.c",
		"empty_standard_repo/project/dist/foo.o",
		"empty_standard_repo/project/dist/main.o",
		NULL
	};

	make_test_data("empty_standard_repo", test_files);
	cl_git_mkfile(
		"empty_standard_repo/project/.gitignore",
		"/*/\n"
		"!/src\n");

	assert_is_ignored("project/dist/foo.o");
	assert_is_ignored("project/dist/main.o");

	refute_is_ignored("project/src/foo.c");
	refute_is_ignored("project/src/foo/foo.c");
	refute_is_ignored("project/README.md");
}
Example #24
0
void test_status_ignore__do_not_unignore_basename_prefix(void)
{
	static const char *test_files[] = {
		"empty_standard_repo/foo_bar.txt",
		NULL
	};

	make_test_data("empty_standard_repo", test_files);
	cl_git_mkfile(
		"empty_standard_repo/.gitignore",
		"foo_bar.txt\n"
		"!bar.txt\n");

	assert_is_ignored("foo_bar.txt");
}
Example #25
0
void test_attr_ignore__full_paths(void)
{
	cl_git_rewritefile("attr/.gitignore", "Folder/*/Contained");

	assert_is_ignored(true, "Folder/Middle/Contained");
	assert_is_ignored(false, "Folder/Middle/More/More/Contained");

	cl_git_rewritefile("attr/.gitignore", "Folder/**/Contained");

	assert_is_ignored(true, "Folder/Middle/Contained");
	assert_is_ignored(true, "Folder/Middle/More/More/Contained");

	cl_git_rewritefile("attr/.gitignore", "Folder/**/Contained/*/Child");

	assert_is_ignored(true, "Folder/Middle/Contained/Happy/Child");
	assert_is_ignored(false, "Folder/Middle/Contained/Not/Happy/Child");
	assert_is_ignored(true, "Folder/Middle/More/More/Contained/Happy/Child");
	assert_is_ignored(false, "Folder/Middle/More/More/Contained/Not/Happy/Child");
}
Example #26
0
void test_status_ignore__empty_repo_with_gitignore_rewrite(void)
{
	status_entry_single st;

	g_repo = cl_git_sandbox_init("empty_standard_repo");

	cl_git_mkfile(
		"empty_standard_repo/look-ma.txt", "I'm going to be ignored!");

	memset(&st, 0, sizeof(st));
	cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
	cl_assert(st.count == 1);
	cl_assert(st.status == GIT_STATUS_WT_NEW);

	cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
	cl_assert(st.status == GIT_STATUS_WT_NEW);

	refute_is_ignored("look-ma.txt");

	cl_git_rewritefile("empty_standard_repo/.gitignore", "*.nomatch\n");

	memset(&st, 0, sizeof(st));
	cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
	cl_assert(st.count == 2);
	cl_assert(st.status == GIT_STATUS_WT_NEW);

	cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
	cl_assert(st.status == GIT_STATUS_WT_NEW);

	refute_is_ignored("look-ma.txt");

	cl_git_rewritefile("empty_standard_repo/.gitignore", "*.txt\n");

	memset(&st, 0, sizeof(st));
	cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
	cl_assert(st.count == 2);
	cl_assert(st.status == GIT_STATUS_IGNORED);

	cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
	cl_assert(st.status == GIT_STATUS_IGNORED);

	assert_is_ignored("look-ma.txt");
}
Example #27
0
void test_status_ignore__contained_dir_with_matching_name(void)
{
	static const char *test_files[] = {
		"empty_standard_repo/subdir_match/aaa/subdir_match/file",
		"empty_standard_repo/subdir_match/zzz_ignoreme",
		NULL
	};
	static const char *expected_paths[] = {
		"subdir_match/.gitignore",
		"subdir_match/aaa/subdir_match/file",
		"subdir_match/zzz_ignoreme",
	};
	static const unsigned int expected_statuses[] = {
		GIT_STATUS_WT_NEW,  GIT_STATUS_WT_NEW,  GIT_STATUS_IGNORED
	};
	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
	status_entry_counts counts;

	make_test_data("empty_standard_repo", test_files);
	cl_git_mkfile(
		"empty_standard_repo/subdir_match/.gitignore", "*_ignoreme\n");

	refute_is_ignored("subdir_match/aaa/subdir_match/file");
	assert_is_ignored("subdir_match/zzz_ignoreme");

	memset(&counts, 0x0, sizeof(status_entry_counts));
	counts.expected_entry_count = 3;
	counts.expected_paths = expected_paths;
	counts.expected_statuses = expected_statuses;

	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);
}
Example #28
0
void test_status_ignore__negative_ignores_in_slash_star(void)
{
	git_status_options status_opts = GIT_STATUS_OPTIONS_INIT;
	git_status_list *list;
	int found_look_ma = 0, found_what_about = 0;
	size_t i;
	static const char *test_files[] = {
		"empty_standard_repo/bin/look-ma.txt",
		"empty_standard_repo/bin/what-about-me.txt",
		NULL
	};

	make_test_data("empty_standard_repo", test_files);
	cl_git_mkfile(
		"empty_standard_repo/.gitignore",
		"bin/*\n"
		"!bin/w*\n");

	assert_is_ignored("bin/look-ma.txt");
	refute_is_ignored("bin/what-about-me.txt");

	status_opts.flags = GIT_STATUS_OPT_DEFAULTS;
	cl_git_pass(git_status_list_new(&list, g_repo, &status_opts));
	for (i = 0; i < git_status_list_entrycount(list); i++) {
		const git_status_entry *entry = git_status_byindex(list, i);

		if (!strcmp("bin/look-ma.txt", entry->index_to_workdir->new_file.path))
			found_look_ma = 1;

		if (!strcmp("bin/what-about-me.txt", entry->index_to_workdir->new_file.path))
			found_what_about = 1;
	}
	git_status_list_free(list);

	cl_assert(found_look_ma);
	cl_assert(found_what_about);
}
Example #29
0
void test_attr_ignore__globs_and_path_delimiters(void)
{
	cl_git_rewritefile("attr/.gitignore", "foo/bar/**");
	assert_is_ignored(true, "foo/bar/baz");
	assert_is_ignored(true, "foo/bar/baz/quux");

	cl_git_rewritefile("attr/.gitignore", "_*/");
	assert_is_ignored(true, "sub/_test/a/file");
	assert_is_ignored(false, "test_folder/file");
	assert_is_ignored(true, "_test/file");
	assert_is_ignored(true, "_test/a/file");

	cl_git_rewritefile("attr/.gitignore", "**/_*/");
	assert_is_ignored(true, "sub/_test/a/file");
	assert_is_ignored(false, "test_folder/file");
	assert_is_ignored(true, "_test/file");
	assert_is_ignored(true, "_test/a/file");

	cl_git_rewritefile("attr/.gitignore", "**/_*/foo/bar/*ux");

	assert_is_ignored(true, "sub/_test/foo/bar/qux/file");
	assert_is_ignored(true, "_test/foo/bar/qux/file");
	assert_is_ignored(true, "_test/foo/bar/crux/file");
	assert_is_ignored(false, "_test/foo/bar/code/file");
}
Example #30
0
void test_attr_ignore__leading_stars(void)
{
	cl_git_rewritefile(
		"attr/.gitignore",
		"*/onestar\n"
		"**/twostars\n"
		"*/parent1/kid1/*\n"
		"**/parent2/kid2/*\n");

	assert_is_ignored(true, "dir1/onestar");
	assert_is_ignored(true, "dir1/onestar/child"); /* in ignored dir */
	assert_is_ignored(false, "dir1/dir2/onestar");

	assert_is_ignored(true, "dir1/twostars");
	assert_is_ignored(true, "dir1/twostars/child"); /* in ignored dir */
	assert_is_ignored(true, "dir1/dir2/twostars");
	assert_is_ignored(true, "dir1/dir2/twostars/child"); /* in ignored dir */
	assert_is_ignored(true, "dir1/dir2/dir3/twostars");

	assert_is_ignored(true, "dir1/parent1/kid1/file");
	assert_is_ignored(true, "dir1/parent1/kid1/file/inside/parent");
	assert_is_ignored(false, "dir1/dir2/parent1/kid1/file");
	assert_is_ignored(false, "dir1/parent1/file");
	assert_is_ignored(false, "dir1/kid1/file");

	assert_is_ignored(true, "dir1/parent2/kid2/file");
	assert_is_ignored(true, "dir1/parent2/kid2/file/inside/parent");
	assert_is_ignored(true, "dir1/dir2/parent2/kid2/file");
	assert_is_ignored(true, "dir1/dir2/dir3/parent2/kid2/file");
	assert_is_ignored(false, "dir1/parent2/file");
	assert_is_ignored(false, "dir1/kid2/file");
}