The eleventh batch
[git.git] / t / t5605-clone-local.sh
blobd9a320abd216579362dac3f4d82288b570eceb93
1 #!/bin/sh
3 test_description='test local clone'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 repo_is_hardlinked() {
11 find "$1/objects" -type f -links 1 >output &&
12 test_line_count = 0 output
15 test_expect_success 'preparing origin repository' '
16 : >file && git add . && git commit -m1 &&
17 git clone --bare . a.git &&
18 git clone --bare . x &&
19 echo true >expect &&
20 git -C a.git config --bool core.bare >actual &&
21 test_cmp expect actual &&
22 echo true >expect &&
23 git -C x config --bool core.bare >actual &&
24 test_cmp expect actual &&
25 git bundle create b1.bundle --all &&
26 git bundle create b2.bundle main &&
27 mkdir dir &&
28 cp b1.bundle dir/b3 &&
29 cp b1.bundle b4 &&
30 git branch not-main main &&
31 git bundle create b5.bundle not-main
34 test_expect_success 'local clone without .git suffix' '
35 git clone -l -s a b &&
36 (cd b &&
37 echo false >expect &&
38 git config --bool core.bare >actual &&
39 test_cmp expect actual &&
40 git fetch)
43 test_expect_success 'local clone with .git suffix' '
44 git clone -l -s a.git c &&
45 (cd c && git fetch)
48 test_expect_success 'local clone from x' '
49 git clone -l -s x y &&
50 (cd y && git fetch)
53 test_expect_success 'local clone from x.git that does not exist' '
54 test_must_fail git clone -l -s x.git z
57 test_expect_success 'With -no-hardlinks, local will make a copy' '
58 git clone --bare --no-hardlinks x w &&
59 ! repo_is_hardlinked w
62 test_expect_success 'Even without -l, local will make a hardlink' '
63 rm -fr w &&
64 git clone -l --bare x w &&
65 repo_is_hardlinked w
68 test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
69 git -C a.git symbolic-ref HEAD refs/heads/nonexistent &&
70 git clone a d &&
71 (cd d &&
72 git fetch &&
73 test_ref_missing refs/remotes/origin/HEAD)
76 test_expect_success 'bundle clone without .bundle suffix' '
77 git clone dir/b3 &&
78 (cd b3 && git fetch)
81 test_expect_success 'bundle clone with .bundle suffix' '
82 git clone b1.bundle &&
83 (cd b1 && git fetch)
86 test_expect_success 'bundle clone from b4' '
87 git clone b4 bdl &&
88 (cd bdl && git fetch)
91 test_expect_success 'bundle clone from b4.bundle that does not exist' '
92 test_must_fail git clone b4.bundle bb
95 test_expect_success 'bundle clone with nonexistent HEAD (match default)' '
96 git clone b2.bundle b2 &&
97 (cd b2 &&
98 git fetch &&
99 git rev-parse --verify refs/heads/main)
102 test_expect_success 'bundle clone with nonexistent HEAD (no match default)' '
103 git clone b5.bundle b5 &&
104 (cd b5 &&
105 git fetch &&
106 test_must_fail git rev-parse --verify refs/heads/main &&
107 test_must_fail git rev-parse --verify refs/heads/not-main)
110 test_expect_success 'clone empty repository' '
111 mkdir empty &&
112 (cd empty &&
113 git init &&
114 git config receive.denyCurrentBranch warn) &&
115 git clone empty empty-clone &&
116 test_tick &&
117 (cd empty-clone &&
118 echo "content" >> foo &&
119 git add foo &&
120 git commit -m "Initial commit" &&
121 git push origin main &&
122 expected=$(git rev-parse main) &&
123 actual=$(git --git-dir=../empty/.git rev-parse main) &&
124 test $actual = $expected)
127 test_expect_success 'clone empty repository, and then push should not segfault.' '
128 rm -fr empty/ empty-clone/ &&
129 mkdir empty &&
130 (cd empty && git init) &&
131 git clone empty empty-clone &&
132 (cd empty-clone &&
133 test_must_fail git push)
136 test_expect_success 'cloning non-existent directory fails' '
137 rm -rf does-not-exist &&
138 test_must_fail git clone does-not-exist
141 test_expect_success 'cloning non-git directory fails' '
142 rm -rf not-a-git-repo not-a-git-repo-clone &&
143 mkdir not-a-git-repo &&
144 test_must_fail git clone not-a-git-repo not-a-git-repo-clone
147 test_expect_success 'cloning file:// does not hardlink' '
148 git clone --bare file://"$(pwd)"/a non-local &&
149 ! repo_is_hardlinked non-local
152 test_expect_success 'cloning a local path with --no-local does not hardlink' '
153 git clone --bare --no-local a force-nonlocal &&
154 ! repo_is_hardlinked force-nonlocal
157 test_expect_success 'cloning locally respects "-u" for fetching refs' '
158 test_must_fail git clone --bare -u false a should_not_work.git
161 test_expect_success REFFILES 'local clone from repo with corrupt refs fails gracefully' '
162 git init corrupt &&
163 test_commit -C corrupt one &&
164 echo a >corrupt/.git/refs/heads/topic &&
166 test_must_fail git clone corrupt working 2>err &&
167 grep "has neither a valid OID nor a target" err
170 test_done