File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020 - manual
2121 types :
2222 - yaml
23+ - id : check-restored-packages
24+ name : Check restored packages against withdrawn
25+ description : Ensures packages being added to restored-packages.txt are removed from withdrawn-packages.txt first
26+ entry : scripts/check-restored-packages.sh
27+ language : script
28+ stages :
29+ - pre-commit
30+ - manual
31+ files : ^restored-packages\.txt$
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -e
3+
4+ # Check if restored-packages.txt is being modified
5+ if ! git diff --cached --name-only | grep -q " restored-packages.txt" ; then
6+ exit 0
7+ fi
8+
9+ if [ ! -f " withdrawn-packages.txt" ] || [ ! -f " restored-packages.txt" ]; then
10+ exit 0
11+ fi
12+
13+ # Get the new lines being added to restored-packages.txt
14+ NEW_PACKAGES=$( git diff --cached " restored-packages.txt" | grep " ^+" | grep -v " ^+++" | sed ' s/^+//' | grep -v ' ^$' | grep -v ' ^#' )
15+
16+ if [ -z " $NEW_PACKAGES " ]; then
17+ exit 0
18+ fi
19+
20+ # Check if any new packages are in withdrawn-packages.txt
21+ CONFLICTS=" "
22+ while IFS= read -r package; do
23+ if [ -n " $package " ]; then
24+ if grep -Fxq " $package " " withdrawn-packages.txt" ; then
25+ CONFLICTS=" ${CONFLICTS}${package} \n"
26+ fi
27+ fi
28+ done <<< " $NEW_PACKAGES"
29+
30+ if [ -n " $CONFLICTS " ]; then
31+ echo " ERROR: The following packages are being added to restored-packages.txt but are still present in withdrawn-packages.txt:"
32+ echo -e " $CONFLICTS "
33+ echo " Please remove these packages from withdrawn-packages.txt first, then commit again."
34+ exit 1
35+ fi
36+
37+ exit 0
You can’t perform that action at this time.
0 commit comments