@@ -135,3 +135,51 @@ def test_dynamic_cache_initialization(tmp_dir, scm):
135135 dvc .close ()
136136
137137 Repo (str (tmp_dir )).close ()
138+
139+
140+ def test_monorepo_relpath (tmp_dir , scm ):
141+ from dvc .repo .destroy import destroy
142+
143+ tmp_dir .gen ({"project_a" : {}, "subdir/project_b" : {}})
144+
145+ non_monorepo = Repo .init (tmp_dir )
146+ assert non_monorepo .get_subrepo_relpath () == ""
147+
148+ destroy (non_monorepo )
149+
150+ monorepo_project_a = Repo .init (tmp_dir / "project_a" , subdir = True )
151+
152+ assert monorepo_project_a .get_subrepo_relpath () == "project_a"
153+
154+ monorepo_project_b = Repo .init (tmp_dir / "subdir" / "project_b" , subdir = True )
155+
156+ assert monorepo_project_b .get_subrepo_relpath () == "subdir/project_b"
157+
158+
159+ def test_virtual_monorepo_relpath (tmp_dir , scm ):
160+ from dvc .fs .git import GitFileSystem
161+ from dvc .repo .destroy import destroy
162+
163+ tmp_dir .gen ({"project_a" : {}, "subdir/project_b" : {}})
164+ scm .commit ("initial commit" )
165+ gfs = GitFileSystem (scm = scm , rev = "master" )
166+
167+ non_monorepo = Repo .init (tmp_dir )
168+ non_monorepo .fs = gfs
169+ non_monorepo .root_dir = "/"
170+
171+ assert non_monorepo .get_subrepo_relpath () == ""
172+
173+ destroy (non_monorepo )
174+
175+ monorepo_project_a = Repo .init (tmp_dir / "project_a" , subdir = True )
176+ monorepo_project_a .fs = gfs
177+ monorepo_project_a .root_dir = "/project_a"
178+
179+ assert monorepo_project_a .get_subrepo_relpath () == "project_a"
180+
181+ monorepo_project_b = Repo .init (tmp_dir / "subdir" / "project_b" , subdir = True )
182+ monorepo_project_b .fs = gfs
183+ monorepo_project_b .root_dir = "/subdir/project_b"
184+
185+ assert monorepo_project_b .get_subrepo_relpath () == "subdir/project_b"
0 commit comments