Created
November 15, 2016 08:15
-
-
Save AdmiringWorm/fd2fcf854fedbbdeab3f0fdf2cdc7efb to your computer and use it in GitHub Desktop.
git hooks I'm using when creating packages for the chocolatey/coreteampackages repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
# If you want to allow non-ASCII filenames set this variable to true. | |
allownonascii=$(git config --bool hooks.allownonascii) | |
# Redirect output to stderr. | |
exec 1>&2 | |
# Cross platform projects tend to avoid non-ASCII filenames; prevent | |
# them from being added to the repository. We exploit the fact that the | |
# printable range starts at the space character and ends with tilde. | |
if [ "$allownonascii" != "true" ] && | |
# Note that the use of brackets around a tr range is ok here, (it's | |
# even required, for portability to Solaris 10's /usr/bin/tr), since | |
# the square bracket bytes happen to fall in the designated range. | |
test $(git diff --cached --name-only --diff-filter=A -z $against | | |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 | |
then | |
cat <<\EOF | |
Error: Attempt to add a non-ASCII file name. | |
This can cause problems if you want to work with people on other platforms. | |
To be portable it is advisable to rename the file. | |
If you know what you are doing you can disable this check using: | |
git config hooks.allownonascii true | |
EOF | |
exit 1 | |
fi | |
allFiles=`git diff --cached --name-only --diff-filter=AM $against` | |
for file in $allFiles; do | |
toolong=`grep -rEn '.{150}' $file` | |
if [ -n "$toolong" ]; then | |
echo -e "\033[0;31mThe Following lines in '$file' is too long" | |
echo -e "\033[0m" | |
echo "$toolong" | |
exit 2 | |
fi | |
done | |
# If there are whitespace errors, print the offending file names and fail. | |
exec git diff-index --check --cached $against -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
remote="$1" | |
url="$2" | |
z40=0000000000000000000000000000000000000000 | |
while read local_ref local_sha remote_ref remote_sha | |
do | |
if [ "$local_sha" = $z40 ] | |
then | |
# Handle delete | |
: | |
else | |
range="upstream/master" | |
files=`git diff-index $range --diff-filter=AM | grep -E -o -i '[A|M]\s*\S+update\.ps1' | sed -re 's;[A|M]\s+(.*);\1;'` | |
if [ -n "$files" ] | |
then | |
invalid=`grep -i -E -l '^update.*-(Force|NoCheckChocoVersion)' --with-filename $files` | |
if [ -n "$invalid" ] | |
then | |
echo >&2 "ERROR: Found Either Force or NoCheckChocoVersion in the following files" | |
echo >&2 $invalid | |
exit 1 | |
fi | |
fi | |
todoFiles=`git diff-index $range --name-only --diff-filter=AM` | |
todoExist=`grep -i -l 'TODO' --with-filename $todoFiles` | |
if [ -n "$todoExist" ] | |
then | |
echo >&2 "ERROR: Found a reference to incomplete files (TODO in file)" | |
echo >&2 $todoExist | |
exit 1 | |
fi | |
packages=`echo $files | sed -e 's|automatic/||g' -e 's|/update.ps1||g'` | |
if [ -n "$packages" ] | |
then | |
packages=`echo $packages | sed -e 's/\n/ /'` | |
count=`echo $packages | sed -e 's/ /\n/' | wc -l` | |
for package in $packages; do | |
echo "Test Running update on $package" | |
output=`exec powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\test_all.ps1" -Name "$package"` | |
if [ ! -z "$(echo $output | grep -o -e "$package ERROR" -e "FAILED: $package")" ] | |
then | |
echo >&2 $output | |
echo >&2 "ERROR: $package failed to update!" | |
exit 2 | |
fi | |
done | |
fi | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment