view tests/test-import @ 5378:8a2915f57dfc

convert: add a mode where mercurial_sink skips empty revisions. The getchanges function of some converter_source classes can return some false positives. I.e. they sometimes claim that a file "foo" was changed in some revision, even though its contents are still the same. convert_svn is particularly bad, but I think this can also happen with convert_cvs and, at least in theory, with mercurial_source. For regular conversions this is not really a problem - as long as getfile returns the right contents, we'll get a converted revision with the right contents. But when we use --filemap, this could lead to superfluous revisions being converted. Instead of fixing every converter_source, I decided to change mercurial_sink to work around this problem. When --filemap is used, we're interested only in revisions that touch some specific files. If a revision doesn't change any of these files, then we're not interested in it (at least for revisions with a single parent; merges are special). For mercurial_sink, we abuse this property and rollback a commit if the manifest text hasn't changed. This avoids duplicating the logic from localrepo.filecommit to detect unchanged files.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Thu, 04 Oct 2007 23:21:37 -0300
parents a7915f79d4cc
children 9b469bdb1ce1
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 % 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').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]
cat > mkmsg2.py <<EOF
import email.Message, sys
msg = email.Message.Message()
msg.set_payload('email patch\n\nnext line\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


# 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