<commit_before>include(CMakeParseArguments) # cmake_parse_arguments

include(hunter_internal_error)
include(hunter_status_debug)

set(_HUNTER_TEMPLATE_SCHEME_DIR "${CMAKE_CURRENT_LIST_DIR}/../templates")

function(hunter_pack_git_submodule)
  set(PACKAGE_NAME "${_hunter_current_project}")
  string(COMPARE EQUAL "${PACKAGE_NAME}" "" is_empty)
  if(is_empty)
    hunter_internal_error("_hunter_current_project is empty")
  endif()

  set(optional "")
  set(one GIT_SUBMODULE PROJECT_FILE VERSION SUBMODULE_SOURCE_SUBDIR)
  set(multiple "")

  # Introduce:
  # * x_GIT_SUBMODULE
  # * x_PROJECT_FILE
  # * x_VERSION
  # * x_SUBMODULE_SOURCE_SUBDIR
  cmake_parse_arguments(x "${optional}" "${one}" "${multiple}" "${ARGV}")

  string(COMPARE NOTEQUAL "${x_UNPARSED_ARGUMENTS}" "" has_unparsed)
  if(has_unparsed)
    hunter_internal_error("Unparsed arguments: ${x_UNPARSED_ARGUMENTS}")
  endif()

  string(COMPARE EQUAL "${x_GIT_SUBMODULE}" "" is_empty)
  if(is_empty)
    hunter_internal_error("GIT_SUBMODULE is empty")
  endif()

  find_package(Git REQUIRED)
  hunter_status_debug("Using git executable: ${GIT_EXECUTABLE}")

  # For '--git-path':
  # * https://git-scm.com/docs/git-rev-parse/2.5.0
  if(GIT_VERSION_STRING VERSION_LESS "2.5.0")
    hunter_user_error("At least Git 2.5.0 required")
  endif()

  set(cmd "${GIT_EXECUTABLE}" rev-parse --show-toplevel)
  execute_process(
      COMMAND ${cmd}
      WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
      RESULT_VARIABLE result
      OUTPUT_VARIABLE output
      ERROR_VARIABLE error
      OUTPUT_STRIP_TRAILING_WHITESPACE
      ERROR_STRIP_TRAILING_WHITESPACE
  )

  if(NOT result EQUAL 0)
    hunter_internal_error(
        "Command failed: ${cmd} (${result}, ${output}, ${error})"
    )
  endif()
<commit_msg>hunter_pack_git_submodule: Use HUNTER_GIT_EXECUTABLE<commit_after>include(CMakeParseArguments) # cmake_parse_arguments

include(hunter_internal_error)
include(hunter_status_debug)

set(_HUNTER_TEMPLATE_SCHEME_DIR "${CMAKE_CURRENT_LIST_DIR}/../templates")

function(hunter_pack_git_submodule)
  set(PACKAGE_NAME "${_hunter_current_project}")
  string(COMPARE EQUAL "${PACKAGE_NAME}" "" is_empty)
  if(is_empty)
    hunter_internal_error("_hunter_current_project is empty")
  endif()

  set(optional "")
  set(one GIT_SUBMODULE PROJECT_FILE VERSION SUBMODULE_SOURCE_SUBDIR)
  set(multiple "")

  # Introduce:
  # * x_GIT_SUBMODULE
  # * x_PROJECT_FILE
  # * x_VERSION
  # * x_SUBMODULE_SOURCE_SUBDIR
  cmake_parse_arguments(x "${optional}" "${one}" "${multiple}" "${ARGV}")

  string(COMPARE NOTEQUAL "${x_UNPARSED_ARGUMENTS}" "" has_unparsed)
  if(has_unparsed)
    hunter_internal_error("Unparsed arguments: ${x_UNPARSED_ARGUMENTS}")
  endif()

  string(COMPARE EQUAL "${x_GIT_SUBMODULE}" "" is_empty)
  if(is_empty)
    hunter_internal_error("GIT_SUBMODULE is empty")
  endif()

  string(COMPARE EQUAL "$ENV{HUNTER_GIT_EXECUTABLE}" "" is_empty)

  if(is_empty)
    find_package(Git REQUIRED)
  else()
    set(GIT_EXECUTABLE "$ENV{HUNTER_GIT_EXECUTABLE}")
    execute_process(
        COMMAND
        ${GIT_EXECUTABLE} --version
        RESULT_VARIABLE result
        OUTPUT_VARIABLE output
        ERROR_VARIABLE output
        OUTPUT_STRIP_TRAILING_WHITESPACES
        ERROR_STRIP_TRAILING_WHITESPACES
    )
    if(result EQUAL "0")
      if(output MATCHES "^git version [0-9]")
        string(REPLACE "git version " "" GIT_VERSION_STRING "${output}")
      else()
        hunter_internal_error("Unexpected output: ${output}")
      endif()
    else()
      hunter_internal_error("Can't get Git version: ${result} ${output}")
    endif()
  endif()
  hunter_status_debug("Using git executable: ${GIT_EXECUTABLE}")

  # For '--git-path':
  # * https://git-scm.com/docs/git-rev-parse/2.5.0
  if(GIT_VERSION_STRING VERSION_LESS "2.5.0")
    hunter_user_error("At least Git 2.5.0 required")
  endif()

  set(cmd "${GIT_EXECUTABLE}" rev-parse --show-toplevel)
  execute_process(
      COMMAND ${cmd}
      WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
      RESULT_VARIABLE result
      OUTPUT_VARIABLE output
      ERROR_VARIABLE error
      OUTPUT_STRIP_TRAILING_WHITESPACE
      ERROR_STRIP_TRAILING_WHITESPACE
  )

  if(NOT result EQUAL 0)
    hunter_internal_error(
        "Command failed: ${cmd} (${result}, ${output}, ${error})"
    )
  endif()

{'fraction_non_alphanumeric': 0.11995359628770301, 'fraction_numerical': 0.0053364269141531325, 'mean_word_length': 4.5987012987012985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4033344', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1592, 'n_words': 249}