 
 (defun git-read-tree (tree &optional index-file)
   "Read a tree into the index file."
-  (apply #'git-call-process-env nil
-         (if index-file `(("GIT_INDEX_FILE" . ,index-file)) nil)
-         "read-tree" (if tree (list tree))))
+  (let ((process-environment
+         (append (and index-file (list (concat "GIT_INDEX_FILE=" index-file))) process-environment)))
+    (apply 'git-call-process-display-error "read-tree" (if tree (list tree)))))
 
 (defun git-write-tree (&optional index-file)
   "Call git-write-tree and return the resulting tree SHA1 as a string."
-  (git-get-string-sha1
-   (git-call-process-env-string (and index-file `(("GIT_INDEX_FILE" . ,index-file))) "write-tree")))
+  (let ((process-environment
+         (append (and index-file (list (concat "GIT_INDEX_FILE=" index-file))) process-environment)))
+    (git-get-string-sha1
+     (git-call-process-string-display-error "write-tree"))))
 
 (defun git-commit-tree (buffer tree head)
   "Call git-commit-tree with buffer as input and return the resulting commit SHA1."


(defun git-update-index (index-file files)
  "Run git-update-index on a list of files."
  (let ((env (and index-file `(("GIT_INDEX_FILE" . ,index-file))))
        added deleted modified)
    (dolist (info files)
      (case (git-fileinfo->state info)
        ('added (push info added))
        ('deleted (push info deleted))
        ('modified (push info modified))))
    (when added
      (apply #'git-call-process-env nil env "update-index" "--add" "--" (git-get-filenames added)))
    (when deleted
      (apply #'git-call-process-env nil env "update-index" "--remove" "--" (git-get-filenames deleted)))
    (when modified
      (apply #'git-call-process-env nil env "update-index" "--" (git-get-filenames modified)))))

(defun git-run-pre-commit-hook ()
  "Run the pre-commit hook if any."

          (message "You cannot commit unmerged files, resolve them first.")
        (unwind-protect
            (let ((files (git-marked-files-state 'added 'deleted 'modified))
                  head tree head-tree)
              (unless (git-empty-db-p)
                (setq head (git-rev-parse "HEAD")
                      head-tree (git-rev-parse "HEAD^{tree}")))
              (if files
                  (progn
                    (message "Running git commit...")
                    (when
                        (and
                         (git-read-tree head-tree index-file)
                         (git-update-index nil files)         ;update both the default index
                         (git-update-index index-file files)  ;and the temporary one
                         (setq tree (git-write-tree index-file)))
                      (if (or (not (string-equal tree head-tree))
                              (yes-or-no-p "The tree was not modified, do you really want to perform an empty commit? "))
                          (let ((commit (git-commit-tree buffer tree head)))
