views:

216

answers:

2

I have multiple mercurial repositories and used hg clone to create backups of them on our file server. Now I want to write a batch file that updates them once a day by running hg pull -u on each subdirectory.

I want to keep this backup script as generic as possible, so it should update all backup repositories stored in my H:\BACKUPS\REPOS folder. This is my hgbackup.bat that is stored in the same folder:

for /f "delims=" %%i in ('dir /ad/b') do hg pull -u

The problem: hg pull only seems to operate on the current working directory, there seems to be no switch to specify the target repository for the pull. As I hate Windows Batch Scripting, I want to keep my .bat as simple as possible and avoid cd'ing to the different directories.

Any ideas how I can run hg pull -u on a different directory?

+4  A: 

Use the -R-switch:

hg pull -u -R /path/to/repository

See hg -v help pull for all command line options of hg pull (the -v switch tells help to include global options).

piquadrat
thanks for the help! Yes, I stumpled across the -R option, but I thought it would specify the repository to pull from.
Franz
A: 

Found this question quite a bit later due to a script I was working on for my own computer, and rather than a batch script, I did it in PowerShell (since you mentioned it's on a server, I assumed PS was available). This handles both Subversion and Mercurial repositories:

$path = "c:\users\mattgwagner\Documents\Code"

foreach($fi in get-childitem $path)
{
    if(test-path $path\$fi\.svn)
    {
        "Updating " + $fi + " via Subversion..."
        svn update $path\$fi
    }
    elseif(test-path $path\$fi\.hg)
    {
        "Updating " + $fi + " via Mercurial..."
        hg pull -u -R $path\$fi
    }
}
MattGWagner