diff --git a/mercurial/patch.py b/mercurial/patch.py index 0e8403f4ce317c7b68dfa73d0e3aff8b7cb48528_bWVyY3VyaWFsL3BhdGNoLnB5..d94832c4a31d49eb5747c364540c9fd36f639689_bWVyY3VyaWFsL3BhdGNoLnB5 100644 --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -933,8 +933,10 @@ missing = not goodb and not gooda and not createfunc() # some diff programs apparently produce create patches where the - # afile is not /dev/null, but rather the same name as the bfile - if missing and afile == bfile: + # afile is not /dev/null, but afile starts with bfile + abasedir = afile[:afile.rfind('/') + 1] + bbasedir = bfile[:bfile.rfind('/') + 1] + if missing and abasedir == bbasedir and afile.startswith(bfile): # this isn't very pretty hunk.create = True if createfunc(): diff --git a/tests/test-import b/tests/test-import index 0e8403f4ce317c7b68dfa73d0e3aff8b7cb48528_dGVzdHMvdGVzdC1pbXBvcnQ=..d94832c4a31d49eb5747c364540c9fd36f639689_dGVzdHMvdGVzdC1pbXBvcnQ= 100755 --- a/tests/test-import +++ b/tests/test-import @@ -351,7 +351,15 @@ @@ -0,0 +1,1 @@ +a EOF +# some people have patches like the following too +cat > create2.patch <<EOF +diff -Naur proj-orig/foo proj-new/foo +--- proj-orig/foo.orig 1969-12-31 16:00:00.000000000 -0800 ++++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700 +@@ -0,0 +1,1 @@ ++a +EOF hg init oddcreate cd oddcreate hg import --no-commit ../create.patch cat foo @@ -354,7 +362,11 @@ hg init oddcreate cd oddcreate hg import --no-commit ../create.patch cat foo +rm foo +hg revert foo +hg import --no-commit ../create2.patch +cat foo echo % 'first line mistaken for email headers (issue 1859)' hg init emailconfusion diff --git a/tests/test-import.out b/tests/test-import.out index 0e8403f4ce317c7b68dfa73d0e3aff8b7cb48528_dGVzdHMvdGVzdC1pbXBvcnQub3V0..d94832c4a31d49eb5747c364540c9fd36f639689_dGVzdHMvdGVzdC1pbXBvcnQub3V0 100644 --- a/tests/test-import.out +++ b/tests/test-import.out @@ -305,6 +305,8 @@ % create file when source is not /dev/null applying ../create.patch a +applying ../create2.patch +a % first line mistaken for email headers (issue 1859) applying a.patch changeset: 0:5a681217c0ad