Skip to content

Commit 7298bcc

Browse files
pks-tgitster
authored andcommitted
builtin/bundle: have unbundle check for repo before opening its bundle
The `git bundle unbundle` subcommand requires a repository to unbundle the contents into. As thus, the subcommand checks whether we have a startup repository in the first place, and if not it dies. This check happens after we have already opened the bundle though. This causes a segfault when running outside of a repository starting with c8aed5e (repository: stop setting SHA1 as the default object hash, 2024-05-07) because we have no hash function set up, but we do try to parse refs advertised by the bundle's header. The next commit will fix that underlying issue by defaulting to the SHA1 object format for bundles, which will also fix the described segfault here. But as we know that we will die anyway, we can do better than that and avoid some vain work by moving the check for a repository before we try to open the bundle. Reported-by: ArcticLampyrid <[email protected]> Suggested-by: Jeff King <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 39bf06a commit 7298bcc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
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);

t/t6020-bundle-misc.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,4 +652,11 @@ 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+
655662
test_done

0 commit comments

Comments
 (0)