# HG changeset patch # User Vadim Gelfer # Date 1151425850 25200 # Node ID f22e3e8fd4576c7f8b362454de9fa7eeaeb391bb # Parent e4deeaac5e743ded15ec252b79b27cd48426e963 import: added tests, fixed bugs found by tests and asak. diff -r e4deeaac5e74 -r f22e3e8fd457 mercurial/commands.py --- a/mercurial/commands.py Tue Jun 27 10:49:46 2006 -0400 +++ b/mercurial/commands.py Tue Jun 27 09:30:50 2006 -0700 @@ -1787,10 +1787,16 @@ diffs_seen += 1 hgpatch = False fp = cStringIO.StringIO() + if message: + fp.write(message) + fp.write('\n') for line in payload[:m.start(0)].splitlines(): if line.startswith('# HG changeset patch'): ui.debug(_('patch generated by hg export\n')) hgpatch = True + # drop earlier commit message content + fp.seek(0) + fp.truncate() elif hgpatch: if line.startswith('# User '): user = line[7:] @@ -1800,8 +1806,7 @@ if not line.startswith('# '): fp.write(line) fp.write('\n') - hgpatch = False - message = fp.getvalue() or message + message = fp.getvalue() if tmpfp: tmpfp.write(payload) if not payload.endswith('\n'): diff -r e4deeaac5e74 -r f22e3e8fd457 tests/test-import --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-import Tue Jun 27 09:30:50 2006 -0700 @@ -0,0 +1,81 @@ +#!/bin/sh + +hg init a +echo line 1 > a/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 -rf 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 -rf 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 -rf b + +echo % import from stdin +hg clone -r0 a b +hg --cwd a export tip | hg --cwd b import - +rm -rf 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 -rf b + +cat > mkmsg.py < tip.patch +python mkmsg.py > msg.patch +hg --cwd b import ../msg.patch +hg --cwd b tip | grep email +rm -rf 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 -rf 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 -rf b + +echo % plain diff in email, no subject, no message body, should fail +hg clone -r0 a b +grep -v '^\(Subject\|email\)' msg.patch | hg --cwd b import - +rm -rf 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 -rf b + diff -r e4deeaac5e74 -r f22e3e8fd457 tests/test-import.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-import.out Tue Jun 27 09:30:50 2006 -0700 @@ -0,0 +1,103 @@ +adding a +% import exported patch +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying ../tip.patch +patching file a +% message should be same +summary: second change +% committer should be same +user: someone +% import of plain diff should fail without message +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying ../tip.patch +patching file a +transaction abort! +rollback completed +% import of plain diff should be ok with message +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying ../tip.patch +patching file a +% import from stdin +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying patch from stdin +patching file a +% override commit message +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying patch from stdin +patching file a +summary: override +% plain diff in email, subject, message body +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying ../msg.patch +patching file a +user: email patcher +summary: email patch +% plain diff in email, no subject, message body +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying patch from stdin +patching file a +% plain diff in email, subject, no message body +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying patch from stdin +patching file a +% plain diff in email, no subject, no message body, should fail +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying patch from stdin +patching file a +transaction abort! +rollback completed +% hg export in email, should use patch header +requesting all changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying patch from stdin +patching file a +summary: second change