git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Bug: git branch returns EXIT_SUCCESS when no branches found
@ 2019-04-24 10:13 Christoffer Stjernlöf
  2019-04-24 10:36 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Christoffer Stjernlöf @ 2019-04-24 10:13 UTC (permalink / raw)
  To: git; +Cc: a

[-- Attachment #1: Type: text/plain, Size: 983 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-04-24 11:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-24 10:13 Bug: git branch returns EXIT_SUCCESS when no branches found Christoffer Stjernlöf
2019-04-24 10:36 ` Junio C Hamano
2019-04-24 10:44   ` Junio C Hamano
2019-04-24 10:53     ` Christoffer Stjernlöf
2019-04-24 10:47   ` Christoffer Stjernlöf
2019-04-24 11:11   ` SZEDER Gábor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).