parse-options: use prefix_filename_except_for_dash() helper
[alt-git.git] / t / t5605-clone-local.sh
blob38b850c10ef8cddeb790ed276209bb5019439eae
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 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 git branch not-main main &&
26 git bundle create b5.bundle not-main
29 test_expect_success 'local clone without .git suffix' '
30 git clone -l -s a b &&
31 (cd b &&
32 test "$(git config --bool core.bare)" = false &&
33 git fetch)
36 test_expect_success 'local clone with .git suffix' '
37 git clone -l -s a.git c &&
38 (cd c && git fetch)
41 test_expect_success 'local clone from x' '
42 git clone -l -s x y &&
43 (cd y && git fetch)
46 test_expect_success 'local clone from x.git that does not exist' '
47 test_must_fail git clone -l -s x.git z
50 test_expect_success 'With -no-hardlinks, local will make a copy' '
51 git clone --bare --no-hardlinks x w &&
52 ! repo_is_hardlinked w
55 test_expect_success 'Even without -l, local will make a hardlink' '
56 rm -fr w &&
57 git clone -l --bare x w &&
58 repo_is_hardlinked w
61 test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
62 echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
63 git clone a d &&
64 (cd d &&
65 git fetch &&
66 test ! -e .git/refs/remotes/origin/HEAD)
69 test_expect_success 'bundle clone without .bundle suffix' '
70 git clone dir/b3 &&
71 (cd b3 && git fetch)
74 test_expect_success 'bundle clone with .bundle suffix' '
75 git clone b1.bundle &&
76 (cd b1 && git fetch)
79 test_expect_success 'bundle clone from b4' '
80 git clone b4 bdl &&
81 (cd bdl && git fetch)
84 test_expect_success 'bundle clone from b4.bundle that does not exist' '
85 test_must_fail git clone b4.bundle bb
88 test_expect_success 'bundle clone with nonexistent HEAD (match default)' '
89 git clone b2.bundle b2 &&
90 (cd b2 &&
91 git fetch &&
92 git rev-parse --verify refs/heads/main)
95 test_expect_success 'bundle clone with nonexistent HEAD (no match default)' '
96 git clone b5.bundle b5 &&
97 (cd b5 &&
98 git fetch &&
99 test_must_fail git rev-parse --verify refs/heads/main &&
100 test_must_fail git rev-parse --verify refs/heads/not-main)
103 test_expect_success 'clone empty repository' '
104 mkdir empty &&
105 (cd empty &&
106 git init &&
107 git config receive.denyCurrentBranch warn) &&
108 git clone empty empty-clone &&
109 test_tick &&
110 (cd empty-clone &&
111 echo "content" >> foo &&
112 git add foo &&
113 git commit -m "Initial commit" &&
114 git push origin main &&
115 expected=$(git rev-parse main) &&
116 actual=$(git --git-dir=../empty/.git rev-parse main) &&
117 test $actual = $expected)
120 test_expect_success 'clone empty repository, and then push should not segfault.' '
121 rm -fr empty/ empty-clone/ &&
122 mkdir empty &&
123 (cd empty && git init) &&
124 git clone empty empty-clone &&
125 (cd empty-clone &&
126 test_must_fail git push)
129 test_expect_success 'cloning non-existent directory fails' '
130 rm -rf does-not-exist &&
131 test_must_fail git clone does-not-exist
134 test_expect_success 'cloning non-git directory fails' '
135 rm -rf not-a-git-repo not-a-git-repo-clone &&
136 mkdir not-a-git-repo &&
137 test_must_fail git clone not-a-git-repo not-a-git-repo-clone
140 test_expect_success 'cloning file:// does not hardlink' '
141 git clone --bare file://"$(pwd)"/a non-local &&
142 ! repo_is_hardlinked non-local
145 test_expect_success 'cloning a local path with --no-local does not hardlink' '
146 git clone --bare --no-local a force-nonlocal &&
147 ! repo_is_hardlinked force-nonlocal
150 test_expect_success 'cloning locally respects "-u" for fetching refs' '
151 test_must_fail git clone --bare -u false a should_not_work.git
154 test_expect_success 'local clone from repo with corrupt refs fails gracefully' '
155 git init corrupt &&
156 test_commit -C corrupt one &&
157 echo a >corrupt/.git/refs/heads/topic &&
159 test_must_fail git clone corrupt working 2>err &&
160 grep "has a null OID" err
163 test_done