MacHg Script to Export Mercurial Changes

Here is an adapted script that I use to create my upgrade packages for Simple Review. I like to create a zip file containing all changes between my last tagged version and the latest committed changes. The script has a variable rev which is set to the last tagged version (this could easily be made into a command line parameter). I am using the bundled version of Mercurial that comes with MacHg, so if you are using something else or already have hg in your path you can change or remove the hg variable. You will also need to change the repository and export variables.

#!/bin/bash
#Adapted from http://stackoverflow.com/questions/1871522/mercurial-how-do-i-create-a-zip-of-files-changed-between-two-revisions/2645765#2645765
hg=/Applications/MacHg.app/Contents/Resources/localhg
repository="/Users/row1/Documents/Mercurial/MyProject"
projectName=$(basename "$repository")
export="/Users/row1/Documents/Mercurial"
#Change this to the last tagged version.
rev="3.0.10:tip"

cd "$repository"
cd ..

FILES=$($hg status --rev $rev --cwd "$repository" | cut -c3-)

IFS=$'\n'
FILENAMES=""
for line in ${FILES}
do
    FILENAMES=$FILENAMES" \""$projectName"/"$line"\""
done

zipFileName="$export/$projectName"".zip"
zipCommand="zip -r \"$zipFileName\" $FILENAMES --exclude *.hg*"
eval $zipCommand 

mv "$zipFileName" "export/MyProject-Changes.zip"
exit