Commit 1a8990082aeeb1fbf6028d7c2b480f3086c87307

Patrick Wang 2020-05-26T20:36:13

tests: index::version: write v4 index: re-open repo to read written v4 index The `git_index_free()` merely decrement the reference counter from 2 to 1, and does not "free" the index. Thus, the following `git_repository_index()` merely increase the counter to 2, instead of read index from disk. The written index is not read and parsed, which makes this test case effectively becomes a no-op.

diff --git a/tests/index/version.c b/tests/index/version.c
index 3827df8..b6c0b79 100644
--- a/tests/index/version.c
+++ b/tests/index/version.c
@@ -43,6 +43,7 @@ void test_index_version__can_write_v4(void)
 	    "xz",
 	    "xyzzyx"
 	};
+	git_repository *repo;
 	git_index_entry entry;
 	git_index *index;
 	size_t i;
@@ -63,7 +64,8 @@ void test_index_version__can_write_v4(void)
 	cl_git_pass(git_index_write(index));
 	git_index_free(index);
 
-	cl_git_pass(git_repository_index(&index, g_repo));
+	cl_git_pass(git_repository_open(&repo, git_repository_path(g_repo)));
+	cl_git_pass(git_repository_index(&index, repo));
 	cl_assert(git_index_version(index) == 4);
 
 	for (i = 0; i < ARRAY_SIZE(paths); i++) {
@@ -74,6 +76,7 @@ void test_index_version__can_write_v4(void)
 	}
 
 	git_index_free(index);
+	git_repository_free(repo);
 }
 
 void test_index_version__v4_uses_path_compression(void)