Project.pm: tolerate a peculiar HEAD
commitd718e1648fed16fc10bc1e5287fc40121d3a7d5b
authorKyle J. McKay <mackyle@gmail.com>
Sun, 11 Mar 2018 17:40:24 +0000 (11 10:40 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Sun, 11 Mar 2018 17:40:24 +0000 (11 10:40 -0700)
tree4b33ac0ea8e48cc27a61adcbdd1ba7b3624ae59c
parente23c0e9493273fb69cf95f46e584c1c1b72f5fc9
Project.pm: tolerate a peculiar HEAD

Previously the get_HEAD function would die if HEAD was not set
to a symbolic ref to something under the refs/heads namespace.

With the advent of reluctant accomodation for linked working
trees and perhaps even non-bare Girocco repositories, it's
quite plausible that a bizarre HEAD could be encountered.

Do not die when an unpalatable HEAD pops up.

Instead return a descriptive value surrounded by square
brackets ('[' and ']') for the result of get_HEAD.

A missing or invalid HEAD will still cause the code to dia (as it
should since the repository would not be usable in that case).

Since Git will reject any ref name with a left square bracket '['
character in it, there's no danger of such a "descriptive value"
ending up being somehow set as the project's HEAD.

The web UI will even show such a value provided there are no other
ref/heads/... refs in the repository as a side-effect of not
wanting to fail to show the HEAD symref of an empty repository.

The project will even be editable in such a state since the
update code will not try to set the HEAD if it's unchanged.

Although if there are any existing refs/heads/... refs editing the
project and saving the changes will always reattach the HEAD since
a "descriptive value" will only be a choice if there are no heads.

With this change repositories having an unsavory HEAD can still
be manipulated by Girocco without issues.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
Girocco/Project.pm