Skip to content

Instantly share code, notes, and snippets.

@Kurukshetran
Forked from ziadoz/hgupdate.sh
Created October 11, 2018 08:58
Show Gist options
  • Save Kurukshetran/17cd2739a1dcd15c7df1b52e3ba148e9 to your computer and use it in GitHub Desktop.
Save Kurukshetran/17cd2739a1dcd15c7df1b52e3ba148e9 to your computer and use it in GitHub Desktop.
Bash Mercurial Update Script
#!/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