tests/test-import
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
Fri, 16 Mar 2007 00:22:58 -0300
changeset 4230 c93562fb12cc
parent 3988 9dcf9d45cab8
child 4779 a7915f79d4cc
permissions -rwxr-xr-x
Fix handling of paths when run outside the repo. The main problem was that dirstate.getcwd() returned just "", which was interpreted as "we're at the repo root". It now returns an absolute path. The util.pathto function was also changed to deal with the "cwd is an absolute path" case.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     1
#!/bin/sh
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     2
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     3
hg init a
2773
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
     4
mkdir a/d1
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
     5
mkdir a/d1/d2
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     6
echo line 1 > a/a
2773
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
     7
echo line 1 > a/d1/d2/a
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     8
hg --cwd a ci -d '0 0' -Ama
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     9
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    10
echo line 2 >> a/a
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    11
hg --cwd a ci -u someone -d '1 0' -m'second change'
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    12
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    13
echo % import exported patch
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    14
hg clone -r0 a b
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    15
hg --cwd a export tip > tip.patch
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    16
hg --cwd b import ../tip.patch
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    17
echo % message should be same
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    18
hg --cwd b tip | grep 'second change'
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    19
echo % committer should be same
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    20
hg --cwd b tip | grep someone
3988
9dcf9d45cab8 Don't use -f for rm in tests where not needed. Drop /bin/ from /bin/rm.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2843
diff changeset
    21
rm -r b
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    22
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    23
echo % import of plain diff should fail without message
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    24
hg clone -r0 a b
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    25
hg --cwd a diff -r0:1 > tip.patch
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    26
hg --cwd b import ../tip.patch
3988
9dcf9d45cab8 Don't use -f for rm in tests where not needed. Drop /bin/ from /bin/rm.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2843
diff changeset
    27
rm -r b
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    28
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    29
echo % import of plain diff should be ok with message
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    30
hg clone -r0 a b
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    31
hg --cwd a diff -r0:1 > tip.patch
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    32
hg --cwd b import -mpatch ../tip.patch
3988
9dcf9d45cab8 Don't use -f for rm in tests where not needed. Drop /bin/ from /bin/rm.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2843
diff changeset
    33
rm -r b
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    34
4230
c93562fb12cc Fix handling of paths when run outside the repo.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3988
diff changeset
    35
echo % hg -R repo import
c93562fb12cc Fix handling of paths when run outside the repo.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3988
diff changeset
    36
# put the clone in a subdir - having a directory named "a"
c93562fb12cc Fix handling of paths when run outside the repo.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3988
diff changeset
    37
# used to hide a bug.
c93562fb12cc Fix handling of paths when run outside the repo.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3988
diff changeset
    38
mkdir dir
c93562fb12cc Fix handling of paths when run outside the repo.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3988
diff changeset
    39
hg clone -r0 a dir/b
c93562fb12cc Fix handling of paths when run outside the repo.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3988
diff changeset
    40
hg --cwd a export tip > dir/tip.patch
c93562fb12cc Fix handling of paths when run outside the repo.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3988
diff changeset
    41
cd dir
c93562fb12cc Fix handling of paths when run outside the repo.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3988
diff changeset
    42
hg -R b import tip.patch
c93562fb12cc Fix handling of paths when run outside the repo.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3988
diff changeset
    43
cd ..
c93562fb12cc Fix handling of paths when run outside the repo.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3988
diff changeset
    44
rm -r dir
c93562fb12cc Fix handling of paths when run outside the repo.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3988
diff changeset
    45
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    46
echo % import from stdin
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    47
hg clone -r0 a b
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    48
hg --cwd a export tip | hg --cwd b import -
3988
9dcf9d45cab8 Don't use -f for rm in tests where not needed. Drop /bin/ from /bin/rm.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2843
diff changeset
    49
rm -r b
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    50
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    51
echo % override commit message
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    52
hg clone -r0 a b
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    53
hg --cwd a export tip | hg --cwd b import -m 'override' -
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    54
hg --cwd b tip | grep override
3988
9dcf9d45cab8 Don't use -f for rm in tests where not needed. Drop /bin/ from /bin/rm.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2843
diff changeset
    55
rm -r b
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    56
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    57
cat > mkmsg.py <<EOF
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    58
import email.Message, sys
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    59
msg = email.Message.Message()
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    60
msg.set_payload('email commit message\n' + open('tip.patch').read())
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    61
msg['Subject'] = 'email patch'
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    62
msg['From'] = 'email patcher'
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    63
sys.stdout.write(msg.as_string())
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    64
EOF
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    65
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    66
echo % plain diff in email, subject, message body
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    67
hg clone -r0 a b
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    68
hg --cwd a diff -r0:1 > tip.patch
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    69
python mkmsg.py > msg.patch
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    70
hg --cwd b import ../msg.patch
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    71
hg --cwd b tip | grep email
3988
9dcf9d45cab8 Don't use -f for rm in tests where not needed. Drop /bin/ from /bin/rm.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2843
diff changeset
    72
rm -r b
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    73
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    74
echo % plain diff in email, no subject, message body
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    75
hg clone -r0 a b
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    76
grep -v '^Subject:' msg.patch | hg --cwd b import -
3988
9dcf9d45cab8 Don't use -f for rm in tests where not needed. Drop /bin/ from /bin/rm.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2843
diff changeset
    77
rm -r b
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    78
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    79
echo % plain diff in email, subject, no message body
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    80
hg clone -r0 a b
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    81
grep -v '^email ' msg.patch | hg --cwd b import -
3988
9dcf9d45cab8 Don't use -f for rm in tests where not needed. Drop /bin/ from /bin/rm.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2843
diff changeset
    82
rm -r b
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    83
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    84
echo % plain diff in email, no subject, no message body, should fail
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    85
hg clone -r0 a b
2843
0b9ac7dfcf56 Fix some tests for portability.
Danek Duvall <danek.duvall@sun.com>
parents: 2773
diff changeset
    86
egrep -v '^(Subject|email)' msg.patch | hg --cwd b import -
3988
9dcf9d45cab8 Don't use -f for rm in tests where not needed. Drop /bin/ from /bin/rm.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2843
diff changeset
    87
rm -r b
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    88
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    89
echo % hg export in email, should use patch header
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    90
hg clone -r0 a b
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    91
hg --cwd a export tip > tip.patch
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    92
python mkmsg.py | hg --cwd b import -
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    93
hg --cwd b tip | grep second
3988
9dcf9d45cab8 Don't use -f for rm in tests where not needed. Drop /bin/ from /bin/rm.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2843
diff changeset
    94
rm -r b
2513
f22e3e8fd457 import: added tests, fixed bugs found by tests and asak.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    95
2773
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
    96
# bug non regression test
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
    97
# importing a patch in a subdirectory failed at the commit stage
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
    98
echo line 2 >> a/d1/d2/a
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
    99
hg --cwd a ci -u someoneelse -d '1 0' -m'subdir change'
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
   100
echo % hg import in a subdirectory
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
   101
hg clone -r0 a b
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
   102
hg --cwd a export tip | sed -e 's/d1\/d2\///' > tip.patch
2843
0b9ac7dfcf56 Fix some tests for portability.
Danek Duvall <danek.duvall@sun.com>
parents: 2773
diff changeset
   103
dir=`pwd`
0b9ac7dfcf56 Fix some tests for portability.
Danek Duvall <danek.duvall@sun.com>
parents: 2773
diff changeset
   104
cd b/d1/d2 2>&1 > /dev/null
2773
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
   105
hg import  ../../../tip.patch
2843
0b9ac7dfcf56 Fix some tests for portability.
Danek Duvall <danek.duvall@sun.com>
parents: 2773
diff changeset
   106
cd $dir
2773
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
   107
echo "% message should be 'subdir change'"
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
   108
hg --cwd b tip | grep 'subdir change'
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
   109
echo "% committer should be 'someoneelse'"
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
   110
hg --cwd b tip | grep someoneelse
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
   111
echo "% should be empty"
871ca5b9d348 Import say a file is not tracked after patching : test case
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2513
diff changeset
   112
hg --cwd b status