summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authoryuangli <yuangli@mathworks.com>2022-07-19 15:42:12 +0100
committeryuangli <yuangli@mathworks.com>2022-07-19 15:42:12 +0100
commitf19ffc8a6d88432146a87cd3fb2ca21528478be4 (patch)
tree9fb44acf07c7d2367c696b13c8a63095c7ce4853 /tests
parentc652f3d13372398fc86c72a7b05c90002d1cc763 (diff)
downloadlibgit2-f19ffc8a6d88432146a87cd3fb2ca21528478be4.tar.gz
add test for shallow repo depth 1
Diffstat (limited to 'tests')
-rw-r--r--tests/clone/shallow.c60
1 files changed, 49 insertions, 11 deletions
diff --git a/tests/clone/shallow.c b/tests/clone/shallow.c
index b3e8f1617..01852dfed 100644
--- a/tests/clone/shallow.c
+++ b/tests/clone/shallow.c
@@ -4,17 +4,15 @@
void test_clone_shallow__initialize(void)
{
-
+ cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 1));
}
void test_clone_shallow__cleanup(void)
{
+ git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 0);
cl_git_sandbox_cleanup();
}
-
-#define CLONE_DEPTH 5
-
static int remote_single_branch(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload)
{
GIT_UNUSED(payload);
@@ -24,7 +22,47 @@ static int remote_single_branch(git_remote **out, git_repository *repo, const ch
return 0;
}
-void test_clone_shallow__clone_depth(void)
+void test_clone_shallow__clone_depth_one(void)
+{
+ git_buf path = GIT_BUF_INIT;
+ git_repository *repo;
+ git_revwalk *walk;
+ git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
+ git_oid oid;
+ git_oidarray roots;
+ size_t num_commits = 0;
+ int error = 0;
+
+ clone_opts.fetch_opts.depth = 1;
+ clone_opts.remote_cb = remote_single_branch;
+
+ git_buf_joinpath(&path, clar_sandbox_path(), "shallowclone_1");
+
+ cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_buf_cstr(&path), &clone_opts));
+
+ cl_assert_equal_b(true, git_repository_is_shallow(repo));
+
+ cl_git_pass(git_repository_shallow_roots(&roots, repo));
+ cl_assert_equal_i(1, roots.count);
+ cl_assert_equal_s("49322bb17d3acc9146f98c97d078513228bbf3c0", git_oid_tostr_s(&roots.ids[0]));
+
+ git_revwalk_new(&walk, repo);
+
+ git_revwalk_push_head(walk);
+
+ while ((error = git_revwalk_next(&oid, walk)) == GIT_OK) {
+ num_commits++;
+ }
+
+ cl_assert_equal_i(num_commits, 1);
+ cl_assert_equal_i(error, GIT_ITEROVER);
+
+ git_buf_dispose(&path);
+ git_revwalk_free(walk);
+ git_repository_free(repo);
+}
+
+void test_clone_shallow__clone_depth_five(void)
{
git_buf path = GIT_BUF_INIT;
git_repository *repo;
@@ -32,13 +70,13 @@ void test_clone_shallow__clone_depth(void)
git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
git_oid oid;
git_oidarray roots;
- size_t depth = 0;
+ size_t num_commits = 0;
int error = 0;
- clone_opts.fetch_opts.depth = CLONE_DEPTH;
+ clone_opts.fetch_opts.depth = 5;
clone_opts.remote_cb = remote_single_branch;
- git_buf_joinpath(&path, clar_sandbox_path(), "shallowclone");
+ git_buf_joinpath(&path, clar_sandbox_path(), "shallowclone_5");
cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_buf_cstr(&path), &clone_opts));
@@ -55,11 +93,11 @@ void test_clone_shallow__clone_depth(void)
git_revwalk_push_head(walk);
while ((error = git_revwalk_next(&oid, walk)) == GIT_OK) {
- if (depth + 1 > CLONE_DEPTH)
- cl_fail("expected depth mismatch");
+ num_commits++;
}
- cl_git_pass(error);
+ cl_assert_equal_i(num_commits, 13);
+ cl_assert_equal_i(error, GIT_ITEROVER);
git_buf_dispose(&path);
git_revwalk_free(walk);