Skip to content

Commit b772c9c

Browse files
committed
Merge branch 'ps/bundle-outside-repo-fix'
"git bundle unbundle" outside a repository triggered a BUG() unnecessarily, which has been corrected. * ps/bundle-outside-repo-fix: bundle: default to SHA1 when reading bundle headers builtin/bundle: have unbundle check for repo before opening its bundle
2 parents fdf70da + 96a9a3e commit b772c9c

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

builtin/bundle.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,13 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
207207
builtin_bundle_unbundle_usage, options, &bundle_file);
208208
/* bundle internals use argv[1] as further parameters */
209209

210+
if (!startup_info->have_repository)
211+
die(_("Need a repository to unbundle."));
212+
210213
if ((bundle_fd = open_bundle(bundle_file, &header, NULL)) < 0) {
211214
ret = 1;
212215
goto cleanup;
213216
}
214-
if (!startup_info->have_repository)
215-
die(_("Need a repository to unbundle."));
216217
if (progress)
217218
strvec_pushl(&extra_index_pack_args, "-v", "--progress-title",
218219
_("Unbundling objects"), NULL);

bundle.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ int read_bundle_header_fd(int fd, struct bundle_header *header,
8989
goto abort;
9090
}
9191

92-
header->hash_algo = the_hash_algo;
92+
/*
93+
* The default hash format for bundles is SHA1, unless told otherwise
94+
* by an "object-format=" capability, which is being handled in
95+
* `parse_capability()`.
96+
*/
97+
header->hash_algo = &hash_algos[GIT_HASH_SHA1];
9398

9499
/* The bundle header ends with an empty line */
95100
while (!strbuf_getwholeline_fd(&buf, fd, '\n') &&

t/t6020-bundle-misc.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,4 +652,36 @@ test_expect_success 'send a bundle to standard output' '
652652
test_cmp expect actual
653653
'
654654

655+
test_expect_success 'unbundle outside of a repository' '
656+
git bundle create some.bundle HEAD &&
657+
echo "fatal: Need a repository to unbundle." >expect &&
658+
nongit test_must_fail git bundle unbundle "$(pwd)/some.bundle" 2>err &&
659+
test_cmp expect err
660+
'
661+
662+
test_expect_success 'list-heads outside of a repository' '
663+
git bundle create some.bundle HEAD &&
664+
cat >expect <<-EOF &&
665+
$(git rev-parse HEAD) HEAD
666+
EOF
667+
nongit git bundle list-heads "$(pwd)/some.bundle" >actual &&
668+
test_cmp expect actual
669+
'
670+
671+
for hash in sha1 sha256
672+
do
673+
test_expect_success "list-heads with bundle using $hash" '
674+
test_when_finished "rm -rf hash" &&
675+
git init --object-format=$hash hash &&
676+
test_commit -C hash initial &&
677+
git -C hash bundle create hash.bundle HEAD &&
678+
679+
cat >expect <<-EOF &&
680+
$(git -C hash rev-parse HEAD) HEAD
681+
EOF
682+
git bundle list-heads hash/hash.bundle >actual &&
683+
test_cmp expect actual
684+
'
685+
done
686+
655687
test_done

0 commit comments

Comments
 (0)