summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/diff/submodules.c10
-rw-r--r--tests/stash/submodules.c3
-rw-r--r--tests/status/submodules.c2
-rw-r--r--tests/submodule/lookup.c95
-rw-r--r--tests/submodule/modify.c22
-rw-r--r--tests/submodule/status.c275
-rw-r--r--tests/submodule/submodule_helpers.c29
-rw-r--r--tests/submodule/submodule_helpers.h5
8 files changed, 197 insertions, 244 deletions
diff --git a/tests/diff/submodules.c b/tests/diff/submodules.c
index da96ba9c5..62e07e0c6 100644
--- a/tests/diff/submodules.c
+++ b/tests/diff/submodules.c
@@ -123,7 +123,7 @@ void test_diff_submodules__dirty_submodule_2(void)
g_repo = setup_fixture_submodules();
- cl_git_pass(git_submodule_reload_all(g_repo));
+ cl_git_pass(git_submodule_reload_all(g_repo, 1));
opts.flags = GIT_DIFF_INCLUDE_UNTRACKED |
GIT_DIFF_SHOW_UNTRACKED_CONTENT |
@@ -157,7 +157,7 @@ void test_diff_submodules__dirty_submodule_2(void)
git_diff_free(diff);
- cl_git_pass(git_submodule_reload_all(g_repo));
+ cl_git_pass(git_submodule_reload_all(g_repo, 1));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_dirty);
@@ -281,7 +281,9 @@ void test_diff_submodules__invalid_cache(void)
check_diff_patches(diff, expected_dirty);
git_diff_free(diff);
- cl_git_pass(git_submodule_reload_all(g_repo));
+ git_submodule_free(sm);
+
+ cl_git_pass(git_submodule_reload_all(g_repo, 1));
cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
@@ -334,6 +336,8 @@ void test_diff_submodules__invalid_cache(void)
p_unlink("submod2/sm_changed_head/new_around_here");
+ git_submodule_free(sm);
+
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_moved);
git_diff_free(diff);
diff --git a/tests/stash/submodules.c b/tests/stash/submodules.c
index 137c4408c..8cadca0f2 100644
--- a/tests/stash/submodules.c
+++ b/tests/stash/submodules.c
@@ -19,6 +19,9 @@ void test_stash_submodules__initialize(void)
void test_stash_submodules__cleanup(void)
{
+ git_submodule_free(sm);
+ sm = NULL;
+
git_signature_free(signature);
signature = NULL;
}
diff --git a/tests/status/submodules.c b/tests/status/submodules.c
index 80ff162fd..8575f9f2d 100644
--- a/tests/status/submodules.c
+++ b/tests/status/submodules.c
@@ -29,6 +29,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)
@@ -136,6 +137,7 @@ 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(
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index ac3fa0415..cc29b11b2 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -12,31 +12,25 @@ void test_submodule_lookup__initialize(void)
void test_submodule_lookup__simple_lookup(void)
{
- git_submodule *sm;
-
- /* lookup existing */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_assert(sm);
+ assert_submodule_exists(g_repo, "sm_unchanged");
/* lookup pending change in .gitmodules that is not in HEAD */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
- cl_assert(sm);
+ assert_submodule_exists(g_repo, "sm_added_and_uncommited");
- /* lookup pending change in .gitmodules that is neither in HEAD nor index */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only"));
- cl_assert(sm);
+ /* lookup pending change in .gitmodules that is not in HEAD nor index */
+ assert_submodule_exists(g_repo, "sm_gitmodules_only");
/* lookup git repo subdir that is not added as submodule */
- cl_assert(git_submodule_lookup(&sm, g_repo, "not-submodule") == GIT_EEXISTS);
+ refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS);
/* lookup existing directory that is not a submodule */
- cl_assert(git_submodule_lookup(&sm, g_repo, "just_a_dir") == GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND);
/* lookup existing file that is not a submodule */
- cl_assert(git_submodule_lookup(&sm, g_repo, "just_a_file") == GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "just_a_file", GIT_ENOTFOUND);
/* lookup non-existent item */
- cl_assert(git_submodule_lookup(&sm, g_repo, "no_such_file") == GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "no_such_file", GIT_ENOTFOUND);
}
void test_submodule_lookup__accessors(void)
@@ -57,6 +51,9 @@ void test_submodule_lookup__accessors(void)
cl_assert(git_submodule_ignore(sm) == GIT_SUBMODULE_IGNORE_NONE);
cl_assert(git_submodule_update(sm) == GIT_SUBMODULE_UPDATE_CHECKOUT);
+ git_submodule_free(sm);
+
+
cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
cl_assert_equal_s("sm_changed_head", git_submodule_name(sm));
@@ -65,6 +62,9 @@ void test_submodule_lookup__accessors(void)
cl_assert(git_oid_streq(git_submodule_wd_id(sm),
"3d9386c507f6b093471a3e324085657a3c2b4247") == 0);
+ git_submodule_free(sm);
+
+
cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
cl_assert_equal_s("sm_added_and_uncommited", git_submodule_name(sm));
@@ -72,6 +72,9 @@ void test_submodule_lookup__accessors(void)
cl_assert(git_submodule_head_id(sm) == NULL);
cl_assert(git_oid_streq(git_submodule_wd_id(sm), oid) == 0);
+ git_submodule_free(sm);
+
+
cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits"));
cl_assert_equal_s("sm_missing_commits", git_submodule_name(sm));
@@ -79,6 +82,8 @@ void test_submodule_lookup__accessors(void)
cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0);
cl_assert(git_oid_streq(git_submodule_wd_id(sm),
"5e4963595a9774b90524d35a807169049de8ccad") == 0);
+
+ git_submodule_free(sm);
}
typedef struct {
@@ -104,69 +109,35 @@ void test_submodule_lookup__foreach(void)
void test_submodule_lookup__lookup_even_with_unborn_head(void)
{
git_reference *head;
- git_submodule *sm;
/* put us on an unborn branch */
cl_git_pass(git_reference_symbolic_create(
&head, g_repo, "HEAD", "refs/heads/garbage", 1, NULL, NULL));
git_reference_free(head);
- /* lookup existing */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_assert(sm);
-
- /* lookup pending change in .gitmodules that is not in HEAD */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
- cl_assert(sm);
-
- /* lookup pending change in .gitmodules that is neither in HEAD nor index */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only"));
- cl_assert(sm);
-
- /* lookup git repo subdir that is not added as submodule */
- cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, g_repo, "not-submodule"));
-
- /* lookup existing directory that is not a submodule */
- cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_dir"));
-
- /* lookup existing file that is not a submodule */
- cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_file"));
-
- /* lookup non-existent item */
- cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "no_such_file"));
+ assert_submodule_exists(g_repo, "sm_unchanged");
+ assert_submodule_exists(g_repo, "sm_added_and_uncommited");
+ assert_submodule_exists(g_repo, "sm_gitmodules_only");
+ refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS);
+ refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "just_a_file", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "no_such_file", GIT_ENOTFOUND);
}
void test_submodule_lookup__lookup_even_with_missing_index(void)
{
git_index *idx;
- git_submodule *sm;
/* give the repo an empty index */
cl_git_pass(git_index_new(&idx));
git_repository_set_index(g_repo, idx);
git_index_free(idx);
- /* lookup existing */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_assert(sm);
-
- /* lookup pending change in .gitmodules that is not in HEAD */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
- cl_assert(sm);
-
- /* lookup pending change in .gitmodules that is neither in HEAD nor index */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only"));
- cl_assert(sm);
-
- /* lookup git repo subdir that is not added as submodule */
- cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, g_repo, "not-submodule"));
-
- /* lookup existing directory that is not a submodule */
- cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_dir"));
-
- /* lookup existing file that is not a submodule */
- cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_file"));
-
- /* lookup non-existent item */
- cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "no_such_file"));
+ assert_submodule_exists(g_repo, "sm_unchanged");
+ assert_submodule_exists(g_repo, "sm_added_and_uncommited");
+ assert_submodule_exists(g_repo, "sm_gitmodules_only");
+ refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS);
+ refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "just_a_file", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "no_such_file", GIT_ENOTFOUND);
}
diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c
index e3e4d8aed..1aaa56388 100644
--- a/tests/submodule/modify.c
+++ b/tests/submodule/modify.c
@@ -21,15 +21,16 @@ void test_submodule_modify__add(void)
const char *s;
/* re-add existing submodule */
- cl_assert(
- git_submodule_add_setup(NULL, g_repo, "whatever", "sm_unchanged", 1) ==
- GIT_EEXISTS );
+ cl_assert_equal_i(
+ GIT_EEXISTS,
+ git_submodule_add_setup(NULL, g_repo, "whatever", "sm_unchanged", 1));
/* add a submodule using a gitlink */
cl_git_pass(
git_submodule_add_setup(&sm, g_repo, SM_LIBGIT2_URL, SM_LIBGIT2, 1)
);
+ git_submodule_free(sm);
cl_assert(git_path_isfile("submod2/" SM_LIBGIT2 "/.git"));
@@ -48,6 +49,7 @@ void test_submodule_modify__add(void)
cl_git_pass(
git_submodule_add_setup(&sm, g_repo, SM_LIBGIT2_URL, SM_LIBGIT2B, 0)
);
+ git_submodule_free(sm);
cl_assert(git_path_isdir("submod2/" SM_LIBGIT2B "/.git"));
cl_assert(git_path_isfile("submod2/" SM_LIBGIT2B "/.git/HEAD"));
@@ -95,7 +97,7 @@ void test_submodule_modify__init(void)
/* call init and see that settings are copied */
cl_git_pass(git_submodule_foreach(g_repo, init_one_submodule, NULL));
- git_submodule_reload_all(g_repo);
+ git_submodule_reload_all(g_repo, 1);
/* confirm submodule data in config */
cl_git_pass(git_repository_config(&cfg, g_repo));
@@ -159,6 +161,10 @@ void test_submodule_modify__sync(void)
cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM3".url"));
cl_assert_equal_s(git_submodule_url(sm3), str);
git_config_free(cfg);
+
+ git_submodule_free(sm1);
+ git_submodule_free(sm2);
+ git_submodule_free(sm3);
}
void test_submodule_modify__edit_and_save(void)
@@ -231,7 +237,7 @@ void test_submodule_modify__edit_and_save(void)
cl_assert_equal_i(GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm1));
/* call reload and check that the new values are loaded */
- cl_git_pass(git_submodule_reload(sm1));
+ cl_git_pass(git_submodule_reload(sm1, 0));
cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm1));
cl_assert_equal_i(
@@ -253,16 +259,18 @@ void test_submodule_modify__edit_and_save(void)
GIT_SUBMODULE_RECURSE_NO, git_submodule_fetch_recurse_submodules(sm2));
/* set fetchRecurseSubmodules on-demand */
- cl_git_pass(git_submodule_reload(sm1));
+ cl_git_pass(git_submodule_reload(sm1, 0));
git_submodule_set_fetch_recurse_submodules(sm1, GIT_SUBMODULE_RECURSE_ONDEMAND);
cl_assert_equal_i(
GIT_SUBMODULE_RECURSE_ONDEMAND, git_submodule_fetch_recurse_submodules(sm1));
/* call save */
cl_git_pass(git_submodule_save(sm1));
- cl_git_pass(git_submodule_reload(sm1));
+ cl_git_pass(git_submodule_reload(sm1, 0));
cl_assert_equal_i(
GIT_SUBMODULE_RECURSE_ONDEMAND, git_submodule_fetch_recurse_submodules(sm1));
+ git_submodule_free(sm1);
+ git_submodule_free(sm2);
git_repository_free(r2);
git__free(old_url);
}
diff --git a/tests/submodule/status.c b/tests/submodule/status.c
index f5111c84f..4fa7114a4 100644
--- a/tests/submodule/status.c
+++ b/tests/submodule/status.c
@@ -18,19 +18,43 @@ void test_submodule_status__cleanup(void)
void test_submodule_status__unchanged(void)
{
- unsigned int status, expected;
- git_submodule *sm;
-
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_git_pass(git_submodule_status(&status, sm));
- cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
-
- expected = GIT_SUBMODULE_STATUS_IN_HEAD |
+ unsigned int status = get_submodule_status(g_repo, "sm_unchanged");
+ unsigned int expected =
+ GIT_SUBMODULE_STATUS_IN_HEAD |
GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS_IN_CONFIG |
GIT_SUBMODULE_STATUS_IN_WD;
- cl_assert(status == expected);
+ cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
+ cl_assert(expected == status);
+}
+
+static void rm_submodule(const char *name)
+{
+ git_buf path = GIT_BUF_INIT;
+ cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), name));
+ cl_git_pass(git_futils_rmdir_r(path.ptr, NULL, GIT_RMDIR_REMOVE_FILES));
+ git_buf_free(&path);
+}
+
+static void add_submodule_to_index(const char *name)
+{
+ git_submodule *sm;
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, name));
+ cl_git_pass(git_submodule_add_to_index(sm, true));
+ git_submodule_free(sm);
+}
+
+static void rm_submodule_from_index(const char *name)
+{
+ git_index *index;
+ size_t pos;
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_assert(!git_index_find(&pos, index, name));
+ cl_git_pass(git_index_remove(index, name, 0));
+ cl_git_pass(git_index_write(index));
+ git_index_free(index);
}
/* 4 values of GIT_SUBMODULE_IGNORE to check */
@@ -38,81 +62,49 @@ void test_submodule_status__unchanged(void)
void test_submodule_status__ignore_none(void)
{
unsigned int status;
- git_submodule *sm;
- git_buf path = GIT_BUF_INIT;
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged"));
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+ rm_submodule("sm_unchanged");
- cl_assert_equal_i(GIT_ENOTFOUND,
- git_submodule_lookup(&sm, g_repo, "just_a_dir"));
- cl_assert_equal_i(GIT_EEXISTS,
- git_submodule_lookup(&sm, g_repo, "not-submodule"));
- cl_assert_equal_i(GIT_EEXISTS,
- git_submodule_lookup(&sm, g_repo, "not"));
+ refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS);
+ refute_submodule_exists(g_repo, "not", GIT_EEXISTS);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_index");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED) != 0);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_head");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_file"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_file");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_WD_MODIFIED) != 0);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_untracked_file"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_untracked_file");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNTRACKED) != 0);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_missing_commits");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_added_and_uncommited");
cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_ADDED) != 0);
/* removed sm_unchanged for deleted workdir */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_unchanged");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0);
/* now mkdir sm_unchanged to test uninitialized */
- cl_git_pass(git_futils_mkdir(git_buf_cstr(&path), NULL, 0755, 0));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_git_pass(git_submodule_reload(sm));
- cl_git_pass(git_submodule_status(&status, sm));
+ cl_git_pass(git_futils_mkdir("sm_unchanged", "submod2", 0755, 0));
+ status = get_submodule_status(g_repo, "sm_unchanged");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0);
/* update sm_changed_head in index */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
- cl_git_pass(git_submodule_add_to_index(sm, true));
- /* reload is not needed because add_to_index updates the submodule data */
- cl_git_pass(git_submodule_status(&status, sm));
+ add_submodule_to_index("sm_changed_head");
+ status = get_submodule_status(g_repo, "sm_changed_head");
cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_MODIFIED) != 0);
/* remove sm_changed_head from index */
- {
- git_index *index;
- size_t pos;
-
- cl_git_pass(git_repository_index(&index, g_repo));
- cl_assert(!git_index_find(&pos, index, "sm_changed_head"));
- cl_git_pass(git_index_remove(index, "sm_changed_head", 0));
- cl_git_pass(git_index_write(index));
-
- git_index_free(index);
- }
-
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
- cl_git_pass(git_submodule_reload(sm));
- cl_git_pass(git_submodule_status(&status, sm));
+ rm_submodule_from_index("sm_changed_head");
+ status = get_submodule_status(g_repo, "sm_changed_head");
cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_DELETED) != 0);
-
- git_buf_free(&path);
}
static int set_sm_ignore(git_submodule *sm, const char *name, void *payload)
@@ -126,191 +118,136 @@ static int set_sm_ignore(git_submodule *sm, const char *name, void *payload)
void test_submodule_status__ignore_untracked(void)
{
unsigned int status;
- git_submodule *sm;
- git_buf path = GIT_BUF_INIT;
git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_UNTRACKED;
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged"));
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
-
+ rm_submodule("sm_unchanged");
cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));
- cl_git_fail(git_submodule_lookup(&sm, g_repo, "not-submodule"));
+ refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS);
+ refute_submodule_exists(g_repo, "not", GIT_EEXISTS);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_index");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED) != 0);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_head");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_file"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_file");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_WD_MODIFIED) != 0);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_untracked_file"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_untracked_file");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_missing_commits");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_added_and_uncommited");
cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_ADDED) != 0);
/* removed sm_unchanged for deleted workdir */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_unchanged");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0);
/* now mkdir sm_unchanged to test uninitialized */
- cl_git_pass(git_futils_mkdir(git_buf_cstr(&path), NULL, 0755, 0));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_git_pass(git_submodule_reload(sm));
- cl_git_pass(git_submodule_status(&status, sm));
+ cl_git_pass(git_futils_mkdir("sm_unchanged", "submod2", 0755, 0));
+ status = get_submodule_status(g_repo, "sm_unchanged");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0);
/* update sm_changed_head in index */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
- cl_git_pass(git_submodule_add_to_index(sm, true));
- /* reload is not needed because add_to_index updates the submodule data */
- cl_git_pass(git_submodule_status(&status, sm));
+ add_submodule_to_index("sm_changed_head");
+ status = get_submodule_status(g_repo, "sm_changed_head");
cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_MODIFIED) != 0);
-
- git_buf_free(&path);
}
void test_submodule_status__ignore_dirty(void)
{
unsigned int status;
- git_submodule *sm;
- git_buf path = GIT_BUF_INIT;
git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_DIRTY;
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged"));
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
-
+ rm_submodule("sm_unchanged");
cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));
- cl_assert_equal_i(GIT_ENOTFOUND,
- git_submodule_lookup(&sm, g_repo, "just_a_dir"));
- cl_assert_equal_i(GIT_EEXISTS,
- git_submodule_lookup(&sm, g_repo, "not-submodule"));
- cl_assert_equal_i(GIT_EEXISTS,
- git_submodule_lookup(&sm, g_repo, "not"));
+ refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS);
+ refute_submodule_exists(g_repo, "not", GIT_EEXISTS);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_index");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_head");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_file"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_file");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_untracked_file"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_untracked_file");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_missing_commits");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_added_and_uncommited");
cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_ADDED) != 0);
/* removed sm_unchanged for deleted workdir */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_unchanged");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0);
/* now mkdir sm_unchanged to test uninitialized */
- cl_git_pass(git_futils_mkdir(git_buf_cstr(&path), NULL, 0755, 0));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_git_pass(git_submodule_reload(sm));
- cl_git_pass(git_submodule_status(&status, sm));
+ cl_git_pass(git_futils_mkdir("sm_unchanged", "submod2", 0755, 0));
+ status = get_submodule_status(g_repo, "sm_unchanged");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0);
/* update sm_changed_head in index */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
- cl_git_pass(git_submodule_add_to_index(sm, true));
- /* reload is not needed because add_to_index updates the submodule data */
- cl_git_pass(git_submodule_status(&status, sm));
+ add_submodule_to_index("sm_changed_head");
+ status = get_submodule_status(g_repo, "sm_changed_head");
cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_MODIFIED) != 0);
-
- git_buf_free(&path);
}
void test_submodule_status__ignore_all(void)
{
unsigned int status;
- git_submodule *sm;
- git_buf path = GIT_BUF_INIT;
git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_ALL;
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged"));
- cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
-
+ rm_submodule("sm_unchanged");
cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));
- cl_assert_equal_i(GIT_ENOTFOUND,
- git_submodule_lookup(&sm, g_repo, "just_a_dir"));
- cl_assert_equal_i(GIT_EEXISTS,
- git_submodule_lookup(&sm, g_repo, "not-submodule"));
- cl_assert_equal_i(GIT_EEXISTS,
- git_submodule_lookup(&sm, g_repo, "not"));
+ refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS);
+ refute_submodule_exists(g_repo, "not", GIT_EEXISTS);
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_index");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_head");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_file"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_file");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_untracked_file"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_changed_untracked_file");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_missing_commits");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_added_and_uncommited");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
/* removed sm_unchanged for deleted workdir */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_git_pass(git_submodule_status(&status, sm));
+ status = get_submodule_status(g_repo, "sm_unchanged");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
/* now mkdir sm_unchanged to test uninitialized */
- cl_git_pass(git_futils_mkdir(git_buf_cstr(&path), NULL, 0755, 0));
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_git_pass(git_submodule_reload(sm));
- cl_git_pass(git_submodule_status(&status, sm));
+ cl_git_pass(git_futils_mkdir("sm_unchanged", "submod2", 0755, 0));
+ status = get_submodule_status(g_repo, "sm_unchanged");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
/* update sm_changed_head in index */
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
- cl_git_pass(git_submodule_add_to_index(sm, true));
- /* reload is not needed because add_to_index updates the submodule data */
- cl_git_pass(git_submodule_status(&status, sm));
+ add_submodule_to_index("sm_changed_head");
+ status = get_submodule_status(g_repo, "sm_changed_head");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
-
- git_buf_free(&path);
}
typedef struct {
@@ -397,29 +334,23 @@ void test_submodule_status__iterator(void)
void test_submodule_status__untracked_dirs_containing_ignored_files(void)
{
- git_buf path = GIT_BUF_INIT;
unsigned int status, expected;
- git_submodule *sm;
-
- cl_git_pass(git_buf_joinpath(&path, git_repository_path(g_repo), "modules/sm_unchanged/info/exclude"));
- cl_git_append2file(git_buf_cstr(&path), "\n*.ignored\n");
- cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged/directory"));
- cl_git_pass(git_futils_mkdir(git_buf_cstr(&path), NULL, 0755, 0));
- cl_git_pass(git_buf_joinpath(&path, git_buf_cstr(&path), "i_am.ignored"));
- cl_git_mkfile(git_buf_cstr(&path), "ignored this file, please\n");
+ cl_git_append2file(
+ "submod2/.git/modules/sm_unchanged/info/exclude", "\n*.ignored\n");
- cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
- cl_git_pass(git_submodule_status(&status, sm));
+ cl_git_pass(
+ git_futils_mkdir("sm_unchanged/directory", "submod2", 0755, 0));
+ cl_git_mkfile(
+ "submod2/sm_unchanged/directory/i_am.ignored",
+ "ignore this file, please\n");
+ status = get_submodule_status(g_repo, "sm_unchanged");
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
expected = GIT_SUBMODULE_STATUS_IN_HEAD |
GIT_SUBMODULE_STATUS_IN_INDEX |
GIT_SUBMODULE_STATUS_IN_CONFIG |
GIT_SUBMODULE_STATUS_IN_WD;
-
cl_assert(status == expected);
-
- git_buf_free(&path);
}
diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c
index d5750675c..546f0913a 100644
--- a/tests/submodule/submodule_helpers.c
+++ b/tests/submodule/submodule_helpers.c
@@ -125,3 +125,32 @@ git_repository *setup_fixture_submod2(void)
return repo;
}
+
+void assert_submodule_exists(git_repository *repo, const char *name)
+{
+ git_submodule *sm;
+ cl_git_pass(git_submodule_lookup(&sm, repo, name));
+ cl_assert(sm);
+ git_submodule_free(sm);
+}
+
+void refute_submodule_exists(
+ git_repository *repo, const char *name, int expected_error)
+{
+ git_submodule *sm;
+ cl_assert_equal_i(
+ expected_error, git_submodule_lookup(&sm, repo, name));
+}
+
+unsigned int get_submodule_status(git_repository *repo, const char *name)
+{
+ git_submodule *sm = NULL;
+ unsigned int status = 0;
+
+ cl_git_pass(git_submodule_lookup(&sm, repo, name));
+ cl_assert(sm);
+ cl_git_pass(git_submodule_status(&status, sm));
+ git_submodule_free(sm);
+
+ return status;
+}
diff --git a/tests/submodule/submodule_helpers.h b/tests/submodule/submodule_helpers.h
index 610c40720..ec5510e3c 100644
--- a/tests/submodule/submodule_helpers.h
+++ b/tests/submodule/submodule_helpers.h
@@ -3,3 +3,8 @@ extern void rewrite_gitmodules(const char *workdir);
/* these will automatically set a cleanup callback */
extern git_repository *setup_fixture_submodules(void);
extern git_repository *setup_fixture_submod2(void);
+
+extern unsigned int get_submodule_status(git_repository *, const char *);
+
+extern void assert_submodule_exists(git_repository *, const char *);
+extern void refute_submodule_exists(git_repository *, const char *, int err);