hooks/post-receive: check to see if we've lost our HEAD
commit0dea41fde8c8078a5d9f912f10ecfcfd0a84bc95
authorKyle J. McKay <mackyle@gmail.com>
Thu, 4 Feb 2021 06:57:46 +0000 (3 23:57 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Thu, 4 Feb 2021 06:57:46 +0000 (3 23:57 -0700)
tree2f269dc818a2c5ae8f16ea69fdd6f3ba419b7bc5
parent75bda576838c97e20d4f3bafaca362506f757aea
hooks/post-receive: check to see if we've lost our HEAD

After a receive, check to see if HEAD is valid and if not, make
sure the headok flag has been cleared.

Do not, however, immediately attempt to find a new HEAD.

When gc runs again, eventually, it will do so (and just in
time for bundle creation).

If the end user removes a ref and then shortly thereafter sets
it again there's no reason for unnecessary churn.

While it's true that if gc happens to run during that interval,
a new HEAD will be attached provided one is available, the
likelihood of hitting that window remains small if the intent
of the end user was to leave HEAD invalid for only a brief
period.

Waiting before trying to find a new HEAD helps to avoid that
case and yet always doing it eventually avoids the case where
the repository ends up with a permanently invalid HEAD which
suppresses bundle creation.

It's a compromise between unintentially changing HEAD prematurely
when the end user intends to remedy the problem shortly and
failing to create a bundle because there's no valid HEAD.

Since generate_auto_gc_update fills in for the behavior of
post-receive when manufacturing an artificial update, make
the same check there too.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
hooks/post-receive
jobd/generate-auto-gc-update.sh