Last active
October 11, 2018 08:58
-
-
Save ziadoz/4675691 to your computer and use it in GitHub Desktop.
Bash Mercurial Update Script
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 | |
# Usage: ./hgupdate.sh /path/to/repositories | |
# Trap Ctrl + C command and exit the script. | |
trap 'exit 1' 2 | |
# Strip trailing slashes from argument and test it's a directory. | |
TARGET=${1%/} | |
if [[ ! -d $TARGET ]]; then | |
echo "Please pass in a directory path." | |
exit 1 | |
fi | |
# Store working directory and directories to update. | |
pwd=$(pwd) | |
dirs=($(find $TARGET -mindepth 1 -maxdepth 1 -type d)) | |
echo "Update all Mercurial Repositories:" | |
echo | |
# Update each directory that contains a Mercurial .hg file. | |
for dir in "${dirs[@]}"; do | |
cd $dir | |
if [ -e ".hg" ]; then | |
echo "Updating $dir:" | |
hg pull -u | |
echo | |
fi | |
done | |
# Switch back to working directory. | |
cd $pwd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment