diff --git a/hgext/transplant.py b/hgext/transplant.py
index 8bce1e0d280105db1fa286aff28d08550767fa2c_aGdleHQvdHJhbnNwbGFudC5weQ==..eba6c8687fd2b105e46368661dc11277d21ae49a_aGdleHQvdHJhbnNwbGFudC5weQ== 100644
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -227,8 +227,6 @@
                 finally:
                     files = patch.updatedir(self.ui, repo, files)
             except Exception, inst:
-                if filter:
-                    os.unlink(patchfile)
                 seriespath = os.path.join(self.path, 'series')
                 if os.path.exists(seriespath):
                     os.unlink(seriespath)
diff --git a/tests/test-transplant b/tests/test-transplant
index 8bce1e0d280105db1fa286aff28d08550767fa2c_dGVzdHMvdGVzdC10cmFuc3BsYW50..eba6c8687fd2b105e46368661dc11277d21ae49a_dGVzdHMvdGVzdC10cmFuc3BsYW50 100755
--- a/tests/test-transplant
+++ b/tests/test-transplant
@@ -136,6 +136,15 @@
 hg log --template '{rev} {parents} {desc}\n'
 cd ..
 
+echo '% test filter with failed patch'
+cd filter
+hg up 0
+echo foo > b1
+hg ci -d '0 0' -Am foo
+hg transplant 1 --filter ./test-filter |\
+    sed 's/filtering.*/filtering/g'
+cd ..
+
 echo '% test with a win32ext like setup (differing EOLs)'
 hg init twin1
 cd twin1
@@ -156,4 +165,4 @@
 hg ci -m addb
 hg transplant -s ../twin1 tip
 python -c "print repr(file('b', 'rb').read())"
-cd ..
\ No newline at end of file
+cd ..
diff --git a/tests/test-transplant.out b/tests/test-transplant.out
index 8bce1e0d280105db1fa286aff28d08550767fa2c_dGVzdHMvdGVzdC10cmFuc3BsYW50Lm91dA==..eba6c8687fd2b105e46368661dc11277d21ae49a_dGVzdHMvdGVzdC10cmFuc3BsYW50Lm91dA== 100644
--- a/tests/test-transplant.out
+++ b/tests/test-transplant.out
@@ -159,6 +159,17 @@
 2  b2
 1  b1
 0  r2
+% test filter with failed patch
+0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+adding b1
+adding test-filter
+created new head
+file b1 already exists
+1 out of 1 hunks FAILED -- saving rejects to file b1.rej
+abort: Fix up the merge and run hg transplant --continue
+filtering
+applying 348b36d0b6a5
+patch failed to apply
 % test with a win32ext like setup (differing EOLs)
 adding a
 adding b