Update GlobFunction to check for subdirectories crossing into a local repository.

Part of #4056.

Change-Id: I4b8e41660b0a135e23aa572bbfeea27a7cda0581
PiperOrigin-RevId: 176362103
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/GlobFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/GlobFunction.java
index 22bb428..16846bc 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/GlobFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/GlobFunction.java
@@ -74,6 +74,10 @@
         // We crossed the package boundary, that is, pkg/subdir contains a BUILD file and thus
         // defines another package, so glob expansion should not descend into that subdir.
         return GlobValue.EMPTY;
+      } else if (globSubdirPkgLookupValue
+          instanceof PackageLookupValue.IncorrectRepositoryReferencePackageLookupValue) {
+        // We crossed a repository boundary, so glob expansion should not descend into that subdir.
+        return GlobValue.EMPTY;
       }
     }
 
@@ -351,11 +355,18 @@
           valueRequested,
           fileName,
           glob);
-      if (!((PackageLookupValue) valueRequested).packageExists()) {
+      PackageLookupValue packageLookupValue = (PackageLookupValue) valueRequested;
+      if (packageLookupValue.packageExists()) {
+        // This is a separate package, so ignore it.
+        return null;
+      } else if (packageLookupValue
+          instanceof PackageLookupValue.IncorrectRepositoryReferencePackageLookupValue) {
+        // This is a separate repository, so ignore it.
+        return null;
+      } else {
         return glob.getSubdir().getRelative(fileName);
       }
     }
-    return null;
   }
 
   @Nullable