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
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
Previous: Christoffer Stjernlöf
Message 6 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.