44
55set -e
66
7- # Find files missing copyright headers
8- files=$( git ls-files ' bin/**' ' scripts/**' ' src/**' ' test/**' | \
9- grep -E ' \.(js|ts|mjs|mts|jsx|tsx|c|cpp|h)$' | \
10- xargs grep -L ' Copyright.*Amazon\.com' || true)
11-
12- if [ -z " $files " ]; then
7+ # Create patch file
8+ patch_file=$( mktemp)
9+ trap " rm -f $patch_file " EXIT
10+
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
36+ fi
37+ done
38+
39+ if [ ! -s " $patch_file " ]; then
1340 echo " ✓ All files already have copyright headers"
1441 exit 0
1542fi
1643
17- echo " Found $( echo " $files " | wc -l) files missing headers"
18-
19- # Add headers
20- for file in $files ; do
21- if [[ " $file " == * .sh ]]; then
22- header=" #!/bin/bash
23- # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
24- # SPDX-License-Identifier: Apache-2.0
25-
26- "
27- else
28- header=" /*
29- Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
30- SPDX-License-Identifier: Apache-2.0
31- */
32-
33- "
34- fi
35-
36- echo " $header $( cat " $file " ) " > " $file "
37- echo " ✓ Added header to $file "
38- done
44+ echo " Applying copyright header patch..."
45+ git apply " $patch_file "
3946
40- echo
41- echo " ✓ All copyright headers added successfully"
42- echo " Run 'git diff' to review changes before committing"
47+ echo " ✓ Copyright headers added successfully"
48+ echo " Run 'git diff --cached' or 'git diff' to review changes"
0 commit comments