code: def test_GitRepo_commit(path=None):
      gr = GitRepo(path)
      filename = get_most_obscure_supported_name()
      with open(op.join(path, filename), "w") as f:
          f.write("File to add to git")
  
      gr.add(filename)
      gr.commit("Testing GitRepo.commit().")
      assert_repo_status(gr)
      eq_("Testing GitRepo.commit().", gr.format_commit("%B").strip())
  
      with open(op.join(path, filename), "w") as f:
          f.write("changed content")
  
      gr.add(filename)
      gr.commit("commit with options", options=to_options(dry_run=True))
      # wasn't actually committed:
      ok_(gr.dirty)
  
      # commit with empty message:
      gr.commit()
      assert_repo_status(gr)
      assert_equal(
          gr.format_commit("%B").strip(), "[DATALAD] Recorded changes"
      )
  
      # amend commit:
      assert_equal(len(list(gr.get_branch_commits_())), 2)
      last_sha = gr.get_hexsha()
      with open(op.join(path, filename), "w") as f:
          f.write("changed again")
      gr.add(filename)
      gr.commit("amend message", options=to_options(amend=True))
      assert_repo_status(gr)
      assert_equal(gr.format_commit("%B").strip(), "amend message")
      assert_not_equal(last_sha, gr.get_hexsha())
      assert_equal(len(list(gr.get_branch_commits_())), 2)
      # amend w/o message maintains previous one:
      gr.commit(options=to_options(amend=True))
      assert_repo_status(gr)
      assert_equal(len(list(gr.get_branch_commits_())), 2)
      assert_equal(gr.format_commit("%B").strip(), "amend message")
  
      # nothing to commit doesn't raise by default:
      gr.commit()
      # but does with careless=False:
      assert_raises(CommandError, gr.commit, careless=False)
  
      # committing untracked file raises:
      with open(op.join(path, "untracked"), "w") as f:
          f.write("some")
      assert_raises(
          FileNotInRepositoryError, gr.commit, files="untracked"
      )
      # not existing file as well:
      assert_raises(
          FileNotInRepositoryError, gr.commit, files="not-existing"
      )
  
imports: import logging
  import os
  import os.path
  import sys
  import pytest
  from datalad import get_encoding_info
  from datalad.cmd import StdOutCapture, StdOutErrCapture, WitlessRunner
  from datalad.support.exceptions import CommandError, FileNotInRepositoryError, InvalidGitRepositoryError, NoSuchPathError, PathKnownToRepositoryError
  from datalad.support.external_versions import external_versions
  from datalad.support.gitrepo import GitRepo, _normalize_path, normalize_paths, to_options
  from datalad.support.sshconnector import get_connection_hash
  from datalad.tests.utils_pytest import DEFAULT_BRANCH, DEFAULT_REMOTE, SkipTest, assert_cwd_unchanged, assert_equal, assert_false, assert_in, assert_in_results, assert_is_instance, assert_not_equal, assert_not_in, assert_raises, assert_repo_status, assert_true, create_tree, eq_, get_most_obscure_supported_name, integration, neq_, ok_, skip_if_no_network, skip_if_on_windows, skip_nomultiplex_ssh, slow, swallow_logs, with_tempfile, with_tree, xfail_buggy_annex_info
  from datalad.utils import Path, chpwd, getpwd, on_windows, rmtree
label_desc: Use image node_id 11 for calling a global function with example usage: test_GitRepo_commit(path) without return types