mirror of
https://github.com/git/git.git
synced 2024-11-19 00:14:12 +01:00
git.el: Update a file status in the git buffer upon save.
Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
9f5599b982
commit
0365d885ad
@ -36,7 +36,6 @@
|
|||||||
;; TODO
|
;; TODO
|
||||||
;; - portability to XEmacs
|
;; - portability to XEmacs
|
||||||
;; - better handling of subprocess errors
|
;; - better handling of subprocess errors
|
||||||
;; - hook into file save (after-save-hook)
|
|
||||||
;; - diff against other branch
|
;; - diff against other branch
|
||||||
;; - renaming files from the status buffer
|
;; - renaming files from the status buffer
|
||||||
;; - creating tags
|
;; - creating tags
|
||||||
@ -1352,9 +1351,24 @@ Commands:
|
|||||||
(cd dir)
|
(cd dir)
|
||||||
(git-status-mode)
|
(git-status-mode)
|
||||||
(git-refresh-status)
|
(git-refresh-status)
|
||||||
(goto-char (point-min)))
|
(goto-char (point-min))
|
||||||
|
(add-hook 'after-save-hook 'git-update-saved-file))
|
||||||
(message "%s is not a git working tree." dir)))
|
(message "%s is not a git working tree." dir)))
|
||||||
|
|
||||||
|
(defun git-update-saved-file ()
|
||||||
|
"Update the corresponding git-status buffer when a file is saved.
|
||||||
|
Meant to be used in `after-save-hook'."
|
||||||
|
(let* ((file (expand-file-name buffer-file-name))
|
||||||
|
(dir (condition-case nil (git-get-top-dir (file-name-directory file))))
|
||||||
|
(buffer (and dir (git-find-status-buffer dir))))
|
||||||
|
(when buffer
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(let ((filename (file-relative-name file dir)))
|
||||||
|
; skip files located inside the .git directory
|
||||||
|
(unless (string-match "^\\.git/" filename)
|
||||||
|
(git-call-process-env nil nil "add" "--refresh" "--" filename)
|
||||||
|
(git-update-status-files (list filename) 'uptodate)))))))
|
||||||
|
|
||||||
(defun git-help ()
|
(defun git-help ()
|
||||||
"Display help for Git mode."
|
"Display help for Git mode."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
Loading…
Reference in New Issue
Block a user