Mercurial > hg
view tests/test-mq-qqueue @ 11989:f853873fc66d
aliases: provide more flexible ways to work with shell alias arguments
This patch changes the functionality of shell aliases to add more powerful
options for working with shell alias arguments.
First: the alias name + arguments to a shell alias are set as an HG_ARGS
environment variable, delimited by spaces. This matches the behavior of hooks.
Second: any occurrences of "$@" (without quotes) are replaced with the
arguments, separated by spaces. This happens *before* the alias gets to the shell.
Third: any positive numeric variables ("$1", "$2", etc) are replaced with the
appropriate argument, indexed from 1. "$0" is replaced with the name of the
alias. Any "extra" numeric variables are replaced with an empty string. This
happens *before* the alias gets to the shell.
These changes allow for more flexible shell aliases:
[alias]
echo = !echo $@
count = !hg log -r "$@" --template='.' | wc -c | sed -e 's/ //g'
qqueuemv = !mv "`hg root`/.hg/patches-$1" "`hg root`/.hg/patches-$2"
In action:
$ hg echo foo
foo
$ hg count 'branch(default)'
901
$ hg count 'branch(stable) and keyword(fixes)'
102
$ hg qqueuemv myfeature somefeature
author | Steve Losh <steve@stevelosh.com> |
---|---|
date | Wed, 18 Aug 2010 18:56:44 -0400 |
parents | 6e3875a80533 |
children |
line wrap: on
line source
#!/bin/sh echo "[extensions]" >> $HGRCPATH echo "mq=" >> $HGRCPATH hg init foo cd foo echo a > a hg ci -qAm a echo %% default queue hg qqueue echo b > a hg qnew -fgDU somestuff echo %% applied patches in default queue hg qap echo %% try to change patch \(create succeeds, switch fails\) hg qqueue foo --create hg qqueue echo %% empty default queue hg qpop echo %% switch queue hg qqueue foo hg qqueue echo %% list queues, quiet hg qqueue --quiet echo %% fail creating queue with already existing name hg qqueue --create foo hg qqueue echo %% create new queue for rename hg qqueue --create bar hg qqueue echo %% rename queue, same name hg qqueue --rename bar echo %% rename queue to existing hg qqueue --rename foo echo %% rename queue hg qqueue --rename buz hg qqueue echo %% switch back to previous queue hg qqueue foo hg qqueue --delete buz hg qqueue echo %% create queue for purge hg qqueue --create purge-me hg qqueue echo %% create patch for purge hg qnew patch-purge-me ls -1d .hg/patches-purge-me 2>/dev/null || true hg qpop -a echo %% purge queue hg qqueue foo hg qqueue --purge purge-me hg qqueue ls -1d .hg/patches-purge-me 2>/dev/null || true echo %% unapplied patches hg qun echo c > a hg qnew -fgDU otherstuff echo %% fail switching back hg qqueue patches echo %% fail deleting current hg qqueue foo --delete echo %% switch back and delete foo hg qpop -a hg qqueue patches hg qqueue foo --delete hg qqueue echo %% tricky cases hg qqueue store --create hg qnew journal hg qqueue hg qpop -a hg qqueue patches hg qun echo %% invalid names hg qqueue test/../../bar --create hg qqueue . --create cd ..