Skip to content

Commit

Permalink
Notice when git apply --check --cached returns an error.
Browse files Browse the repository at this point in the history
This is good for not letting you enter commit mode if you have
a patch that doesn't pass "git apply" for whatever reason, such
as introduction of trailing whitespace.
  • Loading branch information
dsedivec committed Apr 24, 2010
1 parent e2f112f commit 41ff312
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions gitsum.el
Expand Up @@ -93,21 +93,22 @@ A numeric argument serves as a repeat count."
(defun gitsum-commit ()
"Commit the patch as-is, asking for a commit message."
(interactive)
(shell-command-on-region (point-min) (point-max) "git apply --check --cached")
(let ((buffer (get-buffer-create "*gitsum-commit*"))
(dir default-directory))
(shell-command-on-region (point-min) (point-max) "(cat; git diff --cached) | git apply --stat" buffer)
(with-current-buffer buffer
(setq default-directory dir)
(goto-char (point-min))
(insert "\n")
(while (re-search-forward "^" nil t)
(replace-match "# " nil nil))
(forward-line 0)
(forward-char -1)
(delete-region (point) (point-max))
(goto-char (point-min)))
(log-edit 'gitsum-do-commit nil nil buffer)))
(when (zerop (shell-command-on-region (point-min) (point-max)
"git apply --check --cached"))
(let ((buffer (get-buffer-create "*gitsum-commit*"))
(dir default-directory))
(shell-command-on-region (point-min) (point-max) "(cat; git diff --cached) | git apply --stat" buffer)
(with-current-buffer buffer
(setq default-directory dir)
(goto-char (point-min))
(insert "\n")
(while (re-search-forward "^" nil t)
(replace-match "# " nil nil))
(forward-line 0)
(forward-char -1)
(delete-region (point) (point-max))
(goto-char (point-min)))
(log-edit 'gitsum-do-commit nil nil buffer))))

(defun gitsum-amend ()
"Amend the last commit."
Expand Down

0 comments on commit 41ff312

Please sign in to comment.