From: Junio C Hamano Date: Thu, 11 Oct 2018 06:54:23 GMT Subject: Re: [PATCH v2 1/1] branch: introduce --show-current display option Message-ID: In-Reply-To: <20181010205432.11990-2-daniels@umanovskis.se> Daniels Umanovskis writes: > +static void print_current_branch_name() > +{ > + const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL); > + const char *shortname; > + if (refname == NULL || !strcmp(refname, "HEAD")) > + return; Is it a normal situation to have refname==NULL, or is it something worth reporting as an error? Without passing the &flag argument, I do not think there is a reliable way to ask resolve_ref_unsafe() if "HEAD" is a symbolic ref. int flag; const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, &flag); const char *branchname; if (!refname) die(...); else if (!(flag & REF_ISSYMREF)) return; /* detached HEAD */ else if (skip_prefix(refname, "refs/heads/", &branchname)) puts(branchname); else die("HEAD (%s) points outside refs/heads/?", refname); or something like that?