diff --git a/git-status.el b/git-status.el index b2c1a258..6dace2b1 100644 --- a/git-status.el +++ b/git-status.el @@ -149,7 +149,7 @@ (suppress-keymap gits-keymap) (define-key gits-keymap (kbd "g") 'git-status) (define-key gits-keymap (kbd "S") 'git-stage-all) - (define-key gits-keymap (kbd "a") 'gits-add-thing-at-point) + (define-key gits-keymap (kbd "a") 'gits-stage-thing-at-point) (define-key gits-keymap (kbd "u") 'gits-unstage-thing-at-point) (define-key gits-keymap (kbd "i") 'gits-ignore-thing-at-point) (define-key gits-keymap (kbd "RET") 'gits-visit-thing-at-point) @@ -250,11 +250,14 @@ ;;; Staging +(defun gits-write-diff-patch (info file) + (write-region (elt info 1) (elt info 2) file)) + (defun gits-write-hunk-patch (info file) (write-region (elt info 1) (elt info 2) file) (write-region (elt info 3) (elt info 4) file t)) -(defun gits-add-thing-at-point () +(defun gits-stage-thing-at-point () (interactive) (let ((info (get-char-property (point) 'gits-info))) (if info @@ -263,6 +266,9 @@ (gits-run "git" "add" (cadr info))) ((hunk) (gits-write-hunk-patch info ".git/gits-tmp") + (gits-run "git" "apply" "--cached" ".git/gits-tmp")) + ((diff) + (gits-write-diff-patch info ".git/gits-tmp") (gits-run "git" "apply" "--cached" ".git/gits-tmp")))))) (defun gits-unstage-thing-at-point () @@ -272,6 +278,9 @@ (case (car info) ((hunk) (gits-write-hunk-patch info ".git/gits-tmp") + (gits-run "git" "apply" "--cached" "--reverse" ".git/gits-tmp")) + ((diff) + (gits-write-diff-patch info ".git/gits-tmp") (gits-run "git" "apply" "--cached" "--reverse" ".git/gits-tmp")))))) (defun gits-ignore-thing-at-point ()