t8*: adjust the references to the default branch name "main"
[git] / t / t5605-clone-local.sh
1 #!/bin/sh
2
3 test_description='test local clone'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 . ./test-lib.sh
8
9 repo_is_hardlinked() {
10         find "$1/objects" -type f -links 1 >output &&
11         test_line_count = 0 output
12 }
13
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         test "$(cd a.git && git config --bool core.bare)" = true &&
19         test "$(cd x && git config --bool core.bare)" = true &&
20         git bundle create b1.bundle --all &&
21         git bundle create b2.bundle main &&
22         mkdir dir &&
23         cp b1.bundle dir/b3 &&
24         cp b1.bundle b4
25 '
26
27 test_expect_success 'local clone without .git suffix' '
28         git clone -l -s a b &&
29         (cd b &&
30         test "$(git config --bool core.bare)" = false &&
31         git fetch)
32 '
33
34 test_expect_success 'local clone with .git suffix' '
35         git clone -l -s a.git c &&
36         (cd c && git fetch)
37 '
38
39 test_expect_success 'local clone from x' '
40         git clone -l -s x y &&
41         (cd y && git fetch)
42 '
43
44 test_expect_success 'local clone from x.git that does not exist' '
45         test_must_fail git clone -l -s x.git z
46 '
47
48 test_expect_success 'With -no-hardlinks, local will make a copy' '
49         git clone --bare --no-hardlinks x w &&
50         ! repo_is_hardlinked w
51 '
52
53 test_expect_success 'Even without -l, local will make a hardlink' '
54         rm -fr w &&
55         git clone -l --bare x w &&
56         repo_is_hardlinked w
57 '
58
59 test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
60         echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
61         git clone a d &&
62         (cd d &&
63         git fetch &&
64         test ! -e .git/refs/remotes/origin/HEAD)
65 '
66
67 test_expect_success 'bundle clone without .bundle suffix' '
68         git clone dir/b3 &&
69         (cd b3 && git fetch)
70 '
71
72 test_expect_success 'bundle clone with .bundle suffix' '
73         git clone b1.bundle &&
74         (cd b1 && git fetch)
75 '
76
77 test_expect_success 'bundle clone from b4' '
78         git clone b4 bdl &&
79         (cd bdl && git fetch)
80 '
81
82 test_expect_success 'bundle clone from b4.bundle that does not exist' '
83         test_must_fail git clone b4.bundle bb
84 '
85
86 test_expect_success 'bundle clone with nonexistent HEAD' '
87         git clone b2.bundle b2 &&
88         (cd b2 &&
89         git fetch &&
90         test_must_fail git rev-parse --verify refs/heads/main)
91 '
92
93 test_expect_success 'clone empty repository' '
94         mkdir empty &&
95         (cd empty &&
96          git init &&
97          git config receive.denyCurrentBranch warn) &&
98         git clone empty empty-clone &&
99         test_tick &&
100         (cd empty-clone &&
101          echo "content" >> foo &&
102          git add foo &&
103          git commit -m "Initial commit" &&
104          git push origin main &&
105          expected=$(git rev-parse main) &&
106          actual=$(git --git-dir=../empty/.git rev-parse main) &&
107          test $actual = $expected)
108 '
109
110 test_expect_success 'clone empty repository, and then push should not segfault.' '
111         rm -fr empty/ empty-clone/ &&
112         mkdir empty &&
113         (cd empty && git init) &&
114         git clone empty empty-clone &&
115         (cd empty-clone &&
116         test_must_fail git push)
117 '
118
119 test_expect_success 'cloning non-existent directory fails' '
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' '
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
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
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
144 test_done