aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--midx-write.c14
-rwxr-xr-xt/t5319-multi-pack-index.sh2
2 files changed, 15 insertions, 1 deletions
diff --git a/midx-write.c b/midx-write.c
index 40abe3868c..51e1390164 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -1022,6 +1022,20 @@ static bool midx_needs_update(struct multi_pack_index *midx, struct write_midx_c
bool needed = true;
/*
+ * Ensure that we have a valid checksum before consulting the
+ * exisiting MIDX in order to determine if we can avoid an
+ * update.
+ *
+ * This is necessary because the given MIDX is loaded directly
+ * from the object store (because we still compare our proposed
+ * update to any on-disk MIDX regardless of whether or not we
+ * have assigned "ctx.m") and is thus not guaranteed to have a
+ * valid checksum.
+ */
+ if (!midx_checksum_valid(midx))
+ goto out;
+
+ /*
* Ignore incremental updates for now. The assumption is that any
* incremental update would be either empty (in which case we will bail
* out later) or it would actually cover at least one new pack.
diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh
index b6622849db..faae98c7e7 100755
--- a/t/t5319-multi-pack-index.sh
+++ b/t/t5319-multi-pack-index.sh
@@ -563,7 +563,7 @@ test_expect_success 'git fsck suppresses MIDX output with --no-progress' '
! grep "Verifying object offsets" err
'
-test_expect_failure 'corrupt MIDX is not reused' '
+test_expect_success 'corrupt MIDX is not reused' '
corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
"incorrect object offset" &&
git multi-pack-index write 2>err &&