35

I would like to define a Mercurial command alias in my hgrc file that invokes multiple commands. For example I would like to do something like the following:

[alias]
giveup = revert --all --no-backup; purge
syncprod = fetch production; push production

This would allow me to call hg syncprod and have it invoke a fetch and then a push. Haven't been able to determine if this capability exists. (I'm guessing that means no.)

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
Jim Bolla
  • 8,265
  • 36
  • 54

3 Answers3

34

Use the shell alias style like this:

giveup = !$HG revert --all --no-backup ; $HG purge

Though, personally I'd just create a bash alias for those so I could skip the hg part altogether.

GazB
  • 3,510
  • 1
  • 36
  • 42
Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
11

To do this on Windows, the following syntax worked for me, without having to use PowerShell or cygwin.

giveup = !hg revert --all --no-backup && hg purge

Alternatively, this version will execute the purge regardless of whether the revert was successful:

giveup = !hg revert --all --no-backup & hg purge

It is possible to string together more than two commands, for instance:

shebase = !hg shelve && hg rebase && hg unshelve
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Kim
  • 728
  • 10
  • 20
0

You can call powershell or cmd from the alias. E.g. I use following alias with powershell:

amend = !powershell -NoProfile -Command hg ci -m $(cat .hg\last-message.txt)

(Comment left by Bozydar Sobczak Apr 7, 2012)

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81