       (setf (git-fileinfo->orig-name info) nil)
       (setf (git-fileinfo->needs-refresh info) t))))
 
+(defun git-set-filenames-state (status files state)
+  "Set the state of a list of named files."
+  (when files
+    (setq files (sort files #'string-lessp))
+    (let ((file (pop files))
+          (node (ewoc-nth status 0)))
+      (while (and file node)
+        (let ((info (ewoc-data node)))
+          (cond ((string-lessp (git-fileinfo->name info) file)
+                 (setq node (ewoc-next status node)))
+                ((string-equal (git-fileinfo->name info) file)
+                 (unless (eq (git-fileinfo->state info) state)
+                   (setf (git-fileinfo->state info) state)
+                   (setf (git-fileinfo->rename-state info) nil)
+                   (setf (git-fileinfo->orig-name info) nil)
+                   (setf (git-fileinfo->needs-refresh info) t))
+                 (setq file (pop files)))
+                (t (setq file (pop files)))))))
+    (unless state  ;; delete files whose state has been set to nil
+      (ewoc-filter status (lambda (info) (git-fileinfo->state info))))))
+
 (defun git-state-code (code)
   "Convert from a string to a added/deleted/modified state."
   (case (string-to-char code)

                  "  " (git-escape-file-name (git-fileinfo->name info))
                  (git-rename-as-string info))))

(defun git-insert-fileinfo (status info &optional refresh)
  "Insert INFO in the status buffer, optionally refreshing an existing one."
  (let ((node (and refresh
                   (git-find-status-file status (git-fileinfo->name info)))))
    (setf (git-fileinfo->needs-refresh info) t)
    (when node   ;preserve the marked flag
      (setf (git-fileinfo->marked info) (git-fileinfo->marked (ewoc-data node))))
    (if node (setf (ewoc-data node) info) (ewoc-enter-last status info))))

(defun git-run-diff-index (status files)
  "Run git-diff-index on FILES and parse the results into STATUS.
Return the list of files that haven't been handled."
  (let ((refresh files))
    (with-temp-buffer
      (apply #'git-run-command t nil "diff-index" "-z" "-M" "HEAD" "--" files)
      (goto-char (point-min))

        (setq remaining-files (apply #'git-run-ls-files status remaining-files 'unknown "-o"
                                     (concat "--exclude-per-directory=" git-per-dir-ignore-file)
                                     (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files)))))
    (git-set-filenames-state status remaining-files default-state)
    (git-refresh-files)
    (git-refresh-ewoc-hf status)))

