diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b7d181f..d1cfab0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,8 +37,9 @@ repos: - repo: local hooks: - - id: reuse annotate + # Keep in sync with .pre-commit-hooks.yaml, too much hazzle to reuse the same hook definition + - id: reuse-annotate name: Check and fix copyright headers with reuse annotate entry: ./scripts/run_reuse_annotate.sh - language: system + language: unsupported_script pass_filenames: false diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 0000000..6f0c4a7 --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,22 @@ +--- +# ******************************************************************************* +# Copyright (c) 2026 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-FileCopyrightText: 2026 Contributors to the Eclipse Foundation +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + + # Keep in sync with .pre-commit-config.yaml, too much hazzle to reuse the same hook definition + - id: reuse-annotate + name: Check and fix copyright headers with reuse annotate + entry: scripts/run_reuse_annotate.sh + language: unsupported_script + pass_filenames: false + minimum_pre_commit_version: 3.2.0 diff --git a/scripts/run_reuse_annotate.sh b/scripts/run_reuse_annotate.sh index d0a1827..a94ecd8 100755 --- a/scripts/run_reuse_annotate.sh +++ b/scripts/run_reuse_annotate.sh @@ -19,17 +19,23 @@ set -euxo pipefail SCRIPT_PATH=$(readlink -f "$0") SCRIPT_DIR=$(dirname -- "${SCRIPT_PATH}") -pushd "${SCRIPT_DIR}/.." > /dev/null - -files_to_annotate=$(git ls-files) - # remove deleted files from the list of files to annotate deleted_files=$(git ls-files --deleted) -files_to_annotate=$(comm -23 <(git ls-files | sort) <(echo "${deleted_files}" | sort)) +files_to_annotate_rel=$(comm -23 <(git ls-files | sort) <(echo "${deleted_files}" | sort)) + +# absolute paths are needed, when used via .pre-commit-hooks.yaml by other repositories +root="$(pwd)" +files_to_annotate="" +for file in ${files_to_annotate_rel}; do + files_to_annotate+="${root}/${file} " +done + +# Use .reuse/templates specified at the devcontainer / source of pre-commit hook +pushd "${SCRIPT_DIR}/.." > /dev/null # shellcheck disable=SC2086 # Expansion of ${files_to_annotate} is intentional to pass the list of files as separate arguments to the reuse annotate command. -pipx run reuse annotate --template apache-2.0 --merge-copyrights --recursive --skip-unrecognised \ +"${PIPX_BIN_DIR}/pipx" run reuse annotate --template apache-2.0 --merge-copyrights --recursive --skip-unrecognised \ --copyright="Contributors to the Eclipse Foundation" --license=Apache-2.0 ${files_to_annotate} popd > /dev/null