Last active
March 24, 2024 18:28
-
-
Save Len42/bc96536337e952467e52abaa60161a7c to your computer and use it in GitHub Desktop.
git pre-push script to mirror pushed files to another directory
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/bash | |
# git pre-push script to mirror pushed files to another directory | |
destdir=/mirror-dir | |
if [ `git branch --show-current` != "main" ]; then | |
echo "pre-push: Not on main branch - skipping" | |
else | |
echo "pre-push: Mirroring to $destdir" | |
(git diff @{push} @ --diff-filter=ACMR --name-only | while read file; do | |
echo "pre-push: Copying $file" | |
install -D "$file" "$destdir/$file" | |
retVal=$? | |
if [ $retVal -ne 0 ]; then | |
echo "pre-push: Error " $retVal | |
exit $retVal | |
fi | |
done) || exit | |
(git diff @{push} @ --diff-filter=D --name-only | while read file; do | |
echo "pre-push: Deleting $file" | |
rm "$destdir/$file" | |
retVal=$? | |
if [ $retVal -ne 0 ]; then | |
echo "pre-push: Error " $retVal | |
exit $retVal | |
fi | |
done) || exit | |
echo "pre-push: OK" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment