Fix RepoGroup::hasForeignRepos() and RepoGroup::forEachForeignRepo()

Also add unit tests for those methods.

Change-Id: Ic72be60d13820492efc90b5925bb5cfc1813d28a
Merge "Fix RepoGroup::hasForeignRepos() and RepoGroup::forEachForeignRepo()"