Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='some bundle related tests' |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 7 | . ./test-lib.sh |
| 8 | |
| 9 | test_expect_success 'setup' ' |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 10 | test_oid_cache <<-EOF && |
| 11 | version sha1:2 |
| 12 | version sha256:3 |
| 13 | EOF |
Thomas Rast | 8a557bb | 2012-02-23 10:42:23 +0100 | [diff] [blame] | 14 | test_commit initial && |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 15 | test_tick && |
| 16 | git tag -m tag tag && |
Thomas Rast | 8a557bb | 2012-02-23 10:42:23 +0100 | [diff] [blame] | 17 | test_commit second && |
| 18 | test_commit third && |
| 19 | git tag -d initial && |
| 20 | git tag -d second && |
| 21 | git tag -d third |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 22 | ' |
| 23 | |
Johannes Schindelin | 3bbbe46 | 2019-05-27 12:59:14 -0700 | [diff] [blame] | 24 | test_expect_success '"verify" needs a worktree' ' |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 25 | git bundle create tip.bundle -1 main && |
Denton Liu | 85db348 | 2020-03-26 04:27:52 -0400 | [diff] [blame] | 26 | nongit test_must_fail git bundle verify ../tip.bundle 2>err && |
Johannes Schindelin | 3bbbe46 | 2019-05-27 12:59:14 -0700 | [diff] [blame] | 27 | test_i18ngrep "need a repository" err |
| 28 | ' |
| 29 | |
Lukas Fleischer | 2c8544a | 2014-08-02 10:39:06 +0200 | [diff] [blame] | 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 && |
Ævar Arnfjörð Bjarmason | 6376651 | 2021-07-22 01:53:29 +0200 | [diff] [blame] | 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 | |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 40 | git bundle create bundle --all --since=7.Apr.2005.15:16:00.-0700 && |
Ævar Arnfjörð Bjarmason | 6376651 | 2021-07-22 01:53:29 +0200 | [diff] [blame] | 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 |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 47 | ' |
| 48 | |
Csaba Henk | 0f5cdf6 | 2010-08-27 20:31:47 +0000 | [diff] [blame] | 49 | test_expect_success 'die if bundle file cannot be created' ' |
Csaba Henk | 0f5cdf6 | 2010-08-27 20:31:47 +0000 | [diff] [blame] | 50 | mkdir adir && |
| 51 | test_must_fail git bundle create adir --all |
Csaba Henk | 0f5cdf6 | 2010-08-27 20:31:47 +0000 | [diff] [blame] | 52 | ' |
| 53 | |
Jiang Xin | 5bb0fd2 | 2021-01-11 21:27:03 -0500 | [diff] [blame] | 54 | test_expect_success 'bundle --stdin' ' |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 55 | echo main | git bundle create stdin-bundle.bdl --stdin && |
Ævar Arnfjörð Bjarmason | 6376651 | 2021-07-22 01:53:29 +0200 | [diff] [blame] | 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 |
Jonathan Nieder | f62e0a3 | 2010-04-19 03:03:03 -0500 | [diff] [blame] | 61 | ' |
| 62 | |
Jiang Xin | 5bb0fd2 | 2021-01-11 21:27:03 -0500 | [diff] [blame] | 63 | test_expect_success 'bundle --stdin <rev-list options>' ' |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 64 | echo main | git bundle create hybrid-bundle.bdl --stdin tag && |
Ævar Arnfjörð Bjarmason | 6376651 | 2021-07-22 01:53:29 +0200 | [diff] [blame] | 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 |
Jonathan Nieder | f62e0a3 | 2010-04-19 03:03:03 -0500 | [diff] [blame] | 70 | ' |
| 71 | |
Brian Harring | 54440e1 | 2012-01-03 05:46:03 -0800 | [diff] [blame] | 72 | test_expect_success 'empty bundle file is rejected' ' |
Ævar Arnfjörð Bjarmason | 95cf646 | 2021-07-22 01:53:28 +0200 | [diff] [blame] | 73 | >empty-bundle && |
Thomas Rast | 8a557bb | 2012-02-23 10:42:23 +0100 | [diff] [blame] | 74 | test_must_fail git fetch empty-bundle |
Brian Harring | 54440e1 | 2012-01-03 05:46:03 -0800 | [diff] [blame] | 75 | ' |
| 76 | |
Thomas Rast | bc2fed4 | 2012-02-22 20:34:23 +0100 | [diff] [blame] | 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' ' |
Ævar Arnfjörð Bjarmason | 95cf646 | 2021-07-22 01:53:28 +0200 | [diff] [blame] | 80 | >file4 && |
Thomas Rast | bc2fed4 | 2012-02-22 20:34:23 +0100 | [diff] [blame] | 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 && |
Ævar Arnfjörð Bjarmason | 6376651 | 2021-07-22 01:53:29 +0200 | [diff] [blame] | 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 | |
Thomas Rast | bc2fed4 | 2012-02-22 20:34:23 +0100 | [diff] [blame] | 92 | git fetch long-subject-bundle.bdl && |
Ævar Arnfjörð Bjarmason | 6376651 | 2021-07-22 01:53:29 +0200 | [diff] [blame] | 93 | |
brian m. carlson | b227bea | 2021-08-11 23:16:44 +0000 | [diff] [blame] | 94 | algo=$(test_oid algo) && |
| 95 | if test "$algo" != sha1 |
Ævar Arnfjörð Bjarmason | 6376651 | 2021-07-22 01:53:29 +0200 | [diff] [blame] | 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 | |
brian m. carlson | b227bea | 2021-08-11 23:16:44 +0000 | [diff] [blame] | 104 | if test "$algo" = sha1 |
Ævar Arnfjörð Bjarmason | 6376651 | 2021-07-22 01:53:29 +0200 | [diff] [blame] | 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 |
Thomas Rast | bc2fed4 | 2012-02-22 20:34:23 +0100 | [diff] [blame] | 112 | ' |
| 113 | |
Lukas Fleischer | 5446e33 | 2013-04-07 13:53:15 +0200 | [diff] [blame] | 114 | test_expect_success 'prerequisites with an empty commit message' ' |
Ævar Arnfjörð Bjarmason | 95cf646 | 2021-07-22 01:53:28 +0200 | [diff] [blame] | 115 | >file1 && |
Lukas Fleischer | 5446e33 | 2013-04-07 13:53:15 +0200 | [diff] [blame] | 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 | |
Jeff King | 2c8ee1f | 2018-11-16 04:43:59 -0500 | [diff] [blame] | 124 | test_expect_success 'failed bundle creation does not leave cruft' ' |
| 125 | # This fails because the bundle would be empty. |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 126 | test_must_fail git bundle create fail.bundle main..main && |
Jeff King | 2c8ee1f | 2018-11-16 04:43:59 -0500 | [diff] [blame] | 127 | test_path_is_missing fail.bundle.lock |
| 128 | ' |
| 129 | |
Jonathan Tan | fddf2eb | 2019-08-21 15:20:10 -0700 | [diff] [blame] | 130 | test_expect_success 'fetch SHA-1 from bundle' ' |
| 131 | test_create_repo foo && |
| 132 | test_commit -C foo x && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 133 | git -C foo bundle create tip.bundle -1 main && |
Jonathan Tan | fddf2eb | 2019-08-21 15:20:10 -0700 | [diff] [blame] | 134 | git -C foo rev-parse HEAD >hash && |
| 135 | |
| 136 | # Exercise to ensure that fetching a SHA-1 from a bundle works with no |
| 137 | # errors |
| 138 | git fetch --no-tags foo/tip.bundle "$(cat hash)" |
| 139 | ' |
| 140 | |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 141 | test_expect_success 'git bundle uses expected default format' ' |
| 142 | git bundle create bundle HEAD^.. && |
Ævar Arnfjörð Bjarmason | 6376651 | 2021-07-22 01:53:29 +0200 | [diff] [blame] | 143 | cat >expect <<-EOF && |
| 144 | # v$(test_oid version) git bundle |
| 145 | EOF |
| 146 | head -n1 bundle >actual && |
| 147 | test_cmp expect actual |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 148 | ' |
| 149 | |
| 150 | test_expect_success 'git bundle v3 has expected contents' ' |
| 151 | git branch side HEAD && |
| 152 | git bundle create --version=3 bundle HEAD^..side && |
| 153 | head -n2 bundle >actual && |
| 154 | cat >expect <<-EOF && |
| 155 | # v3 git bundle |
| 156 | @object-format=$(test_oid algo) |
| 157 | EOF |
| 158 | test_cmp expect actual && |
| 159 | git bundle verify bundle |
| 160 | ' |
| 161 | |
| 162 | test_expect_success 'git bundle v3 rejects unknown capabilities' ' |
| 163 | cat >new <<-EOF && |
| 164 | # v3 git bundle |
| 165 | @object-format=$(test_oid algo) |
| 166 | @unknown=silly |
| 167 | EOF |
| 168 | test_must_fail git bundle verify new 2>output && |
| 169 | test_i18ngrep "unknown capability .unknown=silly." output |
| 170 | ' |
| 171 | |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 172 | test_done |