From 9d9a90ad3d64d54948b736f6866a82c6670b61c1 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Fri, 16 Sep 2022 14:27:13 -0400 Subject: [PATCH] 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). --- ci/test.sh | 37 +++++++++++++----- tests/libgit2/CMakeLists.txt | 1 + tests/libgit2/online/clone.c | 19 +++++++++ tests/resources/namespace.git/COMMIT_EDITMSG | 1 + tests/resources/namespace.git/HEAD | 1 + tests/resources/namespace.git/config | 7 ++++ tests/resources/namespace.git/description | 1 + tests/resources/namespace.git/index | Bin 0 -> 321 bytes tests/resources/namespace.git/info/exclude | 6 +++ tests/resources/namespace.git/logs/HEAD | 9 +++++ .../namespace.git/logs/refs/heads/branch | 3 ++ .../namespace.git/logs/refs/heads/four | 2 + .../namespace.git/logs/refs/heads/main | 2 + .../namespace.git/logs/refs/heads/one | 1 + .../04/433ff5b52d6ad534fd6288de4a57b81cc12188 | Bin 0 -> 160 bytes .../0a/890bd10328d68f6d85efd2535e3a4c588ee8e6 | Bin 0 -> 54 bytes .../10/fcb1c85bd6b3bc6f43e0a3932ff5859121a84e | Bin 0 -> 54 bytes .../24/bbdca8b223aaa3384d78312f730c58492aa30a | Bin 0 -> 54 bytes .../27/0c611ee72c567bc1b2abec4cbc345bab9f15ba | Bin 0 -> 30 bytes .../2b/df67abb163a4ffb2d7f3f0880c9fe5068ce782 | Bin 0 -> 21 bytes .../3d/669d1b33ec8add4609d8043d025527db4989eb | 2 + .../42/0d51ce75a87909e29659da2072ffd3d5daf5b7 | Bin 0 -> 128 bytes .../56/26abf0f72e58d7a153368ba57db4c673c0e171 | Bin 0 -> 19 bytes .../56/300b5eae653453102ac1213e921973c066425b | Bin 0 -> 95 bytes .../7e/eaa70d7c5592db920a2e107ce3918bd4c8a425 | 2 + .../85/10665149157c2bc901848c3e0b746954e9cbd9 | Bin 0 -> 20 bytes .../9e/bfa6bdc9d38075d29d26aa5df89b1cf635b269 | Bin 0 -> 137 bytes .../9e/f15e3c5c0c8c6913936f843ad967cbe5541f0d | Bin 0 -> 121 bytes .../af/5626b4a114abcb82d63db7c8082c3c4756e51b | Bin 0 -> 30 bytes .../af/81e4bd99cbfe6f05a501f1e4c82db2bf803e02 | Bin 0 -> 30 bytes .../bf/d17f429f4e2d121769213171ad57ca2e5173f9 | 2 + .../ec/947e3dd7a7752d078f1ed0cfde7457b21fef58 | Bin 0 -> 54 bytes .../f7/19efd430d52bcfc8566a43b2eb655688d38871 | Bin 0 -> 19 bytes .../f7/5ba05f340c51065cbea2e1fdbfe5fe13144c97 | Bin 0 -> 30 bytes .../resources/namespace.git/refs/heads/branch | 1 + tests/resources/namespace.git/refs/heads/main | 1 + .../refs/namespaces/name1/refs/heads/four | 1 + .../refs/namespaces/name1/refs/heads/one | 1 + 38 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 tests/resources/namespace.git/COMMIT_EDITMSG create mode 100644 tests/resources/namespace.git/HEAD create mode 100644 tests/resources/namespace.git/config create mode 100644 tests/resources/namespace.git/description create mode 100644 tests/resources/namespace.git/index create mode 100644 tests/resources/namespace.git/info/exclude create mode 100644 tests/resources/namespace.git/logs/HEAD create mode 100644 tests/resources/namespace.git/logs/refs/heads/branch create mode 100644 tests/resources/namespace.git/logs/refs/heads/four create mode 100644 tests/resources/namespace.git/logs/refs/heads/main create mode 100644 tests/resources/namespace.git/logs/refs/heads/one create mode 100644 tests/resources/namespace.git/objects/04/433ff5b52d6ad534fd6288de4a57b81cc12188 create mode 100644 tests/resources/namespace.git/objects/0a/890bd10328d68f6d85efd2535e3a4c588ee8e6 create mode 100644 tests/resources/namespace.git/objects/10/fcb1c85bd6b3bc6f43e0a3932ff5859121a84e create mode 100644 tests/resources/namespace.git/objects/24/bbdca8b223aaa3384d78312f730c58492aa30a create mode 100644 tests/resources/namespace.git/objects/27/0c611ee72c567bc1b2abec4cbc345bab9f15ba create mode 100644 tests/resources/namespace.git/objects/2b/df67abb163a4ffb2d7f3f0880c9fe5068ce782 create mode 100644 tests/resources/namespace.git/objects/3d/669d1b33ec8add4609d8043d025527db4989eb create mode 100644 tests/resources/namespace.git/objects/42/0d51ce75a87909e29659da2072ffd3d5daf5b7 create mode 100644 tests/resources/namespace.git/objects/56/26abf0f72e58d7a153368ba57db4c673c0e171 create mode 100644 tests/resources/namespace.git/objects/56/300b5eae653453102ac1213e921973c066425b create mode 100644 tests/resources/namespace.git/objects/7e/eaa70d7c5592db920a2e107ce3918bd4c8a425 create mode 100644 tests/resources/namespace.git/objects/85/10665149157c2bc901848c3e0b746954e9cbd9 create mode 100644 tests/resources/namespace.git/objects/9e/bfa6bdc9d38075d29d26aa5df89b1cf635b269 create mode 100644 tests/resources/namespace.git/objects/9e/f15e3c5c0c8c6913936f843ad967cbe5541f0d create mode 100644 tests/resources/namespace.git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b create mode 100644 tests/resources/namespace.git/objects/af/81e4bd99cbfe6f05a501f1e4c82db2bf803e02 create mode 100644 tests/resources/namespace.git/objects/bf/d17f429f4e2d121769213171ad57ca2e5173f9 create mode 100644 tests/resources/namespace.git/objects/ec/947e3dd7a7752d078f1ed0cfde7457b21fef58 create mode 100644 tests/resources/namespace.git/objects/f7/19efd430d52bcfc8566a43b2eb655688d38871 create mode 100644 tests/resources/namespace.git/objects/f7/5ba05f340c51065cbea2e1fdbfe5fe13144c97 create mode 100644 tests/resources/namespace.git/refs/heads/branch create mode 100644 tests/resources/namespace.git/refs/heads/main create mode 100644 tests/resources/namespace.git/refs/namespaces/name1/refs/heads/four create mode 100644 tests/resources/namespace.git/refs/namespaces/name1/refs/heads/one diff --git a/ci/test.sh b/ci/test.sh index 9e5ff9a3e..c1e514911 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -22,9 +22,14 @@ CONTINUE_ON_FAILURE=0 cleanup() { echo "Cleaning up..." - if [ ! -z "$GITDAEMON_PID" ]; then - echo "Stopping git daemon..." - kill $GITDAEMON_PID + if [ ! -z "$GIT_STANDARD_PID" ]; then + echo "Stopping git daemon (standard)..." + kill $GIT_STANDARD_PID + fi + + if [ ! -z "$GIT_NAMESPACE_PID" ]; then + echo "Stopping git daemon (namespace)..." + kill $GIT_NAMESPACE_PID fi if [ ! -z "$PROXY_BASIC_PID" ]; then @@ -98,11 +103,17 @@ echo "########################################################################## echo "" if [ -z "$SKIP_GITDAEMON_TESTS" ]; then - echo "Starting git daemon..." - GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX` - git init --bare "${GITDAEMON_DIR}/test.git" >/dev/null - git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GITDAEMON_DIR}" "${GITDAEMON_DIR}" 2>/dev/null & - GITDAEMON_PID=$! + echo "Starting git daemon (standard)..." + GIT_STANDARD_DIR=`mktemp -d ${TMPDIR}/git_standard.XXXXXXXX` + git init --bare "${GIT_STANDARD_DIR}/test.git" >/dev/null + git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GIT_STANDARD_DIR}" "${GIT_STANDARD_DIR}" 2>/dev/null & + GIT_STANDARD_PID=$! + + echo "Starting git daemon (namespace)..." + GIT_NAMESPACE_DIR=`mktemp -d ${TMPDIR}/git_namespace.XXXXXXXX` + cp -R "${SOURCE_DIR}/tests/resources/namespace.git" "${GIT_NAMESPACE_DIR}/namespace.git" + GIT_NAMESPACE="name1" git daemon --listen=localhost --port=9419 --export-all --enable=receive-pack --base-path="${GIT_NAMESPACE_DIR}" "${GIT_NAMESPACE_DIR}" & + GIT_NAMESPACE_PID=$! fi if [ -z "$SKIP_PROXY_TESTS" ]; then @@ -229,12 +240,20 @@ fi if [ -z "$SKIP_GITDAEMON_TESTS" ]; then echo "" - echo "Running gitdaemon tests" + echo "Running gitdaemon (standard) tests" echo "" export GITTEST_REMOTE_URL="git://localhost/test.git" run_test gitdaemon unset GITTEST_REMOTE_URL + + echo "" + echo "Running gitdaemon (namespace) tests" + echo "" + + export GITTEST_REMOTE_URL="git://localhost:9419/namespace.git" + run_test gitdaemon_namespace + unset GITTEST_REMOTE_URL fi if [ -z "$SKIP_PROXY_TESTS" ]; then diff --git a/tests/libgit2/CMakeLists.txt b/tests/libgit2/CMakeLists.txt index 7f6fafe77..17f2253f0 100644 --- a/tests/libgit2/CMakeLists.txt +++ b/tests/libgit2/CMakeLists.txt @@ -69,6 +69,7 @@ add_clar_test(libgit2_tests invasive -v -sfilter::stream::bigfile -so add_clar_test(libgit2_tests online -v -sonline -xonline::customcert) add_clar_test(libgit2_tests online_customcert -v -sonline::customcert) add_clar_test(libgit2_tests gitdaemon -v -sonline::push) +add_clar_test(libgit2_tests gitdaemon_namespace -v -sonline::clone::namespace) add_clar_test(libgit2_tests ssh -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths -sonline::clone::path_whitespace_ssh) add_clar_test(libgit2_tests proxy -v -sonline::clone::proxy) add_clar_test(libgit2_tests auth_clone -v -sonline::clone::cred) diff --git a/tests/libgit2/online/clone.c b/tests/libgit2/online/clone.c index 6a087b1af..fd8fb17ea 100644 --- a/tests/libgit2/online/clone.c +++ b/tests/libgit2/online/clone.c @@ -1006,3 +1006,22 @@ void test_online_clone__redirect_initial_fails_for_subsequent(void) cl_git_fail(git_clone(&g_repo, _remote_redirect_subsequent, "./fail", &options)); } + +void test_online_clone__namespace_bare(void) +{ + git_clone_options options = GIT_CLONE_OPTIONS_INIT; + git_reference *head; + + if (!_remote_url) + cl_skip(); + + options.bare = true; + + cl_git_pass(git_clone(&g_repo, _remote_url, "./namespaced.git", &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_s("refs/heads/master", git_reference_symbolic_target(head)); + + git_reference_free(head); +} diff --git a/tests/resources/namespace.git/COMMIT_EDITMSG b/tests/resources/namespace.git/COMMIT_EDITMSG new file mode 100644 index 000000000..851066514 --- /dev/null +++ b/tests/resources/namespace.git/COMMIT_EDITMSG @@ -0,0 +1 @@ +four diff --git a/tests/resources/namespace.git/HEAD b/tests/resources/namespace.git/HEAD new file mode 100644 index 000000000..60cbd742c --- /dev/null +++ b/tests/resources/namespace.git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/four diff --git a/tests/resources/namespace.git/config b/tests/resources/namespace.git/config new file mode 100644 index 000000000..6c9406b7d --- /dev/null +++ b/tests/resources/namespace.git/config @@ -0,0 +1,7 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = true diff --git a/tests/resources/namespace.git/description b/tests/resources/namespace.git/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/tests/resources/namespace.git/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/resources/namespace.git/index b/tests/resources/namespace.git/index new file mode 100644 index 0000000000000000000000000000000000000000..5ed27feb0636755a2a55a6ddf376fb411434c183 GIT binary patch literal 321 zcmZ?q402{*U|<4bmSm>(R(|Gx=U_A=P>fOYlQ9EB;}Ql2#;-s%A|Q2PYO6nd*NeEm zFxaenY3-I{#Rnc1GB6r40QI%Ye!VdPMnm;mpzHrG`TmN*RqgX9!m^w 1661110058 -0400 commit (initial): Hello, world. +9ebfa6bdc9d38075d29d26aa5df89b1cf635b269 7eeaa70d7c5592db920a2e107ce3918bd4c8a425 Edward Thomson 1661110068 -0400 commit: with enthusiasm +7eeaa70d7c5592db920a2e107ce3918bd4c8a425 7eeaa70d7c5592db920a2e107ce3918bd4c8a425 Edward Thomson 1661110072 -0400 checkout: moving from main to branch +7eeaa70d7c5592db920a2e107ce3918bd4c8a425 3d669d1b33ec8add4609d8043d025527db4989eb Edward Thomson 1661110088 -0400 commit: capitalize +3d669d1b33ec8add4609d8043d025527db4989eb bfd17f429f4e2d121769213171ad57ca2e5173f9 Edward Thomson 1661110104 -0400 commit: less enthusiastic +bfd17f429f4e2d121769213171ad57ca2e5173f9 7eeaa70d7c5592db920a2e107ce3918bd4c8a425 Edward Thomson 1661110107 -0400 checkout: moving from branch to main +0000000000000000000000000000000000000000 420d51ce75a87909e29659da2072ffd3d5daf5b7 Edward Thomson 1661110166 -0400 commit (initial): 1 2 3 +420d51ce75a87909e29659da2072ffd3d5daf5b7 420d51ce75a87909e29659da2072ffd3d5daf5b7 Edward Thomson 1661110209 -0400 checkout: moving from one to four +420d51ce75a87909e29659da2072ffd3d5daf5b7 04433ff5b52d6ad534fd6288de4a57b81cc12188 Edward Thomson 1661110212 -0400 commit: four diff --git a/tests/resources/namespace.git/logs/refs/heads/branch b/tests/resources/namespace.git/logs/refs/heads/branch new file mode 100644 index 000000000..e3dfea400 --- /dev/null +++ b/tests/resources/namespace.git/logs/refs/heads/branch @@ -0,0 +1,3 @@ +0000000000000000000000000000000000000000 7eeaa70d7c5592db920a2e107ce3918bd4c8a425 Edward Thomson 1661110072 -0400 branch: Created from HEAD +7eeaa70d7c5592db920a2e107ce3918bd4c8a425 3d669d1b33ec8add4609d8043d025527db4989eb Edward Thomson 1661110088 -0400 commit: capitalize +3d669d1b33ec8add4609d8043d025527db4989eb bfd17f429f4e2d121769213171ad57ca2e5173f9 Edward Thomson 1661110104 -0400 commit: less enthusiastic diff --git a/tests/resources/namespace.git/logs/refs/heads/four b/tests/resources/namespace.git/logs/refs/heads/four new file mode 100644 index 000000000..2abf339ac --- /dev/null +++ b/tests/resources/namespace.git/logs/refs/heads/four @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 420d51ce75a87909e29659da2072ffd3d5daf5b7 Edward Thomson 1661110209 -0400 branch: Created from HEAD +420d51ce75a87909e29659da2072ffd3d5daf5b7 04433ff5b52d6ad534fd6288de4a57b81cc12188 Edward Thomson 1661110212 -0400 commit: four diff --git a/tests/resources/namespace.git/logs/refs/heads/main b/tests/resources/namespace.git/logs/refs/heads/main new file mode 100644 index 000000000..04de95a49 --- /dev/null +++ b/tests/resources/namespace.git/logs/refs/heads/main @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 9ebfa6bdc9d38075d29d26aa5df89b1cf635b269 Edward Thomson 1661110058 -0400 commit (initial): Hello, world. +9ebfa6bdc9d38075d29d26aa5df89b1cf635b269 7eeaa70d7c5592db920a2e107ce3918bd4c8a425 Edward Thomson 1661110068 -0400 commit: with enthusiasm diff --git a/tests/resources/namespace.git/logs/refs/heads/one b/tests/resources/namespace.git/logs/refs/heads/one new file mode 100644 index 000000000..bd3c5fa25 --- /dev/null +++ b/tests/resources/namespace.git/logs/refs/heads/one @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 420d51ce75a87909e29659da2072ffd3d5daf5b7 Edward Thomson 1661110166 -0400 commit (initial): 1 2 3 diff --git a/tests/resources/namespace.git/objects/04/433ff5b52d6ad534fd6288de4a57b81cc12188 b/tests/resources/namespace.git/objects/04/433ff5b52d6ad534fd6288de4a57b81cc12188 new file mode 100644 index 0000000000000000000000000000000000000000..be49bee0e6040ca0bfb3d840be3a38a9d56994a9 GIT binary patch literal 160 zcmV;R0AK%j0i}*X4#F@D1Ucsw`2fgH>ZFzs;=&L3KpHzLhY}Q0@qG&72i$gNq}ArS zEVpi*=Us2AmbDA-yB!<|Vb(}#j0~)f1F<9r z(Ul@zNK&CGnzZ)0HhYm*YGSW*U7q!BkGj!MI_p>b+9B8FWHAIp1c%P9XD~D{Ff%bx$Vkn}$=55XC}H>>y&&F%Cy*^>-=c?q_doq7 MEaEdA08&R0S}ze5g#Z8m literal 0 HcmV?d00001 diff --git a/tests/resources/namespace.git/objects/10/fcb1c85bd6b3bc6f43e0a3932ff5859121a84e b/tests/resources/namespace.git/objects/10/fcb1c85bd6b3bc6f43e0a3932ff5859121a84e new file mode 100644 index 0000000000000000000000000000000000000000..3005ed15a1cd161a1c024bfcb8a973f3694ff74f GIT binary patch literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bx$Vkn}$=55XC}CLN_+;`A9X-2PSJ?3njnQ0{NCRYB{7O8Mao39COiF*M=zN1Y|7{AsPn7G-EI{FfcPQQ7~i(Q(OJvyI#cgg~4XsOKZ0rD?aeB5GrZJ z@Llr#6@#nV=TC%XId6KM8rE^S114$ApnX4m^~U5S|2JL#{Go$q{!_M|=S@(ZCJe0t bX@Q=iHQFZ`TYBucOEN=Vp1uhHLFhAm!lpO` literal 0 HcmV?d00001 diff --git a/tests/resources/namespace.git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b b/tests/resources/namespace.git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b new file mode 100644 index 0000000000000000000000000000000000000000..822bc151862ec3763cf2d3fa2372b93bbd3a4b65 GIT binary patch literal 30 mcmb9XD~D{Ff%bx$Vkn}$=55XC}CJ1rnY6F$m-Kg*KD_+;Lx#g M4|^&N08n)hS3(jNrT_o{ literal 0 HcmV?d00001 diff --git a/tests/resources/namespace.git/objects/f7/19efd430d52bcfc8566a43b2eb655688d38871 b/tests/resources/namespace.git/objects/f7/19efd430d52bcfc8566a43b2eb655688d38871 new file mode 100644 index 0000000000000000000000000000000000000000..b2d51d93bbfbc7f6aa088167bc6218ce86581967 GIT binary patch literal 19 acmb