code: def test_save_typechange(path=None):
      ckwa = dict(result_renderer="disabled")
      ds = Dataset(path).create(**ckwa)
      foo = ds.pathobj / "foo"
      # save a file
      foo.write_text("some")
      ds.save(**ckwa)
      # now delete the file and replace with a directory and a file in it
      foo.unlink()
      foo.mkdir()
      bar = foo / "bar"
      bar.write_text("foobar")
      res = ds.save(**ckwa)
      assert_in_results(res, path=str(bar), action="add", status="ok")
      assert_repo_status(ds.repo)
      if not on_windows:
          # now replace file with subdataset
          # (this is https://github.com/datalad/datalad/issues/5418)
          bar.unlink()
          Dataset(ds.pathobj / "tmp").create(**ckwa)
          shutil.move(ds.pathobj / "tmp", bar)
          res = ds.save(**ckwa)
          assert_repo_status(ds.repo)
          assert len(ds.subdatasets(**ckwa)) == 1
      # now replace directory with subdataset
      rmtree(foo)
      Dataset(ds.pathobj / "tmp").create(**ckwa)
      shutil.move(ds.pathobj / "tmp", foo)
      # right now a first save() will save the subdataset removal only
      ds.save(**ckwa)
      # subdataset is gone
      assert len(ds.subdatasets(**ckwa)) == 0
      # but it takes a second save() run to get a valid status report
      # to understand that there is a new subdataset on a higher level
      ds.save(**ckwa)
      assert_repo_status(ds.repo)
      assert len(ds.subdatasets(**ckwa)) == 1
      # now replace subdataset with a file
      rmtree(foo)
      foo.write_text("some")
      ds.save(**ckwa)
      assert_repo_status(ds.repo)
  
file_path: datalad/datalad/support/tests/test_repo_save.py
imports: import shutil
  from datalad.api import create
  from datalad.distribution.dataset import Dataset
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.gitrepo import GitRepo
  from datalad.tests.utils_pytest import assert_in, assert_in_results, assert_not_in, assert_repo_status, create_tree, eq_, get_annexstatus, get_convoluted_situation, known_failure_windows, slow, with_tempfile
  from datalad.utils import on_windows, rmtree
label_desc: Use image node_id 5 for calling a global function with example usage: test_save_typechange(path) without return types