Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Post merge git hook to check Laravel 5+ typical resources were updated
#!/bin/bash
# Looks for changes and automates running bundle and other tasks.
# Does not run if your local branch is behind the remote.
# https://gist.github.com/stefansundin/82051ad2c8565999b914
# post-checkout hook - looks for changes,
# when you change branches, and if found, reinstalls the given packages every
# Exit early if this was only a file checkout, not a branch change ($3 == 1)
[[ $3 == 0 ]] && exit 0
oldRef=$1
newRef=$2
# Exit early if the local branch is behind the remote
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse @{u} 2> /dev/null)
BASE=$(git merge-base @ @{u} 2> /dev/null)
if [[ "$LOCAL" != "$REMOTE" && "$LOCAL" = "$BASE" ]]; then
echo "You are behind origin, not running bundle/migrate post-checkout hook."
exit 1
fi
function changed {
git diff --name-only $oldRef $newRef | grep "^$1" > /dev/null 2>&1
}
if changed 'package.lock'; then
echo "[package.lock] changed: Installing npm dependencies..."
npm install
git add package.json package-lock.json
fi
if changed 'composer.lock'; then
echo "[composer.lock] changed: Installing composer dependencies..."
composer install
fi
if changed 'resources/assets'; then
echo "Front-end sources are changed: Building new dev bundle..."
npm run dev
fi
if changed 'database/migrations'; then
echo "Migrations are changed: Migrating..."
php artisan migrate
fi
if changed 'database/seeds'; then
echo "Seeds are changed: Seeding new data..."
php artisan db:seed
fi
#!/bin/bash
# Looks for changes and automates running bundle and other tasks.
# https://gist.github.com/stefansundin/82051ad2c8565999b914
function changed {
git diff --name-only HEAD@{2} HEAD | grep "^$1" > /dev/null 2>&1
}
if changed 'package.lock'; then
echo "[package.lock] changed: Installing npm dependencies..."
npm install
git add package.json package-lock.json
fi
if changed 'composer.lock'; then
echo "[composer.lock] changed: Installing composer dependencies..."
composer install
fi
if changed 'resources/assets'; then
echo "Front-end sources are changed: Building new dev bundle..."
npm run dev
fi
if changed 'database/migrations'; then
echo "Migrations are changed: Migrating..."
php artisan migrate
fi
if changed 'database/seeds'; then
echo "Seeds are changed: Seeding new data..."
php artisan db:seed
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment