Check Multiple Mercurial Repositories for Incoming Changes

Currently I have a whole bunch of Mercurial repositories in a directory. All of these are cloned from a central repository that the team pushes their changes to. I like to generally keep my local repositories up-to-date so that I can review changes. Manually running hg incoming -R some_directory on 20 different projects is a lot of work. So I automated it with a simple shell script.

This script will run incoming (or outgoing) on all of the local repositories and print the results to the console. Then I can manually sync the ones that have changed if I want.

I called this file hgcheckall.sh and run it like: ./hgcheckall.sh incoming

#!/bin/bash

# Find all the directories that are mercurial repos
dirs=(`find . -name ".hg"`)
# Remove the /.hg from the path and that's the base repo dir
merc_dirs=( "${dirs[@]//\/.hg/}" )

case $1 in
incoming)
for indir in ${merc_dirs[@]}; do
echo "Checking: ${indir}"
hg -R "$indir" incoming
done
;;
outgoing)
for outdir in ${merc_dirs[@]}; do
echo "Checking: ${outdir}"
hg -R "$outdir" outgoing
done
;;
*)
echo "Usage: hgcheckall.sh [incoming|outgoing]"
;;
esac

I guess the next major improvement would be to capture the output and then automatically sync the ones that have changed, but I haven’t gotten around to that yet.

2 thoughts on “Check Multiple Mercurial Repositories for Incoming Changes”

  1. Hi Geoff.
    Thanks for the script. I was looking for exactly this kind of “tool”, and found yours in about 20 seconds thanks to the very precise headline.

    I have hacked around a little with my own version, and thought I would share back.

    Mainly I have changed the two “commands” to ‘inc’ and ‘out’ as my fingers are used to typing this, and changed the actual hg commands to give a much more space-saving overview:

    hg -q -R "$indir" incoming --template '{rev} {node|short} | {date|isodatesec} | {author|user}: {desc|strip|firstline}\n'

    I might consider reinserting your original versions for the “long format” and using my short-commands as above for the abbreviated one-line format.

    I also added a “io” command that gives a very concise summary like:
    MyProject inc:2
    SecondP inc:1 out:3
    ThirdP
    AnotherP out:4

    but this one uses the hg-prompt extension by Steve Losh

    Hope some of this is useful.
    Regards Jan

  2. hi
    you can do it like that to
    find . -name “.hg” -exec hg -R ‘{}/..’ incoming \; -exec hg -R ‘{}/..’ outgoing \;

    thx for inspiration

    enjoy your stay on earth

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>