Skip to content

Commit 7176a31

Browse files
peffgitster
authored andcommitted
index-pack: complain when --stdin is used outside of a repo
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent de95302 commit 7176a31

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

builtin/index-pack.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
17301730
usage(index_pack_usage);
17311731
if (fix_thin_pack && !from_stdin)
17321732
die(_("--fix-thin cannot be used without --stdin"));
1733+
if (from_stdin && !startup_info->have_repository)
1734+
die(_("--stdin requires a git repository"));
17331735
if (!index_name && pack_name)
17341736
index_name = derive_filename(pack_name, ".idx", &index_name_buf);
17351737
if (keep_msg && !keep_name && pack_name)

t/t5300-pack-object.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,21 @@ test_expect_success 'verify resulting packs' '
406406
git verify-pack test-11-*.pack
407407
'
408408

409+
test_expect_success 'set up pack for non-repo tests' '
410+
# make sure we have a pack with no matching index file
411+
cp test-1-*.pack foo.pack
412+
'
413+
414+
test_expect_success 'index-pack --stdin complains of non-repo' '
415+
nongit test_must_fail git index-pack --stdin <foo.pack &&
416+
test_path_is_missing non-repo/.git
417+
'
418+
419+
test_expect_success 'index-pack <pack> works in non-repo' '
420+
nongit git index-pack ../foo.pack &&
421+
test_path_is_file foo.idx
422+
'
423+
409424
#
410425
# WARNING!
411426
#

0 commit comments

Comments
 (0)