Fix detached heads on completion, tern and Rails plugins