aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-03-10 23:56:11 +0100
committerJunio C Hamano <gitster@pobox.com>2022-03-13 18:37:08 +0000
commit57be9c6deeb1be7c3ce6270df52473eddc09a86c (patch)
tree932d20bfc08710ef9770f666db94bb722639e98b
parentfcd2c3d9d854712e7fbb8e7be5a809029aab0a84 (diff)
downloadgit-57be9c6deeb1be7c3ce6270df52473eddc09a86c.tar.gz
reflog: don't be noisy on empty reflogs
Fix a regression in my daf1d8285ee (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 <j6t@kdbg.org> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Tested-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/reflog.c2
-rwxr-xr-xt/t1410-reflog.sh9
2 files changed, 11 insertions, 0 deletions
diff --git a/builtin/reflog.c b/builtin/reflog.c
index a4b1dd27e1..83a98cface 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -382,6 +382,8 @@ static void reflog_expiry_prepare(const char *refname,
cb->unreachable_expire_kind = UE_HEAD;
} else {
commit = lookup_commit(the_repository, oid);
+ if (commit && is_null_oid(&commit->object.oid))
+ commit = NULL;
cb->unreachable_expire_kind = commit ? UE_NORMAL : UE_ALWAYS;
}
diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh
index d42f067ff8..7d5cfeb8bf 100755
--- a/t/t1410-reflog.sh
+++ b/t/t1410-reflog.sh
@@ -422,4 +422,13 @@ test_expect_success 'expire with multiple worktrees' '
)
'
+test_expect_success REFFILES 'empty reflog' '
+ test_when_finished "rm -rf empty" &&
+ git init empty &&
+ test_commit -C empty A &&
+ >empty/.git/logs/refs/heads/foo &&
+ git -C empty reflog expire --all 2>err &&
+ test_must_be_empty err
+'
+
test_done