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
10 test_expect_success
'setup' '
11 test_oid_cache <<-EOF &&
15 test_commit initial &&
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 &&
34 $(git rev-parse HEAD) HEAD
35 $(git rev-parse tag) refs/tags/tag
36 $(git rev-parse main) refs/heads/main
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 &&
43 $(git rev-parse HEAD) HEAD
44 $(git rev-parse main) refs/heads/main
46 git ls-remote bundle >actual &&
47 test_cmp expect actual
50 test_expect_success
'die if bundle file cannot be created' '
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 &&
58 $(git rev-parse main) refs/heads/main
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 &&
67 $(git rev-parse main) refs/heads/main
69 git ls-remote stdin-bundle.bdl >actual &&
70 test_cmp expect actual
73 test_expect_success
'empty bundle file is rejected' '
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' '
84 printf "%01200d\n" 0 | git commit -F - &&
86 git bundle create long-subject-bundle.bdl HEAD^..HEAD &&
88 $(git rev-parse main) HEAD
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
98 echo "@object-format=sha256"
100 cat >>expect <<-EOF &&
101 -$(git log --pretty=format:"%H %s" -1 HEAD^)
102 $(git rev-parse HEAD) HEAD
105 if test "$algo" = sha1
107 head -n 3 long-subject-bundle.bdl
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' '
119 git commit --allow-empty-message -m "" &&
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
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 &&
147 commit_a=$(git rev-parse A) &&
148 tree_a=$(git rev-parse A^{tree}) &&
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
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 &&
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' '
201 @object-format=$(test_oid algo)
204 test_must_fail git bundle verify new 2>output &&
205 test_grep "unknown capability .unknown=silly." output