Mercurial > hg
view tests/test-diff-upgrade @ 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 | 4484a7b661f2 |
children |
line wrap: on
line source
#!/bin/sh echo "[extensions]" >> $HGRCPATH echo "autodiff=$TESTDIR/autodiff.py" >> $HGRCPATH echo "[diff]" >> $HGRCPATH echo "nodates=1" >> $HGRCPATH hg init repo cd repo echo '% make a combination of new, changed and deleted file' echo regular > regular echo rmregular > rmregular touch rmempty echo exec > exec chmod +x exec echo rmexec > rmexec chmod +x rmexec echo setexec > setexec echo unsetexec > unsetexec chmod +x unsetexec echo binary > binary python -c "file('rmbinary', 'wb').write('\0')" hg ci -Am addfiles echo regular >> regular echo newregular >> newregular rm rmempty touch newempty rm rmregular echo exec >> exec echo newexec > newexec chmod +x newexec rm rmexec chmod +x setexec chmod -x unsetexec python -c "file('binary', 'wb').write('\0\0')" python -c "file('newbinary', 'wb').write('\0')" rm rmbinary hg addremove -s 0 echo '% git=no: regular diff for all files' hg autodiff --git=no echo '% git=no: git diff for single regular file' hg autodiff --git=yes regular echo '% git=auto: regular diff for regular files and removals' hg autodiff --git=auto regular newregular rmregular rmbinary rmexec for f in exec newexec setexec unsetexec binary newbinary newempty rmempty; do echo '% git=auto: git diff for' $f hg autodiff --git=auto $f done echo '% git=warn: regular diff with data loss warnings' hg autodiff --git=warn echo '% git=abort: fail on execute bit change' hg autodiff --git=abort regular setexec echo '% git=abort: succeed on regular file' hg autodiff --git=abort regular cd ..