code: def get_git_commit(path: str) -> Optional[str]:
      """
      Obtains the hash of the latest commit on the current branch of the git repository associated
      with the specified path, returning ``None`` if the path does not correspond to a git
      repository.
      """
      try:
          from git import Repo
      except ImportError as e:
          _logger.warning(
              "Failed to import Git (the Git executable is probably not on your PATH),"
              " so Git SHA is not available. Error: %s",
              e,
          )
          return None
      try:
          if os.path.isfile(path):
              path = os.path.dirname(path)
          repo = Repo(path, search_parent_directories=True)
          if path in repo.ignored(path):
              return None
          return repo.head.commit.hexsha
      except Exception:
          return None
  
imports: import logging
  import os
  from typing import Optional
label_desc: Use image node_id 2 for calling a global function with example usage: get_git_commit(path) and returns: repo, None, None, None