Sync with Git 2.46-rc1
[alt-git.git] / t / t5607-clone-bundle.sh
blob7ceaa8194d83f4c11fd80b89498969450c34a979
1 #!/bin/sh
3 test_description='some bundle related tests'
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 test_expect_success 'setup' '
11 test_oid_cache <<-EOF &&
12 version sha1:2
13 version sha256:3
14 EOF
15 test_commit initial &&
16 test_tick &&
17 git tag -m tag tag &&
18 test_commit second &&
19 test_commit third &&
20 git tag -d initial &&
21 git tag -d second &&
22 git tag -d third
25 test_expect_success '"verify" needs a worktree' '
26 git bundle create tip.bundle -1 main &&
27 nongit test_must_fail git bundle verify ../tip.bundle 2>err &&
28 test_grep "need a repository" err
31 test_expect_success 'annotated tags can be excluded by rev-list options' '
32 git bundle create bundle --all --since=7.Apr.2005.15:14:00.-0700 &&
33 cat >expect <<-EOF &&
34 $(git rev-parse HEAD) HEAD
35 $(git rev-parse tag) refs/tags/tag
36 $(git rev-parse main) refs/heads/main
37 EOF
38 git ls-remote bundle >actual &&
39 test_cmp expect actual &&
41 git bundle create bundle --all --since=7.Apr.2005.15:16:00.-0700 &&
42 cat >expect <<-EOF &&
43 $(git rev-parse HEAD) HEAD
44 $(git rev-parse main) refs/heads/main
45 EOF
46 git ls-remote bundle >actual &&
47 test_cmp expect actual
50 test_expect_success 'die if bundle file cannot be created' '
51 mkdir adir &&
52 test_must_fail git bundle create adir --all
55 test_expect_success 'bundle --stdin' '
56 echo main | git bundle create stdin-bundle.bdl --stdin &&
57 cat >expect <<-EOF &&
58 $(git rev-parse main) refs/heads/main
59 EOF
60 git ls-remote stdin-bundle.bdl >actual &&
61 test_cmp expect actual
64 test_expect_success 'bundle --stdin <rev-list options>' '
65 echo main | git bundle create hybrid-bundle.bdl --stdin tag &&
66 cat >expect <<-EOF &&
67 $(git rev-parse main) refs/heads/main
68 EOF
69 git ls-remote stdin-bundle.bdl >actual &&
70 test_cmp expect actual
73 test_expect_success 'empty bundle file is rejected' '
74 >empty-bundle &&
75 test_must_fail git fetch empty-bundle
78 # This triggers a bug in older versions where the resulting line (with
79 # --pretty=oneline) was longer than a 1024-char buffer.
80 test_expect_success 'ridiculously long subject in boundary' '
81 >file4 &&
82 test_tick &&
83 git add file4 &&
84 printf "%01200d\n" 0 | git commit -F - &&
85 test_commit fifth &&
86 git bundle create long-subject-bundle.bdl HEAD^..HEAD &&
87 cat >expect <<-EOF &&
88 $(git rev-parse main) HEAD
89 EOF
90 git bundle list-heads long-subject-bundle.bdl >actual &&
91 test_cmp expect actual &&
93 git fetch long-subject-bundle.bdl &&
95 algo=$(test_oid algo) &&
96 if test "$algo" != sha1
97 then
98 echo "@object-format=sha256"
99 fi >expect &&
100 cat >>expect <<-EOF &&
101 -$(git log --pretty=format:"%H %s" -1 HEAD^)
102 $(git rev-parse HEAD) HEAD
105 if test "$algo" = sha1
106 then
107 head -n 3 long-subject-bundle.bdl
108 else
109 head -n 4 long-subject-bundle.bdl
110 fi | grep -v "^#" >actual &&
112 test_cmp expect actual
115 test_expect_success 'prerequisites with an empty commit message' '
116 >file1 &&
117 git add file1 &&
118 test_tick &&
119 git commit --allow-empty-message -m "" &&
120 test_commit file2 &&
121 git bundle create bundle HEAD^.. &&
122 git bundle verify bundle
125 test_expect_success 'failed bundle creation does not leave cruft' '
126 # This fails because the bundle would be empty.
127 test_must_fail git bundle create fail.bundle main..main &&
128 test_path_is_missing fail.bundle.lock
131 test_expect_success 'fetch SHA-1 from bundle' '
132 test_create_repo foo &&
133 test_commit -C foo x &&
134 git -C foo bundle create tip.bundle -1 main &&
135 git -C foo rev-parse HEAD >hash &&
137 # Exercise to ensure that fetching a SHA-1 from a bundle works with no
138 # errors
139 git fetch --no-tags foo/tip.bundle "$(cat hash)"
142 test_expect_success 'clone bundle with different fsckObjects configurations' '
143 test_create_repo bundle-fsck &&
145 cd bundle-fsck &&
146 test_commit A &&
147 commit_a=$(git rev-parse A) &&
148 tree_a=$(git rev-parse A^{tree}) &&
149 cat >data <<-EOF &&
150 tree $tree_a
151 parent $commit_a
152 author A U Thor
153 committer A U Thor
155 commit: this is a commit with bad emails
158 bad_commit=$(git hash-object --literally -t commit -w --stdin <data) &&
159 git branch bad $bad_commit &&
160 git bundle create bad.bundle bad
161 ) &&
163 git clone bundle-fsck/bad.bundle bundle-no-fsck &&
165 git -c fetch.fsckObjects=false -c transfer.fsckObjects=true \
166 clone bundle-fsck/bad.bundle bundle-fetch-no-fsck &&
168 test_must_fail git -c fetch.fsckObjects=true \
169 clone bundle-fsck/bad.bundle bundle-fetch-fsck 2>err &&
170 test_grep "missingEmail" err &&
172 test_must_fail git -c transfer.fsckObjects=true \
173 clone bundle-fsck/bad.bundle bundle-transfer-fsck 2>err &&
174 test_grep "missingEmail" err
177 test_expect_success 'git bundle uses expected default format' '
178 git bundle create bundle HEAD^.. &&
179 cat >expect <<-EOF &&
180 # v$(test_oid version) git bundle
182 head -n1 bundle >actual &&
183 test_cmp expect actual
186 test_expect_success 'git bundle v3 has expected contents' '
187 git branch side HEAD &&
188 git bundle create --version=3 bundle HEAD^..side &&
189 head -n2 bundle >actual &&
190 cat >expect <<-EOF &&
191 # v3 git bundle
192 @object-format=$(test_oid algo)
194 test_cmp expect actual &&
195 git bundle verify bundle
198 test_expect_success 'git bundle v3 rejects unknown capabilities' '
199 cat >new <<-EOF &&
200 # v3 git bundle
201 @object-format=$(test_oid algo)
202 @unknown=silly
204 test_must_fail git bundle verify new 2>output &&
205 test_grep "unknown capability .unknown=silly." output
208 test_done