summaryrefslogtreecommitdiff
path: root/tests/libgit2/graph/commitgraph.c
diff options
context:
space:
mode:
authorlmcglash <lmcglash@mathworks.com>2023-03-10 08:51:43 +0000
committerlmcglash <lmcglash@mathworks.com>2023-03-10 08:51:43 +0000
commit570ef74a07f80d8890a2bf0125d72ee42f83187e (patch)
treec3106ddd08967e3f071f1eec872a1d6db01dec37 /tests/libgit2/graph/commitgraph.c
parenta9793ac643a0cd82b00970d0d6e0b67681ec3112 (diff)
parentd066d0d95c43e97df6624292f3f527f9372ca8fe (diff)
downloadlibgit2-570ef74a07f80d8890a2bf0125d72ee42f83187e.tar.gz
Merge commit 'd066d0d95c43e97df6624292f3f527f9372ca8fe'
Diffstat (limited to 'tests/libgit2/graph/commitgraph.c')
-rw-r--r--tests/libgit2/graph/commitgraph.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/libgit2/graph/commitgraph.c b/tests/libgit2/graph/commitgraph.c
index e2452000d..82f7f936f 100644
--- a/tests/libgit2/graph/commitgraph.c
+++ b/tests/libgit2/graph/commitgraph.c
@@ -124,3 +124,44 @@ void test_graph_commitgraph__writer(void)
git_commit_graph_writer_free(w);
git_repository_free(repo);
}
+
+void test_graph_commitgraph__validate(void)
+{
+ git_repository *repo;
+ struct git_commit_graph *cgraph;
+ git_str objects_dir = GIT_STR_INIT;
+
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+ cl_git_pass(git_str_joinpath(&objects_dir, git_repository_path(repo), "objects"));
+
+ /* git_commit_graph_open() calls git_commit_graph_validate() */
+ cl_git_pass(git_commit_graph_open(&cgraph, git_str_cstr(&objects_dir)));
+
+ git_commit_graph_free(cgraph);
+ git_str_dispose(&objects_dir);
+ git_repository_free(repo);
+}
+
+void test_graph_commitgraph__validate_corrupt(void)
+{
+ git_repository *repo;
+ struct git_commit_graph *cgraph;
+ int fd = -1;
+
+ cl_fixture_sandbox("testrepo.git");
+ cl_git_pass(git_repository_open(&repo, cl_git_sandbox_path(1, "testrepo.git", NULL)));
+
+ /* corrupt commit graph checksum at the end of the file */
+ cl_assert((fd = p_open(cl_git_sandbox_path(0, "testrepo.git", "objects", "info", "commit-graph", NULL), O_WRONLY)) > 0);
+ cl_assert(p_lseek(fd, -5, SEEK_END) > 0);
+ cl_must_pass(p_write(fd, "\0\0", 2));
+ cl_must_pass(p_close(fd));
+
+ /* git_commit_graph_open() calls git_commit_graph_validate() */
+ cl_git_fail(git_commit_graph_open(&cgraph, cl_git_sandbox_path(1, "testrepo.git", "objects", NULL)));
+
+ git_commit_graph_free(cgraph);
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("testrepo.git");
+}