code: def test_dirty(path=None):
      for mode in _dirty_modes:
          # does nothing without a dataset
          handle_dirty_dataset(None, mode)
      # placeholder, but not yet created
      ds = Dataset(path)
      # unknown mode
      assert_raises(ValueError, handle_dirty_dataset, ds, "MADEUP")
      # not yet created is very dirty
      assert_raises(RuntimeError, handle_dirty_dataset, ds, "fail")
      handle_dirty_dataset(ds, "ignore")
      assert_raises(
          RuntimeError, handle_dirty_dataset, ds, "save-before"
      )
      # should yield a clean repo
      ds.create()
      orig_state = ds.repo.get_hexsha()
      _check_all_clean(ds, orig_state)
      # tainted: untracked
      with open(opj(ds.path, "something"), "w") as f:
          f.write("some")
      # we don't want to auto-add untracked files by saving (anymore)
      assert_raises(AssertionError, _check_auto_save, ds, orig_state)
      # tainted: staged
      ds.repo.add("something", git=True)
      orig_state = _check_auto_save(ds, orig_state)
      # tainted: submodule
      # not added to super on purpose!
      subds = ds.create("subds")
      _check_all_clean(subds, subds.repo.get_hexsha())
      assert_repo_status(ds.path)
      # subdataset must be added as a submodule!
      assert_equal(ds.subdatasets(result_xfm="relpaths"), ["subds"])
  
imports: import logging
  import re
  from contextlib import contextmanager
  from os.path import exists
  from os.path import join
  from time import sleep
  from datalad.distribution.dataset import Dataset, EnsureDataset, datasetmethod
  from datalad.interface.base import build_doc, eval_results
  from datalad.support.constraints import EnsureKeyChoice, EnsureNone, EnsureStr
  from datalad.support.param import Parameter
  from datalad.tests.utils_pytest import assert_dict_equal, assert_equal, assert_in, assert_not_equal, assert_not_in, assert_raises, assert_re_in, assert_repo_status, assert_result_count, assert_true, ok_, slow, with_tempfile, with_tree
  from datalad.utils import swallow_logs, swallow_outputs
  from ..base import Interface
  from ..results import get_status_dict
  from ..utils import discover_dataset_trace_to_targets, handle_dirty_dataset
label_desc: Use image node_id 3 for calling a global function with example usage: test_dirty(path) without return types