def test_submodule_deinit(path): from datalad.support.annexrepo import AnnexRepo top_repo = AnnexRepo(path, create=False) eq_({'subm 1', '2'}, {s.name for s in top_repo.get_submodules()}) # note: here init=True is ok, since we are using it just for testing with swallow_logs(new_level=logging.WARN) as cml: top_repo.update_submodule('subm 1', init=True) assert_in('Do not use update_submodule with init=True', cml.out) top_repo.update_submodule('2', init=True) # ok_(all([s.module_exists() for s in top_repo.get_submodules()])) # TODO: old assertion above if non-bare? (can't use "direct mode" in test_gitrepo) # Alternatively: New testrepo (plain git submodules) and have a dedicated # test for annexes in addition ok_( all([ GitRepo.is_valid_repo(op.join(top_repo.path, s.path)) for s in top_repo.get_submodules() ])) # modify submodule: with open(op.join(top_repo.path, 'subm 1', 'file_ut.dat'), "w") as f: f.write("some content") assert_raises(CommandError, top_repo.deinit_submodule, 'sub1') # using force should work: top_repo.deinit_submodule('subm 1', force=True) ok_(not top_repo.repo.submodule('subm 1').module_exists())
def test_submodule_deinit(path): from datalad.support.annexrepo import AnnexRepo top_repo = AnnexRepo(path, create=False) eq_({'subm 1', '2'}, {s.name for s in top_repo.get_submodules()}) # note: here init=True is ok, since we are using it just for testing with swallow_logs(new_level=logging.WARN) as cml: top_repo.update_submodule('subm 1', init=True) assert_in('Do not use update_submodule with init=True', cml.out) top_repo.update_submodule('2', init=True) # ok_(all([s.module_exists() for s in top_repo.get_submodules()])) # TODO: old assertion above if non-bare? (can't use "direct mode" in test_gitrepo) # Alternatively: New testrepo (plain git submodules) and have a dedicated # test for annexes in addition ok_(all([GitRepo.is_valid_repo(op.join(top_repo.path, s.path)) for s in top_repo.get_submodules()])) # modify submodule: with open(op.join(top_repo.path, 'subm 1', 'file_ut.dat'), "w") as f: f.write("some content") assert_raises(CommandError, top_repo.deinit_submodule, 'sub1') # using force should work: top_repo.deinit_submodule('subm 1', force=True) ok_(not top_repo.repo.submodule('subm 1').module_exists())
def test_direct_cfg(path1, path2): # and if repo already exists and we have env var - we fail too # Adding backend so we get some commit into the repo ar = AnnexRepo(path1, create=True, backend='MD5E') del ar AnnexRepo._unique_instances.clear() # fight flyweight for path in (path1, path2): with patch.dict('os.environ', {'DATALAD_REPO_DIRECT': 'True'}): # try to create annex repo in direct mode as see how it fails with assert_raises(DirectModeNoLongerSupportedError) as cme: AnnexRepo(path, create=True) assert_in("no longer supported by DataLad", str(cme.exception)) # we have generic part assert_in("datalad.repo.direct configuration", str(cme.exception)) # situation specific part # assert not op.exists(path2) # that we didn't create it - we do! # fixing for that would be too cumbersome since we first call GitRepo.__init__ # with create ar = AnnexRepo(path1) # check if we somehow didn't reset the flag assert not ar.is_direct_mode() if ar.config.obtain("datalad.repo.version") >= 6: raise SkipTest( "Created repo not v5, cannot test detection of direct mode repos") # and if repo existed before and was in direct mode, we fail too # Since direct= option was deprecated entirely, we use protected method now ar._set_direct_mode(True) assert ar.is_direct_mode() del ar # but we would need to disable somehow the flywheel with patch.dict('os.environ', {'DATALAD_REPO_DIRECT': 'True'}): with assert_raises(DirectModeNoLongerSupportedError) as cme: AnnexRepo(path1, create=False) # TODO: RM DIRECT decide what should we here -- should we test/blow? # ATM both tests below just pass ar2 = AnnexRepo(path2, create=True) # happily can do it since it doesn't need a worktree to do the clone ar2.add_submodule('sub1', url=path1) ar2sub1 = AnnexRepo(op.join(path2, 'sub1')) # but now let's convert that sub1 to direct mode assert not ar2sub1.is_direct_mode() ar2sub1._set_direct_mode(True) assert ar2sub1.is_direct_mode() del ar2 del ar2sub1 AnnexRepo._unique_instances.clear() # fight flyweight ar2 = AnnexRepo(path2) ar2.get_submodules() # And what if we are trying to add pre-cloned repo in direct mode? ar2sub2 = AnnexRepo.clone(path1, op.join(path2, 'sub2')) ar2sub2._set_direct_mode(True) del ar2sub2 AnnexRepo._unique_instances.clear() # fight flyweight ar2.add('sub2')
def test_direct_cfg(path1, path2): # and if repo already exists and we have env var - we fail too # Adding backend so we get some commit into the repo ar = AnnexRepo(path1, create=True, backend='MD5E') del ar; AnnexRepo._unique_instances.clear() # fight flyweight for path in (path1, path2): with patch.dict('os.environ', {'DATALAD_REPO_DIRECT': 'True'}): # try to create annex repo in direct mode as see how it fails with assert_raises(DirectModeNoLongerSupportedError) as cme: AnnexRepo(path, create=True) assert_in("no longer supported by DataLad", str(cme.exception)) # we have generic part assert_in("datalad.repo.direct configuration", str(cme.exception)) # situation specific part # assert not op.exists(path2) # that we didn't create it - we do! # fixing for that would be too cumbersome since we first call GitRepo.__init__ # with create ar = AnnexRepo(path1) # check if we somehow didn't reset the flag assert not ar.is_direct_mode() if ar.config.obtain("datalad.repo.version") >= 6: raise SkipTest("Created repo not v5, cannot test detection of direct mode repos") # and if repo existed before and was in direct mode, we fail too # Since direct= option was deprecated entirely, we use protected method now ar._set_direct_mode(True) assert ar.is_direct_mode() del ar # but we would need to disable somehow the flywheel with patch.dict('os.environ', {'DATALAD_REPO_DIRECT': 'True'}): with assert_raises(DirectModeNoLongerSupportedError) as cme: AnnexRepo(path1, create=False) # TODO: RM DIRECT decide what should we here -- should we test/blow? # ATM both tests below just pass ar2 = AnnexRepo(path2, create=True) # happily can do it since it doesn't need a worktree to do the clone ar2.add_submodule('sub1', url=path1) ar2sub1 = AnnexRepo(op.join(path2, 'sub1')) # but now let's convert that sub1 to direct mode assert not ar2sub1.is_direct_mode() ar2sub1._set_direct_mode(True) assert ar2sub1.is_direct_mode() del ar2; del ar2sub1; AnnexRepo._unique_instances.clear() # fight flyweight ar2 = AnnexRepo(path2) ar2.get_submodules() # And what if we are trying to add pre-cloned repo in direct mode? ar2sub2 = AnnexRepo.clone(path1, op.join(path2, 'sub2')) ar2sub2._set_direct_mode(True) del ar2sub2; AnnexRepo._unique_instances.clear() # fight flyweight ar2.add('sub2')