interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t5607-clone-bundle.sh

233 lines · 6332 bytes Raw Blame History
1#!/bin/sh
2
3test_description='some bundle related tests'
4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7. ./test-lib.sh
8
9test_expect_success 'setup' '
10 test_oid_cache <<-EOF &&
11 version sha1:2
12 version sha256:3
13 EOF
14 test_commit initial &&
15 test_tick &&
16 git tag -m tag tag &&
17 test_commit second &&
18 test_commit third &&
19 git tag -d initial &&
20 git tag -d second &&
21 git tag -d third
22'
23
24test_expect_success '"verify" needs a worktree' '
25 git bundle create tip.bundle -1 main &&
26 nongit test_must_fail git bundle verify ../tip.bundle 2>err &&
27 test_grep "need a repository" err
28'
29
30test_expect_success 'annotated tags can be excluded by rev-list options' '
31 git bundle create bundle --all --since=7.Apr.2005.15:14:00.-0700 &&
32 cat >expect <<-EOF &&
33 $(git rev-parse HEAD) HEAD
34 $(git rev-parse tag) refs/tags/tag
35 $(git rev-parse main) refs/heads/main
36 EOF
37 git ls-remote bundle >actual &&
38 test_cmp expect actual &&
39
40 git bundle create bundle --all --since=7.Apr.2005.15:16:00.-0700 &&
41 cat >expect <<-EOF &&
42 $(git rev-parse HEAD) HEAD
43 $(git rev-parse main) refs/heads/main
44 EOF
45 git ls-remote bundle >actual &&
46 test_cmp expect actual
47'
48
49test_expect_success 'die if bundle file cannot be created' '
50 mkdir adir &&
51 test_must_fail git bundle create adir --all
52'
53
54test_expect_success 'bundle --stdin' '
55 echo main | git bundle create stdin-bundle.bdl --stdin &&
56 cat >expect <<-EOF &&
57 $(git rev-parse main) refs/heads/main
58 EOF
59 git ls-remote stdin-bundle.bdl >actual &&
60 test_cmp expect actual
61'
62
63test_expect_success 'bundle --stdin <rev-list options>' '
64 echo main | git bundle create hybrid-bundle.bdl --stdin tag &&
65 cat >expect <<-EOF &&
66 $(git rev-parse main) refs/heads/main
67 EOF
68 git ls-remote stdin-bundle.bdl >actual &&
69 test_cmp expect actual
70'
71
72test_expect_success 'empty bundle file is rejected' '
73 >empty-bundle &&
74 test_must_fail git fetch empty-bundle
75'
76
77# This triggers a bug in older versions where the resulting line (with
78# --pretty=oneline) was longer than a 1024-char buffer.
79test_expect_success 'ridiculously long subject in boundary' '
80 >file4 &&
81 test_tick &&
82 git add file4 &&
83 printf "%01200d\n" 0 | git commit -F - &&
84 test_commit fifth &&
85 git bundle create long-subject-bundle.bdl HEAD^..HEAD &&
86 cat >expect <<-EOF &&
87 $(git rev-parse main) HEAD
88 EOF
89 git bundle list-heads long-subject-bundle.bdl >actual &&
90 test_cmp expect actual &&
91
92 git fetch long-subject-bundle.bdl &&
93
94 algo=$(test_oid algo) &&
95 if test "$algo" != sha1
96 then
97 echo "@object-format=sha256"
98 fi >expect &&
99 cat >>expect <<-EOF &&
100 -$(git log --pretty=format:"%H %s" -1 HEAD^)
101 $(git rev-parse HEAD) HEAD
102 EOF
103
104 if test "$algo" = sha1
105 then
106 head -n 3 long-subject-bundle.bdl
107 else
108 head -n 4 long-subject-bundle.bdl
109 fi | grep -v "^#" >actual &&
110
111 test_cmp expect actual
112'
113
114test_expect_success 'prerequisites with an empty commit message' '
115 >file1 &&
116 git add file1 &&
117 test_tick &&
118 git commit --allow-empty-message -m "" &&
119 test_commit file2 &&
120 git bundle create bundle HEAD^.. &&
121 git bundle verify bundle
122'
123
124test_expect_success 'failed bundle creation does not leave cruft' '
125 # This fails because the bundle would be empty.
126 test_must_fail git bundle create fail.bundle main..main &&
127 test_path_is_missing fail.bundle.lock
128'
129
130test_expect_success 'an unknown argument after the revisions is an error' '
131 test_must_fail git bundle create unknown.bundle main --no-such-option \
132 2>err &&
133 test_grep "unrecognized argument: --no-such-option" err &&
134 test_path_is_missing unknown.bundle
135'
136
137test_expect_success 'fetch SHA-1 from bundle' '
138 test_create_repo foo &&
139 test_commit -C foo x &&
140 git -C foo bundle create tip.bundle -1 main &&
141 git -C foo rev-parse HEAD >hash &&
142
143 # Exercise to ensure that fetching a SHA-1 from a bundle works with no
144 # errors
145 git fetch --no-tags foo/tip.bundle "$(cat hash)"
146'
147
148test_expect_success 'clone bundle with different fsckObjects configurations' '
149 test_create_repo bundle-fsck &&
150 (
151 cd bundle-fsck &&
152 test_commit A &&
153 commit_a=$(git rev-parse A) &&
154 tree_a=$(git rev-parse A^{tree}) &&
155 cat >data <<-EOF &&
156 tree $tree_a
157 parent $commit_a
158 author A U Thor
159 committer A U Thor
160
161 commit: this is a commit with bad emails
162
163 EOF
164 bad_commit=$(git hash-object --literally -t commit -w --stdin <data) &&
165 git branch bad $bad_commit &&
166 git bundle create bad.bundle bad
167 ) &&
168
169 git clone bundle-fsck/bad.bundle bundle-no-fsck &&
170
171 git -c fetch.fsckObjects=false -c transfer.fsckObjects=true \
172 clone bundle-fsck/bad.bundle bundle-fetch-no-fsck &&
173
174 test_must_fail git -c fetch.fsckObjects=true \
175 clone bundle-fsck/bad.bundle bundle-fetch-fsck 2>err &&
176 test_grep "missingEmail" err &&
177
178 test_must_fail git -c transfer.fsckObjects=true \
179 clone bundle-fsck/bad.bundle bundle-transfer-fsck 2>err &&
180 test_grep "missingEmail" err &&
181
182 git -c fetch.fsckObjects=true -c fetch.fsck.missingEmail=ignore \
183 clone bundle-fsck/bad.bundle bundle-fsck-ignore &&
184
185 test_must_fail git -c fetch.fsckObjects=true -c fetch.fsck.missingEmail=error \
186 clone bundle-fsck/bad.bundle bundle-fsck-error 2>err &&
187 test_grep "missingEmail" err
188'
189
190test_expect_success 'git bundle uses expected default format' '
191 git bundle create bundle HEAD^.. &&
192 cat >expect <<-EOF &&
193 # v$(test_oid version) git bundle
194 EOF
195 head -n1 bundle >actual &&
196 test_cmp expect actual
197'
198
199test_expect_success 'git bundle v3 has expected contents' '
200 git branch side HEAD &&
201 git bundle create --version=3 bundle HEAD^..side &&
202 head -n2 bundle >actual &&
203 cat >expect <<-EOF &&
204 # v3 git bundle
205 @object-format=$(test_oid algo)
206 EOF
207 test_cmp expect actual &&
208 git bundle verify bundle
209'
210
211test_expect_success 'git bundle v3 rejects unknown capabilities' '
212 cat >new <<-EOF &&
213 # v3 git bundle
214 @object-format=$(test_oid algo)
215 @unknown=silly
216 EOF
217 test_must_fail git bundle verify new 2>output &&
218 test_grep "unknown capability .unknown=silly." output
219'
220
221test_expect_success 'cloning bundle suppresses default branch name advice' '
222 test_when_finished "rm -rf bundle-repo clone-repo" &&
223
224 git init bundle-repo &&
225 git -C bundle-repo commit --allow-empty -m init &&
226 git -C bundle-repo bundle create repo.bundle --all &&
227 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
228 git clone --single-branch bundle-repo/repo.bundle clone-repo 2>err &&
229
230 test_grep ! "hint: " err
231'
232
233test_done