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

[PATCH] branch: return error when --list finds no matches

From
JGJosh Hunt via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 3, 2021, 17:44 UTC
Message-ID
<pull.892.git.1614793491538.gitgitgadget@gmail.com>
From: Josh Hunt <johunt@akamai.com>

Currently git branch --list foo always returns an exit status of 0 even when the branch being searched for does not exist. Now an error is printed and returns a non-zero exit status.

Signed-off-by: Josh Hunt <johunt@akamai.com>
---
    branch: return error when --list finds no matches
    
    Currently git branch --list foo always returns an exit status of 0 even
    when the branch being searched for does not exist. Now an error is
    printed and returns a non-zero exit status.
    
    Signed-off-by: Josh Hunt johunt@akamai.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-892%2Fjoshuahunt%2Fjohunt%2Fgit-branch-list-return-error-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-892/joshuahunt/johunt/git-branch-list-return-error-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/892
 builtin/branch.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/builtin/branch.c b/builtin/branch.c
index bcc00bcf182d..5573175734fe 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -426,6 +426,8 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
 	memset(&array, 0, sizeof(array));
 
 	filter_refs(&array, filter, filter->kind | FILTER_REFS_INCLUDE_BROKEN);
+	if (!array.nr)
+		die(_("no branches found"));
 
 	if (filter->verbose)
 		maxwidth = calc_maxwidth(&array, strlen(remote_prefix));

base-commit: ec125d1bc1053df7e4103f71ebd24fe48dd624a2
-- 
gitgitgadget
Next: Junio C Hamano
Message 1 of 3 in “branch: return error when --list finds no matches”
  1. branch: return error when --list finds no matchesJosh Hunt via GitGitGadget, Mar 3, 2021
  2. Junio C HamanoMar 4, 2021
  3. Josh HuntMar 5, 2021

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.