Mercurial > hg
view tests/test-hardlinks-safety @ 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 | 7e5e13bee8f4 |
children |
line wrap: on
line source
#!/bin/sh # some implementations of cp can't create hardlinks cat > cp.py <<EOF from mercurial import util import sys util.copyfiles(sys.argv[1], sys.argv[2], hardlink=True) EOF # test hardlinking outside hg mkdir x echo foo > x/a python cp.py x y echo bar >> y/a echo % no diff if hardlink diff x/a y/a # test mq hardlinking echo "[extensions]" >> $HGRCPATH echo "mq=" >> $HGRCPATH echo % init hg init a cd a hg qimport -n foo - << EOF # HG changeset patch # Date 1 0 diff -r 2588a8b53d66 a --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/a Wed Jul 23 15:54:29 2008 +0200 @@ -0,0 +1,1 @@ +a EOF hg qpush cd .. python cp.py a b cd b hg qimport -n bar - << EOF # HG changeset patch # Date 2 0 diff -r 2588a8b53d66 a --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/b Wed Jul 23 15:54:29 2008 +0200 @@ -0,0 +1,1 @@ +b EOF hg qpush cat .hg/patches/status echo % cat .hg/patches/series echo %%% cat ../a/.hg/patches/status echo % cat ../a/.hg/patches/series # test tags hardlinking hg qdel -r qbase:qtip hg tag -l lfoo hg tag foo cd .. python cp.py b c cd c hg tag -l -r 0 lbar hg tag -r 0 bar echo %%% cat .hgtags echo % cat .hg/localtags echo %%% cat ../b/.hgtags echo % cat ../b/.hg/localtags