Last active
September 11, 2024 10:45
-
-
Save mortenscheel/9cf1d93b33268e4d1b2172146cbd6e20 to your computer and use it in GitHub Desktop.
Laravel specific git hooks for post-checkout and post-merge
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
#!/usr/bin/env bash | |
NC='\033[0m' # No Color | |
YELLOW='\033[0;33m' | |
CYAN='\033[0;36m' | |
GREEN='\033[0;32m' | |
RED='\033[0;31m' | |
MAGENTA='\033[0;35m' | |
notify_about_actions_required() { | |
changed_files="$(git diff-tree -r --name-status --no-commit-id $1 $2)" | |
is_changed() { | |
echo "$changed_files" | grep -Eq "$1" | |
} | |
is_added() { | |
echo "$changed_files" | grep -Eq "^A\s+$1" | |
} | |
is_modified() { | |
echo "$changed_files" | grep -Eq "^M\s+$1" | |
} | |
is_deleted() { | |
echo "$changed_files" | grep -Eq "^D\s+$1" | |
} | |
print_notification() { | |
filename="$1" | |
shift | |
action="$@" | |
echo -e "${YELLOW}${filename}${NC} changed. Please run ${CYAN}${action}${NC}" | |
} | |
is_changed composer.lock && print_notification "composer.lock" "composer install" | |
is_changed package-lock.json && print_notification "package-lock.json" "npm install" | |
is_changed ^database/seeders && print_notification "Seeders" "php artisan db:seed" | |
if is_deleted database/migrations; then | |
echo -e "${YELLOW}Migration files${NC} ${RED}removed${NC}. Consider going back to the previous branch to rollback changes with ${CYAN}php artisan migrate:rollback${NC}" | |
fi | |
if is_modified database/migrations; then | |
echo -e "${YELLOW}Migration files${NC} ${MAGENTA}modified${NC}. Consider running ${CYAN}php artisan migrate:rollback && php artisan migrate${NC}" | |
fi | |
if is_added database/migrations; then | |
echo -e "${YELLOW}Migration files${NC} ${GREEN}added${NC}. Please run ${CYAN}php artisan migrate${NC}" | |
fi | |
} |
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
#!/usr/bin/env bash | |
source "$(dirname $0)/functions.sh" | |
notify_about_actions_required $1 $2 | |
exit 0 |
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
#!/usr/bin/env bash | |
source "$(dirname $0)/functions.sh" | |
notify_about_actions_required HEAD@{1} HEAD@{0} | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is pretty smart! Thanks for sharing! ❤️