]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/show-ref: treat directory as non-existing in --exists
authorToon Claes <toon@iotcl.com>
Wed, 10 Jan 2024 14:15:59 +0000 (15:15 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Jan 2024 19:17:25 +0000 (11:17 -0800)
9080a7f178 (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 <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/show-ref.c
t/t1403-show-ref.sh

index 7aac525a878b3b3ae4959a831de4747d379e140f..6025ce223d5e7fccaa5030ad6852f285eab6ffc2 100644 (file)
@@ -239,7 +239,7 @@ static int cmd_show_ref__exists(const char **refs)
        if (refs_read_raw_ref(get_main_ref_store(the_repository), ref,
                              &unused_oid, &unused_referent, &unused_type,
                              &failure_errno)) {
-               if (failure_errno == ENOENT) {
+               if (failure_errno == ENOENT || failure_errno == EISDIR) {
                        error(_("reference does not exist"));
                        ret = 2;
                } else {
index b50ae6fcf115abe384444db1ef0ddbf04ce247d3..a8055f7fe18143c01b9bac6902c3a54a19fb656f 100755 (executable)
@@ -260,9 +260,9 @@ test_expect_success '--exists with non-commit object' '
 
 test_expect_success '--exists with directory fails with generic error' '
        cat >expect <<-EOF &&
-       error: failed to look up reference: Is a directory
+       error: reference does not exist
        EOF
-       test_expect_code 1 git show-ref --exists refs/heads 2>err &&
+       test_expect_code 2 git show-ref --exists refs/heads 2>err &&
        test_cmp expect err
 '