Merge branch 'mh/reporting-broken-refs-from-for-each-ref'
"git for-each-ref" reported "missing object" for 0{40} when it encounters a broken ref. The lack of object whose name is 0{40} is not the problem; the ref being broken is. * mh/reporting-broken-refs-from-for-each-ref: read_loose_refs(): treat NULL_SHA1 loose references as broken read_loose_refs(): simplify function logic for-each-ref: report broken references correctly t6301: new tests of for-each-ref error handling
This commit is contained in:
commit
9d71c5f408
@ -866,6 +866,11 @@ static int grab_single_ref(const char *refname, const struct object_id *oid,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flag & REF_ISBROKEN) {
|
||||||
|
warning("ignoring broken ref %s", refname);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (*cb->grab_pattern) {
|
if (*cb->grab_pattern) {
|
||||||
const char **pattern;
|
const char **pattern;
|
||||||
int namelen = strlen(refname);
|
int namelen = strlen(refname);
|
||||||
|
29
refs.c
29
refs.c
@ -1373,19 +1373,34 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
|
|||||||
create_dir_entry(refs, refname.buf,
|
create_dir_entry(refs, refname.buf,
|
||||||
refname.len, 1));
|
refname.len, 1));
|
||||||
} else {
|
} else {
|
||||||
|
int read_ok;
|
||||||
|
|
||||||
if (*refs->name) {
|
if (*refs->name) {
|
||||||
hashclr(sha1);
|
hashclr(sha1);
|
||||||
flag = 0;
|
flag = 0;
|
||||||
if (resolve_gitlink_ref(refs->name, refname.buf, sha1) < 0) {
|
read_ok = !resolve_gitlink_ref(refs->name,
|
||||||
hashclr(sha1);
|
refname.buf, sha1);
|
||||||
flag |= REF_ISBROKEN;
|
} else {
|
||||||
}
|
read_ok = !read_ref_full(refname.buf,
|
||||||
} else if (read_ref_full(refname.buf,
|
RESOLVE_REF_READING,
|
||||||
RESOLVE_REF_READING,
|
sha1, &flag);
|
||||||
sha1, &flag)) {
|
}
|
||||||
|
|
||||||
|
if (!read_ok) {
|
||||||
hashclr(sha1);
|
hashclr(sha1);
|
||||||
flag |= REF_ISBROKEN;
|
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,
|
if (check_refname_format(refname.buf,
|
||||||
REFNAME_ALLOW_ONELEVEL)) {
|
REFNAME_ALLOW_ONELEVEL)) {
|
||||||
if (!refname_is_safe(refname.buf))
|
if (!refname_is_safe(refname.buf))
|
||||||
|
56
t/t6301-for-each-ref-errors.sh
Executable file
56
t/t6301-for-each-ref-errors.sh
Executable file
@ -0,0 +1,56 @@
|
|||||||
|
#!/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
|
Loading…
Reference in New Issue
Block a user