Skip to content

Commit 368b4e5

Browse files
peffgitster
authored andcommitted
index-pack: handle --strict checks of non-repo packs
Commit 73c3f0f (index-pack: check .gitmodules files with --strict, 2018-05-04) added a call to add_packed_git(), with the intent that the newly-indexed objects would be available to the process when we run fsck_finish(). But that's not what add_packed_git() does. It only allocates the struct, and you must install_packed_git() on the result. So that call was effectively doing nothing (except leaking a struct). But wait, we passed all of the tests! Does that mean we don't need the call at all? For normal cases, no. When we run "index-pack --stdin" inside a repository, we write the new pack into the object directory. If fsck_finish() needs to access one of the new objects, then our initial lookup will fail to find it, but we'll follow up by running reprepare_packed_git() and looking again. That logic was meant to handle somebody else repacking simultaneously, but it ends up working for us here. But there is a case that does need this, that we were not testing. You can run "git index-pack foo.pack" on any file, even when it is not inside the object directory. Or you may not even be in a repository at all! This case fails without doing the proper install_packed_git() call. We can make this work by adding the install call. Note that we should be prepared to handle add_packed_git() failing. We can just silently ignore this case, though. If fsck_finish() later needs the objects and they're not available, it will complain itself. And if it doesn't (because we were able to resolve the whole fsck in the first pass), then it actually isn't an interesting error at all. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 14a9bd2 commit 368b4e5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

builtin/index-pack.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,8 +1480,12 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
14801480
} else
14811481
chmod(final_index_name, 0444);
14821482

1483-
if (do_fsck_object)
1484-
add_packed_git(final_index_name, strlen(final_index_name), 0);
1483+
if (do_fsck_object) {
1484+
struct packed_git *p;
1485+
p = add_packed_git(final_index_name, strlen(final_index_name), 0);
1486+
if (p)
1487+
install_packed_git(the_repository, p);
1488+
}
14851489

14861490
if (!from_stdin) {
14871491
printf("%s\n", sha1_to_hex(hash));

t/t7415-submodule-names.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ test_expect_success 'transfer.fsckObjects handles odd pack (index)' '
122122
test_must_fail git -C dst.git index-pack --strict --stdin <odd.pack
123123
'
124124

125+
test_expect_success 'index-pack --strict works for non-repo pack' '
126+
rm -rf dst.git &&
127+
git init --bare dst.git &&
128+
cp odd.pack dst.git &&
129+
test_must_fail git -C dst.git index-pack --strict odd.pack 2>output &&
130+
# Make sure we fail due to bad gitmodules content, not because we
131+
# could not read the blob in the first place.
132+
grep gitmodulesName output
133+
'
134+
125135
test_expect_success 'fsck detects symlinked .gitmodules file' '
126136
git init symlink &&
127137
(

0 commit comments

Comments
 (0)