Git 2.33.8
[git.git] / t / t5607-clone-bundle.sh
blobed0d911e953e7536f8fb2ce7cc885a3a7dbce167
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-lib.sh
9 test_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
24 test_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_i18ngrep "need a repository" err
30 test_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 &&
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
49 test_expect_success 'die if bundle file cannot be created' '
50 mkdir adir &&
51 test_must_fail git bundle create adir --all
54 test_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
63 test_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
72 test_expect_success 'empty bundle file is rejected' '
73 >empty-bundle &&
74 test_must_fail git fetch empty-bundle
77 # This triggers a bug in older versions where the resulting line (with
78 # --pretty=oneline) was longer than a 1024-char buffer.
79 test_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 &&
92 git fetch long-subject-bundle.bdl &&
94 if ! test_have_prereq SHA1
95 then
96 echo "@object-format=sha256"
97 fi >expect &&
98 cat >>expect <<-EOF &&
99 -$(git log --pretty=format:"%H %s" -1 HEAD^)
100 $(git rev-parse HEAD) HEAD
103 if test_have_prereq SHA1
104 then
105 head -n 3 long-subject-bundle.bdl
106 else
107 head -n 4 long-subject-bundle.bdl
108 fi | grep -v "^#" >actual &&
110 test_cmp expect actual
113 test_expect_success 'prerequisites with an empty commit message' '
114 >file1 &&
115 git add file1 &&
116 test_tick &&
117 git commit --allow-empty-message -m "" &&
118 test_commit file2 &&
119 git bundle create bundle HEAD^.. &&
120 git bundle verify bundle
123 test_expect_success 'failed bundle creation does not leave cruft' '
124 # This fails because the bundle would be empty.
125 test_must_fail git bundle create fail.bundle main..main &&
126 test_path_is_missing fail.bundle.lock
129 test_expect_success 'fetch SHA-1 from bundle' '
130 test_create_repo foo &&
131 test_commit -C foo x &&
132 git -C foo bundle create tip.bundle -1 main &&
133 git -C foo rev-parse HEAD >hash &&
135 # Exercise to ensure that fetching a SHA-1 from a bundle works with no
136 # errors
137 git fetch --no-tags foo/tip.bundle "$(cat hash)"
140 test_expect_success 'git bundle uses expected default format' '
141 git bundle create bundle HEAD^.. &&
142 cat >expect <<-EOF &&
143 # v$(test_oid version) git bundle
145 head -n1 bundle >actual &&
146 test_cmp expect actual
149 test_expect_success 'git bundle v3 has expected contents' '
150 git branch side HEAD &&
151 git bundle create --version=3 bundle HEAD^..side &&
152 head -n2 bundle >actual &&
153 cat >expect <<-EOF &&
154 # v3 git bundle
155 @object-format=$(test_oid algo)
157 test_cmp expect actual &&
158 git bundle verify bundle
161 test_expect_success 'git bundle v3 rejects unknown capabilities' '
162 cat >new <<-EOF &&
163 # v3 git bundle
164 @object-format=$(test_oid algo)
165 @unknown=silly
167 test_must_fail git bundle verify new 2>output &&
168 test_i18ngrep "unknown capability .unknown=silly." output
171 test_done