44
55set -e
66
7- # Create patch file
8- patch_file=$( mktemp)
9- trap " rm -f $patch_file " EXIT
7+ script_dir=" $( dirname " $0 " ) "
8+ files_modified=0
109
11- # Generate patch for missing headers
12- files_count=0
13- git ls-files ' bin/**' ' scripts/**' ' src/**' ' test/**' | \
14- grep -E ' \.(js|ts|mjs|mts|jsx|tsx|c|cpp|h|sh)$' | \
15- while read file; do
16- if ! grep -q ' Copyright.*Amazon\.com' " $file " ; then
17- files_count=$(( files_count + 1 ))
18-
19- if [[ " $file " == * .sh ]]; then
20- header=" #!/bin/bash\n# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n# SPDX-License-Identifier: Apache-2.0\n\n"
21- else
22- header=" /*\nCopyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: Apache-2.0\n*/\n\n"
23- fi
24-
25- # Get first line for context
26- first_line=$( head -n1 " $file " 2> /dev/null || echo " " )
27-
28- # Create patch entry
29- echo " --- a/$file " >> " $patch_file "
30- echo " +++ b/$file " >> " $patch_file "
31- echo " @@ -1,1 +1,$( echo -e " $header " | wc -l) @@" >> " $patch_file "
32- echo -e " $header " | sed ' s/^/+/' >> " $patch_file "
33- if [ -n " $first_line " ]; then
34- echo " $first_line " >> " $patch_file "
35- fi
10+ while IFS= read -r file; do
11+ if ! grep -q ' Copyright.*Amazon\.com' " $file " ; then
12+ if [[ " $file " == * .sh ]]; then
13+ sed " s|PLACEHOLDER|$file |" " $script_dir /patches/sh-files.patch" | git apply
14+ else
15+ sed " s|PLACEHOLDER|$file |" " $script_dir /patches/js-files.patch" | git apply
3616 fi
37- done
17+ files_modified=$(( files_modified + 1 ))
18+ fi
19+ done < <( git ls-files ' bin/**' ' scripts/**' ' src/**' ' test/**' | grep -E ' \.(js|ts|mjs|mts|jsx|tsx|c|cpp|h|sh)$' )
3820
39- if [ ! -s " $patch_file " ]; then
21+ if [ " $files_modified " -eq 0 ]; then
4022 echo " ✓ All files already have copyright headers"
41- exit 0
42- fi
43-
44- echo " Applying copyright header patch..."
45- git apply " $patch_file "
46-
47- echo " ✓ Copyright headers added successfully"
48- echo " Run 'git diff --cached' or 'git diff' to review changes"
23+ else
24+ echo " ✓ Copyright headers added to $files_modified files"
25+ echo " Run 'git diff' to review changes"
26+ fi
0 commit comments