|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# copyright ############################### # |
| 4 | +# This file is part of the Xcoll Package. # |
| 5 | +# Copyright (c) CERN, 2023. # |
| 6 | +# ######################################### # |
| 7 | + |
| 8 | + |
| 9 | +cat << 'EOF' > pre-commit |
| 10 | +#!/bin/sh |
| 11 | +
|
| 12 | +branch="$(git rev-parse --abbrev-ref HEAD)" |
| 13 | +
|
| 14 | +if [ "$branch" = "main" ] |
| 15 | +then |
| 16 | + echo "Cannot commit to main!" |
| 17 | + echo "Use pull requests or, if package admin, the versioning script." |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | +
|
| 21 | +for file in pyproject.toml version.sh LICENSE install_protection_hook.sh xcoll/general.py |
| 22 | +do |
| 23 | + git diff --name-only | grep '^'${file}'$' &> /dev/null |
| 24 | + if [ $? -eq 0 ] |
| 25 | + then |
| 26 | + thisfile=${file/.\*/\*} |
| 27 | + echo "File $thisfile is protected but has local changes." |
| 28 | + echo "Restore the file with 'git restore "${thisfile}"' before commiting anything," |
| 29 | + echo "or force this commit with 'git commit --no-verify'." |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | + git diff --cached --name-only | grep '^'${file}'$' &> /dev/null |
| 33 | + if [ $? -eq 0 ] |
| 34 | + then |
| 35 | + thisfile=${file/.\*/\*} |
| 36 | + echo "File $thisfile is protected but has local changes that are staged." |
| 37 | + echo "First unstage the file with 'git restore --staged "${thisfile}"', then " |
| 38 | + echo "restore the file with 'git restore "${thisfile}"' before commiting anything." |
| 39 | + echo "Alternatively, force this commit with 'git commit --no-verify'." |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | +done |
| 43 | +EOF |
| 44 | + |
| 45 | +chmod +x pre-commit |
| 46 | +mv pre-commit .git/hooks/ |
0 commit comments