summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--refs.c10
-rwxr-xr-xt/t6301-for-each-ref-errors.sh2
2 files changed, 11 insertions, 1 deletions
diff --git a/refs.c b/refs.c
index 3c311d44c1..07f8847e6d 100644
--- a/refs.c
+++ b/refs.c
@@ -1297,6 +1297,16 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
if (!read_ok) {
hashclr(sha1);
flag |= REF_ISBROKEN;
+ } else if (is_null_sha1(sha1)) {
+ /*
+ * It is so astronomically unlikely
+ * that NULL_SHA1 is the SHA-1 of an
+ * actual object that we consider its
+ * appearance in a loose reference
+ * file to be repo corruption
+ * (probably due to a software bug).
+ */
+ flag |= REF_ISBROKEN;
}
if (check_refname_format(refname.buf,
diff --git a/t/t6301-for-each-ref-errors.sh b/t/t6301-for-each-ref-errors.sh
index 72d2397e12..cdb67a03b7 100755
--- a/t/t6301-for-each-ref-errors.sh
+++ b/t/t6301-for-each-ref-errors.sh
@@ -24,7 +24,7 @@ test_expect_success 'Broken refs are reported correctly' '
test_cmp broken-err err
'
-test_expect_failure 'NULL_SHA1 refs are reported correctly' '
+test_expect_success 'NULL_SHA1 refs are reported correctly' '
r=refs/heads/zeros &&
echo $ZEROS >.git/$r &&
test_when_finished "rm -f .git/$r" &&