Skip to content

Instantly share code, notes, and snippets.

@stantonk
Created March 8, 2012 17:06
Show Gist options
  • Save stantonk/2002098 to your computer and use it in GitHub Desktop.
Save stantonk/2002098 to your computer and use it in GitHub Desktop.
Batch execute any single mercurial command on all repositories within a directory.
#!/bin/bash
# This script finds all the mercurial repositories in the current directory
# and does a "hg $@" to batch execute a mercurial command in all the repositories.
#
# Make sure you know what you're doing before running this ;-)
#
# Examples:
#
# Perform pull -u on all repositories to get the latest changes and update:
# $ hgbatch pull -u
#
# Check for all incoming changes on all repositories:
# $ hgbatch incoming
confirm_prompt() {
read -p "Are you sure you want to 'hg $cmd' every repository? " -n 1
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
}
cmd=$@
targetDir=`pwd`
dirObjs=`ls $targetDir`
confirm_prompt
# check the current directory for mercurial repositories
for d in $dirObjs
do
if [ -d $d ] && [ -f "$d/.hg/hgrc" ]; then
echo "--------"
echo "Executing 'hg $cmd' in $d:"
cd $d
hg $cmd
cd ..
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment