Ensure submodule repos and indices are freed ...before the helper's cleanup method tries to delete their files.
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
diff --git a/tests-clar/stash/submodules.c b/tests-clar/stash/submodules.c
index 60dbbad..137c440 100644
--- a/tests-clar/stash/submodules.c
+++ b/tests-clar/stash/submodules.c
@@ -6,9 +6,7 @@ static git_repository *repo;
static git_signature *signature;
static git_oid stash_tip_oid;
-static git_index *smindex;
static git_submodule *sm;
-static git_repository *smrepo;
void test_stash_submodules__initialize(void)
{
@@ -17,8 +15,6 @@ void test_stash_submodules__initialize(void)
repo = setup_fixture_submodules();
cl_git_pass(git_submodule_lookup(&sm, repo, "testrepo"));
- cl_git_pass(git_submodule_open(&smrepo, sm));
- cl_git_pass(git_repository_index(&smindex, smrepo));
}
void test_stash_submodules__cleanup(void)
@@ -29,6 +25,9 @@ void test_stash_submodules__cleanup(void)
void test_stash_submodules__does_not_stash_modified_submodules(void)
{
+ static git_index *smindex;
+ static git_repository *smrepo;
+
assert_status(repo, "modified", GIT_STATUS_WT_MODIFIED);
/* modify file in submodule */
@@ -36,6 +35,8 @@ void test_stash_submodules__does_not_stash_modified_submodules(void)
assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED);
/* add file to index in submodule */
+ cl_git_pass(git_submodule_open(&smrepo, sm));
+ cl_git_pass(git_repository_index(&smindex, smrepo));
cl_git_pass(git_index_add_bypath(smindex, "README"));
/* commit changed index of submodule */
@@ -46,10 +47,16 @@ void test_stash_submodules__does_not_stash_modified_submodules(void)
assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED);
assert_status(repo, "modified", GIT_STATUS_CURRENT);
+
+ git_index_free(smindex);
+ git_repository_free(smrepo);
}
void test_stash_submodules__stash_is_empty_with_modified_submodules(void)
{
+ static git_index *smindex;
+ static git_repository *smrepo;
+
cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
assert_status(repo, "modified", GIT_STATUS_CURRENT);
@@ -58,6 +65,8 @@ void test_stash_submodules__stash_is_empty_with_modified_submodules(void)
assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED);
/* add file to index in submodule */
+ cl_git_pass(git_submodule_open(&smrepo, sm));
+ cl_git_pass(git_repository_index(&smindex, smrepo));
cl_git_pass(git_index_add_bypath(smindex, "README"));
/* commit changed index of submodule */
@@ -65,4 +74,7 @@ void test_stash_submodules__stash_is_empty_with_modified_submodules(void)
assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED);
cl_git_fail_with(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT), GIT_ENOTFOUND);
+
+ git_index_free(smindex);
+ git_repository_free(smrepo);
}