Skip to content

Commit 9d9a90a

Browse files
committed
clone: test bare clone namespaced repo with no HEAD
Test that we can successfully clone a repository that is namespace scoped to a bare repository locally. We need not specify a checkout branch in this case (obviously, since we do not check anything out in a bare clone).
1 parent c928d96 commit 9d9a90a

38 files changed

+91
-9
lines changed

ci/test.sh

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ CONTINUE_ON_FAILURE=0
2222
cleanup() {
2323
echo "Cleaning up..."
2424

25-
if [ ! -z "$GITDAEMON_PID" ]; then
26-
echo "Stopping git daemon..."
27-
kill $GITDAEMON_PID
25+
if [ ! -z "$GIT_STANDARD_PID" ]; then
26+
echo "Stopping git daemon (standard)..."
27+
kill $GIT_STANDARD_PID
28+
fi
29+
30+
if [ ! -z "$GIT_NAMESPACE_PID" ]; then
31+
echo "Stopping git daemon (namespace)..."
32+
kill $GIT_NAMESPACE_PID
2833
fi
2934

3035
if [ ! -z "$PROXY_BASIC_PID" ]; then
@@ -98,11 +103,17 @@ echo "##########################################################################
98103
echo ""
99104

100105
if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
101-
echo "Starting git daemon..."
102-
GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX`
103-
git init --bare "${GITDAEMON_DIR}/test.git" >/dev/null
104-
git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GITDAEMON_DIR}" "${GITDAEMON_DIR}" 2>/dev/null &
105-
GITDAEMON_PID=$!
106+
echo "Starting git daemon (standard)..."
107+
GIT_STANDARD_DIR=`mktemp -d ${TMPDIR}/git_standard.XXXXXXXX`
108+
git init --bare "${GIT_STANDARD_DIR}/test.git" >/dev/null
109+
git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GIT_STANDARD_DIR}" "${GIT_STANDARD_DIR}" 2>/dev/null &
110+
GIT_STANDARD_PID=$!
111+
112+
echo "Starting git daemon (namespace)..."
113+
GIT_NAMESPACE_DIR=`mktemp -d ${TMPDIR}/git_namespace.XXXXXXXX`
114+
cp -R "${SOURCE_DIR}/tests/resources/namespace.git" "${GIT_NAMESPACE_DIR}/namespace.git"
115+
GIT_NAMESPACE="name1" git daemon --listen=localhost --port=9419 --export-all --enable=receive-pack --base-path="${GIT_NAMESPACE_DIR}" "${GIT_NAMESPACE_DIR}" &
116+
GIT_NAMESPACE_PID=$!
106117
fi
107118

108119
if [ -z "$SKIP_PROXY_TESTS" ]; then
@@ -229,12 +240,20 @@ fi
229240

230241
if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
231242
echo ""
232-
echo "Running gitdaemon tests"
243+
echo "Running gitdaemon (standard) tests"
233244
echo ""
234245

235246
export GITTEST_REMOTE_URL="git://localhost/test.git"
236247
run_test gitdaemon
237248
unset GITTEST_REMOTE_URL
249+
250+
echo ""
251+
echo "Running gitdaemon (namespace) tests"
252+
echo ""
253+
254+
export GITTEST_REMOTE_URL="git://localhost:9419/namespace.git"
255+
run_test gitdaemon_namespace
256+
unset GITTEST_REMOTE_URL
238257
fi
239258

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

tests/libgit2/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ add_clar_test(libgit2_tests invasive -v -sfilter::stream::bigfile -so
6969
add_clar_test(libgit2_tests online -v -sonline -xonline::customcert)
7070
add_clar_test(libgit2_tests online_customcert -v -sonline::customcert)
7171
add_clar_test(libgit2_tests gitdaemon -v -sonline::push)
72+
add_clar_test(libgit2_tests gitdaemon_namespace -v -sonline::clone::namespace)
7273
add_clar_test(libgit2_tests ssh -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths -sonline::clone::path_whitespace_ssh)
7374
add_clar_test(libgit2_tests proxy -v -sonline::clone::proxy)
7475
add_clar_test(libgit2_tests auth_clone -v -sonline::clone::cred)

tests/libgit2/online/clone.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,3 +1006,22 @@ void test_online_clone__redirect_initial_fails_for_subsequent(void)
10061006

10071007
cl_git_fail(git_clone(&g_repo, _remote_redirect_subsequent, "./fail", &options));
10081008
}
1009+
1010+
void test_online_clone__namespace_bare(void)
1011+
{
1012+
git_clone_options options = GIT_CLONE_OPTIONS_INIT;
1013+
git_reference *head;
1014+
1015+
if (!_remote_url)
1016+
cl_skip();
1017+
1018+
options.bare = true;
1019+
1020+
cl_git_pass(git_clone(&g_repo, _remote_url, "./namespaced.git", &options));
1021+
1022+
cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE));
1023+
cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head));
1024+
cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
1025+
1026+
git_reference_free(head);
1027+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
four

tests/resources/namespace.git/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/four
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = false
5+
logallrefupdates = true
6+
ignorecase = true
7+
precomposeunicode = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unnamed repository; edit this file 'description' to name the repository.
321 Bytes
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# git ls-files --others --exclude-from=.git/info/exclude
2+
# Lines that start with '#' are comments.
3+
# For a project mostly in C, the following would be a good set of
4+
# exclude patterns (uncomment them if you want to use them):
5+
# *.[oa]
6+
# *~
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
0000000000000000000000000000000000000000 9ebfa6bdc9d38075d29d26aa5df89b1cf635b269 Edward Thomson <ethomson@edwardthomson.com> 1661110058 -0400 commit (initial): Hello, world.
2+
9ebfa6bdc9d38075d29d26aa5df89b1cf635b269 7eeaa70d7c5592db920a2e107ce3918bd4c8a425 Edward Thomson <ethomson@edwardthomson.com> 1661110068 -0400 commit: with enthusiasm
3+
7eeaa70d7c5592db920a2e107ce3918bd4c8a425 7eeaa70d7c5592db920a2e107ce3918bd4c8a425 Edward Thomson <ethomson@edwardthomson.com> 1661110072 -0400 checkout: moving from main to branch
4+
7eeaa70d7c5592db920a2e107ce3918bd4c8a425 3d669d1b33ec8add4609d8043d025527db4989eb Edward Thomson <ethomson@edwardthomson.com> 1661110088 -0400 commit: capitalize
5+
3d669d1b33ec8add4609d8043d025527db4989eb bfd17f429f4e2d121769213171ad57ca2e5173f9 Edward Thomson <ethomson@edwardthomson.com> 1661110104 -0400 commit: less enthusiastic
6+
bfd17f429f4e2d121769213171ad57ca2e5173f9 7eeaa70d7c5592db920a2e107ce3918bd4c8a425 Edward Thomson <ethomson@edwardthomson.com> 1661110107 -0400 checkout: moving from branch to main
7+
0000000000000000000000000000000000000000 420d51ce75a87909e29659da2072ffd3d5daf5b7 Edward Thomson <ethomson@edwardthomson.com> 1661110166 -0400 commit (initial): 1 2 3
8+
420d51ce75a87909e29659da2072ffd3d5daf5b7 420d51ce75a87909e29659da2072ffd3d5daf5b7 Edward Thomson <ethomson@edwardthomson.com> 1661110209 -0400 checkout: moving from one to four
9+
420d51ce75a87909e29659da2072ffd3d5daf5b7 04433ff5b52d6ad534fd6288de4a57b81cc12188 Edward Thomson <ethomson@edwardthomson.com> 1661110212 -0400 commit: four

0 commit comments

Comments
 (0)