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 &&
18 test "$(cd a.git && git config --bool core.bare)" = true &&
19 test "$(cd x && git config --bool core.bare)" = true &&
20 git bundle create b1.bundle --all &&
21 git bundle create b2.bundle main &&
23 cp b1.bundle dir/b3 &&
25 git branch not-main main &&
26 git bundle create b5.bundle not-main
29 test_expect_success
'local clone without .git suffix' '
30 git clone -l -s a b &&
32 test "$(git config --bool core.bare)" = false &&
36 test_expect_success
'local clone with .git suffix' '
37 git clone -l -s a.git c &&
41 test_expect_success
'local clone from x' '
42 git clone -l -s x y &&
46 test_expect_success
'local clone from x.git that does not exist' '
47 test_must_fail git clone -l -s x.git z
50 test_expect_success
'With -no-hardlinks, local will make a copy' '
51 git clone --bare --no-hardlinks x w &&
52 ! repo_is_hardlinked w
55 test_expect_success
'Even without -l, local will make a hardlink' '
57 git clone -l --bare x w &&
61 test_expect_success
'local clone of repo with nonexistent ref in HEAD' '
62 echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
66 test ! -e .git/refs/remotes/origin/HEAD)
69 test_expect_success
'bundle clone without .bundle suffix' '
74 test_expect_success
'bundle clone with .bundle suffix' '
75 git clone b1.bundle &&
79 test_expect_success
'bundle clone from b4' '
84 test_expect_success
'bundle clone from b4.bundle that does not exist' '
85 test_must_fail git clone b4.bundle bb
88 test_expect_success
'bundle clone with nonexistent HEAD (match default)' '
89 git clone b2.bundle b2 &&
92 git rev-parse --verify refs/heads/main)
95 test_expect_success
'bundle clone with nonexistent HEAD (no match default)' '
96 git clone b5.bundle b5 &&
99 test_must_fail git rev-parse --verify refs/heads/main &&
100 test_must_fail git rev-parse --verify refs/heads/not-main)
103 test_expect_success
'clone empty repository' '
107 git config receive.denyCurrentBranch warn) &&
108 git clone empty empty-clone &&
111 echo "content" >> foo &&
113 git commit -m "Initial commit" &&
114 git push origin main &&
115 expected=$(git rev-parse main) &&
116 actual=$(git --git-dir=../empty/.git rev-parse main) &&
117 test $actual = $expected)
120 test_expect_success
'clone empty repository, and then push should not segfault.' '
121 rm -fr empty/ empty-clone/ &&
123 (cd empty && git init) &&
124 git clone empty empty-clone &&
126 test_must_fail git push)
129 test_expect_success
'cloning non-existent directory fails' '
130 rm -rf does-not-exist &&
131 test_must_fail git clone does-not-exist
134 test_expect_success
'cloning non-git directory fails' '
135 rm -rf not-a-git-repo not-a-git-repo-clone &&
136 mkdir not-a-git-repo &&
137 test_must_fail git clone not-a-git-repo not-a-git-repo-clone
140 test_expect_success
'cloning file:// does not hardlink' '
141 git clone --bare file://"$(pwd)"/a non-local &&
142 ! repo_is_hardlinked non-local
145 test_expect_success
'cloning a local path with --no-local does not hardlink' '
146 git clone --bare --no-local a force-nonlocal &&
147 ! repo_is_hardlinked force-nonlocal
150 test_expect_success
'cloning locally respects "-u" for fetching refs' '
151 test_must_fail git clone --bare -u false a should_not_work.git
154 test_expect_success
'local clone from repo with corrupt refs fails gracefully' '
156 test_commit -C corrupt one &&
157 echo a >corrupt/.git/refs/heads/topic &&
159 test_must_fail git clone corrupt working 2>err &&
160 grep "has a null OID" err