Deformations of a morphism along a foliation and applications