stgit/ Handle a reset that changes files to directories

If reset() takes us from a tree where some path is a file to one
where it is a directory, then checkout() will replace the file
with the directory, and we don't want to try to os.remove() the
path (which would throw an exception because we're trying to
remove a directory.) This fixes bug

Signed-off-by: Peter Maydell <>
Signed-off-by: Catalin Marinas <>
diff --git a/stgit/ b/stgit/
index 0316342..b94b445 100644
--- a/stgit/
+++ b/stgit/
@@ -745,7 +745,7 @@
         checkout(files, tree_id, True)
         # checkout doesn't remove files
-        map(os.remove, rm_files)
+        map(os.remove, [f for f in rm_files if not os.path.isdir(f)])
     # if the reset refers to the whole tree, switch the HEAD as well
     if not files: