summaryrefslogtreecommitdiff
path: root/tests/submodule
diff options
context:
space:
mode:
Diffstat (limited to 'tests/submodule')
-rw-r--r--tests/submodule/add.c117
-rw-r--r--tests/submodule/lookup.c147
-rw-r--r--tests/submodule/modify.c83
-rw-r--r--tests/submodule/nosubs.c83
-rw-r--r--tests/submodule/submodule_helpers.c36
-rw-r--r--tests/submodule/submodule_helpers.h15
6 files changed, 388 insertions, 93 deletions
diff --git a/tests/submodule/add.c b/tests/submodule/add.c
new file mode 100644
index 000000000..af81713f1
--- /dev/null
+++ b/tests/submodule/add.c
@@ -0,0 +1,117 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "path.h"
+#include "submodule_helpers.h"
+
+static git_repository *g_repo = NULL;
+
+void test_submodule_add__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+static void assert_submodule_url(const char* name, const char *url)
+{
+ git_config *cfg;
+ const char *s;
+ git_buf key = GIT_BUF_INIT;
+
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+
+ cl_git_pass(git_buf_printf(&key, "submodule.%s.url", name));
+ cl_git_pass(git_config_get_string(&s, cfg, git_buf_cstr(&key)));
+ cl_assert_equal_s(s, url);
+
+ git_config_free(cfg);
+ git_buf_free(&key);
+}
+
+void test_submodule_add__url_absolute(void)
+{
+ git_submodule *sm;
+
+ g_repo = setup_fixture_submod2();
+
+ /* re-add existing submodule */
+ cl_git_fail_with(
+ 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, "https://github.com/libgit2/libgit2.git", "sm_libgit2", 1)
+ );
+ git_submodule_free(sm);
+
+ cl_assert(git_path_isfile("submod2/" "sm_libgit2" "/.git"));
+
+ cl_assert(git_path_isdir("submod2/.git/modules"));
+ cl_assert(git_path_isdir("submod2/.git/modules/" "sm_libgit2"));
+ cl_assert(git_path_isfile("submod2/.git/modules/" "sm_libgit2" "/HEAD"));
+ assert_submodule_url("sm_libgit2", "https://github.com/libgit2/libgit2.git");
+
+ /* add a submodule not using a gitlink */
+
+ cl_git_pass(
+ git_submodule_add_setup(&sm, g_repo, "https://github.com/libgit2/libgit2.git", "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"));
+ cl_assert(!git_path_exists("submod2/.git/modules/" "sm_libgit2b"));
+ assert_submodule_url("sm_libgit2b", "https://github.com/libgit2/libgit2.git");
+}
+
+void test_submodule_add__url_relative(void)
+{
+ git_submodule *sm;
+ git_remote *remote;
+
+ /* default remote url is https://github.com/libgit2/false.git */
+ g_repo = cl_git_sandbox_init("testrepo2");
+
+ /* make sure we don't default to origin - rename origin -> test_remote */
+ cl_git_pass(git_remote_load(&remote, g_repo, "origin"));
+ cl_git_pass(git_remote_rename(remote, "test_remote", NULL, NULL));
+ cl_git_fail(git_remote_load(&remote, g_repo, "origin"));
+ git_remote_free(remote);
+
+ cl_git_pass(
+ git_submodule_add_setup(&sm, g_repo, "../TestGitRepository", "TestGitRepository", 1)
+ );
+ git_submodule_free(sm);
+
+ assert_submodule_url("TestGitRepository", "https://github.com/libgit2/TestGitRepository");
+}
+
+void test_submodule_add__url_relative_to_origin(void)
+{
+ git_submodule *sm;
+
+ /* default remote url is https://github.com/libgit2/false.git */
+ g_repo = cl_git_sandbox_init("testrepo2");
+
+ cl_git_pass(
+ git_submodule_add_setup(&sm, g_repo, "../TestGitRepository", "TestGitRepository", 1)
+ );
+ git_submodule_free(sm);
+
+ assert_submodule_url("TestGitRepository", "https://github.com/libgit2/TestGitRepository");
+}
+
+void test_submodule_add__url_relative_to_workdir(void)
+{
+ git_submodule *sm;
+
+ /* In this repo, HEAD (master) has no remote tracking branc h*/
+ g_repo = cl_git_sandbox_init("testrepo");
+
+ cl_git_pass(
+ git_submodule_add_setup(&sm, g_repo, "./", "TestGitRepository", 1)
+ );
+ git_submodule_free(sm);
+
+ assert_submodule_url("TestGitRepository", git_repository_workdir(g_repo));
+}
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index 36bde4f6e..34de5923e 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -1,7 +1,7 @@
#include "clar_libgit2.h"
#include "submodule_helpers.h"
-#include "posix.h"
#include "git2/sys/repository.h"
+#include "fileops.h"
static git_repository *g_repo = NULL;
@@ -115,13 +115,7 @@ void test_submodule_lookup__lookup_even_with_unborn_head(void)
&head, g_repo, "HEAD", "refs/heads/garbage", 1, NULL, NULL));
git_reference_free(head);
- 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);
+ test_submodule_lookup__simple_lookup(); /* baseline should still pass */
}
void test_submodule_lookup__lookup_even_with_missing_index(void)
@@ -133,44 +127,145 @@ void test_submodule_lookup__lookup_even_with_missing_index(void)
git_repository_set_index(g_repo, idx);
git_index_free(idx);
+ test_submodule_lookup__simple_lookup(); /* baseline should still pass */
+}
+
+static void baseline_tests(void)
+{
+ /* small baseline that should work even if we change the index or make
+ * commits from the index
+ */
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__just_added(void)
+static void add_submodule_with_commit(const char *name)
{
git_submodule *sm;
+ git_repository *smrepo;
+ git_index *idx;
+ git_buf p = GIT_BUF_INIT;
+
+ cl_git_pass(git_submodule_add_setup(&sm, g_repo,
+ "https://github.com/libgit2/libgit2.git", name, 1));
+
+ assert_submodule_exists(g_repo, name);
+
+ cl_git_pass(git_submodule_open(&smrepo, sm));
+ cl_git_pass(git_repository_index(&idx, smrepo));
+
+ cl_git_pass(git_buf_joinpath(&p, git_repository_workdir(smrepo), "file"));
+ cl_git_mkfile(p.ptr, "new file");
+ git_buf_free(&p);
+
+ cl_git_pass(git_index_add_bypath(idx, "file"));
+ cl_git_pass(git_index_write(idx));
+ git_index_free(idx);
+
+ cl_repo_commit_from_index(NULL, smrepo, NULL, 0, "initial commit");
+ git_repository_free(smrepo);
+
+ cl_git_pass(git_submodule_add_finalize(sm));
- cl_git_pass(git_submodule_add_setup(&sm, g_repo, "https://github.com/libgit2/libgit2.git", "sm_just_added", 1));
+ git_submodule_free(sm);
+}
+
+void test_submodule_lookup__just_added(void)
+{
+ git_submodule *sm;
+ git_buf snap1 = GIT_BUF_INIT, snap2 = GIT_BUF_INIT;
+ git_reference *original_head = NULL;
+
+ refute_submodule_exists(g_repo, "sm_just_added", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "sm_just_added_2", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "sm_just_added_idx", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "sm_just_added_head", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "mismatch_name", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "mismatch_path", GIT_ENOTFOUND);
+ baseline_tests();
+
+ cl_git_pass(git_futils_readbuffer(&snap1, "submod2/.gitmodules"));
+ cl_git_pass(git_repository_head(&original_head, g_repo));
+
+ cl_git_pass(git_submodule_add_setup(&sm, g_repo,
+ "https://github.com/libgit2/libgit2.git", "sm_just_added", 1));
git_submodule_free(sm);
assert_submodule_exists(g_repo, "sm_just_added");
- cl_git_pass(git_submodule_add_setup(&sm, g_repo, "https://github.com/libgit2/libgit2.git", "sm_just_added_2", 1));
+ cl_git_pass(git_submodule_add_setup(&sm, g_repo,
+ "https://github.com/libgit2/libgit2.git", "sm_just_added_2", 1));
assert_submodule_exists(g_repo, "sm_just_added_2");
+ cl_git_fail(git_submodule_add_finalize(sm)); /* fails if no HEAD */
git_submodule_free(sm);
- cl_git_append2file("submod2/.gitmodules", "\n[submodule \"mismatch_name\"]\n\tpath = mismatch_path\n\turl = https://example.com/example.git\n\n");
+ add_submodule_with_commit("sm_just_added_head");
+ cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "commit new sm to head");
+ assert_submodule_exists(g_repo, "sm_just_added_head");
+
+ add_submodule_with_commit("sm_just_added_idx");
+ assert_submodule_exists(g_repo, "sm_just_added_idx");
- cl_git_pass(git_submodule_reload_all(g_repo, 1));
+ cl_git_pass(git_futils_readbuffer(&snap2, "submod2/.gitmodules"));
+
+ cl_git_append2file(
+ "submod2/.gitmodules",
+ "\n[submodule \"mismatch_name\"]\n"
+ "\tpath = mismatch_path\n"
+ "\turl = https://example.com/example.git\n\n");
assert_submodule_exists(g_repo, "mismatch_name");
assert_submodule_exists(g_repo, "mismatch_path");
-
assert_submodule_exists(g_repo, "sm_just_added");
assert_submodule_exists(g_repo, "sm_just_added_2");
+ assert_submodule_exists(g_repo, "sm_just_added_idx");
+ assert_submodule_exists(g_repo, "sm_just_added_head");
+ baseline_tests();
- /* all the regular ones should still be working right, too */
+ cl_git_rewritefile("submod2/.gitmodules", snap2.ptr);
+ git_buf_free(&snap2);
- 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);
+ refute_submodule_exists(g_repo, "mismatch_name", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "mismatch_path", GIT_ENOTFOUND);
+ assert_submodule_exists(g_repo, "sm_just_added");
+ assert_submodule_exists(g_repo, "sm_just_added_2");
+ assert_submodule_exists(g_repo, "sm_just_added_idx");
+ assert_submodule_exists(g_repo, "sm_just_added_head");
+ baseline_tests();
+
+ cl_git_rewritefile("submod2/.gitmodules", snap1.ptr);
+ git_buf_free(&snap1);
+
+ refute_submodule_exists(g_repo, "mismatch_name", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "mismatch_path", GIT_ENOTFOUND);
+ /* note error code change, because add_setup made a repo in the workdir */
+ refute_submodule_exists(g_repo, "sm_just_added", GIT_EEXISTS);
+ refute_submodule_exists(g_repo, "sm_just_added_2", GIT_EEXISTS);
+ /* these still exist in index and head respectively */
+ assert_submodule_exists(g_repo, "sm_just_added_idx");
+ assert_submodule_exists(g_repo, "sm_just_added_head");
+ baseline_tests();
+
+ {
+ git_index *idx;
+ cl_git_pass(git_repository_index(&idx, g_repo));
+ cl_git_pass(git_index_remove_bypath(idx, "sm_just_added_idx"));
+ cl_git_pass(git_index_remove_bypath(idx, "sm_just_added_head"));
+ cl_git_pass(git_index_write(idx));
+ git_index_free(idx);
+ }
+
+ refute_submodule_exists(g_repo, "sm_just_added_idx", GIT_EEXISTS);
+ assert_submodule_exists(g_repo, "sm_just_added_head");
+
+ {
+ git_signature *sig;
+ cl_git_pass(git_signature_now(&sig, "resetter", "resetter@email.com"));
+ cl_git_pass(git_reference_create(NULL, g_repo, "refs/heads/master", git_reference_target(original_head), 1, sig, "move head back"));
+ git_signature_free(sig);
+ git_reference_free(original_head);
+ }
+
+ refute_submodule_exists(g_repo, "sm_just_added_head", GIT_EEXISTS);
}
+
diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c
index 1aaa56388..582d4166b 100644
--- a/tests/submodule/modify.c
+++ b/tests/submodule/modify.c
@@ -7,61 +7,12 @@ static git_repository *g_repo = NULL;
#define SM_LIBGIT2_URL "https://github.com/libgit2/libgit2.git"
#define SM_LIBGIT2 "sm_libgit2"
-#define SM_LIBGIT2B "sm_libgit2b"
void test_submodule_modify__initialize(void)
{
g_repo = setup_fixture_submod2();
}
-void test_submodule_modify__add(void)
-{
- git_submodule *sm;
- git_config *cfg;
- const char *s;
-
- /* re-add existing submodule */
- 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"));
-
- cl_assert(git_path_isdir("submod2/.git/modules"));
- cl_assert(git_path_isdir("submod2/.git/modules/" SM_LIBGIT2));
- cl_assert(git_path_isfile("submod2/.git/modules/" SM_LIBGIT2 "/HEAD"));
-
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(
- git_config_get_string(&s, cfg, "submodule." SM_LIBGIT2 ".url"));
- cl_assert_equal_s(s, SM_LIBGIT2_URL);
- git_config_free(cfg);
-
- /* add a submodule not using a gitlink */
-
- 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"));
- cl_assert(!git_path_exists("submod2/.git/modules/" SM_LIBGIT2B));
-
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(
- git_config_get_string(&s, cfg, "submodule." SM_LIBGIT2B ".url"));
- cl_assert_equal_s(s, SM_LIBGIT2_URL);
- git_config_free(cfg);
-}
-
static int delete_one_config(const git_config_entry *entry, void *payload)
{
git_config *cfg = payload;
@@ -118,6 +69,26 @@ static int sync_one_submodule(
return git_submodule_sync(sm);
}
+static void assert_submodule_url_is_synced(
+ git_submodule *sm, const char *parent_key, const char *child_key)
+{
+ git_config *cfg;
+ const char *str;
+ git_repository *smrepo;
+
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+ cl_git_pass(git_config_get_string(&str, cfg, parent_key));
+ cl_assert_equal_s(git_submodule_url(sm), str);
+ git_config_free(cfg);
+
+ cl_git_pass(git_submodule_open(&smrepo, sm));
+ cl_git_pass(git_repository_config(&cfg, smrepo));
+ cl_git_pass(git_config_get_string(&str, cfg, child_key));
+ cl_assert_equal_s(git_submodule_url(sm), str);
+ git_config_free(cfg);
+ git_repository_free(smrepo);
+}
+
void test_submodule_modify__sync(void)
{
git_submodule *sm1, *sm2, *sm3;
@@ -153,14 +124,12 @@ void test_submodule_modify__sync(void)
cl_git_pass(git_submodule_foreach(g_repo, sync_one_submodule, NULL));
/* check that submodule config is updated */
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM1".url"));
- cl_assert_equal_s(git_submodule_url(sm1), str);
- cl_git_pass(git_config_get_string(&str, cfg, "submodule."SM2".url"));
- cl_assert_equal_s(git_submodule_url(sm2), str);
- 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);
+ assert_submodule_url_is_synced(
+ sm1, "submodule."SM1".url", "branch.origin.remote");
+ assert_submodule_url_is_synced(
+ sm2, "submodule."SM2".url", "branch.origin.remote");
+ assert_submodule_url_is_synced(
+ sm3, "submodule."SM3".url", "branch.origin.remote");
git_submodule_free(sm1);
git_submodule_free(sm2);
diff --git a/tests/submodule/nosubs.c b/tests/submodule/nosubs.c
index 5ef4f42ab..e343c1620 100644
--- a/tests/submodule/nosubs.c
+++ b/tests/submodule/nosubs.c
@@ -2,6 +2,7 @@
#include "clar_libgit2.h"
#include "posix.h"
+#include "fileops.h"
void test_submodule_nosubs__cleanup(void)
{
@@ -68,7 +69,10 @@ void test_submodule_nosubs__reload_add_reload(void)
cl_git_pass(git_submodule_reload_all(repo, 0));
- cl_git_pass(git_submodule_add_setup(&sm, repo, "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1));
+ /* try one add with a reload (to make sure no errors happen) */
+
+ cl_git_pass(git_submodule_add_setup(&sm, repo,
+ "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1));
cl_git_pass(git_submodule_reload_all(repo, 0));
@@ -78,6 +82,17 @@ void test_submodule_nosubs__reload_add_reload(void)
cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2"));
cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm));
git_submodule_free(sm);
+
+ /* try one add without a reload (to make sure cache inval works, too) */
+
+ cl_git_pass(git_submodule_add_setup(&sm, repo,
+ "https://github.com/libgit2/libgit2.git", "libgit2-again", 1));
+ cl_assert_equal_s("libgit2-again", git_submodule_name(sm));
+ git_submodule_free(sm);
+
+ cl_git_pass(git_submodule_lookup(&sm, repo, "libgit2-again"));
+ cl_assert_equal_s("libgit2-again", git_submodule_name(sm));
+ git_submodule_free(sm);
}
void test_submodule_nosubs__bad_gitmodules(void)
@@ -93,3 +108,69 @@ void test_submodule_nosubs__bad_gitmodules(void)
cl_git_pass(git_submodule_lookup(NULL, repo, "foobar"));
cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(NULL, repo, "subdir"));
}
+
+void test_submodule_nosubs__add_and_delete(void)
+{
+ git_repository *repo = cl_git_sandbox_init("status");
+ git_submodule *sm;
+ git_buf buf = GIT_BUF_INIT;
+
+ /* note lack of calls to git_submodule_reload_all - this *should* work */
+
+ cl_git_fail(git_submodule_lookup(NULL, repo, "libgit2"));
+ cl_git_fail(git_submodule_lookup(NULL, repo, "submodules/libgit2"));
+
+ /* create */
+
+ cl_git_pass(git_submodule_add_setup(
+ &sm, repo, "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1));
+ cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm));
+ cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm));
+ git_submodule_free(sm);
+
+ cl_git_pass(git_futils_readbuffer(&buf, "status/.gitmodules"));
+ cl_assert(strstr(buf.ptr, "[submodule \"submodules/libgit2\"]") != NULL);
+ cl_assert(strstr(buf.ptr, "path = submodules/libgit2") != NULL);
+ git_buf_free(&buf);
+
+ /* lookup */
+
+ cl_git_fail(git_submodule_lookup(&sm, repo, "libgit2"));
+ cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2"));
+ cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm));
+ cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm));
+ git_submodule_free(sm);
+
+ /* update name */
+
+ cl_git_rewritefile(
+ "status/.gitmodules",
+ "[submodule \"libgit2\"]\n"
+ " path = submodules/libgit2\n"
+ " url = https://github.com/libgit2/libgit2.git\n");
+
+ cl_git_pass(git_submodule_lookup(&sm, repo, "libgit2"));
+ cl_assert_equal_s("libgit2", git_submodule_name(sm));
+ cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm));
+ git_submodule_free(sm);
+ cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2"));
+ git_submodule_free(sm);
+
+ /* revert name update */
+
+ cl_git_rewritefile(
+ "status/.gitmodules",
+ "[submodule \"submodules/libgit2\"]\n"
+ " path = submodules/libgit2\n"
+ " url = https://github.com/libgit2/libgit2.git\n");
+
+ cl_git_fail(git_submodule_lookup(&sm, repo, "libgit2"));
+ cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2"));
+ git_submodule_free(sm);
+
+ /* remove completely */
+
+ cl_must_pass(p_unlink("status/.gitmodules"));
+ cl_git_fail(git_submodule_lookup(&sm, repo, "libgit2"));
+ cl_git_fail(git_submodule_lookup(&sm, repo, "submodules/libgit2"));
+}
diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c
index 546f0913a..50aa97568 100644
--- a/tests/submodule/submodule_helpers.c
+++ b/tests/submodule/submodule_helpers.c
@@ -126,20 +126,26 @@ git_repository *setup_fixture_submod2(void)
return repo;
}
-void assert_submodule_exists(git_repository *repo, const char *name)
+void assert__submodule_exists(
+ git_repository *repo, const char *name,
+ const char *msg, const char *file, int line)
{
git_submodule *sm;
- cl_git_pass(git_submodule_lookup(&sm, repo, name));
- cl_assert(sm);
+ int error = git_submodule_lookup(&sm, repo, name);
+ if (error)
+ cl_git_report_failure(error, file, line, msg);
+ cl_assert_at_line(sm != NULL, file, line);
git_submodule_free(sm);
}
-void refute_submodule_exists(
- git_repository *repo, const char *name, int expected_error)
+void refute__submodule_exists(
+ git_repository *repo, const char *name, int expected_error,
+ const char *msg, const char *file, int line)
{
git_submodule *sm;
- cl_assert_equal_i(
- expected_error, git_submodule_lookup(&sm, repo, name));
+ clar__assert_equal(
+ file, line, msg, 1, "%i",
+ expected_error, (int)(git_submodule_lookup(&sm, repo, name)));
}
unsigned int get_submodule_status(git_repository *repo, const char *name)
@@ -154,3 +160,19 @@ unsigned int get_submodule_status(git_repository *repo, const char *name)
return status;
}
+
+static int print_submodules(git_submodule *sm, const char *name, void *p)
+{
+ unsigned int loc = 0;
+ GIT_UNUSED(p);
+ git_submodule_location(&loc, sm);
+ fprintf(stderr, "# submodule %s (at %s) flags %x\n",
+ name, git_submodule_path(sm), loc);
+ return 0;
+}
+
+void dump_submodules(git_repository *repo)
+{
+ git_submodule_foreach(repo, print_submodules, NULL);
+}
+
diff --git a/tests/submodule/submodule_helpers.h b/tests/submodule/submodule_helpers.h
index ec5510e3c..4b2620bfa 100644
--- a/tests/submodule/submodule_helpers.h
+++ b/tests/submodule/submodule_helpers.h
@@ -6,5 +6,16 @@ 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);
+extern void assert__submodule_exists(
+ git_repository *, const char *, const char *, const char *, int);
+
+#define assert_submodule_exists(repo,name) \
+ assert__submodule_exists(repo, name, "git_submodule_lookup(" #name ") failed", __FILE__, __LINE__)
+
+extern void refute__submodule_exists(
+ git_repository *, const char *, int err, const char *, const char *, int);
+
+#define refute_submodule_exists(repo,name,code) \
+ refute__submodule_exists(repo, name, code, "expected git_submodule_lookup(" #name ") to fail with error " #code, __FILE__, __LINE__)
+
+extern void dump_submodules(git_repository *repo);