mirror of
https://github.com/git/git.git
synced 2024-11-14 21:23:03 +01:00
501cf47cdd
NULL_SHA1 is used to indicate an "invalid object name" throughout our code (and the code of other git implementations), so it is vastly more likely that an on-disk reference was set to this value due to a software bug than that NULL_SHA1 is the legitimate SHA-1 of an actual object. Therefore, if a loose reference has the value NULL_SHA1, consider it to be broken. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
56 lines
1.6 KiB
Bash
Executable file
56 lines
1.6 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='for-each-ref errors for broken refs'
|
|
|
|
. ./test-lib.sh
|
|
|
|
ZEROS=$_z40
|
|
MISSING=abababababababababababababababababababab
|
|
|
|
test_expect_success setup '
|
|
git commit --allow-empty -m "Initial" &&
|
|
git tag testtag &&
|
|
git for-each-ref >full-list &&
|
|
git for-each-ref --format="%(objectname) %(refname)" >brief-list
|
|
'
|
|
|
|
test_expect_success 'Broken refs are reported correctly' '
|
|
r=refs/heads/bogus &&
|
|
: >.git/$r &&
|
|
test_when_finished "rm -f .git/$r" &&
|
|
echo "warning: ignoring broken ref $r" >broken-err &&
|
|
git for-each-ref >out 2>err &&
|
|
test_cmp full-list out &&
|
|
test_cmp broken-err err
|
|
'
|
|
|
|
test_expect_success 'NULL_SHA1 refs are reported correctly' '
|
|
r=refs/heads/zeros &&
|
|
echo $ZEROS >.git/$r &&
|
|
test_when_finished "rm -f .git/$r" &&
|
|
echo "warning: ignoring broken ref $r" >zeros-err &&
|
|
git for-each-ref >out 2>err &&
|
|
test_cmp full-list out &&
|
|
test_cmp zeros-err err &&
|
|
git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err &&
|
|
test_cmp brief-list brief-out &&
|
|
test_cmp zeros-err brief-err
|
|
'
|
|
|
|
test_expect_success 'Missing objects are reported correctly' '
|
|
r=refs/heads/missing &&
|
|
echo $MISSING >.git/$r &&
|
|
test_when_finished "rm -f .git/$r" &&
|
|
echo "fatal: missing object $MISSING for $r" >missing-err &&
|
|
test_must_fail git for-each-ref 2>err &&
|
|
test_cmp missing-err err &&
|
|
(
|
|
cat brief-list &&
|
|
echo "$MISSING $r"
|
|
) | sort -k 2 >missing-brief-expected &&
|
|
git for-each-ref --format="%(objectname) %(refname)" >brief-out 2>brief-err &&
|
|
test_cmp missing-brief-expected brief-out &&
|
|
test_must_be_empty brief-err
|
|
'
|
|
|
|
test_done
|