diff --git a/mercurial/patch.py b/mercurial/patch.py
index a7582980d65484557673077290dccb174ddc7588_bWVyY3VyaWFsL3BhdGNoLnB5..ba0b2dacc6235daab2ee2a0223692ac4c5c617b7_bWVyY3VyaWFsL3BhdGNoLnB5 100644
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -789,7 +789,7 @@
         pathlen = len(path)
         i = 0
         if count == 0:
-            return path.rstrip()
+            return '', path.rstrip()
         while count > 0:
             i = path.find('/', i)
             if i == -1:
diff --git a/tests/test-import b/tests/test-import
index a7582980d65484557673077290dccb174ddc7588_dGVzdHMvdGVzdC1pbXBvcnQ=..ba0b2dacc6235daab2ee2a0223692ac4c5c617b7_dGVzdHMvdGVzdC1pbXBvcnQ= 100755
--- a/tests/test-import
+++ b/tests/test-import
@@ -244,3 +244,20 @@
 # 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 ..
diff --git a/tests/test-import.out b/tests/test-import.out
index a7582980d65484557673077290dccb174ddc7588_dGVzdHMvdGVzdC1pbXBvcnQub3V0..ba0b2dacc6235daab2ee2a0223692ac4c5c617b7_dGVzdHMvdGVzdC1pbXBvcnQub3V0 100644
--- a/tests/test-import.out
+++ b/tests/test-import.out
@@ -256,3 +256,7 @@
 a
 % view a2
 a
+% test -p0
+adding a
+applying patch from stdin
+bb