git: protect against unbalanced calls to {save,restore}_env()