Git fork
at reftables-rust 178 lines 4.8 kB view raw
1#!/bin/sh 2 3test_description='test local clone' 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 6 7. ./test-lib.sh 8 9repo_is_hardlinked() { 10 find "$1/objects" -type f -links 1 >output && 11 test_line_count = 0 output 12} 13 14test_expect_success 'preparing origin repository' ' 15 : >file && git add . && git commit -m1 && 16 git clone --bare . a.git && 17 git clone --bare . x && 18 echo true >expect && 19 git -C a.git config --bool core.bare >actual && 20 test_cmp expect actual && 21 echo true >expect && 22 git -C x config --bool core.bare >actual && 23 test_cmp expect actual && 24 git bundle create b1.bundle --all && 25 git bundle create b2.bundle main && 26 mkdir dir && 27 cp b1.bundle dir/b3 && 28 cp b1.bundle b4 && 29 git branch not-main main && 30 git bundle create b5.bundle not-main 31' 32 33test_expect_success 'local clone without .git suffix' ' 34 git clone -l -s a b && 35 (cd b && 36 echo false >expect && 37 git config --bool core.bare >actual && 38 test_cmp expect actual && 39 git fetch) 40' 41 42test_expect_success 'local clone with .git suffix' ' 43 git clone -l -s a.git c && 44 (cd c && git fetch) 45' 46 47test_expect_success 'local clone from x' ' 48 git clone -l -s x y && 49 (cd y && git fetch) 50' 51 52test_expect_success 'local clone from x.git that does not exist' ' 53 test_must_fail git clone -l -s x.git z 54' 55 56test_expect_success 'With -no-hardlinks, local will make a copy' ' 57 git clone --bare --no-hardlinks x w && 58 ! repo_is_hardlinked w 59' 60 61test_expect_success 'Even without -l, local will make a hardlink' ' 62 rm -fr w && 63 git clone -l --bare x w && 64 repo_is_hardlinked w 65' 66 67test_expect_success 'local clone of repo with nonexistent ref in HEAD' ' 68 git -C a.git symbolic-ref HEAD refs/heads/nonexistent && 69 git clone a d && 70 (cd d && 71 git fetch && 72 test_ref_missing refs/remotes/origin/HEAD) 73' 74 75test_expect_success 'bundle clone without .bundle suffix' ' 76 git clone dir/b3 && 77 (cd b3 && git fetch) 78' 79 80test_expect_success 'bundle clone with .bundle suffix' ' 81 git clone b1.bundle && 82 (cd b1 && git fetch) 83' 84 85test_expect_success 'bundle clone from b4' ' 86 git clone b4 bdl && 87 (cd bdl && git fetch) 88' 89 90test_expect_success 'bundle clone from b4.bundle that does not exist' ' 91 test_must_fail git clone b4.bundle bb 92' 93 94test_expect_success 'bundle clone with nonexistent HEAD (match default)' ' 95 git clone b2.bundle b2 && 96 (cd b2 && 97 git fetch && 98 git rev-parse --verify refs/heads/main) 99' 100 101test_expect_success 'bundle clone with nonexistent HEAD (no match default)' ' 102 git clone b5.bundle b5 && 103 (cd b5 && 104 git fetch && 105 test_must_fail git rev-parse --verify refs/heads/main && 106 test_must_fail git rev-parse --verify refs/heads/not-main) 107' 108 109test_expect_success 'clone empty repository' ' 110 mkdir empty && 111 (cd empty && 112 git init && 113 git config receive.denyCurrentBranch warn) && 114 git clone empty empty-clone && 115 test_tick && 116 (cd empty-clone && 117 echo "content" >> foo && 118 git add foo && 119 git commit -m "Initial commit" && 120 git push origin main && 121 expected=$(git rev-parse main) && 122 actual=$(git --git-dir=../empty/.git rev-parse main) && 123 test $actual = $expected) 124' 125 126test_expect_success 'clone empty repository, and then push should not segfault.' ' 127 rm -fr empty/ empty-clone/ && 128 mkdir empty && 129 (cd empty && git init) && 130 git clone empty empty-clone && 131 (cd empty-clone && 132 test_must_fail git push) 133' 134 135test_expect_success 'cloning non-existent directory fails' ' 136 rm -rf does-not-exist && 137 test_must_fail git clone does-not-exist 138' 139 140test_expect_success 'cloning non-git directory fails' ' 141 rm -rf not-a-git-repo not-a-git-repo-clone && 142 mkdir not-a-git-repo && 143 test_must_fail git clone not-a-git-repo not-a-git-repo-clone 144' 145 146test_expect_success 'cloning file:// does not hardlink' ' 147 git clone --bare file://"$(pwd)"/a non-local && 148 ! repo_is_hardlinked non-local 149' 150 151test_expect_success 'cloning a local path with --no-local does not hardlink' ' 152 git clone --bare --no-local a force-nonlocal && 153 ! repo_is_hardlinked force-nonlocal 154' 155 156test_expect_success 'cloning a local path with --no-local from a different user succeeds' ' 157 git clone --upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \ 158 --no-local a nonlocal-otheruser 2>err && 159 ! repo_is_hardlinked nonlocal-otheruser/.git && 160 # Verify that this is a git repository. 161 git -C nonlocal-otheruser rev-parse --show-toplevel && 162 test_grep ! "detected dubious ownership" err 163' 164 165test_expect_success 'cloning locally respects "-u" for fetching refs' ' 166 test_must_fail git clone --bare -u false a should_not_work.git 167' 168 169test_expect_success REFFILES 'local clone from repo with corrupt refs fails gracefully' ' 170 git init corrupt && 171 test_commit -C corrupt one && 172 echo a >corrupt/.git/refs/heads/topic && 173 174 test_must_fail git clone corrupt working 2>err && 175 grep "has neither a valid OID nor a target" err 176' 177 178test_done