Remove most submodule reloads from tests With the new submodule cache validity checks, we generally don't need to call git_submodule_reload_all to have up-to-date submodule data. Some tests are still calling it where I want to actually test that it can be called safely and doesn't break anything, but mostly it is not needed. This also expands some of the existing submodule tests to cover some variants on the behavior that was already being tested.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
diff --git a/tests/diff/submodules.c b/tests/diff/submodules.c
index 2881f74..02870ac 100644
--- a/tests/diff/submodules.c
+++ b/tests/diff/submodules.c
@@ -131,8 +131,6 @@ void test_diff_submodules__dirty_submodule_2(void)
g_repo = setup_fixture_submodules();
- cl_git_pass(git_submodule_reload_all(g_repo, 1));
-
opts.flags = GIT_DIFF_INCLUDE_UNTRACKED |
GIT_DIFF_SHOW_UNTRACKED_CONTENT |
GIT_DIFF_RECURSE_UNTRACKED_DIRS |
@@ -165,8 +163,6 @@ void test_diff_submodules__dirty_submodule_2(void)
git_diff_free(diff);
- 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);
git_diff_free(diff);
@@ -299,7 +295,6 @@ void test_diff_submodules__invalid_cache(void)
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));
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index 36bde4f..86ba25c 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,62 @@ void test_submodule_lookup__lookup_even_with_missing_index(void)
git_repository_set_index(g_repo, idx);
git_index_free(idx);
- 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__just_added(void)
{
git_submodule *sm;
+ git_buf snap1 = GIT_BUF_INIT, snap2 = GIT_BUF_INIT;
+
+ 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, "mismatch_name", GIT_ENOTFOUND);
+ refute_submodule_exists(g_repo, "mismatch_path", GIT_ENOTFOUND);
+ test_submodule_lookup__simple_lookup(); /* baseline */
- cl_git_pass(git_submodule_add_setup(&sm, g_repo, "https://github.com/libgit2/libgit2.git", "sm_just_added", 1));
+ cl_git_pass(git_futils_readbuffer(&snap1, "submod2/.gitmodules"));
+
+ 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");
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");
+ cl_git_pass(git_futils_readbuffer(&snap2, "submod2/.gitmodules"));
- cl_git_pass(git_submodule_reload_all(g_repo, 1));
+ 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");
+ test_submodule_lookup__simple_lookup();
+
+ cl_git_rewritefile("submod2/.gitmodules", snap2.ptr);
+ git_buf_free(&snap2);
+ 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");
+ test_submodule_lookup__simple_lookup();
- /* all the regular ones should still be working right, too */
+ cl_git_rewritefile("submod2/.gitmodules", snap1.ptr);
+ git_buf_free(&snap1);
- 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);
+ /* 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);
+ test_submodule_lookup__simple_lookup();
}
diff --git a/tests/submodule/nosubs.c b/tests/submodule/nosubs.c
index cabb53e..e343c16 100644
--- a/tests/submodule/nosubs.c
+++ b/tests/submodule/nosubs.c
@@ -69,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));
@@ -79,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)
@@ -101,7 +115,7 @@ void test_submodule_nosubs__add_and_delete(void)
git_submodule *sm;
git_buf buf = GIT_BUF_INIT;
- /* note the lack of calls to git_submodule_reload - this *should* work */
+ /* 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"));