IIRC resolve can return null here, and setObjectId won't check.  We'll later crash hard.  Check the result of resolve() and if its null use the NoHeadException.  At which point you can probably just remove getRef() above and just do the resolve HEAD^{commit}, if that fails for any reason we throw NoHeadException.