Skip to content

Commit 970957d

Browse files
committed
Merge branch 'jc/maint-refs-dangling' into maint
* jc/maint-refs-dangling: refs: ref entry with NULL sha1 is can be a dangling symref
2 parents 4318d3b + e01de1c commit 970957d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

refs.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/* ISSYMREF=01 and ISPACKED=02 are public interfaces */
88
#define REF_KNOWS_PEELED 04
9+
#define REF_BROKEN 010
910

1011
struct ref_list {
1112
struct ref_list *next;
@@ -275,8 +276,10 @@ static struct ref_list *get_ref_dir(const char *base, struct ref_list *list)
275276
list = get_ref_dir(ref, list);
276277
continue;
277278
}
278-
if (!resolve_ref(ref, sha1, 1, &flag))
279+
if (!resolve_ref(ref, sha1, 1, &flag)) {
279280
hashclr(sha1);
281+
flag |= REF_BROKEN;
282+
}
280283
list = add_ref(ref, sha1, flag, list, NULL);
281284
}
282285
free(ref);
@@ -539,10 +542,10 @@ static int do_one_ref(const char *base, each_ref_fn fn, int trim,
539542
{
540543
if (strncmp(base, entry->name, trim))
541544
return 0;
542-
/* Is this a "negative ref" that represents a deleted ref? */
543-
if (is_null_sha1(entry->sha1))
544-
return 0;
545+
545546
if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) {
547+
if (entry->flag & REF_BROKEN)
548+
return 0; /* ignore dangling symref */
546549
if (!has_sha1_file(entry->sha1)) {
547550
error("%s does not point to a valid object!", entry->name);
548551
return 0;

t/t5505-remote.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,15 +507,15 @@ test_expect_success 'remote prune to cause a dangling symref' '
507507
(
508508
cd seven &&
509509
git remote prune origin
510-
) 2>err &&
510+
) >err 2>&1 &&
511511
grep "has become dangling" err &&
512512
513-
: And the dangling symref will not cause other annoying errors
513+
: And the dangling symref will not cause other annoying errors &&
514514
(
515515
cd seven &&
516516
git branch -a
517517
) 2>err &&
518-
! grep "points nowhere" err
518+
! grep "points nowhere" err &&
519519
(
520520
cd seven &&
521521
test_must_fail git branch nomore origin

0 commit comments

Comments
 (0)