#!/bin/sh

#
# Copyright (c) 2026 PersistentAI
#
# Use of this software is governed by the Business Source License 1.1 included in the file LICENSE.txt.
#
# As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0.
#

files=$(
  git diff --cached --name-only --diff-filter=ACM \
  | grep -E '\.(ts|js|tsx|jsx|css)$' \
  | grep -vE '\.config\.(ts|js|mjs)$' \
  | grep -vE '\.(md|svg|html|yaml|yml|sh|json|sh)$' \
  | grep -vE '^\.changeset/' \
  | grep -vE '*\.gen\.ts$' \
) || exit 0

# If no matching files, exit successfully
if [ -z "$files" ]; then
  exit 0
fi

for file in $files; do
    if ! grep -q "Copyright (c)" "$file"; then
        echo "❌ Error: Missing license header in $file"
        exit 1
    fi
done

exit 0
