Skip to content
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 12 additions & 6 deletions scripts/run_reuse_annotate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this requires the presence of pipx in the running environment. Thus either pre-commit actions need to be run within the devcontainer or this script might install it, if missing

--copyright="Contributors to the Eclipse Foundation" --license=Apache-2.0 ${files_to_annotate}

popd > /dev/null