Subject: Re: [PATCH] branch: fix funny-sounding error message

From: Jeff King <[email-masked]>
Date: Tue, 5 May 2015 19:06:30 -0400

On Tue, May 05, 2015 at 02:58:24PM -0700, Junio C Hamano wrote:

> I think this "branch is NULL" condition is when an earlier call to
> branch_get() returned a NULL, and _one_ way to make that happen is
> to detach the HEAD.  There may be others, but I didn't check.

FWIW, since I have just been looking through the branch code,
branch_get() should only return NULL when:

  1. We passed NULL or "HEAD" to it (i.e., we asked for the current branch). If
     you ask for a branch by name, you will always get a non-NULL return,
     even if that branch does not exist.

  2. There is no current branch (i.e., a detached HEAD).

I think the "no such branch" error message here:

               if (!branch) {
                        if (!argc || !strcmp(argv[0], "HEAD"))
                                die(_("could not unset upstream of HEAD when "
                                      "it does not point to any branch."));
			die(_("no such branch '%s'"), argv[0]);
	       }

cannot actually be triggered (and I double-checked that the test suite
does not trigger it by replacing it with "exit(141)", which should cause
even test_must_fail to complain).

-Peff