]>
Commit | Line | Data |
---|---|---|
defe13a2 AR |
1 | #!/bin/sh |
2 | ||
3 | test_description='test local clone' | |
95cf2c01 | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
defe13a2 AR |
7 | . ./test-lib.sh |
8 | ||
f27e7654 JK |
9 | repo_is_hardlinked() { |
10 | find "$1/objects" -type f -links 1 >output && | |
11 | test_line_count = 0 output | |
12 | } | |
defe13a2 AR |
13 | |
14 | test_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 | ||
27 | test_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 | ||
34 | test_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 | ||
39 | test_expect_success 'local clone from x' ' | |
defe13a2 | 40 | git clone -l -s x y && |
f27e7654 | 41 | (cd y && git fetch) |
defe13a2 AR |
42 | ' |
43 | ||
44 | test_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 | 48 | test_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 | ||
53 | test_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 | 59 | test_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 | 67 | test_expect_success 'bundle clone without .bundle suffix' ' |
c6fef0bb | 68 | git clone dir/b3 && |
f27e7654 | 69 | (cd b3 && git fetch) |
c6fef0bb SB |
70 | ' |
71 | ||
72 | test_expect_success 'bundle clone with .bundle suffix' ' | |
c6fef0bb | 73 | git clone b1.bundle && |
f27e7654 | 74 | (cd b1 && git fetch) |
c6fef0bb SB |
75 | ' |
76 | ||
77 | test_expect_success 'bundle clone from b4' ' | |
c6fef0bb | 78 | git clone b4 bdl && |
f27e7654 | 79 | (cd bdl && git fetch) |
c6fef0bb SB |
80 | ' |
81 | ||
82 | test_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 | ||
86 | test_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 | 93 | test_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 | 110 | test_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 | 119 | test_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 | ||
124 | test_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 |
130 | test_expect_success 'cloning file:// does not hardlink' ' |
131 | git clone --bare file://"$(pwd)"/a non-local && | |
132 | ! repo_is_hardlinked non-local | |
133 | ' | |
134 | ||
135 | test_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 |
140 | test_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 | 144 | test_done |