code: def test_install_consistent_state(
      src=None, dest=None, dest2=None, dest3=None
  ):
      # if we install a dataset, where sub-dataset "went ahead" in that branch,
      # while super-dataset was not yet updated (e.g. we installed super before)
      # then it is desired to get that default installed branch to get to the
      # position where previous location was pointing to.
      # It is indeed a mere heuristic which might not hold the assumption in some
      # cases, but it would work for most simple and thus mostly used ones
      ds1 = create(src)
      sub1 = ds1.create("sub1")
  
      def check_consistent_installation(ds):
          datasets = [ds] + list(
              map(
                  Dataset,
                  ds.subdatasets(
                      recursive=True,
                      state="present",
                      result_xfm="paths",
                  ),
              )
          )
          assert len(datasets) == 2  # in this test
          for ds in datasets:
              # all of them should be in the default branch
              eq_(ds.repo.get_active_branch(), DEFAULT_BRANCH)
              # all of them should be clean, so sub should be installed in a "version"
              # as pointed by the super
              ok_(not ds.repo.dirty)
  
      dest_ds = install(dest, source=src)
      # now we progress sub1 by adding sub2
      subsub2 = sub1.create("sub2")
  
      # and progress subsub2 forward to stay really thorough
      put_file_under_git(subsub2.path, "file.dat", content="data")
      subsub2.save(
          message="added a file"
      )  # above function does not commit
  
      # just installing a submodule -- apparently different code/logic
      # but also the same story should hold - we should install the version pointed
      # by the super, and stay all clean
      dest_sub1 = dest_ds.install("sub1")
      check_consistent_installation(dest_ds)
  
      # So now we have source super-dataset "dirty" with sub1 progressed forward
      # Our install should try to "retain" consistency of the installation
      # whenever possible.
  
      # install entire hierarchy without specifying dataset
      # no filter, we want full report
      dest2_ds = install(
          dest2, source=src, recursive=True, result_filter=None
      )
      check_consistent_installation(
          dest2_ds[0]
      )  # [1] is the subdataset
  
      # install entire hierarchy by first installing top level ds
      # and then specifying sub-dataset
      dest3_ds = install(dest3, source=src, recursive=False)
      # and then install both submodules recursively while pointing
      # to it based on dest3_ds
      dest3_ds.install("sub1", recursive=True)
      check_consistent_installation(dest3_ds)
  
imports: import logging
  import os
  from os.path import basename, dirname, exists, isdir
  from os.path import join
  from unittest.mock import patch
  import pytest
  from datalad import cfg
  from datalad.api import create, get, install
  from datalad.cmd import WitlessRunner
  from datalad.interface.results import YieldDatasets
  from datalad.support import path
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.exceptions import IncompleteResultsError, InsufficientArgumentsError
  from datalad.support.gitrepo import GitRepo
  from datalad.support.network import get_local_file_url
  from datalad.tests.utils_testdatasets import _make_dataset_hierarchy, _mk_submodule_annex
  from datalad.tests.utils_pytest import DEFAULT_BRANCH, DEFAULT_REMOTE, assert_false, assert_in, assert_in_results, assert_is_instance, assert_not_in, assert_raises, assert_repo_status, assert_result_count, assert_status, create_tree, eq_, get_datasets_topdir, integration, known_failure_githubci_win, known_failure_windows, ok_, ok_file_has_content, ok_startswith, put_file_under_git, serve_path_via_http, skip_if_no_network, skip_if_on_windows, skip_ssh, slow, swallow_logs, use_cassette, usecase, with_tempfile, with_tree
  from datalad.utils import Path, _path_, chpwd, getpwd, on_windows, rmtree
  from ..dataset import Dataset
label_desc: Use image node_id 24 for calling a global function with example usage: test_install_consistent_state(src, dest, dest2, dest3) without return types