3 test_description
='test local clone'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 find "$1/objects" -type f
-links 1 >output
&&
11 test_line_count
= 0 output
14 test_expect_success
'preparing origin repository' '
15 : >file && git add . && git commit -m1 &&
16 git clone --bare . a.git &&
17 git clone --bare . x &&
19 git -C a.git config --bool core.bare >actual &&
20 test_cmp expect actual &&
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 &&
27 cp b1.bundle dir/b3 &&
29 git branch not-main main &&
30 git bundle create b5.bundle not-main
33 test_expect_success
'local clone without .git suffix' '
34 git clone -l -s a b &&
37 git config --bool core.bare >actual &&
38 test_cmp expect actual &&
42 test_expect_success
'local clone with .git suffix' '
43 git clone -l -s a.git c &&
47 test_expect_success
'local clone from x' '
48 git clone -l -s x y &&
52 test_expect_success
'local clone from x.git that does not exist' '
53 test_must_fail git clone -l -s x.git z
56 test_expect_success
'With -no-hardlinks, local will make a copy' '
57 git clone --bare --no-hardlinks x w &&
58 ! repo_is_hardlinked w
61 test_expect_success
'Even without -l, local will make a hardlink' '
63 git clone -l --bare x w &&
67 test_expect_success
'local clone of repo with nonexistent ref in HEAD' '
68 echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
72 test ! -e .git/refs/remotes/origin/HEAD)
75 test_expect_success
'bundle clone without .bundle suffix' '
80 test_expect_success
'bundle clone with .bundle suffix' '
81 git clone b1.bundle &&
85 test_expect_success
'bundle clone from b4' '
90 test_expect_success
'bundle clone from b4.bundle that does not exist' '
91 test_must_fail git clone b4.bundle bb
94 test_expect_success
'bundle clone with nonexistent HEAD (match default)' '
95 git clone b2.bundle b2 &&
98 git rev-parse --verify refs/heads/main)
101 test_expect_success
'bundle clone with nonexistent HEAD (no match default)' '
102 git clone b5.bundle b5 &&
105 test_must_fail git rev-parse --verify refs/heads/main &&
106 test_must_fail git rev-parse --verify refs/heads/not-main)
109 test_expect_success
'clone empty repository' '
113 git config receive.denyCurrentBranch warn) &&
114 git clone empty empty-clone &&
117 echo "content" >> 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)
126 test_expect_success
'clone empty repository, and then push should not segfault.' '
127 rm -fr empty/ empty-clone/ &&
129 (cd empty && git init) &&
130 git clone empty empty-clone &&
132 test_must_fail git push)
135 test_expect_success
'cloning non-existent directory fails' '
136 rm -rf does-not-exist &&
137 test_must_fail git clone does-not-exist
140 test_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
146 test_expect_success
'cloning file:// does not hardlink' '
147 git clone --bare file://"$(pwd)"/a non-local &&
148 ! repo_is_hardlinked non-local
151 test_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
156 test_expect_success
'cloning locally respects "-u" for fetching refs' '
157 test_must_fail git clone --bare -u false a should_not_work.git
160 test_expect_success
'local clone from repo with corrupt refs fails gracefully' '
162 test_commit -C corrupt one &&
163 echo a >corrupt/.git/refs/heads/topic &&
165 test_must_fail git clone corrupt working 2>err &&
166 grep "has a null OID" err