Mercurial > hg
view tests/test-convert-baz @ 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 | 6e4cf8319f54 |
children | 7fc79055a62b |
line wrap: on
line source
#!/bin/sh "$TESTDIR/hghave" baz || exit 80 mkdir do_not_use_HOME_baz cd do_not_use_HOME_baz HOME=`pwd`; export HOME cd .. baz my-id "mercurial <mercurial@selenic.com>" echo "[extensions]" >> $HGRCPATH echo "convert=" >> $HGRCPATH echo 'graphlog =' >> $HGRCPATH echo % create baz archive baz make-archive baz@mercurial--convert hg-test-convert-baz echo % initialize baz repo mkdir baz-repo cd baz-repo/ baz init-tree baz@mercurial--convert/baz--test--0 baz import echo % create initial files echo 'this is a file' > a baz add a mkdir src baz add src cd src dd count=1 if=/dev/zero of=b > /dev/null 2> /dev/null baz add b # HACK: hide GNU tar-1.22 "tar: The --preserve option is deprecated, use --preserve-permissions --preserve-order instead" baz commit -s "added a file, src and src/b (binary)" 2>&1 | grep -v '^tar' echo % create link file and modify a ln -s ../a a-link baz add a-link echo 'this a modification to a' >> ../a baz commit -s "added link to a and modify a" echo % create second link and modify b ln -s ../a a-link-2 baz add a-link-2 dd count=1 seek=1 if=/dev/zero of=b > /dev/null 2> /dev/null baz commit -s "added second link and modify b" echo % b file to link and a-link-2 to regular file rm -f a-link-2 echo 'this is now a regular file' > a-link-2 ln -sf ../a b baz commit -s "file to link and link to file test" echo % move a-link-2 file and src directory cd .. baz mv src/a-link-2 c baz mv src test baz commit -s "move and rename a-link-2 file and src directory" echo % move and add the moved file again echo e > e baz add e baz commit -s "add e" baz mv e f echo ee > e baz add e baz commit -s "move e and recreate it again" cd .. echo % converting baz repo to Mercurial hg convert baz-repo baz-repo-hg baz register-archive -d baz@mercurial--convert glog() { hg glog --template '{rev} "{desc|firstline}" files: {files}\n' "$@" } echo % show graph log glog -R baz-repo-hg hg up -q -R baz-repo-hg hg -R baz-repo-hg manifest --debug hg -R baz-repo-hg log -r 5 -r 7 -C --debug | grep copies