view tests/test-import @ 6531:c2c4fa9af016

merge with -stable
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sat, 12 Apr 2008 23:05:51 -0400
parents ba0b2dacc623
children 87c704ac92d4
line wrap: on
line source

#!/bin/sh

hg init a
mkdir a/d1
mkdir a/d1/d2
echo line 1 > a/a
echo line 1 > a/d1/d2/a
hg --cwd a ci -d '0 0' -Ama

echo line 2 >> a/a
hg --cwd a ci -u someone -d '1 0' -m'second change'

echo % import exported patch
hg clone -r0 a b
hg --cwd a export tip > tip.patch
hg --cwd b import ../tip.patch
echo % message should be same
hg --cwd b tip | grep 'second change'
echo % committer should be same
hg --cwd b tip | grep someone
rm -r b

echo % import of plain diff should fail without message
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
hg --cwd b import ../tip.patch
rm -r b

echo % import of plain diff should be ok with message
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
hg --cwd b import -mpatch ../tip.patch
rm -r b

echo % import of plain diff with specific date and user
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
hg --cwd b import -mpatch -d '1 0' -u 'user@nowhere.net' ../tip.patch
hg -R b tip -pv
rm -r b

echo % import of plain diff should be ok with --no-commit
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
hg --cwd b import --no-commit ../tip.patch
hg --cwd b diff --nodates
rm -r b

echo % hg -R repo import
# put the clone in a subdir - having a directory named "a"
# used to hide a bug.
mkdir dir
hg clone -r0 a dir/b
hg --cwd a export tip > dir/tip.patch
cd dir
hg -R b import tip.patch
cd ..
rm -r dir

echo % import from stdin
hg clone -r0 a b
hg --cwd a export tip | hg --cwd b import -
rm -r b

echo % override commit message
hg clone -r0 a b
hg --cwd a export tip | hg --cwd b import -m 'override' -
hg --cwd b tip | grep override
rm -r b

cat > mkmsg.py <<EOF
import email.Message, sys
msg = email.Message.Message()
msg.set_payload('email commit message\n' + open('tip.patch', 'rb').read())
msg['Subject'] = 'email patch'
msg['From'] = 'email patcher'
sys.stdout.write(msg.as_string())
EOF

echo % plain diff in email, subject, message body
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
python mkmsg.py > msg.patch
hg --cwd b import ../msg.patch
hg --cwd b tip | grep email
rm -r b

echo % plain diff in email, no subject, message body
hg clone -r0 a b
grep -v '^Subject:' msg.patch | hg --cwd b import -
rm -r b

echo % plain diff in email, subject, no message body
hg clone -r0 a b
grep -v '^email ' msg.patch | hg --cwd b import -
rm -r b

echo % plain diff in email, no subject, no message body, should fail
hg clone -r0 a b
egrep -v '^(Subject|email)' msg.patch | hg --cwd b import -
rm -r b

echo % hg export in email, should use patch header
hg clone -r0 a b
hg --cwd a export tip > tip.patch
python mkmsg.py | hg --cwd b import -
hg --cwd b tip | grep second
rm -r b

# subject: duplicate detection, removal of [PATCH]
# The '---' tests the gitsendmail handling without proper mail headers
cat > mkmsg2.py <<EOF
import email.Message, sys
msg = email.Message.Message()
msg.set_payload('email patch\n\nnext line\n---\n' + open('tip.patch').read())
msg['Subject'] = '[PATCH] email patch'
msg['From'] = 'email patcher'
sys.stdout.write(msg.as_string())
EOF

echo '% plain diff in email, [PATCH] subject, message body with subject'
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
python mkmsg2.py | hg --cwd b import -
hg --cwd b tip --template '{desc}\n'
rm -r b

# We weren't backing up the correct dirstate file when importing many patches
# (issue963)
echo '% import patch1 patch2; rollback'
echo line 3 >> a/a
hg --cwd a ci -m'third change'
hg --cwd a export -o '../patch%R' 1 2
hg clone -qr0 a b
hg --cwd b parents --template 'parent: #rev#\n'
hg --cwd b import ../patch1 ../patch2
hg --cwd b rollback
hg --cwd b parents --template 'parent: #rev#\n'
rm -r b

# bug non regression test
# importing a patch in a subdirectory failed at the commit stage
echo line 2 >> a/d1/d2/a
hg --cwd a ci -u someoneelse -d '1 0' -m'subdir change'
echo % hg import in a subdirectory
hg clone -r0 a b
hg --cwd a export tip | sed -e 's/d1\/d2\///' > tip.patch
dir=`pwd`
cd b/d1/d2 2>&1 > /dev/null
hg import  ../../../tip.patch
cd $dir
echo "% message should be 'subdir change'"
hg --cwd b tip | grep 'subdir change'
echo "% committer should be 'someoneelse'"
hg --cwd b tip | grep someoneelse
echo "% should be empty"
hg --cwd b status


# Test fuzziness (ambiguous patch location, fuzz=2)
echo % test fuzziness
hg init fuzzy
cd fuzzy
echo line1 > a
echo line0 >> a
echo line3 >> a
hg ci -Am adda
echo line1 > a
echo line2 >> a
echo line0 >> a
echo line3 >> a
hg ci -m change a
hg export tip > tip.patch
hg up -C 0
echo line1 > a
echo line0 >> a
echo line1 >> a
echo line0 >> a
hg ci -m brancha
hg import -v tip.patch
cd ..

# Test hunk touching empty files (issue906)
hg init empty
cd empty
touch a
touch b1
touch c1
echo d > d
hg ci -Am init
echo a > a
echo b > b1
hg mv b1 b2
echo c > c1
hg copy c1 c2
rm d
touch d
hg diff --git
hg ci -m empty
hg export --git tip > empty.diff
hg up -C 0
hg import empty.diff
for name in a b1 b2 c1 c2 d;
do
    echo % $name file
    test -f $name && cat $name
done
cd ..

# Test importing a patch ending with a binary file removal
echo % test trailing binary removal
hg init binaryremoval
cd binaryremoval
echo a > a
python -c "file('b', 'wb').write('a\x00b')"
hg ci -Am addall
hg rm a
hg rm b
hg st
hg ci -m remove
hg export --git . > remove.diff
cat remove.diff | grep git
hg up -C 0
hg import remove.diff
hg manifest
cd ..

echo % 'test update+rename with common name (issue 927)'
hg init t
cd t
touch a
hg ci -Am t
echo a > a
# Here, bfile.startswith(afile)
hg copy a a2
hg ci -m copya
hg export --git tip > copy.diff
hg up -C 0
hg import copy.diff
echo % view a
# a should contain an 'a'
cat a
echo % view a2
# and a2 should have duplicated it
cat a2
cd ..

echo % 'test -p0'
hg init p0
cd p0
echo a > a
hg ci -Am t
hg import -p0 - << EOF
foobar
--- a	Sat Apr 12 22:43:58 2008 -0400
+++ a	Sat Apr 12 22:44:05 2008 -0400
@@ -1,1 +1,1 @@
-a
+bb
EOF
hg status
cat a
cd ..