Make 'opam repo add/remove' more robust.

This fixes regressions introduced in #597