Debian Codegraph @

scripts/pre-commit

raw
1 #!/bin/bash
2 # SPDX-License-Identifier: EUPL-1.2
3
4 IFS=$'\n'
5
6 files_without_header=()
7
8 newly_added_files=($(git diff --name-only --diff-filter=A --cached))
9 #newly_added_files=($(git ls-files))
10 if [ -n "${newly_added_files[0]}" ]
11 then
12 # Check for Copyright statement
13 for newly_added_file in ${newly_added_files}; do
14 # Ignore symbolic links that resolve to directories, because their text content is the name of the directory.
15 if [ -L "${newly_added_file}" ] && [ -d "${newly_added_file}" ]
16 then
17 continue
18 fi
19 files_without_header+=($(grep -L -e "This file is part of meli" -e "This file is part of melib" -e "SPDX-License-Identifier" "${newly_added_file}"))
20 done
21
22 if [ -n "${files_without_header[0]}" ]
23 then
24 echo "License preamble not found in the following newly added files:"
25 for file in "${files_without_header[@]}"
26 do
27 :
28 echo " - ${file}";
29 done
30 exit 1;
31 else
32 exit 0;
33 fi
34
35 ##Debug:
36 #files_without_header+=($(git diff --name-only -S"debug!"))
37 #echo ${files_without_header}
38
39 #if [ -n "${files_without_header}" ]
40 #then
41 # (echo "debug! macro added in the following files:";
42 # echo "";
43 # for file in "${files_without_header[@]}"
44 # do
45 # :
46 # tput bold
47 # echo " - ${file}";
48 # echo "";
49 # tput sgr0;
50 # FORCE_COLOR=true git -c color.status=always diff --color=always -S"debug!" "${file}";
51 # done) | less -R
52 # exit 1;
53 #else
54 # exit 0;
55 #fi
56 fi