Fix sub-package imports.

This fixes a regression where it doesn't know how to checkout branch and tags for packages imported
that are not the base of a repository.

@d2fn I just realized that I broke this with the mercurial integration, sorry about that.

I've added a regression test to make sure it's works properly. Let me know if you think about any other case that I've missed.