]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/bundle: have unbundle check for repo before opening its bundle
authorPatrick Steinhardt <ps@pks.im>
Tue, 13 Aug 2024 09:18:08 +0000 (11:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Aug 2024 17:26:20 +0000 (10:26 -0700)
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
c8aed5e8da (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 <ArcticLampyrid@outlook.com>
Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/bundle.c
t/t6020-bundle-misc.sh

index d5d41a8f6722cf95183a0c9ac5d746b58ac53a76..86d0ed7049c6531d2c198b39813cbfc3cc28e058 100644 (file)
@@ -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);
index fe75a06572aed63c2227398de9f82c8006b8e1e7..703434b4720ac8e8def7ee6f0baa3a80467973de 100755 (executable)
@@ -652,4 +652,11 @@ 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_done