unit-tests: do not mistake `.pdb` files for being executable
[git.git] / t / t5605-clone-local.sh
blob1d7b1abda1a4870971efb8408c11a4dde2e7564e
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-lib.sh
9 repo_is_hardlinked() {
10 find "$1/objects" -type f -links 1 >output &&
11 test_line_count = 0 output
14 test_expect_success 'preparing origin repository' '
15 : >file && git add . && git commit -m1 &&
16 git clone --bare . a.git &&
17 git clone --bare . x &&
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 &&
24 git bundle create b1.bundle --all &&
25 git bundle create b2.bundle main &&
26 mkdir dir &&
27 cp b1.bundle dir/b3 &&
28 cp b1.bundle b4 &&
29 git branch not-main main &&
30 git bundle create b5.bundle not-main
33 test_expect_success 'local clone without .git suffix' '
34 git clone -l -s a b &&
35 (cd b &&
36 echo false >expect &&
37 git config --bool core.bare >actual &&
38 test_cmp expect actual &&
39 git fetch)
42 test_expect_success 'local clone with .git suffix' '
43 git clone -l -s a.git c &&
44 (cd c && git fetch)
47 test_expect_success 'local clone from x' '
48 git clone -l -s x y &&
49 (cd y && git fetch)
52 test_expect_success 'local clone from x.git that does not exist' '
53 test_must_fail git clone -l -s x.git z
56 test_expect_success 'With -no-hardlinks, local will make a copy' '
57 git clone --bare --no-hardlinks x w &&
58 ! repo_is_hardlinked w
61 test_expect_success 'Even without -l, local will make a hardlink' '
62 rm -fr w &&
63 git clone -l --bare x w &&
64 repo_is_hardlinked w
67 test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
68 echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
69 git clone a d &&
70 (cd d &&
71 git fetch &&
72 test ! -e .git/refs/remotes/origin/HEAD)
75 test_expect_success 'bundle clone without .bundle suffix' '
76 git clone dir/b3 &&
77 (cd b3 && git fetch)
80 test_expect_success 'bundle clone with .bundle suffix' '
81 git clone b1.bundle &&
82 (cd b1 && git fetch)
85 test_expect_success 'bundle clone from b4' '
86 git clone b4 bdl &&
87 (cd bdl && git fetch)
90 test_expect_success 'bundle clone from b4.bundle that does not exist' '
91 test_must_fail git clone b4.bundle bb
94 test_expect_success 'bundle clone with nonexistent HEAD (match default)' '
95 git clone b2.bundle b2 &&
96 (cd b2 &&
97 git fetch &&
98 git rev-parse --verify refs/heads/main)
101 test_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)
109 test_expect_success 'clone empty repository' '
110 mkdir empty &&
111 (cd empty &&
112 git init &&
113 git config receive.denyCurrentBranch warn) &&
114 git clone empty empty-clone &&
115 test_tick &&
116 (cd empty-clone &&
117 echo "content" >> foo &&
118 git add foo &&
119 git commit -m "Initial commit" &&
120 git push origin main &&
121 expected=$(git rev-parse main) &&
122 actual=$(git --git-dir=../empty/.git rev-parse main) &&
123 test $actual = $expected)
126 test_expect_success 'clone empty repository, and then push should not segfault.' '
127 rm -fr empty/ empty-clone/ &&
128 mkdir empty &&
129 (cd empty && git init) &&
130 git clone empty empty-clone &&
131 (cd empty-clone &&
132 test_must_fail git push)
135 test_expect_success 'cloning non-existent directory fails' '
136 rm -rf does-not-exist &&
137 test_must_fail git clone does-not-exist
140 test_expect_success 'cloning non-git directory fails' '
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
146 test_expect_success 'cloning file:// does not hardlink' '
147 git clone --bare file://"$(pwd)"/a non-local &&
148 ! repo_is_hardlinked non-local
151 test_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
156 test_expect_success 'cloning locally respects "-u" for fetching refs' '
157 test_must_fail git clone --bare -u false a should_not_work.git
160 test_expect_success 'local clone from repo with corrupt refs fails gracefully' '
161 git init corrupt &&
162 test_commit -C corrupt one &&
163 echo a >corrupt/.git/refs/heads/topic &&
165 test_must_fail git clone corrupt working 2>err &&
166 grep "has a null OID" err
169 test_done