]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5605-clone-local.sh
Sync with 2.36.3
[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 &&
3cc6a6f0
JK
18 test "$(cd a.git && git config --bool core.bare)" = true &&
19 test "$(cd x && git config --bool core.bare)" = true &&
b2a6d1c6 20 git bundle create b1.bundle --all &&
95cf2c01 21 git bundle create b2.bundle main &&
c6fef0bb 22 mkdir dir &&
2dec68cf 23 cp b1.bundle dir/b3 &&
cc8fcd1e
JK
24 cp b1.bundle b4 &&
25 git branch not-main main &&
26 git bundle create b5.bundle not-main
defe13a2
AR
27'
28
29test_expect_success 'local clone without .git suffix' '
defe13a2 30 git clone -l -s a b &&
f27e7654 31 (cd b &&
3cc6a6f0 32 test "$(git config --bool core.bare)" = false &&
f27e7654 33 git fetch)
defe13a2
AR
34'
35
36test_expect_success 'local clone with .git suffix' '
defe13a2 37 git clone -l -s a.git c &&
f27e7654 38 (cd c && git fetch)
defe13a2
AR
39'
40
41test_expect_success 'local clone from x' '
defe13a2 42 git clone -l -s x y &&
f27e7654 43 (cd y && git fetch)
defe13a2
AR
44'
45
46test_expect_success 'local clone from x.git that does not exist' '
f27e7654 47 test_must_fail git clone -l -s x.git z
defe13a2
AR
48'
49
3d5c418f 50test_expect_success 'With -no-hardlinks, local will make a copy' '
3d5c418f 51 git clone --bare --no-hardlinks x w &&
f27e7654 52 ! repo_is_hardlinked w
3d5c418f
JH
53'
54
55test_expect_success 'Even without -l, local will make a hardlink' '
3d5c418f
JH
56 rm -fr w &&
57 git clone -l --bare x w &&
f27e7654 58 repo_is_hardlinked w
3d5c418f
JH
59'
60
5274ba69 61test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
5274ba69
GP
62 echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
63 git clone a d &&
f27e7654 64 (cd d &&
5274ba69 65 git fetch &&
f27e7654
JK
66 test ! -e .git/refs/remotes/origin/HEAD)
67'
5274ba69 68
c6fef0bb 69test_expect_success 'bundle clone without .bundle suffix' '
c6fef0bb 70 git clone dir/b3 &&
f27e7654 71 (cd b3 && git fetch)
c6fef0bb
SB
72'
73
74test_expect_success 'bundle clone with .bundle suffix' '
c6fef0bb 75 git clone b1.bundle &&
f27e7654 76 (cd b1 && git fetch)
c6fef0bb
SB
77'
78
79test_expect_success 'bundle clone from b4' '
c6fef0bb 80 git clone b4 bdl &&
f27e7654 81 (cd bdl && git fetch)
c6fef0bb
SB
82'
83
84test_expect_success 'bundle clone from b4.bundle that does not exist' '
f27e7654 85 test_must_fail git clone b4.bundle bb
c6fef0bb
SB
86'
87
cc8fcd1e 88test_expect_success 'bundle clone with nonexistent HEAD (match default)' '
c6fef0bb 89 git clone b2.bundle b2 &&
f27e7654 90 (cd b2 &&
2dec68cf 91 git fetch &&
cc8fcd1e
JK
92 git rev-parse --verify refs/heads/main)
93'
94
95test_expect_success 'bundle clone with nonexistent HEAD (no match default)' '
96 git clone b5.bundle b5 &&
97 (cd b5 &&
98 git fetch &&
99 test_must_fail git rev-parse --verify refs/heads/main &&
100 test_must_fail git rev-parse --verify refs/heads/not-main)
c6fef0bb
SB
101'
102
86ac7518 103test_expect_success 'clone empty repository' '
86ac7518 104 mkdir empty &&
acd2a45b
JH
105 (cd empty &&
106 git init &&
107 git config receive.denyCurrentBranch warn) &&
86ac7518
SR
108 git clone empty empty-clone &&
109 test_tick &&
51b85471 110 (cd empty-clone &&
86ac7518
SR
111 echo "content" >> foo &&
112 git add foo &&
113 git commit -m "Initial commit" &&
95cf2c01
JS
114 git push origin main &&
115 expected=$(git rev-parse main) &&
116 actual=$(git --git-dir=../empty/.git rev-parse main) &&
86ac7518
SR
117 test $actual = $expected)
118'
119
a162e78d 120test_expect_success 'clone empty repository, and then push should not segfault.' '
a162e78d
MM
121 rm -fr empty/ empty-clone/ &&
122 mkdir empty &&
123 (cd empty && git init) &&
124 git clone empty empty-clone &&
b9d622e7
JS
125 (cd empty-clone &&
126 test_must_fail git push)
a162e78d
MM
127'
128
a9026187 129test_expect_success 'cloning non-existent directory fails' '
a9026187
JK
130 rm -rf does-not-exist &&
131 test_must_fail git clone does-not-exist
132'
133
134test_expect_success 'cloning non-git directory fails' '
a9026187
JK
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
138'
139
189260b1
JK
140test_expect_success 'cloning file:// does not hardlink' '
141 git clone --bare file://"$(pwd)"/a non-local &&
142 ! repo_is_hardlinked non-local
143'
144
145test_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
148'
149
643f918d
JK
150test_expect_success 'cloning locally respects "-u" for fetching refs' '
151 test_must_fail git clone --bare -u false a should_not_work.git
152'
153
d097a23b
DS
154test_expect_success 'local clone from repo with corrupt refs fails gracefully' '
155 git init corrupt &&
156 test_commit -C corrupt one &&
157 echo a >corrupt/.git/refs/heads/topic &&
158
159 test_must_fail git clone corrupt working 2>err &&
160 grep "has a null OID" err
161'
162
defe13a2 163test_done