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

Re: Bug? "git branch" failing to list all branches

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jun 3, 2010, 04:22 UTC
Message-ID
<20100603042218.GA21254@progeny.tock>
In-Reply-To
<AANLkTimTOucIfzSxsYNvmML7MALwj0E3BUASIIKIN1lN@mail.gmail.com>
Hi Simo,
Simo Melenius wrote:
> I noticed this because "git branch -a" and "git branch -av"
> unexpectedly gave a very different output.
Hmm --- so the error message must not have been very visible...
> When listing branches, "git branch" will in certain cases terminate
> iteration at the first broken ref that doesn't point to a commit.

Even in a broken repository, the full branch list would be useful for getting one’s bearings. Thanks.

Show 9 quoted lines
>                 commit = lookup_commit_reference_gently(sha1, 1);
>                 if (!commit)
> -                       return error("branch '%s' does not point at a
> commit", refname);
> +               {
> +                       error("branch '%s' does not point at a
> commit", refname);
> +                       return 0;
> +               }

Will this make ‘git branch’ exit with status zero? Scripts and people with fancy prompts benefit from a nonzero exit status.

If I have 37 branches and an error is encountered looking up one of them, with this patch the error message will scroll off the screen. Is this worth worrying about? It depends on what the usual causes for broken branch refs are and whether they require attention or can be safely ignored.

One other thought: this patch is line-wrapped, which means it cannot be mechanically applied. Documentation/SubmittingPatches has some tips on sending a patch unmangled (and please also see the section labelled "Sign your work").

Cheers, Jonathan

Previous: Simo MeleniusNext: Simo Melenius
Message 2 of 9 in “Bug? "git branch" failing to list all branches”
  1. Simo MeleniusJun 2, 2010
  2. Jonathan NiederJun 3, 2010
  3. Simo MeleniusJun 3, 2010
  4. Jonathan NiederJun 3, 2010
  5. 1/2 branch: exit status now reflects if branch listing finds an errorSimo Melenius, Jun 3, 2010
  6. Jonathan NiederJun 4, 2010
  7. 2/2 branch: don't fail listing branches if one of the commits wasn't foundSimo Melenius, Jun 3, 2010
  8. Sverre RabbelierJun 3, 2010
  9. Jonathan NiederJun 4, 2010

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.