From cf326948b13e066db18f86d3ea8a68916f972a2d Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Fri, 16 Sep 2022 18:02:22 -0400 Subject: [PATCH] clone: test for cloning a repo with namespace scope Test that we can successfully clone a repository that is namespace scoped on the remote and does not advertise a HEAD. To do this, we must specify the branch to checkout. --- ci/test.sh | 2 ++ tests/libgit2/online/clone.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/ci/test.sh b/ci/test.sh index c1e514911..0e1d39e8d 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -252,8 +252,10 @@ if [ -z "$SKIP_GITDAEMON_TESTS" ]; then echo "" export GITTEST_REMOTE_URL="git://localhost:9419/namespace.git" + export GITTEST_REMOTE_BRANCH="four" run_test gitdaemon_namespace unset GITTEST_REMOTE_URL + unset GITTEST_REMOTE_BRANCH fi if [ -z "$SKIP_PROXY_TESTS" ]; then diff --git a/tests/libgit2/online/clone.c b/tests/libgit2/online/clone.c index fd8fb17ea..51a76c78a 100644 --- a/tests/libgit2/online/clone.c +++ b/tests/libgit2/online/clone.c @@ -21,6 +21,7 @@ static git_clone_options g_options; static char *_remote_url = NULL; static char *_remote_user = NULL; static char *_remote_pass = NULL; +static char *_remote_branch = NULL; static char *_remote_sslnoverify = NULL; static char *_remote_ssh_pubkey = NULL; static char *_remote_ssh_privkey = NULL; @@ -69,6 +70,7 @@ void test_online_clone__initialize(void) _remote_url = cl_getenv("GITTEST_REMOTE_URL"); _remote_user = cl_getenv("GITTEST_REMOTE_USER"); _remote_pass = cl_getenv("GITTEST_REMOTE_PASS"); + _remote_branch = cl_getenv("GITTEST_REMOTE_BRANCH"); _remote_sslnoverify = cl_getenv("GITTEST_REMOTE_SSL_NOVERIFY"); _remote_ssh_pubkey = cl_getenv("GITTEST_REMOTE_SSH_PUBKEY"); _remote_ssh_privkey = cl_getenv("GITTEST_REMOTE_SSH_KEY"); @@ -102,6 +104,7 @@ void test_online_clone__cleanup(void) git__free(_remote_url); git__free(_remote_user); git__free(_remote_pass); + git__free(_remote_branch); git__free(_remote_sslnoverify); git__free(_remote_ssh_pubkey); git__free(_remote_ssh_privkey); @@ -1025,3 +1028,23 @@ void test_online_clone__namespace_bare(void) git_reference_free(head); } + +void test_online_clone__namespace_with_specified_branch(void) +{ + git_clone_options options = GIT_CLONE_OPTIONS_INIT; + git_reference *head; + + if (!_remote_url || !_remote_branch) + cl_skip(); + + options.checkout_branch = _remote_branch; + + cl_git_pass(git_clone(&g_repo, _remote_url, "./namespaced", &options)); + + cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE)); + cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head)); + cl_assert_equal_strn("refs/heads/", git_reference_symbolic_target(head), 11); + cl_assert_equal_s(_remote_branch, git_reference_symbolic_target(head) + 11); + + git_reference_free(head); +}