code: def test_subdataset_save(path=None):
      parent = Dataset(path).create()
      sub = parent.create("sub")
      assert_repo_status(parent.path)
      create_tree(
          parent.path, {"untracked": "ignore", "sub": {"new": "wanted"}}
      )
      sub.save("new")
      # defined state: one untracked, modified (but clean in itself) subdataset
      assert_repo_status(sub.path)
      assert_repo_status(
          parent.path, untracked=["untracked"], modified=["sub"]
      )
  
      # `save sub` does not save the parent!!
      with chpwd(parent.path):
          assert_status("notneeded", save(dataset=sub.path))
      assert_repo_status(
          parent.path, untracked=["untracked"], modified=["sub"]
      )
      # `save -u .` saves the state change in the subdataset,
      # but leaves any untracked content alone
      with chpwd(parent.path):
          assert_status("ok", parent.save(updated=True))
      assert_repo_status(parent.path, untracked=["untracked"])
  
      # get back to the original modified state and check that -S behaves in
      # exactly the same way
      create_tree(parent.path, {"sub": {"new2": "wanted2"}})
      sub.save("new2")
      assert_repo_status(
          parent.path, untracked=["untracked"], modified=["sub"]
      )
  
      # https://github.com/datalad/datalad/issues/6843
      # saving subds within super must not add 2nd copy of the submodule within .gitmodules
      with chpwd(sub.path):
          # op.sep is critical to trigger saving within (although should not
          # be relevant sice no changes within sub)
          res = save(dataset="^", path=sub.path + op.sep)
      assert_repo_status(parent.path, untracked=["untracked"])
      git_modules = parent.pathobj / ".gitmodules"
      # there was nothing to do for .gitmodules
      # TODO: enable assert_result_count(res, 0, path=str(git_modules))
      # more thorough test that it also was not modified.
      # ensure that .gitmodules does not have duplicate entries
      submodules = [
          l.strip()
          for l in git_modules.read_text().splitlines()
          if l.strip().split(" ", 1)[0] == "[submodule"
      ]
      assert len(submodules) == 1
  
imports: import itertools
  import logging
  import os
  import os.path
  import pytest
  import datalad.utils
  from datalad.api import create, install, save
  from datalad.distribution.dataset import Dataset
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.exceptions import CommandError
  from datalad.tests.utils_pytest import DEFAULT_BRANCH, OBSCURE_FILENAME, SkipTest, assert_in, assert_in_results, assert_not_in, assert_raises, assert_repo_status, assert_result_count, assert_status, chpwd, create_tree, eq_, known_failure, known_failure_windows, maybe_adjust_repo, neq_, ok_, patch, skip_if_adjusted_branch, skip_wo_symlink_capability, swallow_logs, swallow_outputs, with_tempfile, with_tree
  from datalad.utils import Path, ensure_list, rmtree
label_desc: Use image node_id 5 for calling a global function with example usage: test_subdataset_save(path) without return types