Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@
- manual
types:
- yaml
- id: check-restored-packages
name: Check restored packages against withdrawn
description: Ensures packages being added to restored-packages.txt are removed from withdrawn-packages.txt first
entry: scripts/check-restored-packages.sh
language: script
stages:
- pre-commit
- manual
files: ^restored-packages\.txt$
37 changes: 37 additions & 0 deletions scripts/check-restored-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
set -e

# Check if restored-packages.txt is being modified
if ! git diff --cached --name-only | grep -q "restored-packages.txt"; then
exit 0
fi

if [ ! -f "withdrawn-packages.txt" ] || [ ! -f "restored-packages.txt" ]; then
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be the first check.

exit 0
fi

# Get the new lines being added to restored-packages.txt
NEW_PACKAGES=$(git diff --cached "restored-packages.txt" | grep "^+" | grep -v "^+++" | sed 's/^+//' | grep -v '^$' | grep -v '^#')

if [ -z "$NEW_PACKAGES" ]; then
exit 0
fi

# Check if any new packages are in withdrawn-packages.txt
CONFLICTS=""
while IFS= read -r package; do
if [ -n "$package" ]; then
if grep -Fxq "$package" "withdrawn-packages.txt"; then
CONFLICTS="${CONFLICTS}${package}\n"
fi
fi
done <<< "$NEW_PACKAGES"

if [ -n "$CONFLICTS" ]; then
echo "ERROR: The following packages are being added to restored-packages.txt but are still present in withdrawn-packages.txt:"
echo -e "$CONFLICTS"
echo "Please remove these packages from withdrawn-packages.txt first, then commit again."
exit 1
fi

exit 0
Loading