git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/1] builtin/show-ref: treat directory directory as non-existing in --exists

From
Toon Claes <toon@iotcl.com>
Date
Jan 10, 2024, 14:15 UTC
Message-ID
<20240110141559.387815-2-toon@iotcl.com>
In-Reply-To
<20240110141559.387815-1-toon@iotcl.com>

Recently [1] the option --exists was added 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're getting the following error:

    $ git show-ref --exists refs/heads
    error: failed to look up reference: Is a directory

This error is confusing to the user. Instead, print the same error as when the ref was not found:

    error: reference does not exist

[1]: 9080a7f178 (builtin/show-ref: add new mode to check for reference existence, 2023-10-31)

Signed-off-by: Toon Claes <toon@iotcl.com>
---
 builtin/show-ref.c  | 2 +-
 t/t1403-show-ref.sh | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index aaa2c39b2f..79955c2856 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -238,7 +238,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 {
diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh
index ec1957b709..d0a8f7b121 100755
--- a/t/t1403-show-ref.sh
+++ b/t/t1403-show-ref.sh
@@ -262,9 +262,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
 '
 
-- 
2.42.1
Previous: Toon ClaesNext: Eric Sunshine
Message 2 of 8 in “Fix error message in git-show-ref(1) --exists”
  1. 0/1 Fix error message in git-show-ref(1) --existsToon Claes, Jan 10, 2024
  2. 1/1 builtin/show-ref: treat directory directory as non-existing in --existsToon Claes, Jan 10, 2024
  3. Eric SunshineJan 10, 2024
  4. Toon ClaesJan 10, 2024
  5. Patrick SteinhardtJan 17, 2024
  6. Junio C HamanoJan 17, 2024
  7. Toon ClaesJan 18, 2024
  8. Junio C HamanoJan 18, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.