Skip to content

Instantly share code, notes, and snippets.

@stantonk
Created March 7, 2012 17:05
Show Gist options
  • Save stantonk/1994409 to your computer and use it in GitHub Desktop.
Save stantonk/1994409 to your computer and use it in GitHub Desktop.
Perform batch "pull -u" on multiple Mercurial repositories from the parent directory
#!/bin/bash
# This script finds all the mercurial repositories in the current directory
# and does a "hg pull -u" to get the latest changes from all the repositories.
#
# Make sure you know what you're doing before running this ;-)
confirm_prompt() {
read -p "Are you sure you want to 'hg pull -u' every repository? " -n 1
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
}
confirm_prompt
targetDir=`pwd`
dirObjs=`ls $targetDir`
# check the current directory for mercurial repositories
for d in $dirObjs
do
if [ -d $d ] && [ -f "$d/.hg/hgrc" ]; then
echo "--------"
echo "Updating mercurial repository in $d"
cd $d
hg pull -u
cd ..
fi
done
@SlimDeluxe
Copy link

Cool, this should come in handy!

@rsaraswat
Copy link

This is a handy script, just one suggestion though, if you can add hg update and merge for +1 heads, that will be great.

@Nyurael
Copy link

Nyurael commented Sep 27, 2017

Here is a windows version for that.

`@ECHO OFF

REM This script finds all the mercurial repositories in the current directory
REM and does a "hg pull -u" to get the latest changes from all the repositories.
REM
REM Make sure you know what you're doing before running this ;-)

:choice
set /P c=Are you sure you want to 'hg pull -u' every repository? [Y/N]
if /I "%c%" EQU "Y" goto :pull
if /I "%c%" EQU "N" goto :end
goto :choice

:pull
REM check the current directory for mercurial repositories
echo
for /f "tokens=*" %%i in ('dir /ad /b') do (
cd %%i
if EXIST ..hg (
echo
echo -------- START UPDATE "%%i" --------
hg pull -u
echo --------- END UPDATE "%%i" ---------
echo
)
cd ..
)
echo
echo ALL PROJECTS UPDATED
pause
exit

:end
echo
echo UPDATE CANCELED
pause
exit`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment