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

Bug: git branch returns EXIT_SUCCESS when no branches found

From
CSChristoffer Stjernlöf <a@xkqr.org>
Date
Apr 24, 2019, 10:13 UTC
Message-ID
<875zr3iucd.fsf@xkqr.org>
Dear Sirs/Madams,

A common use case of git branch – for me – is to use it to test whether a particular branch satisfies some conditions. A recent example is this:

    if ! git branch "$DEV_BRANCH" --contains master; then
        echo "The development branch ($DEV_BRANCH) is not up to date"
        echo "with the latest master."
        exit 1
    fi

Except this doesn't work, because git branch returns success even though it failed to list any branches satisfying the condition. My workaround has been to rewrite the condition as

    git branch "$DEV_BRANCH" --contains master \
        | grep -xE '\* *'"$DEV_BRANCH"
but this is obviously not desirable in comparison.

The syntax of e.g. --contains makes it seem almost like this use case of mine was intended, but the exit code makes me doubt it. Is there any consideration I'm missing that's a reason for not returning a failure code when not matching any branches?

Yours faithfully, Chris

Next: Junio C Hamano
Message 1 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.