code: def test_copy_file_prevent_dotgit_placement(
      srcpath=None, destpath=None
  ):
      src = Dataset(srcpath).create()
      sub = src.create("sub")
      dest = Dataset(destpath).create()
  
      # recursion doesn't capture .git/
      dest.copy_file(sub.path, recursive=True)
      nok_((dest.pathobj / "sub" / ".git").exists())
  
      # explicit instruction results in failure
      assert_status(
          "impossible",
          dest.copy_file(
              sub.pathobj / ".git", recursive=True, on_failure="ignore"
          ),
      )
  
      # same when the source has an OK name, but the dest now
      assert_in_results(
          dest.copy_file(
              [
                  sub.pathobj / ".git" / "config",
                  dest.pathobj / "some" / ".git",
              ],
              on_failure="ignore",
          ),
          status="impossible",
          action="copy_file",
      )
  
      # The last path above wasn't treated as a target directory because it
      # wasn't an existing directory. We also guard against a '.git' in the
      # target directory code path, though the handling is different.
      with assert_raises(ValueError):
          dest.copy_file(
              [sub.pathobj / ".git" / "config", dest.pathobj / ".git"]
          )
  
      # A source path can have a leading .git/ if the destination is outside of
      # .git/.
      nok_((dest.pathobj / "config").exists())
      dest.copy_file(sub.pathobj / ".git" / "config")
      ok_((dest.pathobj / "config").exists())
  
      target = dest.pathobj / "some"
      nok_(target.exists())
      dest.copy_file([sub.pathobj / ".git" / "config", target])
      ok_(target.exists())
  
      # But we only waste so many cycles trying to prevent foot shooting. This
      # next one sneaks by because only .name, not all upstream parts, is checked
      # for each destination that comes out of _yield_specs().
      badobj = dest.pathobj / ".git" / "objects" / "i-do-not-exist"
      dest.copy_file([sub.pathobj / ".git" / "config", badobj])
      ok_(badobj.exists())
  
file_path: datalad/datalad/local/tests/test_copy_file.py
imports: from os.path import join
  from datalad.api import copy_file
  from datalad.consts import DATALAD_SPECIAL_REMOTE
  from datalad.distribution.dataset import Dataset
  from datalad.tests.utils_pytest import assert_in_results, assert_raises, assert_repo_status, assert_status, chpwd, eq_, nok_, ok_, ok_file_has_content, serve_path_via_http, slow, with_tempfile, with_tree
  from datalad.utils import Path
label_desc: Use image node_id 9 for calling a global function with example usage: test_copy_file_prevent_dotgit_placement(srcpath, destpath) without return types