@@ -208,6 +208,15 @@ and returns the process output as a string, or nil if the git failed."
208208 (and (eq 0 (apply #' git-call-process-env t env args))
209209 (buffer-string ))))
210210
211+ (defun git-call-process-string-display-error (&rest args )
212+ " Wrapper for call-process that displays error message and returns
213+ the process output as a string, or nil if the git command failed."
214+ (with-temp-buffer
215+ (if (eq 0 (apply #'git-call-process-env (list t t ) nil args))
216+ (buffer-string )
217+ (display-message-or-buffer (current-buffer ))
218+ nil )))
219+
211220(defun git-run-process-region (buffer start end program args )
212221 " Run a git process with a buffer region as input."
213222 (let ((output-buffer (current-buffer ))
@@ -391,14 +400,16 @@ and returns the process output as a string, or nil if the git failed."
391400
392401(defun git-read-tree (tree &optional index-file )
393402 " Read a tree into the index file."
394- (apply # 'git-call- process-env nil
395- (if index-file `(( " GIT_INDEX_FILE" . , index-file )) nil )
396- " read-tree" (if tree (list tree))))
403+ (let (( process-environment
404+ (append ( and index-file ( list ( concat " GIT_INDEX_FILE= " index-file))) process-environment)) )
405+ ( apply 'git-call-process-display-error " read-tree" (if tree (list tree) ))))
397406
398407(defun git-write-tree (&optional index-file )
399408 " Call git-write-tree and return the resulting tree SHA1 as a string."
400- (git-get-string-sha1
401- (git-call-process-env-string (and index-file `((" GIT_INDEX_FILE" . , index-file ))) " write-tree" )))
409+ (let ((process-environment
410+ (append (and index-file (list (concat " GIT_INDEX_FILE=" index-file))) process-environment)))
411+ (git-get-string-sha1
412+ (git-call-process-string-display-error " write-tree" ))))
402413
403414(defun git-commit-tree (buffer tree head )
404415 " Call git-commit-tree with buffer as input and return the resulting commit SHA1."
@@ -824,19 +835,18 @@ Return the list of files that haven't been handled."
824835
825836(defun git-update-index (index-file files )
826837 " Run git-update-index on a list of files."
827- (let ((env (and index-file `((" GIT_INDEX_FILE" . , index-file ))))
838+ (let ((process-environment (append (and index-file (list (concat " GIT_INDEX_FILE=" index-file)))
839+ process-environment))
828840 added deleted modified)
829841 (dolist (info files )
830842 (case (git-fileinfo->state info)
831843 ('added (push info added))
832844 ('deleted (push info deleted))
833845 ('modified (push info modified))))
834- (when added
835- (apply #'git-call-process-env nil env " update-index" " --add" " --" (git-get-filenames added)))
836- (when deleted
837- (apply #'git-call-process-env nil env " update-index" " --remove" " --" (git-get-filenames deleted)))
838- (when modified
839- (apply #'git-call-process-env nil env " update-index" " --" (git-get-filenames modified)))))
846+ (and
847+ (or (not added) (apply #'git-call-process-display-error " update-index" " --add" " --" (git-get-filenames added)))
848+ (or (not deleted) (apply #'git-call-process-display-error " update-index" " --remove" " --" (git-get-filenames deleted)))
849+ (or (not modified) (apply #'git-call-process-display-error " update-index" " --" (git-get-filenames modified))))))
840850
841851(defun git-run-pre-commit-hook ()
842852 " Run the pre-commit hook if any."
@@ -862,17 +872,19 @@ Return the list of files that haven't been handled."
862872 (message " You cannot commit unmerged files, resolve them first. " )
863873 (unwind-protect
864874 (let ((files (git-marked-files-state 'added 'deleted 'modified ))
865- head head-tree)
875+ head tree head-tree)
866876 (unless (git-empty-db-p)
867877 (setq head (git-rev-parse " HEAD" )
868878 head-tree (git-rev-parse " HEAD^{tree}" )))
869879 (if files
870880 (progn
871881 (message " Running git commit... " )
872- (git-read-tree head-tree index-file)
873- (git-update-index nil files ) ; update both the default index
874- (git-update-index index-file files ) ; and the temporary one
875- (let ((tree (git-write-tree index-file)))
882+ (when
883+ (and
884+ (git-read-tree head-tree index-file)
885+ (git-update-index nil files ) ; update both the default index
886+ (git-update-index index-file files ) ; and the temporary one
887+ (setq tree (git-write-tree index-file)))
876888 (if (or (not (string-equal tree head-tree))
877889 (yes-or-no-p " The tree was not modified, do you really want to perform an empty commit? " ))
878890 (let ((commit (git-commit-tree buffer tree head)))
0 commit comments