Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/status')
-rw-r--r--tests/status/ignore.c562
-rw-r--r--tests/status/renames.c226
-rw-r--r--tests/status/status_helpers.c13
-rw-r--r--tests/status/status_helpers.h10
-rw-r--r--tests/status/submodules.c311
-rw-r--r--tests/status/worktree.c94
6 files changed, 949 insertions, 267 deletions
diff --git a/tests/status/ignore.c b/tests/status/ignore.c
index acdc8fb58..a4e766fdf 100644
--- a/tests/status/ignore.c
+++ b/tests/status/ignore.c
@@ -16,6 +16,23 @@ void test_status_ignore__cleanup(void)
cl_git_sandbox_cleanup();
}
+static void assert_ignored_(
+ bool expected, const char *filepath, const char *file, int line)
+{
+ int is_ignored = 0;
+ cl_git_pass_(
+ git_status_should_ignore(&is_ignored, g_repo, filepath), file, line);
+ clar__assert(
+ (expected != 0) == (is_ignored != 0),
+ file, line, "expected != is_ignored", filepath, 1);
+}
+#define assert_ignored(expected, filepath) \
+ assert_ignored_(expected, filepath, __FILE__, __LINE__)
+#define assert_is_ignored(filepath) \
+ assert_ignored_(true, filepath, __FILE__, __LINE__)
+#define refute_is_ignored(filepath) \
+ assert_ignored_(false, filepath, __FILE__, __LINE__)
+
void test_status_ignore__0(void)
{
struct {
@@ -47,51 +64,35 @@ void test_status_ignore__0(void)
g_repo = cl_git_sandbox_init("attr");
- for (one_test = test_cases; one_test->path != NULL; one_test++) {
- int ignored;
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, one_test->path));
- cl_assert_(ignored == one_test->expected, one_test->path);
- }
+ for (one_test = test_cases; one_test->path != NULL; one_test++)
+ assert_ignored(one_test->expected, one_test->path);
/* confirm that ignore files were cached */
- cl_assert(git_attr_cache__is_cached(g_repo, 0, ".git/info/exclude"));
- cl_assert(git_attr_cache__is_cached(g_repo, 0, ".gitignore"));
+ cl_assert(git_attr_cache__is_cached(
+ g_repo, GIT_ATTR_FILE__FROM_FILE, ".git/info/exclude"));
+ cl_assert(git_attr_cache__is_cached(
+ g_repo, GIT_ATTR_FILE__FROM_FILE, ".gitignore"));
}
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);
+ 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 test_status_ignore__empty_repo_with_gitignore_rewrite(void)
{
status_entry_single st;
- int ignored;
g_repo = cl_git_sandbox_init("empty_standard_repo");
@@ -106,8 +107,7 @@ void test_status_ignore__empty_repo_with_gitignore_rewrite(void)
cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
cl_assert(st.status == GIT_STATUS_WT_NEW);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "look-ma.txt"));
- cl_assert(!ignored);
+ refute_is_ignored("look-ma.txt");
cl_git_rewritefile("empty_standard_repo/.gitignore", "*.nomatch\n");
@@ -119,8 +119,7 @@ void test_status_ignore__empty_repo_with_gitignore_rewrite(void)
cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
cl_assert(st.status == GIT_STATUS_WT_NEW);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "look-ma.txt"));
- cl_assert(!ignored);
+ refute_is_ignored("look-ma.txt");
cl_git_rewritefile("empty_standard_repo/.gitignore", "*.txt\n");
@@ -132,8 +131,7 @@ void test_status_ignore__empty_repo_with_gitignore_rewrite(void)
cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
cl_assert(st.status == GIT_STATUS_IGNORED);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "look-ma.txt"));
- cl_assert(ignored);
+ assert_is_ignored("look-ma.txt");
}
void test_status_ignore__ignore_pattern_contains_space(void)
@@ -179,7 +177,6 @@ void test_status_ignore__ignore_pattern_ignorecase(void)
void test_status_ignore__subdirectories(void)
{
status_entry_single st;
- int ignored;
g_repo = cl_git_sandbox_init("empty_standard_repo");
@@ -196,8 +193,7 @@ void test_status_ignore__subdirectories(void)
cl_git_pass(git_status_file(&st.status, g_repo, "ignore_me"));
cl_assert(st.status == GIT_STATUS_IGNORED);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "ignore_me"));
- cl_assert(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
@@ -223,11 +219,37 @@ void test_status_ignore__subdirectories(void)
cl_git_pass(git_status_file(&st.status, g_repo, "test/ignore_me/file"));
cl_assert(st.status == GIT_STATUS_IGNORED);
- cl_git_pass(
- git_status_should_ignore(&ignored, g_repo, "test/ignore_me/file"));
- cl_assert(ignored);
+ assert_is_ignored("test/ignore_me/file");
}
+static void make_test_data(const char *reponame, const char **files)
+{
+ const char **scan;
+ size_t repolen = strlen(reponame) + 1;
+
+ g_repo = cl_git_sandbox_init(reponame);
+
+ for (scan = files; *scan != NULL; ++scan) {
+ cl_git_pass(git_futils_mkdir(
+ *scan + repolen, reponame,
+ 0777, GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST));
+ cl_git_mkfile(*scan, "contents");
+ }
+}
+
+static const char *test_repo_1 = "empty_standard_repo";
+static const char *test_files_1[] = {
+ "empty_standard_repo/dir/a/ignore_me",
+ "empty_standard_repo/dir/b/ignore_me",
+ "empty_standard_repo/dir/ignore_me",
+ "empty_standard_repo/ignore_also/file",
+ "empty_standard_repo/ignore_me",
+ "empty_standard_repo/test/ignore_me/file",
+ "empty_standard_repo/test/ignore_me/file2",
+ "empty_standard_repo/test/ignore_me/and_me/file",
+ NULL
+};
+
void test_status_ignore__subdirectories_recursion(void)
{
/* Let's try again with recursing into ignored dirs turned on */
@@ -235,6 +257,9 @@ void test_status_ignore__subdirectories_recursion(void)
status_entry_counts counts;
static const char *paths_r[] = {
".gitignore",
+ "dir/a/ignore_me",
+ "dir/b/ignore_me",
+ "dir/ignore_me",
"ignore_also/file",
"ignore_me",
"test/ignore_me/and_me/file",
@@ -242,49 +267,30 @@ void test_status_ignore__subdirectories_recursion(void)
"test/ignore_me/file2",
};
static const unsigned int statuses_r[] = {
- GIT_STATUS_WT_NEW,
- GIT_STATUS_IGNORED,
- GIT_STATUS_IGNORED,
- GIT_STATUS_IGNORED,
- GIT_STATUS_IGNORED,
- GIT_STATUS_IGNORED,
+ GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
+ GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
+ GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
};
static const char *paths_nr[] = {
".gitignore",
+ "dir/a/ignore_me",
+ "dir/b/ignore_me",
+ "dir/ignore_me",
"ignore_also/",
"ignore_me",
"test/ignore_me/",
};
static const unsigned int statuses_nr[] = {
GIT_STATUS_WT_NEW,
- GIT_STATUS_IGNORED,
- GIT_STATUS_IGNORED,
- GIT_STATUS_IGNORED,
+ GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
+ GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
};
- g_repo = cl_git_sandbox_init("empty_standard_repo");
-
+ make_test_data(test_repo_1, test_files_1);
cl_git_rewritefile("empty_standard_repo/.gitignore", "ignore_me\n/ignore_also\n");
- cl_git_mkfile(
- "empty_standard_repo/ignore_me", "I'm going to be ignored!");
- cl_git_pass(git_futils_mkdir_r(
- "empty_standard_repo/test/ignore_me", NULL, 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!");
- cl_git_pass(git_futils_mkdir_r(
- "empty_standard_repo/test/ignore_me/and_me", NULL, 0775));
- cl_git_mkfile(
- "empty_standard_repo/test/ignore_me/and_me/file", "Deeply ignored");
- cl_git_pass(git_futils_mkdir_r(
- "empty_standard_repo/ignore_also", NULL, 0775));
- cl_git_mkfile(
- "empty_standard_repo/ignore_also/file", "I'm going to be ignored!");
-
memset(&counts, 0x0, sizeof(status_entry_counts));
- counts.expected_entry_count = 6;
+ counts.expected_entry_count = 9;
counts.expected_paths = paths_r;
counts.expected_statuses = statuses_r;
@@ -299,7 +305,7 @@ void test_status_ignore__subdirectories_recursion(void)
memset(&counts, 0x0, sizeof(status_entry_counts));
- counts.expected_entry_count = 4;
+ counts.expected_entry_count = 7;
counts.expected_paths = paths_nr;
counts.expected_statuses = statuses_nr;
@@ -313,151 +319,256 @@ void test_status_ignore__subdirectories_recursion(void)
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
-void test_status_ignore__adding_internal_ignores(void)
+void test_status_ignore__subdirectories_not_at_root(void)
+{
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts;
+ static const char *paths_1[] = {
+ "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_1[] = {
+ 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_IGNORED, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW,
+ };
+
+ make_test_data(test_repo_1, test_files_1);
+ cl_git_rewritefile("empty_standard_repo/dir/.gitignore", "ignore_me\n/ignore_also\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_1;
+ counts.expected_statuses = statuses_1;
+
+ 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);
+}
+
+void test_status_ignore__leading_slash_ignores(void)
+{
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts;
+ 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(test_repo_1, test_files_1);
+
+ cl_fake_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);
+}
+
+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);
+}
+
+void test_status_ignore__trailing_slash_star(void)
{
- int ignored;
+ 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");
+}
+void test_status_ignore__adding_internal_ignores(void)
+{
g_repo = cl_git_sandbox_init("empty_standard_repo");
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
- cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
- cl_assert(!ignored);
+ refute_is_ignored("one.txt");
+ refute_is_ignored("two.bar");
cl_git_pass(git_ignore_add_rule(g_repo, "*.nomatch\n"));
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
- cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
- cl_assert(!ignored);
+ refute_is_ignored("one.txt");
+ refute_is_ignored("two.bar");
cl_git_pass(git_ignore_add_rule(g_repo, "*.txt\n"));
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
- cl_assert(!ignored);
+ assert_is_ignored("one.txt");
+ refute_is_ignored("two.bar");
cl_git_pass(git_ignore_add_rule(g_repo, "*.bar\n"));
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
- cl_assert(ignored);
+ assert_is_ignored("one.txt");
+ assert_is_ignored("two.bar");
cl_git_pass(git_ignore_clear_internal_rules(g_repo));
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
- cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
- cl_assert(!ignored);
+ 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"));
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
- cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
- cl_assert(ignored);
+ refute_is_ignored("one.txt");
+ assert_is_ignored("two.bar");
}
void test_status_ignore__add_internal_as_first_thing(void)
{
- int ignored;
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));
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.tmp"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
- cl_assert(!ignored);
+ assert_is_ignored("one.tmp");
+ refute_is_ignored("two.bar");
}
void test_status_ignore__internal_ignores_inside_deep_paths(void)
{
- int ignored;
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));
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "Debug"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "and/Debug"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "really/Debug/this/file"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "Debug/what/I/say"));
- cl_assert(ignored);
-
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "and/NoDebug"));
- cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "NoDebug/this"));
- cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "please/NoDebug/this"));
- cl_assert(!ignored);
-
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/deep"));
- cl_assert(ignored);
+ 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 */
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "and/this/is/deep"));
- cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/deep/too"));
- cl_assert(ignored);
+ 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 */
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "but/this/is/deep/and/ignored"));
- cl_assert(!ignored);
-
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/not/deep"));
- cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "is/this/not/as/deep"));
- cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/deepish"));
- cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "xthis/is/deep"));
- cl_assert(!ignored);
+ 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");
}
void test_status_ignore__automatically_ignore_bad_files(void)
{
- int ignored;
-
g_repo = cl_git_sandbox_init("empty_standard_repo");
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, ".git"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/file/."));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/../funky"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/whatever.c"));
- cl_assert(!ignored);
+ 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"));
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, ".git"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/file/."));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/../funky"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/whatever.c"));
- cl_assert(ignored);
+ 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));
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, ".git"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/file/."));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/../funky"));
- cl_assert(ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/whatever.c"));
- cl_assert(!ignored);
+ assert_is_ignored(".git");
+ assert_is_ignored("this/file/.");
+ assert_is_ignored("path/../funky");
+ refute_is_ignored("path/whatever.c");
}
void test_status_ignore__filenames_with_special_prefixes_do_not_interfere_with_status_retrieval(void)
@@ -496,7 +607,6 @@ void test_status_ignore__filenames_with_special_prefixes_do_not_interfere_with_s
void test_status_ignore__issue_1766_negated_ignores(void)
{
- int ignored = 0;
unsigned int status;
g_repo = cl_git_sandbox_init("empty_standard_repo");
@@ -508,11 +618,8 @@ void test_status_ignore__issue_1766_negated_ignores(void)
cl_git_mkfile(
"empty_standard_repo/a/ignoreme", "I should be ignored\n");
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "a/.gitignore"));
- cl_assert(!ignored);
-
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "a/ignoreme"));
- cl_assert(ignored);
+ refute_is_ignored("a/.gitignore");
+ assert_is_ignored("a/ignoreme");
cl_git_pass(git_futils_mkdir_r(
"empty_standard_repo/b", NULL, 0775));
@@ -521,18 +628,12 @@ void test_status_ignore__issue_1766_negated_ignores(void)
cl_git_mkfile(
"empty_standard_repo/b/ignoreme", "I should be ignored\n");
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "b/.gitignore"));
- cl_assert(!ignored);
-
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "b/ignoreme"));
- cl_assert(ignored);
+ refute_is_ignored("b/.gitignore");
+ assert_is_ignored("b/ignoreme");
/* shouldn't have changed results from first couple either */
-
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "a/.gitignore"));
- cl_assert(!ignored);
- cl_git_pass(git_status_should_ignore(&ignored, g_repo, "a/ignoreme"));
- cl_assert(ignored);
+ refute_is_ignored("a/.gitignore");
+ assert_is_ignored("a/ignoreme");
/* status should find the two ignore files and nothing else */
@@ -580,3 +681,110 @@ void test_status_ignore__issue_1766_negated_ignores(void)
}
}
+static void add_one_to_index(const char *file)
+{
+ git_index *index;
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_add_bypath(index, file));
+ git_index_free(index);
+}
+
+/* Some further broken scenarios that have been reported */
+void test_status_ignore__more_breakage(void)
+{
+ static const char *test_files[] = {
+ "empty_standard_repo/d1/pfx-d2/d3/d4/d5/tracked",
+ "empty_standard_repo/d1/pfx-d2/d3/d4/d5/untracked",
+ "empty_standard_repo/d1/pfx-d2/d3/d4/untracked",
+ NULL
+ };
+
+ make_test_data("empty_standard_repo", test_files);
+ cl_git_mkfile(
+ "empty_standard_repo/.gitignore",
+ "/d1/pfx-*\n"
+ "!/d1/pfx-d2/\n"
+ "/d1/pfx-d2/*\n"
+ "!/d1/pfx-d2/d3/\n"
+ "/d1/pfx-d2/d3/*\n"
+ "!/d1/pfx-d2/d3/d4/\n");
+ add_one_to_index("d1/pfx-d2/d3/d4/d5/tracked");
+
+ {
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts;
+ static const char *files[] = {
+ ".gitignore",
+ "d1/pfx-d2/d3/d4/d5/tracked",
+ "d1/pfx-d2/d3/d4/d5/untracked",
+ "d1/pfx-d2/d3/d4/untracked",
+ };
+ static const unsigned int statuses[] = {
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_WT_NEW,
+ };
+
+ memset(&counts, 0x0, sizeof(status_entry_counts));
+ counts.expected_entry_count = 4;
+ 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);
+ }
+
+ refute_is_ignored("d1/pfx-d2/d3/d4/d5/tracked");
+ refute_is_ignored("d1/pfx-d2/d3/d4/d5/untracked");
+ refute_is_ignored("d1/pfx-d2/d3/d4/untracked");
+}
+
+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",
+ NULL
+ };
+
+ make_test_data("empty_standard_repo", test_files);
+ cl_git_mkfile(
+ "empty_standard_repo/.gitignore",
+ "top\n!top/mid/btm\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",
+ };
+ static const unsigned int statuses[] = {
+ GIT_STATUS_WT_NEW, GIT_STATUS_INDEX_NEW, GIT_STATUS_WT_NEW,
+ };
+
+ memset(&counts, 0x0, sizeof(status_entry_counts));
+ counts.expected_entry_count = 3;
+ 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);
+ }
+
+ refute_is_ignored("top/mid/btm/tracked");
+ refute_is_ignored("top/mid/btm/untracked");
+}
diff --git a/tests/status/renames.c b/tests/status/renames.c
index 16fd02676..24b8aca2b 100644
--- a/tests/status/renames.c
+++ b/tests/status/renames.c
@@ -20,40 +20,36 @@ void test_status_renames__cleanup(void)
cl_git_sandbox_cleanup();
}
-static void rename_file(git_repository *repo, const char *oldname, const char *newname)
+static void _rename_helper(
+ git_repository *repo, const char *from, const char *to, const char *extra)
{
git_buf oldpath = GIT_BUF_INIT, newpath = GIT_BUF_INIT;
- git_buf_joinpath(&oldpath, git_repository_workdir(repo), oldname);
- git_buf_joinpath(&newpath, git_repository_workdir(repo), newname);
+ cl_git_pass(git_buf_joinpath(
+ &oldpath, git_repository_workdir(repo), from));
+ cl_git_pass(git_buf_joinpath(
+ &newpath, git_repository_workdir(repo), to));
cl_git_pass(p_rename(oldpath.ptr, newpath.ptr));
- git_buf_free(&oldpath);
- git_buf_free(&newpath);
-}
-
-static void rename_and_edit_file(git_repository *repo, const char *oldname, const char *newname)
-{
- git_buf oldpath = GIT_BUF_INIT, newpath = GIT_BUF_INIT;
-
- git_buf_joinpath(&oldpath, git_repository_workdir(repo), oldname);
- git_buf_joinpath(&newpath, git_repository_workdir(repo), newname);
-
- cl_git_pass(p_rename(oldpath.ptr, newpath.ptr));
- cl_git_append2file(newpath.ptr, "Added at the end to keep similarity!");
+ if (extra)
+ cl_git_append2file(newpath.ptr, extra);
git_buf_free(&oldpath);
git_buf_free(&newpath);
}
+#define rename_file(R,O,N) _rename_helper((R), (O), (N), NULL)
+#define rename_and_edit_file(R,O,N) \
+ _rename_helper((R), (O), (N), "Added at the end to keep similarity!")
+
struct status_entry {
git_status_t status;
const char *oldname;
const char *newname;
};
-static void test_status(
+static void check_status(
git_status_list *status_list,
struct status_entry *expected_list,
size_t expected_len)
@@ -61,9 +57,9 @@ static void test_status(
const git_status_entry *actual;
const struct status_entry *expected;
const char *oldname, *newname;
- size_t i;
+ size_t i, files_in_status = git_status_list_entrycount(status_list);
- cl_assert_equal_sz(expected_len, git_status_list_entrycount(status_list));
+ cl_assert_equal_sz(expected_len, files_in_status);
for (i = 0; i < expected_len; i++) {
actual = git_status_byindex(status_list, i);
@@ -82,10 +78,12 @@ static void test_status(
else
cl_assert(expected->oldname == NULL);
- if (newname)
- cl_assert(git__strcmp(newname, expected->newname) == 0);
- else
- cl_assert(expected->newname == NULL);
+ if (actual->status & (GIT_STATUS_INDEX_RENAMED|GIT_STATUS_WT_RENAMED)) {
+ if (newname)
+ cl_assert(git__strcmp(newname, expected->newname) == 0);
+ else
+ cl_assert(expected->newname == NULL);
+ }
}
}
@@ -109,7 +107,7 @@ void test_status_renames__head2index_one(void)
cl_git_pass(git_index_write(index));
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, expected, 1);
+ check_status(statuslist, expected, 1);
git_status_list_free(statuslist);
git_index_free(index);
@@ -149,7 +147,7 @@ void test_status_renames__head2index_two(void)
cl_git_pass(git_index_write(index));
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, expected, 4);
+ check_status(statuslist, expected, 4);
git_status_list_free(statuslist);
git_index_free(index);
@@ -178,7 +176,7 @@ void test_status_renames__head2index_no_rename_from_rewrite(void)
cl_git_pass(git_index_write(index));
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, expected, 2);
+ check_status(statuslist, expected, 2);
git_status_list_free(statuslist);
git_index_free(index);
@@ -208,7 +206,7 @@ void test_status_renames__head2index_rename_from_rewrite(void)
cl_git_pass(git_index_write(index));
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, expected, 2);
+ check_status(statuslist, expected, 2);
git_status_list_free(statuslist);
git_index_free(index);
@@ -228,7 +226,7 @@ void test_status_renames__index2workdir_one(void)
rename_file(g_repo, "ikeepsix.txt", "newname.txt");
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, expected, 1);
+ check_status(statuslist, expected, 1);
git_status_list_free(statuslist);
}
@@ -254,7 +252,7 @@ void test_status_renames__index2workdir_two(void)
rename_and_edit_file(g_repo, "untimely.txt", "bbb.txt");
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, expected, 4);
+ check_status(statuslist, expected, 4);
git_status_list_free(statuslist);
}
@@ -278,7 +276,7 @@ void test_status_renames__index2workdir_rename_from_rewrite(void)
rename_file(g_repo, "_temp_.txt", "sixserving.txt");
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, expected, 2);
+ check_status(statuslist, expected, 2);
git_status_list_free(statuslist);
git_index_free(index);
@@ -309,7 +307,7 @@ void test_status_renames__both_one(void)
rename_file(g_repo, "newname-index.txt", "newname-workdir.txt");
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, expected, 1);
+ check_status(statuslist, expected, 1);
git_status_list_free(statuslist);
git_index_free(index);
@@ -355,7 +353,7 @@ void test_status_renames__both_two(void)
rename_file(g_repo, "untimely-index.txt", "untimely-both.txt");
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, expected, 4);
+ check_status(statuslist, expected, 4);
git_status_list_free(statuslist);
git_index_free(index);
@@ -399,7 +397,7 @@ void test_status_renames__both_rename_from_rewrite(void)
rename_file(g_repo, "_temp_.txt", "sixserving.txt");
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, expected, 3);
+ check_status(statuslist, expected, 3);
git_status_list_free(statuslist);
git_index_free(index);
@@ -440,7 +438,7 @@ void test_status_renames__rewrites_only_for_renames(void)
"This is enough content for the file to be rewritten.\n");
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, expected, 1);
+ check_status(statuslist, expected, 1);
git_status_list_free(statuslist);
git_index_free(index);
@@ -481,7 +479,7 @@ void test_status_renames__both_casechange_one(void)
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, (index_caps & GIT_INDEXCAP_IGNORE_CASE) ?
+ check_status(statuslist, (index_caps & GIT_INDEXCAP_IGNORE_CASE) ?
expected_icase : expected_case, 1);
git_status_list_free(statuslist);
@@ -548,10 +546,166 @@ void test_status_renames__both_casechange_two(void)
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
- test_status(statuslist, (index_caps & GIT_INDEXCAP_IGNORE_CASE) ?
+ check_status(statuslist, (index_caps & GIT_INDEXCAP_IGNORE_CASE) ?
expected_icase : expected_case, 4);
git_status_list_free(statuslist);
git_index_free(index);
}
+
+void test_status_renames__zero_byte_file_does_not_fail(void)
+{
+ git_status_list *statuslist;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+
+ struct status_entry expected[] = {
+ { GIT_STATUS_WT_DELETED, "ikeepsix.txt", "ikeepsix.txt" },
+ { GIT_STATUS_WT_NEW, "zerobyte.txt", "zerobyte.txt" },
+ };
+
+ opts.flags |= GIT_STATUS_OPT_RENAMES_FROM_REWRITES |
+ GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
+ GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR |
+ GIT_STATUS_OPT_INCLUDE_IGNORED |
+ GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS |
+ GIT_STATUS_SHOW_INDEX_AND_WORKDIR |
+ GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
+
+ p_unlink("renames/ikeepsix.txt");
+ cl_git_mkfile("renames/zerobyte.txt", "");
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected, 2);
+ git_status_list_free(statuslist);
+}
+
+#ifdef GIT_USE_ICONV
+static char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D";
+static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
+#endif
+
+void test_status_renames__precomposed_unicode_rename(void)
+{
+#ifdef GIT_USE_ICONV
+ git_status_list *statuslist;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ struct status_entry expected0[] = {
+ { GIT_STATUS_WT_NEW, nfd, NULL },
+ { GIT_STATUS_WT_DELETED, "sixserving.txt", NULL },
+ };
+ struct status_entry expected1[] = {
+ { GIT_STATUS_WT_RENAMED, "sixserving.txt", nfd },
+ };
+ struct status_entry expected2[] = {
+ { GIT_STATUS_WT_DELETED, "sixserving.txt", NULL },
+ { GIT_STATUS_WT_NEW, nfc, NULL },
+ };
+ struct status_entry expected3[] = {
+ { GIT_STATUS_WT_RENAMED, "sixserving.txt", nfc },
+ };
+
+ rename_file(g_repo, "sixserving.txt", nfc);
+
+ opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED;
+
+ cl_repo_set_bool(g_repo, "core.precomposeunicode", false);
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected0, ARRAY_SIZE(expected0));
+ git_status_list_free(statuslist);
+
+ opts.flags |= GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR;
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected1, ARRAY_SIZE(expected1));
+ git_status_list_free(statuslist);
+
+ cl_repo_set_bool(g_repo, "core.precomposeunicode", true);
+
+ opts.flags &= ~GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR;
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected2, ARRAY_SIZE(expected2));
+ git_status_list_free(statuslist);
+
+ opts.flags |= GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR;
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected3, ARRAY_SIZE(expected3));
+ git_status_list_free(statuslist);
+#endif
+}
+
+void test_status_renames__precomposed_unicode_toggle_is_rename(void)
+{
+#ifdef GIT_USE_ICONV
+ git_status_list *statuslist;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ struct status_entry expected0[] = {
+ { GIT_STATUS_INDEX_RENAMED, "ikeepsix.txt", nfd },
+ };
+ struct status_entry expected1[] = {
+ { GIT_STATUS_WT_RENAMED, nfd, nfc },
+ };
+ struct status_entry expected2[] = {
+ { GIT_STATUS_INDEX_RENAMED, nfd, nfc },
+ };
+ struct status_entry expected3[] = {
+ { GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED, nfd, nfd },
+ };
+
+ cl_repo_set_bool(g_repo, "core.precomposeunicode", false);
+ rename_file(g_repo, "ikeepsix.txt", nfd);
+
+ {
+ git_index *index;
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_remove_bypath(index, "ikeepsix.txt"));
+ cl_git_pass(git_index_add_bypath(index, nfd));
+ cl_git_pass(git_index_write(index));
+ git_index_free(index);
+ }
+
+ opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
+ GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR;
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected0, ARRAY_SIZE(expected0));
+ git_status_list_free(statuslist);
+
+ cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "commit nfd");
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ cl_assert_equal_sz(0, git_status_list_entrycount(statuslist));
+ git_status_list_free(statuslist);
+
+ cl_repo_set_bool(g_repo, "core.precomposeunicode", true);
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected1, ARRAY_SIZE(expected1));
+ git_status_list_free(statuslist);
+
+ {
+ git_index *index;
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_remove_bypath(index, nfd));
+ cl_git_pass(git_index_add_bypath(index, nfc));
+ cl_git_pass(git_index_write(index));
+ git_index_free(index);
+ }
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected2, ARRAY_SIZE(expected2));
+ git_status_list_free(statuslist);
+
+ cl_repo_set_bool(g_repo, "core.precomposeunicode", false);
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected3, ARRAY_SIZE(expected3));
+ git_status_list_free(statuslist);
+#endif
+}
+
diff --git a/tests/status/status_helpers.c b/tests/status/status_helpers.c
index 902b65c4f..088279252 100644
--- a/tests/status/status_helpers.c
+++ b/tests/status/status_helpers.c
@@ -9,20 +9,13 @@ int cb_status__normal(
if (counts->debug)
cb_status__print(path, status_flags, NULL);
- if (counts->entry_count >= counts->expected_entry_count) {
+ if (counts->entry_count >= counts->expected_entry_count)
counts->wrong_status_flags_count++;
- goto exit;
- }
-
- if (strcmp(path, counts->expected_paths[counts->entry_count])) {
+ else if (strcmp(path, counts->expected_paths[counts->entry_count]))
counts->wrong_sorted_path++;
- goto exit;
- }
-
- if (status_flags != counts->expected_statuses[counts->entry_count])
+ else if (status_flags != counts->expected_statuses[counts->entry_count])
counts->wrong_status_flags_count++;
-exit:
counts->entry_count++;
return 0;
}
diff --git a/tests/status/status_helpers.h b/tests/status/status_helpers.h
index f1f009e02..242076cc9 100644
--- a/tests/status/status_helpers.h
+++ b/tests/status/status_helpers.h
@@ -8,9 +8,19 @@ typedef struct {
const unsigned int* expected_statuses;
const char** expected_paths;
int expected_entry_count;
+ const char *file;
+ int line;
bool debug;
} status_entry_counts;
+#define status_counts_init(counts, paths, statuses) do { \
+ memset(&(counts), 0, sizeof(counts)); \
+ (counts).expected_statuses = (statuses); \
+ (counts).expected_paths = (paths); \
+ (counts).file = __FILE__; \
+ (counts).line = __LINE__; \
+ } while (0)
+
/* cb_status__normal takes payload of "status_entry_counts *" */
extern int cb_status__normal(
diff --git a/tests/status/submodules.c b/tests/status/submodules.c
index ef2888f7d..63cf73f36 100644
--- a/tests/status/submodules.c
+++ b/tests/status/submodules.c
@@ -1,7 +1,5 @@
#include "clar_libgit2.h"
-#include "buffer.h"
-#include "path.h"
-#include "posix.h"
+#include "fileops.h"
#include "status_helpers.h"
#include "../submodule/submodule_helpers.h"
@@ -29,6 +27,7 @@ void test_status_submodules__api(void)
cl_assert(sm != NULL);
cl_assert_equal_s("testrepo", git_submodule_name(sm));
cl_assert_equal_s("testrepo", git_submodule_path(sm));
+ git_submodule_free(sm);
}
void test_status_submodules__0(void)
@@ -71,8 +70,15 @@ static int cb_status__match(const char *p, unsigned int s, void *payload)
status_entry_counts *counts = payload;
int idx = counts->entry_count++;
- cl_assert_equal_s(counts->expected_paths[idx], p);
- cl_assert(counts->expected_statuses[idx] == s);
+ clar__assert_equal(
+ counts->file, counts->line,
+ "Status path mismatch", 1,
+ "%s", counts->expected_paths[idx], p);
+
+ clar__assert_equal(
+ counts->file, counts->line,
+ "Status code mismatch", 1,
+ "%o", counts->expected_statuses[idx], s);
return 0;
}
@@ -87,13 +93,9 @@ void test_status_submodules__1(void)
cl_assert(git_path_isdir("submodules/testrepo/.git"));
cl_assert(git_path_isfile("submodules/.gitmodules"));
- memset(&counts, 0, sizeof(counts));
- counts.expected_paths = expected_files;
- counts.expected_statuses = expected_status;
+ status_counts_init(counts, expected_files, expected_status);
- cl_git_pass(
- git_status_foreach(g_repo, cb_status__match, &counts)
- );
+ cl_git_pass( git_status_foreach(g_repo, cb_status__match, &counts) );
cl_assert_equal_i(6, counts.entry_count);
}
@@ -136,32 +138,28 @@ void test_status_submodules__moved_head(void)
cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
cl_git_pass(git_submodule_open(&smrepo, sm));
+ git_submodule_free(sm);
/* move submodule HEAD to c47800c7266a2be04c571c04d5a6614691ea99bd */
cl_git_pass(
git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
- cl_git_pass(git_repository_set_head_detached(smrepo, &oid));
+ cl_git_pass(git_repository_set_head_detached(smrepo, &oid, NULL, NULL));
/* first do a normal status, which should now include the submodule */
- memset(&counts, 0, sizeof(counts));
- counts.expected_paths = expected_files_with_sub;
- counts.expected_statuses = expected_status_with_sub;
-
opts.flags = GIT_STATUS_OPT_DEFAULTS;
+ status_counts_init(
+ counts, expected_files_with_sub, expected_status_with_sub);
cl_git_pass(
git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
cl_assert_equal_i(7, counts.entry_count);
/* try again with EXCLUDE_SUBMODULES which should skip it */
- memset(&counts, 0, sizeof(counts));
- counts.expected_paths = expected_files;
- counts.expected_statuses = expected_status;
-
opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
+ status_counts_init(counts, expected_files, expected_status);
cl_git_pass(
git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
cl_assert_equal_i(6, counts.entry_count);
@@ -199,25 +197,282 @@ void test_status_submodules__dirty_workdir_only(void)
/* first do a normal status, which should now include the submodule */
- memset(&counts, 0, sizeof(counts));
- counts.expected_paths = expected_files_with_sub;
- counts.expected_statuses = expected_status_with_sub;
-
opts.flags = GIT_STATUS_OPT_DEFAULTS;
+ status_counts_init(
+ counts, expected_files_with_sub, expected_status_with_sub);
cl_git_pass(
git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
cl_assert_equal_i(7, counts.entry_count);
/* try again with EXCLUDE_SUBMODULES which should skip it */
- memset(&counts, 0, sizeof(counts));
- counts.expected_paths = expected_files;
- counts.expected_statuses = expected_status;
-
opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
+ status_counts_init(counts, expected_files, expected_status);
cl_git_pass(
git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
cl_assert_equal_i(6, counts.entry_count);
}
+
+void test_status_submodules__uninitialized(void)
+{
+ git_repository *cloned_repo;
+ git_status_list *statuslist;
+
+ g_repo = cl_git_sandbox_init("submod2");
+
+ cl_git_pass(git_clone(&cloned_repo, "submod2", "submod2-clone", NULL));
+
+ cl_git_pass(git_status_list_new(&statuslist, cloned_repo, NULL));
+ cl_assert_equal_i(0, git_status_list_entrycount(statuslist));
+
+ git_status_list_free(statuslist);
+ git_repository_free(cloned_repo);
+ cl_git_sandbox_cleanup();
+}
+
+void test_status_submodules__contained_untracked_repo(void)
+{
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts;
+ git_repository *contained;
+ static const char *expected_files_not_ignored[] = {
+ ".gitmodules",
+ "added",
+ "deleted",
+ "modified",
+ "untracked"
+ };
+ static unsigned int expected_status_not_ignored[] = {
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_INDEX_DELETED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_NEW,
+ };
+ static const char *expected_files_with_untracked[] = {
+ ".gitmodules",
+ "added",
+ "deleted",
+ "dir/file.md",
+ "modified",
+ "untracked"
+ };
+ static const char *expected_files_with_untracked_dir[] = {
+ ".gitmodules",
+ "added",
+ "deleted",
+ "dir/",
+ "modified",
+ "untracked"
+ };
+ static unsigned int expected_status_with_untracked[] = {
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_INDEX_DELETED,
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_NEW
+ };
+
+ g_repo = setup_fixture_submodules();
+
+ /* skip empty directory */
+
+ cl_must_pass(p_mkdir("submodules/dir", 0777));
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED;
+
+ status_counts_init(
+ counts, expected_files_not_ignored, expected_status_not_ignored);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(5, counts.entry_count);
+
+ /* still skipping because empty == ignored */
+
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_not_ignored, expected_status_not_ignored);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(5, counts.entry_count);
+
+ /* find non-ignored contents of directory */
+
+ cl_git_mkfile("submodules/dir/file.md", "hello");
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_with_untracked, expected_status_with_untracked);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(6, counts.entry_count);
+
+ /* but skip if all content is ignored */
+
+ cl_git_append2file("submodules/.git/info/exclude", "\n*.md\n\n");
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_not_ignored, expected_status_not_ignored);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(5, counts.entry_count);
+
+ /* same is true if it contains a git link */
+
+ cl_git_mkfile("submodules/dir/.git", "gitlink: ../.git");
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_not_ignored, expected_status_not_ignored);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(5, counts.entry_count);
+
+ /* but if it contains tracked files, it should just show up as a
+ * directory and exclude the files in it
+ */
+
+ cl_git_mkfile("submodules/dir/another_file", "hello");
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_with_untracked_dir,
+ expected_status_with_untracked);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(6, counts.entry_count);
+
+ /* that applies to a git repo with a .git directory too */
+
+ cl_must_pass(p_unlink("submodules/dir/.git"));
+ cl_git_pass(git_repository_init(&contained, "submodules/dir", false));
+ git_repository_free(contained);
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_with_untracked_dir,
+ expected_status_with_untracked);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(6, counts.entry_count);
+
+ /* same result even if we don't recurse into subdirectories */
+
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED;
+
+ status_counts_init(
+ counts, expected_files_with_untracked_dir,
+ expected_status_with_untracked);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(6, counts.entry_count);
+
+ /* and if we remove the untracked file, it goes back to ignored */
+
+ cl_must_pass(p_unlink("submodules/dir/another_file"));
+
+ status_counts_init(
+ counts, expected_files_not_ignored, expected_status_not_ignored);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(5, counts.entry_count);
+}
+
+void test_status_submodules__broken_stuff_that_git_allows(void)
+{
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts;
+ git_repository *contained;
+ static const char *expected_files_with_broken[] = {
+ ".gitmodules",
+ "added",
+ "broken/tracked",
+ "deleted",
+ "ignored",
+ "modified",
+ "untracked"
+ };
+ static unsigned int expected_status_with_broken[] = {
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_INDEX_DELETED,
+ GIT_STATUS_IGNORED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_NEW,
+ };
+
+ g_repo = setup_fixture_submodules();
+
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS |
+ GIT_STATUS_OPT_INCLUDE_IGNORED;
+
+ /* make a directory and stick a tracked item into the index */
+ {
+ git_index *idx;
+ cl_must_pass(p_mkdir("submodules/broken", 0777));
+ cl_git_mkfile("submodules/broken/tracked", "tracked content");
+ cl_git_pass(git_repository_index(&idx, g_repo));
+ cl_git_pass(git_index_add_bypath(idx, "broken/tracked"));
+ cl_git_pass(git_index_write(idx));
+ git_index_free(idx);
+ }
+
+ status_counts_init(
+ counts, expected_files_with_broken, expected_status_with_broken);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(7, counts.entry_count);
+
+ /* directory with tracked items that looks a little bit like a repo */
+
+ cl_must_pass(p_mkdir("submodules/broken/.git", 0777));
+ cl_must_pass(p_mkdir("submodules/broken/.git/info", 0777));
+ cl_git_mkfile("submodules/broken/.git/info/exclude", "# bogus");
+
+ status_counts_init(
+ counts, expected_files_with_broken, expected_status_with_broken);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(7, counts.entry_count);
+
+ /* directory with tracked items that is a repo */
+
+ cl_git_pass(git_futils_rmdir_r(
+ "submodules/broken/.git", NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_git_pass(git_repository_init(&contained, "submodules/broken", false));
+ git_repository_free(contained);
+
+ status_counts_init(
+ counts, expected_files_with_broken, expected_status_with_broken);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(7, counts.entry_count);
+
+ /* directory with tracked items that claims to be a submodule but is not */
+
+ cl_git_pass(git_futils_rmdir_r(
+ "submodules/broken/.git", NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_git_append2file("submodules/.gitmodules",
+ "\n[submodule \"broken\"]\n"
+ "\tpath = broken\n"
+ "\turl = https://github.com/not/used\n\n");
+
+ status_counts_init(
+ counts, expected_files_with_broken, expected_status_with_broken);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(7, counts.entry_count);
+}
+
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index 34be6d34c..ca9068aba 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -5,6 +5,8 @@
#include "posix.h"
#include "util.h"
#include "path.h"
+#include "../diff/diff_helpers.h"
+#include "git2/sys/diff.h"
/**
* Cleanup
@@ -40,11 +42,15 @@ void test_status_worktree__whole_repository(void)
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
-void assert_show(const int entry_counts, const char *entry_paths[],
- const unsigned int entry_statuses[], git_status_show_t show)
+void assert_show(
+ const int entry_counts,
+ const char *entry_paths[],
+ const unsigned int entry_statuses[],
+ git_repository *repo,
+ git_status_show_t show,
+ unsigned int extra_flags)
{
status_entry_counts counts;
- git_repository *repo = cl_git_sandbox_init("status");
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
memset(&counts, 0x0, sizeof(status_entry_counts));
@@ -52,7 +58,7 @@ void assert_show(const int entry_counts, const char *entry_paths[],
counts.expected_paths = entry_paths;
counts.expected_statuses = entry_statuses;
- opts.flags = GIT_STATUS_OPT_DEFAULTS;
+ opts.flags = GIT_STATUS_OPT_DEFAULTS | extra_flags;
opts.show = show;
cl_git_pass(
@@ -67,19 +73,19 @@ void assert_show(const int entry_counts, const char *entry_paths[],
void test_status_worktree__show_index_and_workdir(void)
{
assert_show(entry_count0, entry_paths0, entry_statuses0,
- GIT_STATUS_SHOW_INDEX_AND_WORKDIR);
+ cl_git_sandbox_init("status"), GIT_STATUS_SHOW_INDEX_AND_WORKDIR, 0);
}
void test_status_worktree__show_index_only(void)
{
assert_show(entry_count5, entry_paths5, entry_statuses5,
- GIT_STATUS_SHOW_INDEX_ONLY);
+ cl_git_sandbox_init("status"), GIT_STATUS_SHOW_INDEX_ONLY, 0);
}
void test_status_worktree__show_workdir_only(void)
{
assert_show(entry_count6, entry_paths6, entry_statuses6,
- GIT_STATUS_SHOW_WORKDIR_ONLY);
+ cl_git_sandbox_init("status"), GIT_STATUS_SHOW_WORKDIR_ONLY, 0);
}
/* this test is equivalent to t18-status.c:statuscb1 */
@@ -455,15 +461,15 @@ void test_status_worktree__conflict_with_diff3(void)
memset(&their_entry, 0x0, sizeof(git_index_entry));
ancestor_entry.path = "modified_file";
- git_oid_fromstr(&ancestor_entry.oid,
+ git_oid_fromstr(&ancestor_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
our_entry.path = "modified_file";
- git_oid_fromstr(&our_entry.oid,
+ git_oid_fromstr(&our_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
their_entry.path = "modified_file";
- git_oid_fromstr(&their_entry.oid,
+ git_oid_fromstr(&their_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
cl_git_pass(git_status_file(&status, repo, "modified_file"));
@@ -552,7 +558,7 @@ static int cb_status__interrupt(const char *p, unsigned int s, void *payload)
(*count)++;
- return (*count == 8);
+ return (*count == 8) ? -111 : 0;
}
void test_status_worktree__interruptable_foreach(void)
@@ -561,7 +567,7 @@ void test_status_worktree__interruptable_foreach(void)
git_repository *repo = cl_git_sandbox_init("status");
cl_assert_equal_i(
- GIT_EUSER, git_status_foreach(repo, cb_status__interrupt, &count)
+ -111, git_status_foreach(repo, cb_status__interrupt, &count)
);
cl_assert_equal_i(8, count);
@@ -578,7 +584,11 @@ void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf(void
cl_git_pass(git_status_file(&status, repo, "current_file"));
- cl_assert_equal_i(GIT_STATUS_CURRENT, status);
+ /* stat data on file should no longer match stat cache, even though
+ * file diff will be empty because of line-ending conversion - matches
+ * the Git command-line behavior here.
+ */
+ cl_assert_equal_i(GIT_STATUS_WT_MODIFIED, status);
}
void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf_issue_1397(void)
@@ -605,15 +615,15 @@ void test_status_worktree__conflicted_item(void)
memset(&their_entry, 0x0, sizeof(git_index_entry));
ancestor_entry.path = "modified_file";
- git_oid_fromstr(&ancestor_entry.oid,
+ git_oid_fromstr(&ancestor_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
our_entry.path = "modified_file";
- git_oid_fromstr(&our_entry.oid,
+ git_oid_fromstr(&our_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
their_entry.path = "modified_file";
- git_oid_fromstr(&their_entry.oid,
+ git_oid_fromstr(&their_entry.id,
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
cl_git_pass(git_status_file(&status, repo, "modified_file"));
@@ -873,3 +883,55 @@ void test_status_worktree__long_filenames(void)
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
+/* The update stat cache tests mostly just mirror other tests and try
+ * to make sure that updating the stat cache doesn't change the results
+ * while reducing the amount of work that needs to be done
+ */
+
+static void check_status0(git_status_list *status)
+{
+ size_t i, max_i = git_status_list_entrycount(status);
+ cl_assert_equal_sz(entry_count0, max_i);
+ for (i = 0; i < max_i; ++i) {
+ const git_status_entry *entry = git_status_byindex(status, i);
+ cl_assert_equal_i(entry_statuses0[i], entry->status);
+ }
+}
+
+void test_status_worktree__update_stat_cache_0(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ git_status_list *status;
+ git_diff_perfdata perf = GIT_DIFF_PERFDATA_INIT;
+
+ opts.flags = GIT_STATUS_OPT_DEFAULTS;
+
+ cl_git_pass(git_status_list_new(&status, repo, &opts));
+ check_status0(status);
+ cl_git_pass(git_status_list_get_perfdata(&perf, status));
+ cl_assert_equal_sz(13 + 3, perf.stat_calls);
+ cl_assert_equal_sz(5, perf.oid_calculations);
+
+ git_status_list_free(status);
+
+ opts.flags |= GIT_STATUS_OPT_UPDATE_INDEX;
+
+ cl_git_pass(git_status_list_new(&status, repo, &opts));
+ check_status0(status);
+ cl_git_pass(git_status_list_get_perfdata(&perf, status));
+ cl_assert_equal_sz(13 + 3, perf.stat_calls);
+ cl_assert_equal_sz(5, perf.oid_calculations);
+
+ git_status_list_free(status);
+
+ opts.flags &= ~GIT_STATUS_OPT_UPDATE_INDEX;
+
+ cl_git_pass(git_status_list_new(&status, repo, &opts));
+ check_status0(status);
+ cl_git_pass(git_status_list_get_perfdata(&perf, status));
+ cl_assert_equal_sz(13 + 3, perf.stat_calls);
+ cl_assert_equal_sz(0, perf.oid_calculations);
+
+ git_status_list_free(status);
+}