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

Re: Bug: git branch returns EXIT_SUCCESS when no branches found

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 24, 2019, 10:44 UTC
Message-ID
<xmqqimv31y3n.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<xmqqmukf1yh9.fsf@gitster-ct.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 13 quoted lines
> The list mode ...
> ... can
> also limit the branches whose tip commits can reach a named commit
> with the "--contains".
>
> 	$ DEV_BRANCH=cs/topic
> 	$ git branch --contains master "$DEV_BRANCH"
>
> asks the subcommand to show only the branches that can reach the
> commit at the tip of 'master', *AND* whose name match cs/topic.  So
> it may show the cs/topic branch (and nothing else, even there are
> cs/topic1 or cs/topic/2 branches) if and only if that branch
> can reach the tip of 'master'.

One crucial bit is missing from my response. In general, a git subcommand that shows zero or more things in response to a request to list things that match criteria does *NOT* consider it an error to make a request that happens to produce a zero result. The above command will exit with non-zero status if 'master' does not name a commit. But if cs/topic branch does not exist, of if the branch does not contain 'master', the command will show "here are the branches that match the criteria you gave me" by giving no lines in its standard output, and exits with 0 to signal that what you see on the screen indeed was computed correctly (as opposed to the command internally crashing and failing to produce a result, in which case you would want to be told with non-zero exit status).

Previous: Junio C HamanoNext: Christoffer Stjernlöf
Message 3 of 6 in “Bug: git branch returns EXIT_SUCCESS when no branches found”
  1. Christoffer StjernlöfApr 24, 2019
  2. Junio C HamanoApr 24, 2019
  3. Junio C HamanoApr 24, 2019
  4. Christoffer StjernlöfApr 24, 2019
  5. Christoffer StjernlöfApr 24, 2019
  6. SZEDER GáborApr 24, 2019

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.