diff --git a/object-name.c b/object-name.c index 3a2ef5d680..511f09bc0f 100644 --- a/object-name.c +++ b/object-name.c @@ -1034,6 +1034,15 @@ static int get_oid_basic(struct repository *r, const char *str, int len, len, str, show_date(co_time, co_tz, DATE_MODE(RFC2822))); } + } else if (nth == co_cnt && !is_null_oid(oid)) { + /* + * We were asked for the Nth reflog (counting + * from 0), but there were only N entries. + * read_ref_at() will have returned "1" to tell + * us it did not find an entry, but it did + * still fill in the oid with the "old" value, + * which we can use. + */ } else { if (flags & GET_OID_QUIETLY) { exit(128); diff --git a/refs.c b/refs.c index ba1a4db754..6b826b002e 100644 --- a/refs.c +++ b/refs.c @@ -1083,7 +1083,7 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid set_read_ref_cutoffs(cb, timestamp, tz, message); oidcpy(cb->oid, ooid); - if (is_null_oid(cb->oid)) + if (cb->at_time && is_null_oid(cb->oid)) oidcpy(cb->oid, noid); /* We just want the first entry */ return 1; diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh index 3e5f32f604..370bf7137e 100755 --- a/t/t1508-at-combinations.sh +++ b/t/t1508-at-combinations.sh @@ -103,7 +103,7 @@ test_expect_success 'create path with @' ' check "@:normal" blob content check "@:fun@ny" blob content -test_expect_failure '@{1} works with only one reflog entry' ' +test_expect_success '@{1} works with only one reflog entry' ' git checkout -B newbranch main && git reflog expire --expire=now refs/heads/newbranch && git commit --allow-empty -m "first after expiration" &&