git.el: Make git-run-command-region display the error if any.

This makes it easier to figure out why a commit has failed.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard
2008-11-23 16:12:45 +01:00
parent ab69e3e43a
commit a7da5c4259

View File

@ -220,7 +220,7 @@ the process output as a string, or nil if the git command failed."
(with-current-buffer buffer (with-current-buffer buffer
(cd dir) (cd dir)
(apply #'call-process-region start end program (apply #'call-process-region start end program
nil (list output-buffer nil) nil args)))) nil (list output-buffer t) nil args))))
(defun git-run-command-buffer (buffer-name &rest args) (defun git-run-command-buffer (buffer-name &rest args)
"Run a git command, sending the output to a buffer named BUFFER-NAME." "Run a git command, sending the output to a buffer named BUFFER-NAME."
@ -237,13 +237,15 @@ the process output as a string, or nil if the git command failed."
(defun git-run-command-region (buffer start end env &rest args) (defun git-run-command-region (buffer start end env &rest args)
"Run a git command with specified buffer region as input." "Run a git command with specified buffer region as input."
(unless (eq 0 (if env (with-temp-buffer
(git-run-process-region (if (eq 0 (if env
buffer start end "env"
(append (git-get-env-strings env) (list "git") args))
(git-run-process-region (git-run-process-region
buffer start end "git" args))) buffer start end "env"
(error "Failed to run \"git %s\":\n%s" (mapconcat (lambda (x) x) args " ") (buffer-string)))) (append (git-get-env-strings env) (list "git") args))
(git-run-process-region buffer start end "git" args)))
(buffer-string)
(display-message-or-buffer (current-buffer))
nil)))
(defun git-run-hook (hook env &rest args) (defun git-run-hook (hook env &rest args)
"Run a git hook and display its output if any." "Run a git hook and display its output if any."
@ -456,18 +458,16 @@ Each entry is a cons of (SHORT-NAME . FULL-NAME)."
(setq coding-system-for-write buffer-file-coding-system)) (setq coding-system-for-write buffer-file-coding-system))
(let ((commit (let ((commit
(git-get-string-sha1 (git-get-string-sha1
(with-output-to-string (let ((env `(("GIT_AUTHOR_NAME" . ,author-name)
(with-current-buffer standard-output ("GIT_AUTHOR_EMAIL" . ,author-email)
(let ((env `(("GIT_AUTHOR_NAME" . ,author-name) ("GIT_COMMITTER_NAME" . ,(git-get-committer-name))
("GIT_AUTHOR_EMAIL" . ,author-email) ("GIT_COMMITTER_EMAIL" . ,(git-get-committer-email)))))
("GIT_COMMITTER_NAME" . ,(git-get-committer-name)) (when author-date (push `("GIT_AUTHOR_DATE" . ,author-date) env))
("GIT_COMMITTER_EMAIL" . ,(git-get-committer-email))))) (apply #'git-run-command-region
(when author-date (push `("GIT_AUTHOR_DATE" . ,author-date) env)) buffer log-start log-end env
(apply #'git-run-command-region "commit-tree" tree (nreverse args))))))
buffer log-start log-end env (when commit (git-update-ref "HEAD" commit head subject))
"commit-tree" tree (nreverse args)))))))) commit)))
(and (git-update-ref "HEAD" commit head subject)
commit))))
(defun git-empty-db-p () (defun git-empty-db-p ()
"Check if the git db is empty (no commit done yet)." "Check if the git db is empty (no commit done yet)."