Fix Error 500 when attempting to retrieve project license when HEAD points to non-existent ref Closes #17537 See merge request !4151