view tests/test-git-export @ 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 6c82beaaa11a
children
line wrap: on
line source

#!/bin/sh

hg init a
cd a

echo start > start
hg ci -Amstart
echo new > new
hg ci -Amnew
echo '% new file'
hg diff --git -r 0

hg cp new copy
hg ci -mcopy
echo '% copy'
hg diff --git -r 1:tip

hg mv copy rename
hg ci -mrename
echo '% rename'
hg diff --git -r 2:tip

hg rm rename
hg ci -mdelete
echo '% delete'
hg diff --git -r 3:tip

cat > src <<EOF
1
2
3
4
5
EOF
hg ci -Amsrc
chmod +x src
hg ci -munexec
echo '% chmod 644'
hg diff --git -r 5:tip

hg mv src dst
chmod -x dst
echo a >> dst
hg ci -mrenamemod
echo '% rename+mod+chmod'
hg diff --git -r 6:tip

echo '% nonexistent in tip+chmod'
hg diff --git -r 5:6

echo '% binary diff'
cp $TESTDIR/binfile.bin .
hg add binfile.bin
hg diff --git > b.diff
cat b.diff

echo '% import binary diff'
hg revert binfile.bin
rm binfile.bin
hg import -mfoo b.diff
cmp binfile.bin $TESTDIR/binfile.bin

echo
echo '% rename binary file'
hg mv binfile.bin renamed.bin
hg diff --git

echo
echo '% diff across many revisions'
hg mv dst dst2
hg ci -m 'mv dst dst2'

echo >> start
hg ci -m 'change start'

hg revert -r -2 start
hg mv dst2 dst3
hg ci -m 'mv dst2 dst3; revert start'

hg diff --git -r 9:11
echo '%  reversed'
hg diff --git -r 11:9

echo a >> foo
hg add foo
hg ci -m 'add foo'
echo b >> foo
hg ci -m 'change foo'
hg mv foo bar
hg ci -m 'mv foo bar'
echo c >> bar
hg ci -m 'change bar'

echo
echo '% file created before r1 and renamed before r2'
hg diff --git -r -3:-1
echo '%  reversed'
hg diff --git -r -1:-3
echo
echo '% file created in r1 and renamed before r2'
hg diff --git -r -4:-1
echo '%  reversed'
hg diff --git -r -1:-4
echo
echo '% file created after r1 and renamed before r2'
hg diff --git -r -5:-1
echo '%  reversed'
hg diff --git -r -1:-5

echo
echo '% comparing with the working dir'
echo >> start
hg ci -m 'change start again'

echo > created
hg add created
hg ci -m 'add created'

hg mv created created2
hg ci -m 'mv created created2'

hg mv created2 created3
echo "% there's a copy in the working dir..."
hg diff --git
echo
echo "% ...but there's another copy between the original rev and the wd"
hg diff --git -r -2
echo
echo "% ...but the source of the copy was created after the original rev"
hg diff --git -r -3
hg ci -m 'mv created2 created3'

echo > brand-new
hg add brand-new
hg ci -m 'add brand-new'
hg mv brand-new brand-new2
echo '% created in parent of wd; renamed in the wd'
hg diff --git

echo
echo '% created between r1 and parent of wd; renamed in the wd'
hg diff --git -r -2
hg ci -m 'mv brand-new brand-new2'

echo '% one file is copied to many destinations and removed'
hg cp brand-new2 brand-new3
hg mv brand-new2 brand-new3-2
hg ci -m 'multiple renames/copies'
hg diff --git -r -2 -r -1
echo '%  reversed'
hg diff --git -r -1 -r -2

echo '% there should be a trailing TAB if there are spaces in the file name'
echo foo > 'with spaces'
hg add 'with spaces'
hg diff --git
hg ci -m 'add filename with spaces'