code: def test_diff_recursive(path=None):
      ds = Dataset(path).create()
      sub = ds.create("sub")
      # look at the last change, and confirm a dataset was added
      res = ds.diff(
          fr=DEFAULT_BRANCH + "~1",
          to=DEFAULT_BRANCH,
          result_renderer="disabled",
      )
      assert_result_count(
          res,
          1,
          action="diff",
          state="added",
          path=sub.path,
          type="dataset",
      )
      # now recursive
      res = ds.diff(
          recursive=True,
          fr=DEFAULT_BRANCH + "~1",
          to=DEFAULT_BRANCH,
          result_renderer="disabled",
      )
      # we also get the entire diff of the subdataset from scratch
      assert_status("ok", res)
      ok_(len(res) > 3)
      # one specific test
      assert_result_count(
          res,
          1,
          action="diff",
          state="added",
          path=op.join(sub.path, ".datalad", "config"),
      )
  
      # now we add a file to just the parent
      create_tree(
          ds.path,
          {"onefile": "tobeadded", "sub": {"twofile": "tobeadded"}},
      )
      res = ds.diff(
          recursive=True, untracked="all", result_renderer="disabled"
      )
      assert_result_count(_dirty_results(res), 3)
      assert_result_count(
          res,
          1,
          action="diff",
          state="untracked",
          path=op.join(ds.path, "onefile"),
          type="file",
      )
      assert_result_count(
          res,
          1,
          action="diff",
          state="modified",
          path=sub.path,
          type="dataset",
      )
      assert_result_count(
          res,
          1,
          action="diff",
          state="untracked",
          path=op.join(sub.path, "twofile"),
          type="file",
      )
      # intentional save in two steps to make check below easier
      ds.save("sub", recursive=True)
      ds.save()
      assert_repo_status(ds.path)
  
      head_ref = (
          DEFAULT_BRANCH if ds.repo.is_managed_branch() else "HEAD"
      )
  
      # look at the last change, only one file was added
      res = ds.diff(
          fr=head_ref + "~1",
          to=head_ref,
          annex="basic",
          result_renderer="disabled",
      )
      assert_result_count(_dirty_results(res), 1)
      assert_result_count(
          res,
          1,
          action="diff",
          state="added",
          path=op.join(ds.path, "onefile"),
          type="file",
      )
  
      # now the exact same thing with recursion, must not be different from the
      # call above
      res = ds.diff(
          recursive=True,
          fr=head_ref + "~1",
          to=head_ref,
          annex="basic",
          result_renderer="disabled",
      )
      assert_result_count(_dirty_results(res), 1)
      # last change in parent
      assert_result_count(
          res,
          1,
          action="diff",
          state="added",
          path=op.join(ds.path, "onefile"),
          type="file",
      )
  
      if ds.repo.is_managed_branch():
          raise SkipTest(
              "Test assumption broken: https://github.com/datalad/datalad/issues/3818"
          )
      # one further back brings in the modified subdataset, and the added file
      # within it
      res = ds.diff(
          recursive=True,
          fr=head_ref + "~2",
          to=head_ref,
          annex="basic",
          result_renderer="disabled",
      )
      assert_result_count(_dirty_results(res), 3)
      assert_result_count(
          res,
          1,
          action="diff",
          state="added",
          path=op.join(ds.path, "onefile"),
          type="file",
      )
      assert_result_count(
          res,
          1,
          action="diff",
          state="added",
          path=op.join(sub.path, "twofile"),
          type="file",
      )
      assert_result_count(
          res,
          1,
          action="diff",
          state="modified",
          path=sub.path,
          type="dataset",
      )
  
imports: import os
  import os.path
  from unittest.mock import patch
  import datalad.utils
  from datalad.api import create, diff, save
  from datalad.cmd import GitWitlessRunner, StdOutCapture
  from datalad.consts import PRE_INIT_COMMIT_SHA
  from datalad.distribution.dataset import Dataset
  from datalad.support.exceptions import NoDatasetFound
  from datalad.tests.utils_pytest import DEFAULT_BRANCH, OBSCURE_FILENAME, SkipTest, assert_in, assert_raises, assert_repo_status, assert_result_count, assert_status, chpwd, create_tree, eq_, get_deeply_nested_structure, has_symlink_capability, known_failure_githubci_win, neq_, ok_, with_tempfile
  from datalad.utils import Path
label_desc: Use image node_id 5 for calling a global function with example usage: test_diff_recursive(path) without return types