Skip to content

Commit b05c2f9

Browse files
committed
Merge branch 'js/gc-with-stale-symref' into maint
"git gc" used to barf when a symbolic ref has gone dangling (e.g. the branch that used to be your upstream's default when you cloned from it is now gone, and you did "fetch --prune"). * js/gc-with-stale-symref: pack-objects: do not get distracted by broken symrefs gc: demonstrate failure with stale remote HEAD
2 parents 3b7c49e + 14886b4 commit b05c2f9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

reachable.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ static void update_progress(struct connectivity_progress *cp)
2525
static int add_one_ref(const char *path, const struct object_id *oid,
2626
int flag, void *cb_data)
2727
{
28-
struct object *object = parse_object_or_die(oid->hash, path);
2928
struct rev_info *revs = (struct rev_info *)cb_data;
29+
struct object *object;
3030

31+
if ((flag & REF_ISSYMREF) && (flag & REF_ISBROKEN)) {
32+
warning("symbolic ref is dangling: %s", path);
33+
return 0;
34+
}
35+
36+
object = parse_object_or_die(oid->hash, path);
3137
add_pending_object(revs, object, "");
3238

3339
return 0;

t/t6500-gc.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,17 @@ test_expect_success 'gc -h with invalid configuration' '
3030
test_i18ngrep "[Uu]sage" broken/usage
3131
'
3232

33+
test_expect_success 'gc is not aborted due to a stale symref' '
34+
git init remote &&
35+
(
36+
cd remote &&
37+
test_commit initial &&
38+
git clone . ../client &&
39+
git branch -m develop &&
40+
cd ../client &&
41+
git fetch --prune &&
42+
git gc
43+
)
44+
'
45+
3346
test_done

0 commit comments

Comments
 (0)