]> git.ipfire.org Git - thirdparty/git.git/commitdiff
index-pack: complain when --stdin is used outside of a repo
authorJeff King <peff@peff.net>
Fri, 16 Dec 2016 02:30:59 +0000 (21:30 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 16 Dec 2016 17:29:43 +0000 (09:29 -0800)
The index-pack builtin is marked as RUN_SETUP_GENTLY,
because it's perfectly fine to index a pack in the
filesystem outside of any repository. However, --stdin mode
will write the result to the object database, which does not
make sense outside of a repository. Doing so creates a bogus
".git" directory with nothing in it except the newly-created
pack and its index.

Instead, let's flag this as an error and abort.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/index-pack.c
t/t5300-pack-object.sh

index 0a27bab11b6b5a1b162c4dfef34c645c7d5f14ad..d450a6ada2a247fc316caada8820241fdf975e0f 100644 (file)
@@ -1730,6 +1730,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
                usage(index_pack_usage);
        if (fix_thin_pack && !from_stdin)
                die(_("--fix-thin cannot be used without --stdin"));
+       if (from_stdin && !startup_info->have_repository)
+               die(_("--stdin requires a git repository"));
        if (!index_name && pack_name)
                index_name = derive_filename(pack_name, ".idx", &index_name_buf);
        if (keep_msg && !keep_name && pack_name)
index 899e52d50f0d73e4a755c4f7991364f34912b336..43a672c3451146f800852a6d8688c10e497b47cf 100755 (executable)
@@ -406,6 +406,21 @@ test_expect_success 'verify resulting packs' '
        git verify-pack test-11-*.pack
 '
 
+test_expect_success 'set up pack for non-repo tests' '
+       # make sure we have a pack with no matching index file
+       cp test-1-*.pack foo.pack
+'
+
+test_expect_success 'index-pack --stdin complains of non-repo' '
+       nongit test_must_fail git index-pack --stdin <foo.pack &&
+       test_path_is_missing non-repo/.git
+'
+
+test_expect_success 'index-pack <pack> works in non-repo' '
+       nongit git index-pack ../foo.pack &&
+       test_path_is_file foo.idx
+'
+
 #
 # WARNING!
 #