Welcome to mirror list, hosted at ThFree Co, Russian Federation.

checkyear.sh « contrib - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ec47f3b895f3e352a265da7c854a86992d647378 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# (C) 2013 see Authors.txt
#
# This file is part of MPC-HC.
#
# MPC-HC is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# MPC-HC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


# pre-commit hook to check if all changed and added files
# have the current year as copyright information.

# to enable the hook, copy this file to .git/hooks/pre-commit (no extension)
# or run this while in the repo root:
# cp contrib/checkyear.sh .git/hooks/pre-commit

year=$(date +%Y)
pattern1='\(C\) ([0-9][0-9][0-9][0-9]-)?[0-9][0-9][0-9][0-9] see Authors.txt'
pattern2='\(C\) ([0-9][0-9][0-9][0-9]-)?'"$year"' see Authors.txt'
extensions=(bat cpp h iss pl)

valid_extension() {
  for e in "${extensions[@]}"; do
    [[ "$e" == "$1" ]] && return 0
  done
  return 1
}

# save output to variable, because MSYS bash doesn't support command substitution
list=$(git diff --cached --name-only --diff-filter=ACMR)

# loop through all new and modified files
error=0
while read -r f; do
  # check if the file has an extension that we care about
  if valid_extension "${f##*.}"; then
    # only verify year if it already has an mpc-hc style copyright entry
    if grep -q -E "$pattern1" "$f"; then
      # check if the year is outdated
      if ! grep -q -E "$pattern2" "$f"; then
        # print filename
        echo "$f"
        # make sure we exit nonzero, later
        error=1
      fi
    fi
  fi
done <<< "$list"

# if there were files with outdated copyright, exit nonzero
if (( error == 1 )); then
  echo "Copyright year in the file(s) listed above is outdated!"
  echo "To ignore this and commit anyways use 'git commit --no-verify'"
  exit 1
fi

# all files valid
exit 0