code: def test_rerun_explicit(path=None):
      ds = Dataset(path).create(force=True)
  
      ds.run("echo o >> foo", explicit=True, outputs=["foo"])
      with open(op.join(ds.path, "foo")) as ifh:
          orig_content = ifh.read()
          orig_head = ds.repo.get_hexsha(DEFAULT_BRANCH)
  
      # Explicit rerun is allowed in a dirty tree.
      ok_(ds.repo.dirty)
      ds.rerun(explicit=True)
      eq_(orig_head, ds.repo.get_hexsha(DEFAULT_BRANCH + "~1"))
      with open(op.join(ds.path, "foo")) as ifh:
          eq_(orig_content * 2, ifh.read())
  
      # --since also works.
      ds.rerun(since="", explicit=True)
      eq_(
          orig_head,
          # Added two rerun commits.
          ds.repo.get_hexsha(DEFAULT_BRANCH + "~3"),
      )
  
      # With just untracked changes, we can rerun with --onto.
      ds.rerun(since="", onto="", explicit=True)
      eq_(
          ds.repo.get_hexsha(orig_head + "^"),
          # Reran the four run commits from above on the initial base.
          ds.repo.get_hexsha("HEAD~4"),
      )
  
      # But checking out a new HEAD can fail when there are modifications.
      ds.repo.checkout(DEFAULT_BRANCH)
      ok_(ds.repo.dirty)
      ds.repo.add(["to_modify"], git=True)
      ds.save()
      assert_false(ds.repo.dirty)
      with open(op.join(ds.path, "to_modify"), "a") as ofh:
          ofh.write("more")
      ok_(ds.repo.dirty)
  
      with assert_raises(CommandError):
          ds.rerun(onto="", since="", explicit=True)
  
imports: import logging
  import os.path
  import sys
  from io import StringIO
  from os import remove
  import pytest
  from unittest.mock import patch
  from datalad.api import install, run
  from datalad.core.local.run import run_command
  from datalad.core.local.tests.test_run import last_commit_msg
  from datalad.distribution.dataset import Dataset
  from datalad.local.rerun import diff_revision, get_run_info, new_or_modified
  from datalad.support.exceptions import CommandError, IncompleteResultsError
  from datalad.support.gitrepo import GitRepo
  from datalad.tests.utils_pytest import DEFAULT_BRANCH, DEFAULT_REMOTE, SkipTest, assert_dict_equal, assert_false, assert_in, assert_in_results, assert_not_in, assert_not_in_results, assert_raises, assert_repo_status, assert_result_count, assert_status, create_tree, eq_, known_failure_windows, neq_, ok_, ok_exists, ok_file_has_content, ok_file_under_git, skip_if_adjusted_branch, slow, swallow_logs, swallow_outputs, with_tempfile, with_tree
  from datalad.utils import Path, chpwd, on_windows
label_desc: Use image node_id 17 for calling a global function with example usage: test_rerun_explicit(path) without return types