mirror of
https://github.com/git/git
synced 2024-11-05 18:59:29 +00:00
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
This commit is contained in:
commit
b772c9cf2e
3 changed files with 41 additions and 3 deletions
|
@ -207,12 +207,13 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
|
|||
builtin_bundle_unbundle_usage, options, &bundle_file);
|
||||
/* bundle internals use argv[1] as further parameters */
|
||||
|
||||
if (!startup_info->have_repository)
|
||||
die(_("Need a repository to unbundle."));
|
||||
|
||||
if ((bundle_fd = open_bundle(bundle_file, &header, NULL)) < 0) {
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
if (!startup_info->have_repository)
|
||||
die(_("Need a repository to unbundle."));
|
||||
if (progress)
|
||||
strvec_pushl(&extra_index_pack_args, "-v", "--progress-title",
|
||||
_("Unbundling objects"), NULL);
|
||||
|
|
7
bundle.c
7
bundle.c
|
@ -89,7 +89,12 @@ int read_bundle_header_fd(int fd, struct bundle_header *header,
|
|||
goto abort;
|
||||
}
|
||||
|
||||
header->hash_algo = the_hash_algo;
|
||||
/*
|
||||
* The default hash format for bundles is SHA1, unless told otherwise
|
||||
* by an "object-format=" capability, which is being handled in
|
||||
* `parse_capability()`.
|
||||
*/
|
||||
header->hash_algo = &hash_algos[GIT_HASH_SHA1];
|
||||
|
||||
/* The bundle header ends with an empty line */
|
||||
while (!strbuf_getwholeline_fd(&buf, fd, '\n') &&
|
||||
|
|
|
@ -652,4 +652,36 @@ test_expect_success 'send a bundle to standard output' '
|
|||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'unbundle outside of a repository' '
|
||||
git bundle create some.bundle HEAD &&
|
||||
echo "fatal: Need a repository to unbundle." >expect &&
|
||||
nongit test_must_fail git bundle unbundle "$(pwd)/some.bundle" 2>err &&
|
||||
test_cmp expect err
|
||||
'
|
||||
|
||||
test_expect_success 'list-heads outside of a repository' '
|
||||
git bundle create some.bundle HEAD &&
|
||||
cat >expect <<-EOF &&
|
||||
$(git rev-parse HEAD) HEAD
|
||||
EOF
|
||||
nongit git bundle list-heads "$(pwd)/some.bundle" >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
for hash in sha1 sha256
|
||||
do
|
||||
test_expect_success "list-heads with bundle using $hash" '
|
||||
test_when_finished "rm -rf hash" &&
|
||||
git init --object-format=$hash hash &&
|
||||
test_commit -C hash initial &&
|
||||
git -C hash bundle create hash.bundle HEAD &&
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
$(git -C hash rev-parse HEAD) HEAD
|
||||
EOF
|
||||
git bundle list-heads hash/hash.bundle >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
done
|
||||
|
||||
test_done
|
||||
|
|
Loading…
Reference in a new issue