3 test_description
='test local clone'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK
=true
10 repo_is_hardlinked
() {
11 find "$1/objects" -type f
-links 1 >output
&&
12 test_line_count
= 0 output
15 test_expect_success
'preparing origin repository' '
16 : >file && git add . && git commit -m1 &&
17 git clone --bare . a.git &&
18 git clone --bare . x &&
20 git -C a.git config --bool core.bare >actual &&
21 test_cmp expect actual &&
23 git -C x config --bool core.bare >actual &&
24 test_cmp expect actual &&
25 git bundle create b1.bundle --all &&
26 git bundle create b2.bundle main &&
28 cp b1.bundle dir/b3 &&
30 git branch not-main main &&
31 git bundle create b5.bundle not-main
34 test_expect_success
'local clone without .git suffix' '
35 git clone -l -s a b &&
38 git config --bool core.bare >actual &&
39 test_cmp expect actual &&
43 test_expect_success
'local clone with .git suffix' '
44 git clone -l -s a.git c &&
48 test_expect_success
'local clone from x' '
49 git clone -l -s x y &&
53 test_expect_success
'local clone from x.git that does not exist' '
54 test_must_fail git clone -l -s x.git z
57 test_expect_success
'With -no-hardlinks, local will make a copy' '
58 git clone --bare --no-hardlinks x w &&
59 ! repo_is_hardlinked w
62 test_expect_success
'Even without -l, local will make a hardlink' '
64 git clone -l --bare x w &&
68 test_expect_success
'local clone of repo with nonexistent ref in HEAD' '
69 git -C a.git symbolic-ref HEAD refs/heads/nonexistent &&
73 test_ref_missing refs/remotes/origin/HEAD)
76 test_expect_success
'bundle clone without .bundle suffix' '
81 test_expect_success
'bundle clone with .bundle suffix' '
82 git clone b1.bundle &&
86 test_expect_success
'bundle clone from b4' '
91 test_expect_success
'bundle clone from b4.bundle that does not exist' '
92 test_must_fail git clone b4.bundle bb
95 test_expect_success
'bundle clone with nonexistent HEAD (match default)' '
96 git clone b2.bundle b2 &&
99 git rev-parse --verify refs/heads/main)
102 test_expect_success
'bundle clone with nonexistent HEAD (no match default)' '
103 git clone b5.bundle b5 &&
106 test_must_fail git rev-parse --verify refs/heads/main &&
107 test_must_fail git rev-parse --verify refs/heads/not-main)
110 test_expect_success
'clone empty repository' '
114 git config receive.denyCurrentBranch warn) &&
115 git clone empty empty-clone &&
118 echo "content" >> foo &&
120 git commit -m "Initial commit" &&
121 git push origin main &&
122 expected=$(git rev-parse main) &&
123 actual=$(git --git-dir=../empty/.git rev-parse main) &&
124 test $actual = $expected)
127 test_expect_success
'clone empty repository, and then push should not segfault.' '
128 rm -fr empty/ empty-clone/ &&
130 (cd empty && git init) &&
131 git clone empty empty-clone &&
133 test_must_fail git push)
136 test_expect_success
'cloning non-existent directory fails' '
137 rm -rf does-not-exist &&
138 test_must_fail git clone does-not-exist
141 test_expect_success
'cloning non-git directory fails' '
142 rm -rf not-a-git-repo not-a-git-repo-clone &&
143 mkdir not-a-git-repo &&
144 test_must_fail git clone not-a-git-repo not-a-git-repo-clone
147 test_expect_success
'cloning file:// does not hardlink' '
148 git clone --bare file://"$(pwd)"/a non-local &&
149 ! repo_is_hardlinked non-local
152 test_expect_success
'cloning a local path with --no-local does not hardlink' '
153 git clone --bare --no-local a force-nonlocal &&
154 ! repo_is_hardlinked force-nonlocal
157 test_expect_success
'cloning locally respects "-u" for fetching refs' '
158 test_must_fail git clone --bare -u false a should_not_work.git
161 test_expect_success REFFILES
'local clone from repo with corrupt refs fails gracefully' '
163 test_commit -C corrupt one &&
164 echo a >corrupt/.git/refs/heads/topic &&
166 test_must_fail git clone corrupt working 2>err &&
167 grep "has neither a valid OID nor a target" err