Re: Bug: git branch returns EXIT_SUCCESS when no branches found
- From
SZEDER Gábor <szeder.dev@gmail.com>
- Date
- Apr 24, 2019, 11:11 UTC
- Message-ID
- <20190424111123.GB8695@szeder.dev>
- In-Reply-To
- <xmqqmukf1yh9.fsf@gitster-ct.c.googlers.com>
On Wed, Apr 24, 2019 at 07:36:34PM +0900, Junio C Hamano wrote:
Show 7 quoted lines
> if git merge-base --is-ancestor master "$DEV_BRANCH" > then > echo "master is an ancestor of $DEV_BRANCH" > else > echo "master has commits not in $DEV_BRANCH" > git --no-pager log "master..$DEV_BRANCH" -- > fi
A non-zero exit code might indicate an error in 'git merge-base' itself; I had basically the same if-else condition in a script of my own that had to check the same thing... until once I mistyped the branchname, and, well, undesired behavior ensued. After that I added one more branch to the condition like this:
git merge-base --is-ancestor master "$DEV_BRANCH"
ret=$?
if test $ret -gt 1
then
die "uh-oh, git merge-base errored out"
elif test $ret -eq 0
then
echo "master is an ancestor of $DEV_BRANCH"
else
echo "master has commits not in $DEV_BRANCH"
fi