Skip to content

Commit cf32694

Browse files
committed
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.
1 parent 9d9a90a commit cf32694

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

ci/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,10 @@ if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
252252
echo ""
253253

254254
export GITTEST_REMOTE_URL="git://localhost:9419/namespace.git"
255+
export GITTEST_REMOTE_BRANCH="four"
255256
run_test gitdaemon_namespace
256257
unset GITTEST_REMOTE_URL
258+
unset GITTEST_REMOTE_BRANCH
257259
fi
258260

259261
if [ -z "$SKIP_PROXY_TESTS" ]; then

tests/libgit2/online/clone.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static git_clone_options g_options;
2121
static char *_remote_url = NULL;
2222
static char *_remote_user = NULL;
2323
static char *_remote_pass = NULL;
24+
static char *_remote_branch = NULL;
2425
static char *_remote_sslnoverify = NULL;
2526
static char *_remote_ssh_pubkey = NULL;
2627
static char *_remote_ssh_privkey = NULL;
@@ -69,6 +70,7 @@ void test_online_clone__initialize(void)
6970
_remote_url = cl_getenv("GITTEST_REMOTE_URL");
7071
_remote_user = cl_getenv("GITTEST_REMOTE_USER");
7172
_remote_pass = cl_getenv("GITTEST_REMOTE_PASS");
73+
_remote_branch = cl_getenv("GITTEST_REMOTE_BRANCH");
7274
_remote_sslnoverify = cl_getenv("GITTEST_REMOTE_SSL_NOVERIFY");
7375
_remote_ssh_pubkey = cl_getenv("GITTEST_REMOTE_SSH_PUBKEY");
7476
_remote_ssh_privkey = cl_getenv("GITTEST_REMOTE_SSH_KEY");
@@ -102,6 +104,7 @@ void test_online_clone__cleanup(void)
102104
git__free(_remote_url);
103105
git__free(_remote_user);
104106
git__free(_remote_pass);
107+
git__free(_remote_branch);
105108
git__free(_remote_sslnoverify);
106109
git__free(_remote_ssh_pubkey);
107110
git__free(_remote_ssh_privkey);
@@ -1025,3 +1028,23 @@ void test_online_clone__namespace_bare(void)
10251028

10261029
git_reference_free(head);
10271030
}
1031+
1032+
void test_online_clone__namespace_with_specified_branch(void)
1033+
{
1034+
git_clone_options options = GIT_CLONE_OPTIONS_INIT;
1035+
git_reference *head;
1036+
1037+
if (!_remote_url || !_remote_branch)
1038+
cl_skip();
1039+
1040+
options.checkout_branch = _remote_branch;
1041+
1042+
cl_git_pass(git_clone(&g_repo, _remote_url, "./namespaced", &options));
1043+
1044+
cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE));
1045+
cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head));
1046+
cl_assert_equal_strn("refs/heads/", git_reference_symbolic_target(head), 11);
1047+
cl_assert_equal_s(_remote_branch, git_reference_symbolic_target(head) + 11);
1048+
1049+
git_reference_free(head);
1050+
}

0 commit comments

Comments
 (0)