diff --git a/mercurial/patch.py b/mercurial/patch.py index 9a69ab6d7cf765c1a3ed43ae8b0e5d770c6eacf6_bWVyY3VyaWFsL3BhdGNoLnB5..648d6a1a1cf25c3471b57e07f52746276a2c81ee_bWVyY3VyaWFsL3BhdGNoLnB5 100644 --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -793,6 +793,17 @@ if reverse: createfunc = hunk.rmfile 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: + # this isn't very pretty + hunk.create = True + if createfunc(): + missing = False + else: + hunk.create = False + # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the # diff is between a file and its backup. In this case, the original # file should be patched (see original mpatch code). diff --git a/tests/test-import b/tests/test-import index 9a69ab6d7cf765c1a3ed43ae8b0e5d770c6eacf6_dGVzdHMvdGVzdC1pbXBvcnQ=..648d6a1a1cf25c3471b57e07f52746276a2c81ee_dGVzdHMvdGVzdC1pbXBvcnQ= 100755 --- a/tests/test-import +++ b/tests/test-import @@ -332,3 +332,16 @@ EOF hg import --no-commit a.patch cd .. + +echo '% create file when source is not /dev/null' +cat > create.patch <<EOF +diff -Naur proj-orig/foo proj-new/foo +--- proj-orig/foo 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 diff --git a/tests/test-import.out b/tests/test-import.out index 9a69ab6d7cf765c1a3ed43ae8b0e5d770c6eacf6_dGVzdHMvdGVzdC1pbXBvcnQub3V0..648d6a1a1cf25c3471b57e07f52746276a2c81ee_dGVzdHMvdGVzdC1pbXBvcnQub3V0 100644 --- a/tests/test-import.out +++ b/tests/test-import.out @@ -292,3 +292,6 @@ % add empty file from the end of patch (issue 1495) adding a applying a.patch +% create file when source is not /dev/null +applying ../create.patch +a