Skip to content

Commit db2664b

Browse files
peffgitster
authored andcommitted
describe: error if blob not found
If describe_blob() does not find the blob in question, it returns an empty strbuf, and we print an empty line. This differs from describe_commit(), which always either returns an answer or calls die() itself. As the blob function was bolted onto the command afterwards, I think its behavior is not intentional, and it is just a bug that it does not report an error. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e715f77 commit db2664b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

builtin/describe.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,9 @@ static void describe_blob(const struct object_id *oid, struct strbuf *dst)
535535
reset_revision_walk();
536536
release_revisions(&revs);
537537
strvec_clear(&args);
538+
539+
if (!dst->len)
540+
die(_("blob '%s' not reachable from HEAD"), oid_to_hex(oid));
538541
}
539542

540543
static void describe(const char *arg, int last_one)

t/t6120-describe.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ test_expect_success 'describe tag object' '
409409
test_grep "fatal: test-blob-1 is neither a commit nor blob" actual
410410
'
411411

412+
test_expect_success 'describe an unreachable blob' '
413+
blob=$(echo not-found-anywhere | git hash-object -w --stdin) &&
414+
test_must_fail git describe $blob 2>actual &&
415+
test_grep "blob .$blob. not reachable from HEAD" actual
416+
'
417+
412418
test_expect_success ULIMIT_STACK_SIZE 'name-rev works in a deep repo' '
413419
i=1 &&
414420
while test $i -lt 8000

0 commit comments

Comments
 (0)