Last active
April 10, 2020 08:12
-
-
Save gwarser/1654d539a46113707048f3fe45f5f131 to your computer and use it in GitHub Desktop.
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 | |
# Finds all git repos inside directories specified in command line or current | |
# directory if no path specified and updates them all. | |
# Uses fetch + ff merge. | |
# Failed updates are marked by 'FAILED-git-update.txt' file left in git dir | |
# and dirs specified in command line or current dir if not specified. | |
# Can be run as cron job, example (includes sleep to randomize startup time): | |
# 0 */3 * * * $USER /bin/sleep $(shuf -i 0-300 -n 1) && /bin/bash $HOME/git/update-all-repos.sh $HOME/git/ | |
DIRECTORY=() | |
for P in "$@" | |
do | |
DIRECTORY+=("$P") | |
done | |
if [ $# -le 0 ] | |
then | |
DIRECTORY=(.) | |
fi | |
for D in "${DIRECTORY[@]}" | |
do | |
echo -e "$D" | |
done | |
# read -r | |
for D in "${DIRECTORY[@]}" | |
do | |
cd "$D" || continue | |
# Cleanup previous failed flag file. | |
rm 'FAILED-git-update.txt' | |
# Two expressions: '-a' assumed | |
# Can be called only on some repos by matching "path": "-path '*repo/.git'" | |
find "$D" -name '.git' -type d -printf "\033[1m######\n# %80h\n\033[0m" \ | |
\( -execdir git fetch --all --tags \;\ | |
-a -execdir git merge --ff-only \;\ | |
-a -execdir rm -f 'FAILED-git-update.txt' \;\ | |
-o -execdir touch 'FAILED-git-update.txt' \;\ | |
-a -exec touch 'FAILED-git-update.txt' \;\ | |
-a -printf "\033[1;31m######\n# ERROR\033[0m\n" \) | |
done | |
for D in "${DIRECTORY[@]}" | |
do | |
date -Iseconds > "$D"/git-last-update.txt | |
done | |
echo -e "\033[1m######\n# DONE\033[0m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment