I am a mercurial user on windows and I am trying to write a batch file to check for incoming changes to a number of repositories stored in a common folder (i.e. there could be 10 or so small mercurial repos under a main folder). I have the following batch file that successfully iterates through the multiple repositories and runs hg incoming. However I can’t seem to get it to execute hg -pull -u when a repository is found that has remote changes.
FOR /D /r %%G in (".hg*") DO (
@echo Processing: %%G
cd /d %%G\..
hg incoming
IF NOT ERRORLEVEL 0 (
echo Pulling changes from the server
hg pull -u
)
cd..
)
I am pretty sure the problem lies with the If statement. hg incoming doesn’t seem to have a return value that can be interpreted by the ERRORLEVEL. Is this the right approach or should I be using python instead?
The exit code for
hg incomingandhg outgoingis1if there were no incoming/outgoing changesets and0otherwise and this means that your test is backwards. (The exit codes have been documented since this question was asked and can now be found inhg help incomingandhg help outgoing.)Also, doing both
hg incomingandhg pulldoes the job twice: you should simply usehg pull. The help forhg incomingsays:So you’re actually downloading all changesets twice, using twice the bandwidth.