Skip to content

Commit 0aabeaa

Browse files
To1negitster
authored andcommitted
builtin/show-ref: treat directory as non-existing in --exists
9080a7f (builtin/show-ref: add new mode to check for reference existence, 2023-10-31) added the option --exists to git-show-ref(1). When you use this option against a ref that doesn't exist, but it is a parent directory of an existing ref, you get the following error: $ git show-ref --exists refs/heads error: failed to look up reference: Is a directory when the ref-files backend is in use. To be more clear to user, hide the error about having found a directory. What matters to the user is that the named ref does not exist. Instead, print the same error as when the ref was not found: error: reference does not exist Signed-off-by: Toon Claes <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 564d025 commit 0aabeaa

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

builtin/show-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static int cmd_show_ref__exists(const char **refs)
239239
if (refs_read_raw_ref(get_main_ref_store(the_repository), ref,
240240
&unused_oid, &unused_referent, &unused_type,
241241
&failure_errno)) {
242-
if (failure_errno == ENOENT) {
242+
if (failure_errno == ENOENT || failure_errno == EISDIR) {
243243
error(_("reference does not exist"));
244244
ret = 2;
245245
} else {

t/t1403-show-ref.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ test_expect_success '--exists with non-commit object' '
260260

261261
test_expect_success '--exists with directory fails with generic error' '
262262
cat >expect <<-EOF &&
263-
error: failed to look up reference: Is a directory
263+
error: reference does not exist
264264
EOF
265-
test_expect_code 1 git show-ref --exists refs/heads 2>err &&
265+
test_expect_code 2 git show-ref --exists refs/heads 2>err &&
266266
test_cmp expect err
267267
'
268268

0 commit comments

Comments
 (0)