File: pre-commit

package info (click to toggle)
meli 0.8.13%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,760 kB
  • sloc: python: 809; ansic: 388; sh: 262; makefile: 206
file content (56 lines) | stat: -rwxr-xr-x 1,627 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# SPDX-License-Identifier: EUPL-1.2

IFS=$'\n'

files_without_header=()

newly_added_files=($(git diff --name-only --diff-filter=A --cached))
#newly_added_files=($(git ls-files))
if [ -n "${newly_added_files[0]}" ]
then
    # Check for Copyright statement
    for newly_added_file in ${newly_added_files}; do
        # Ignore symbolic links that resolve to directories, because their text content is the name of the directory.
        if [ -L "${newly_added_file}" ] && [ -d "${newly_added_file}" ]
        then
          continue
        fi
        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}"))
    done

    if [ -n "${files_without_header[0]}" ]
    then
        echo "License preamble not found in the following newly added files:"
        for file in "${files_without_header[@]}"
        do
            :
            echo "   - ${file}";
        done
        exit 1;
    else
        exit 0;
    fi

    ##Debug:
    #files_without_header+=($(git diff --name-only -S"debug!"))
    #echo ${files_without_header}

    #if [ -n "${files_without_header}" ]
    #then
    #    (echo "debug! macro added in the following files:";
    #        echo "";
    #    for file in "${files_without_header[@]}"
    #    do
    #        :
    #        tput bold
    #        echo "   - ${file}";
    #        echo "";
    #        tput sgr0;
    #        FORCE_COLOR=true git -c color.status=always diff --color=always -S"debug!" "${file}";
    #      done) | less -R
    #    exit 1;
    #else
    #    exit 0;
    #fi
fi