fixing git hook scripts
This commit is contained in:
parent
46b6cb678e
commit
3e42869bbb
@ -5,9 +5,9 @@ sed -i "/^GIT_HASH=\".*\"/ s//GIT_HASH=\"${SHORT_HASH}\"/" .env
|
|||||||
|
|
||||||
DIRTY_STATE=$(git diff --stat)
|
DIRTY_STATE=$(git diff --stat)
|
||||||
if [ -n "$DIRTY_STATE" ]; then
|
if [ -n "$DIRTY_STATE" ]; then
|
||||||
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_TAG=true/" .env
|
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_DIRTY_STATE=true/" .env
|
||||||
else
|
else
|
||||||
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_TAG=false/" .env
|
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_DIRTY_STATE=false/" .env
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GIT_TAG=$(git tag --points-at HEAD)
|
GIT_TAG=$(git tag --points-at HEAD)
|
||||||
|
@ -5,13 +5,10 @@ sed -i "/^GIT_HASH=\".*\"/ s//GIT_HASH=\"${SHORT_HASH}\"/" .env
|
|||||||
|
|
||||||
DIRTY_STATE=$(git diff --stat)
|
DIRTY_STATE=$(git diff --stat)
|
||||||
if [ -n "$DIRTY_STATE" ]; then
|
if [ -n "$DIRTY_STATE" ]; then
|
||||||
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_TAG=true/" .env
|
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_DIRTY_STATE=true/" .env
|
||||||
else
|
else
|
||||||
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_TAG=false/" .env
|
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_DIRTY_STATE=false/" .env
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SHORT_HASH=$(git rev-parse --short HEAD)
|
|
||||||
sed -i "/^GIT_HASH=\".*\"/ s//GIT_HASH=\"${SHORT_HASH}\"/" .env
|
|
||||||
|
|
||||||
GIT_TAG=$(git tag --points-at HEAD)
|
GIT_TAG=$(git tag --points-at HEAD)
|
||||||
if [ -n "$GIT_TAG" ]; then
|
if [ -n "$GIT_TAG" ]; then
|
||||||
@ -19,3 +16,10 @@ if [ -n "$GIT_TAG" ]; then
|
|||||||
else
|
else
|
||||||
sed -i "/^GIT_TAG=\".*\"/ s//GIT_TAG=\"\"/" .env
|
sed -i "/^GIT_TAG=\".*\"/ s//GIT_TAG=\"\"/" .env
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
GIT_BRANCH=$(git branch --show-current)
|
||||||
|
if [ -n "$GIT_BRANCH" ]; then
|
||||||
|
sed -i "/^GIT_BRANCH=\".*\"/ s//GIT_BRANCH=\"${GIT_BRANCH}\"/" .env
|
||||||
|
else
|
||||||
|
sed -i "/^GIT_BRANCH=\".*\"/ s//GIT_BRANCH=\"\"/" .env
|
||||||
|
fi
|
||||||
|
@ -5,9 +5,9 @@ sed -i "/^GIT_HASH=\".*\"/ s//GIT_HASH=\"${SHORT_HASH}\"/" .env
|
|||||||
|
|
||||||
DIRTY_STATE=$(git diff --stat)
|
DIRTY_STATE=$(git diff --stat)
|
||||||
if [ -n "$DIRTY_STATE" ]; then
|
if [ -n "$DIRTY_STATE" ]; then
|
||||||
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_TAG=true/" .env
|
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_DIRTY_STATE=true/" .env
|
||||||
else
|
else
|
||||||
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_TAG=false/" .env
|
sed -i "/^GIT_DIRTY_STATE=.*/ s//GIT_DIRTY_STATE=false/" .env
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GIT_TAG=$(git tag --points-at HEAD)
|
GIT_TAG=$(git tag --points-at HEAD)
|
||||||
|
32
git-hooks/pre-commit
Normal file
32
git-hooks/pre-commit
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# get bash colors and styles here:
|
||||||
|
# http://misc.flogisoft.com/bash/tip_colors_and_formatting
|
||||||
|
C_RESET='\e[0m'
|
||||||
|
C_RED='\e[31m'
|
||||||
|
C_GREEN='\e[32m'
|
||||||
|
C_YELLOW='\e[33m'
|
||||||
|
|
||||||
|
function __run() #(step, name, cmd)
|
||||||
|
{
|
||||||
|
local color output exitcode
|
||||||
|
|
||||||
|
printf "${C_YELLOW}[%s]${C_RESET} %-20s" "$1" "$2"
|
||||||
|
output=$(eval "$3" 2>&1)
|
||||||
|
exitcode=$?
|
||||||
|
|
||||||
|
if [[ 0 == $exitcode || 130 == $exitcode ]]; then
|
||||||
|
echo -e "${C_GREEN}OK!${C_RESET}"
|
||||||
|
else
|
||||||
|
echo -e "${C_RED}NOK!${C_RESET}\n\n$output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
modified="git diff --diff-filter=M --name-only --cached | grep \".php$\""
|
||||||
|
ignore="resources/lang,resources/views,bootstrap/helpers,database/migrations,bin"
|
||||||
|
phpcs="vendor/bin/phpcs --report=code --colors --report-width=80 --ignore=${ignore}"
|
||||||
|
|
||||||
|
__run "1/1" "code sniffer" "${modified} | xargs -r ${phpcs}"
|
||||||
|
# __run "2/3" "php lint" "${modified} | xargs -r php -l"
|
||||||
|
# __run "3/3" "phpstan" "${modified} | xargs -r vendor/bin/phpstan analyse"
|
Loading…
x
Reference in New Issue
Block a user