code: def test_subrepos_are_ignored(tmp_dir, erepo_dir):
      subrepo = erepo_dir / "dir" / "subrepo"
      make_subrepo(subrepo, erepo_dir.scm)
      with erepo_dir.chdir():
          erepo_dir.dvc_gen("dir/foo", "foo", commit="foo")
          erepo_dir.scm_gen("dir/bar", "bar", commit="bar")
  
      with subrepo.chdir():
          subrepo.dvc_gen(
              {"file": "file"}, commit="add files on subrepo"
          )
  
      with external_repo(os.fspath(erepo_dir)) as repo:
          repo.dvcfs.get(
              "dir",
              os.fspath(tmp_dir / "out"),
          )
          expected_files = {
              "foo": "foo",
              "bar": "bar",
              ".gitignore": "/foo\n",
          }
          assert (tmp_dir / "out").read_text() == expected_files
  
          # clear cache to test saving to cache
          cache_dir = tmp_dir / repo.cache.local.path
          remove(cache_dir)
          os.makedirs(cache_dir)
  
          staging, _, obj = build(
              repo.cache.local,
              "dir",
              repo.dvcfs,
              "md5",
              ignore=repo.dvcignore,
          )
          transfer(
              staging,
              repo.cache.local,
              {obj.hash_info},
              shallow=False,
              hardlink=True,
          )
          if os.name == "nt":
              expected_gitignore_path = (
                  cache_dir / "d5" / "61e684092f0ff908aa82ee9cc1e594"
              )
              expected_dir_path = (
                  cache_dir
                  / "0d"
                  / "2086760aea091f1504eafc8843bb18.dir"
              )
          else:
              expected_gitignore_path = (
                  cache_dir / "94" / "7d2b84e5aa88170e80dff467a5bfb6"
              )
              expected_dir_path = (
                  cache_dir
                  / "e1"
                  / "d9e8eae5374860ae025ec84cfd85c7.dir"
              )
          assert set(cache_dir.glob("??/*")) == {
              expected_dir_path,
              expected_gitignore_path,
              cache_dir / "37" / "b51d194a7513e45b56f6524f2d51f2",
              cache_dir / "ac" / "bd18db4cc2f85cedef654fccc4a4d8",
          }
  
file_path: dvc/tests/func/test_external_repo.py
imports: import os
  from dvc.repo.open_repo import CLONES
  from dvc.repo.open_repo import _external_repo
  from dvc.scm import Git
  from dvc.testing.tmp_dir import make_subrepo
  from dvc.utils import relpath
  from dvc.utils.fs import remove
  from dvc_data.hashfile.build import build
  from dvc_data.hashfile.transfer import transfer
label_desc: Use image node_id 9 for calling a global function with example usage: test_subrepos_are_ignored(tmp_dir, erepo_dir) without return types