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:
authorRussell Belfer <rb@github.com>2013-03-26 09:19:39 +0400
committerRussell Belfer <rb@github.com>2013-03-26 09:19:39 +0400
commit37ee70fab4e6dcf35afc08c0edbe9f101d4abf2d (patch)
treee9bee47b3059bbc5189e0833b927a3bf50776bdf /tests-clar/status
parent0c289dd7c6831f4f402f9581b46d0c920053abf9 (diff)
Implement GIT_STATUS_OPT_EXCLUDE_SUBMODULES
This option has been sitting unimplemented for a while, so I finally went through and implemented it along with some tests. As part of this, I improved the implementation of GIT_DIFF_IGNORE_SUBMODULES so it be more diligent about avoiding extra work and about leaving off delta records for submodules to the greatest extent possible (though it may include them still if you are request TYPECHANGE records).
Diffstat (limited to 'tests-clar/status')
-rw-r--r--tests-clar/status/ignore.c5
-rw-r--r--tests-clar/status/submodules.c80
2 files changed, 72 insertions, 13 deletions
diff --git a/tests-clar/status/ignore.c b/tests-clar/status/ignore.c
index d40af7e05..65ab47267 100644
--- a/tests-clar/status/ignore.c
+++ b/tests-clar/status/ignore.c
@@ -245,10 +245,7 @@ void test_status_ignore__subdirectories_recursion(void)
GIT_STATUS_IGNORED,
};
- opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED |
- GIT_STATUS_OPT_RECURSE_IGNORED_DIRS |
- GIT_STATUS_OPT_INCLUDE_UNTRACKED |
- GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+ opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
g_repo = cl_git_sandbox_init("empty_standard_repo");
diff --git a/tests-clar/status/submodules.c b/tests-clar/status/submodules.c
index 24dd660ab..aa88f06a0 100644
--- a/tests-clar/status/submodules.c
+++ b/tests-clar/status/submodules.c
@@ -71,31 +71,34 @@ static unsigned int expected_status[] = {
GIT_STATUS_WT_NEW
};
-static int
-cb_status__match(const char *p, unsigned int s, void *payload)
+static int cb_status__match(const char *p, unsigned int s, void *payload)
{
- volatile int *index = (int *)payload;
+ status_entry_counts *counts = payload;
+ int idx = counts->entry_count++;
- cl_assert_equal_s(expected_files[*index], p);
- cl_assert(expected_status[*index] == s);
- (*index)++;
+ cl_assert_equal_s(counts->expected_paths[idx], p);
+ cl_assert(counts->expected_statuses[idx] == s);
return 0;
}
void test_status_submodules__1(void)
{
- int index = 0;
+ status_entry_counts counts;
cl_assert(git_path_isdir("submodules/.git"));
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;
+
cl_git_pass(
- git_status_foreach(g_repo, cb_status__match, &index)
+ git_status_foreach(g_repo, cb_status__match, &counts)
);
- cl_assert_equal_i(6, index);
+ cl_assert_equal_i(6, counts.entry_count);
}
void test_status_submodules__single_file(void)
@@ -104,3 +107,62 @@ void test_status_submodules__single_file(void)
cl_git_pass( git_status_file(&status, g_repo, "testrepo") );
cl_assert(!status);
}
+
+void test_status_submodules__moved_head(void)
+{
+ git_submodule *sm;
+ git_repository *smrepo;
+ git_oid oid;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts;
+ static const char *expected_files_with_sub[] = {
+ ".gitmodules",
+ "added",
+ "deleted",
+ "ignored",
+ "modified",
+ "testrepo",
+ "untracked"
+ };
+ static unsigned int expected_status_with_sub[] = {
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_INDEX_DELETED,
+ GIT_STATUS_IGNORED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_NEW
+ };
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+ cl_git_pass(git_submodule_open(&smrepo, sm));
+
+ /* move submodule HEAD to c47800c7266a2be04c571c04d5a6614691ea99bd */
+ cl_git_pass(
+ git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
+ cl_git_pass(git_repository_set_head_detached(smrepo, &oid));
+
+ /* 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;
+
+ 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;
+
+ cl_git_pass(
+ git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(6, counts.entry_count);
+}