Skip to content

Commit 44b8248

Browse files
authored
Merge pull request libgit2#6369 from torvalds/main
Don't fail the whole clone if you can't find a default branch
2 parents d111cc9 + cf32694 commit 44b8248

39 files changed

+121
-10
lines changed

ci/test.sh

Lines changed: 30 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,22 @@ 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+
export GITTEST_REMOTE_BRANCH="four"
256+
run_test gitdaemon_namespace
257+
unset GITTEST_REMOTE_URL
258+
unset GITTEST_REMOTE_BRANCH
238259
fi
239260

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

src/libgit2/clone.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,11 @@ static int update_head_to_branch(
282282
reflog_message)) < 0)
283283
goto cleanup;
284284

285-
if ((retcode = git_remote__default_branch(&default_branch, remote)) < 0)
285+
retcode = git_remote__default_branch(&default_branch, remote);
286+
287+
if (retcode == GIT_ENOTFOUND)
288+
retcode = 0;
289+
else if (retcode)
286290
goto cleanup;
287291

288292
if (!git_remote__matching_refspec(remote, git_str_cstr(&default_branch)))

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: 42 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);
@@ -1016,3 +1019,42 @@ void test_online_clone__redirect_initial_fails_for_subsequent(void)
10161019

10171020
cl_git_fail(git_clone(&g_repo, _remote_redirect_subsequent, "./fail", &options));
10181021
}
1022+
1023+
void test_online_clone__namespace_bare(void)
1024+
{
1025+
git_clone_options options = GIT_CLONE_OPTIONS_INIT;
1026+
git_reference *head;
1027+
1028+
if (!_remote_url)
1029+
cl_skip();
1030+
1031+
options.bare = true;
1032+
1033+
cl_git_pass(git_clone(&g_repo, _remote_url, "./namespaced.git", &options));
1034+
1035+
cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE));
1036+
cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head));
1037+
cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
1038+
1039+
git_reference_free(head);
1040+
}
1041+
1042+
void test_online_clone__namespace_with_specified_branch(void)
1043+
{
1044+
git_clone_options options = GIT_CLONE_OPTIONS_INIT;
1045+
git_reference *head;
1046+
1047+
if (!_remote_url || !_remote_branch)
1048+
cl_skip();
1049+
1050+
options.checkout_branch = _remote_branch;
1051+
1052+
cl_git_pass(git_clone(&g_repo, _remote_url, "./namespaced", &options));
1053+
1054+
cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE));
1055+
cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head));
1056+
cl_assert_equal_strn("refs/heads/", git_reference_symbolic_target(head), 11);
1057+
cl_assert_equal_s(_remote_branch, git_reference_symbolic_target(head) + 11);
1058+
1059+
git_reference_free(head);
1060+
}
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+
# *~

0 commit comments

Comments
 (0)