]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5605-clone-local.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t5605-clone-local.sh
CommitLineData
defe13a2
AR
1#!/bin/sh
2
3test_description='test local clone'
95cf2c01 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
defe13a2
AR
7. ./test-lib.sh
8
f27e7654
JK
9repo_is_hardlinked() {
10 find "$1/objects" -type f -links 1 >output &&
11 test_line_count = 0 output
12}
defe13a2
AR
13
14test_expect_success 'preparing origin repository' '
15 : >file && git add . && git commit -m1 &&
16 git clone --bare . a.git &&
312efe9b 17 git clone --bare . x &&
0cd1a881
ÆAB
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 &&
b2a6d1c6 24 git bundle create b1.bundle --all &&
95cf2c01 25 git bundle create b2.bundle main &&
c6fef0bb 26 mkdir dir &&
2dec68cf 27 cp b1.bundle dir/b3 &&
cc8fcd1e
JK
28 cp b1.bundle b4 &&
29 git branch not-main main &&
30 git bundle create b5.bundle not-main
defe13a2
AR
31'
32
33test_expect_success 'local clone without .git suffix' '
defe13a2 34 git clone -l -s a b &&
f27e7654 35 (cd b &&
0cd1a881
ÆAB
36 echo false >expect &&
37 git config --bool core.bare >actual &&
38 test_cmp expect actual &&
f27e7654 39 git fetch)
defe13a2
AR
40'
41
42test_expect_success 'local clone with .git suffix' '
defe13a2 43 git clone -l -s a.git c &&
f27e7654 44 (cd c && git fetch)
defe13a2
AR
45'
46
47test_expect_success 'local clone from x' '
defe13a2 48 git clone -l -s x y &&
f27e7654 49 (cd y && git fetch)
defe13a2
AR
50'
51
52test_expect_success 'local clone from x.git that does not exist' '
f27e7654 53 test_must_fail git clone -l -s x.git z
defe13a2
AR
54'
55
3d5c418f 56test_expect_success 'With -no-hardlinks, local will make a copy' '
3d5c418f 57 git clone --bare --no-hardlinks x w &&
f27e7654 58 ! repo_is_hardlinked w
3d5c418f
JH
59'
60
61test_expect_success 'Even without -l, local will make a hardlink' '
3d5c418f
JH
62 rm -fr w &&
63 git clone -l --bare x w &&
f27e7654 64 repo_is_hardlinked w
3d5c418f
JH
65'
66
5274ba69 67test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
23937116 68 git -C a.git symbolic-ref HEAD refs/heads/nonexistent &&
5274ba69 69 git clone a d &&
f27e7654 70 (cd d &&
5274ba69 71 git fetch &&
0497e6c6 72 test_ref_missing refs/remotes/origin/HEAD)
f27e7654 73'
5274ba69 74
c6fef0bb 75test_expect_success 'bundle clone without .bundle suffix' '
c6fef0bb 76 git clone dir/b3 &&
f27e7654 77 (cd b3 && git fetch)
c6fef0bb
SB
78'
79
80test_expect_success 'bundle clone with .bundle suffix' '
c6fef0bb 81 git clone b1.bundle &&
f27e7654 82 (cd b1 && git fetch)
c6fef0bb
SB
83'
84
85test_expect_success 'bundle clone from b4' '
c6fef0bb 86 git clone b4 bdl &&
f27e7654 87 (cd bdl && git fetch)
c6fef0bb
SB
88'
89
90test_expect_success 'bundle clone from b4.bundle that does not exist' '
f27e7654 91 test_must_fail git clone b4.bundle bb
c6fef0bb
SB
92'
93
cc8fcd1e 94test_expect_success 'bundle clone with nonexistent HEAD (match default)' '
c6fef0bb 95 git clone b2.bundle b2 &&
f27e7654 96 (cd b2 &&
2dec68cf 97 git fetch &&
cc8fcd1e
JK
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)
c6fef0bb
SB
107'
108
86ac7518 109test_expect_success 'clone empty repository' '
86ac7518 110 mkdir empty &&
acd2a45b
JH
111 (cd empty &&
112 git init &&
113 git config receive.denyCurrentBranch warn) &&
86ac7518
SR
114 git clone empty empty-clone &&
115 test_tick &&
51b85471 116 (cd empty-clone &&
86ac7518
SR
117 echo "content" >> foo &&
118 git add foo &&
119 git commit -m "Initial commit" &&
95cf2c01
JS
120 git push origin main &&
121 expected=$(git rev-parse main) &&
122 actual=$(git --git-dir=../empty/.git rev-parse main) &&
86ac7518
SR
123 test $actual = $expected)
124'
125
a162e78d 126test_expect_success 'clone empty repository, and then push should not segfault.' '
a162e78d
MM
127 rm -fr empty/ empty-clone/ &&
128 mkdir empty &&
129 (cd empty && git init) &&
130 git clone empty empty-clone &&
b9d622e7
JS
131 (cd empty-clone &&
132 test_must_fail git push)
a162e78d
MM
133'
134
a9026187 135test_expect_success 'cloning non-existent directory fails' '
a9026187
JK
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' '
a9026187
JK
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
189260b1
JK
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
643f918d
JK
156test_expect_success 'cloning locally respects "-u" for fetching refs' '
157 test_must_fail git clone --bare -u false a should_not_work.git
158'
159
a6f43364 160test_expect_success REFFILES 'local clone from repo with corrupt refs fails gracefully' '
d097a23b
DS
161 git init corrupt &&
162 test_commit -C corrupt one &&
163 echo a >corrupt/.git/refs/heads/topic &&
164
165 test_must_fail git clone corrupt working 2>err &&
166 grep "has a null OID" err
167'
168
defe13a2 169test_done