Skip to content

Commit 57be9c6

Browse files
avargitster
authored andcommitted
reflog: don't be noisy on empty reflogs
Fix a regression in my daf1d82 (reflog expire: don't use lookup_commit_reference_gently(), 2021-12-22), in changing from lookup_commit_reference_gently() to lookup_commit() we stopped trying to call deref_tag() and parse_object() on the provided OID, but we also started returning non-NULL for the null_oid(). As a result we'd emit an error() via mark_reachable() later in this function as we tried to invoke parse_commit() on it. Reported-by: Johannes Sixt <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Tested-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fcd2c3d commit 57be9c6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

builtin/reflog.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ static void reflog_expiry_prepare(const char *refname,
382382
cb->unreachable_expire_kind = UE_HEAD;
383383
} else {
384384
commit = lookup_commit(the_repository, oid);
385+
if (commit && is_null_oid(&commit->object.oid))
386+
commit = NULL;
385387
cb->unreachable_expire_kind = commit ? UE_NORMAL : UE_ALWAYS;
386388
}
387389

t/t1410-reflog.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,13 @@ test_expect_success 'expire with multiple worktrees' '
422422
)
423423
'
424424

425+
test_expect_success REFFILES 'empty reflog' '
426+
test_when_finished "rm -rf empty" &&
427+
git init empty &&
428+
test_commit -C empty A &&
429+
>empty/.git/logs/refs/heads/foo &&
430+
git -C empty reflog expire --all 2>err &&
431+
test_must_be_empty err
432+
'
433+
425434
test_done

0 commit comments

Comments
 (0)