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