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

Bug? "git branch" failing to list all branches

From
SMSimo Melenius <simo.melenius@iki.fi>
Date
Jun 2, 2010, 14:47 UTC
Message-ID
<AANLkTimTOucIfzSxsYNvmML7MALwj0E3BUASIIKIN1lN@mail.gmail.com>

I consider this a bug and wrote a fix. I would now like to ask the git maintainers' opinion with regard to it.

When listing branches, "git branch" will in certain cases terminate iteration at the first broken ref that doesn't point to a commit. This will silently hide any remaining refs from the output listing. However, this failure is not communicated upwards either, so I think append_ref() goes wrong to terminate the whole loop because of this.

I noticed this because "git branch -a" and "git branch -av" unexpectedly gave a very different output.

Simo
diff --git a/builtin/branch.c b/builtin/branch.c
index 6cf7e72..1a8e3d3 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -294,7 +294,10 @@ static int append_ref(const char *refname, const
unsigned char *sha1, int flags,
        if (ref_list->verbose || ref_list->with_commit || merge_filter
!= NO_FILTER) {
                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;
+               }

                /* Filter with with_commit if specified */
                if (!is_descendant_of(commit, ref_list->with_commit))
-- 
() Today is the car of the cdr of your life.
/\ http://arc.pasp.de/
Next: Jonathan Nieder
Message 1 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.