Setup auto pull to run in a before-save-hook
This commit is contained in:
parent
6fc4b1e994
commit
cc78719844
1 changed files with 30 additions and 10 deletions
|
@ -8,6 +8,9 @@
|
||||||
;; Keywords: vc
|
;; Keywords: vc
|
||||||
;; URL: https://github.com/ryuslash/git-auto-commit-mode
|
;; URL: https://github.com/ryuslash/git-auto-commit-mode
|
||||||
|
|
||||||
|
;; Updates by: Kyle Harrington <emacs@kyleharrington.com>
|
||||||
|
;; Updated: Sept 22, 2021
|
||||||
|
|
||||||
;; This file is free software; you can redistribute it and/or
|
;; This file is free software; you can redistribute it and/or
|
||||||
;; modify it under the terms of the GNU General Public License
|
;; modify it under the terms of the GNU General Public License
|
||||||
;; as published by the Free Software Foundation; either version 3
|
;; as published by the Free Software Foundation; either version 3
|
||||||
|
@ -215,7 +218,7 @@ should already have been set up."
|
||||||
|
|
||||||
This doesn't check or ask for a remote, so the correct remote
|
This doesn't check or ask for a remote, so the correct remote
|
||||||
should already have been set up."
|
should already have been set up."
|
||||||
;; gac-pull is currently only called from gac--after-save, where it is wrapped
|
;; gac-pull is currently only called from gac--before-save, where it is wrapped
|
||||||
;; in with-current-buffer, which should already take care of
|
;; in with-current-buffer, which should already take care of
|
||||||
;; default-directory. The explicit binding here is defensive, in case gac-pull
|
;; default-directory. The explicit binding here is defensive, in case gac-pull
|
||||||
;; starts being used elsewhere.
|
;; starts being used elsewhere.
|
||||||
|
@ -261,11 +264,6 @@ should already have been set up."
|
||||||
(or (and gac-automatically-add-new-files-p
|
(or (and gac-automatically-add-new-files-p
|
||||||
(not (gac--buffer-is-tracked buffer)))
|
(not (gac--buffer-is-tracked buffer)))
|
||||||
(gac--buffer-has-changes buffer)))
|
(gac--buffer-has-changes buffer)))
|
||||||
(with-current-buffer buffer
|
|
||||||
;; with-current-buffer required here because gac-automatically-pull-p
|
|
||||||
;; is buffer-local
|
|
||||||
(when gac-automatically-pull-p
|
|
||||||
(gac-pull buffer)))
|
|
||||||
(gac-commit buffer)
|
(gac-commit buffer)
|
||||||
(with-current-buffer buffer
|
(with-current-buffer buffer
|
||||||
;; with-current-buffer required here because gac-automatically-push-p
|
;; with-current-buffer required here because gac-automatically-push-p
|
||||||
|
@ -274,10 +272,24 @@ should already have been set up."
|
||||||
(gac-push buffer))))
|
(gac-push buffer))))
|
||||||
(remhash buffer gac--debounce-timers)))
|
(remhash buffer gac--debounce-timers)))
|
||||||
|
|
||||||
|
(defun gac--before-save (buffer)
|
||||||
|
(unwind-protect
|
||||||
|
(when (and (buffer-live-p buffer)
|
||||||
|
(or (and gac-automatically-add-new-files-p
|
||||||
|
(not (gac--buffer-is-tracked buffer)))
|
||||||
|
(gac--buffer-has-changes buffer)))
|
||||||
|
(with-current-buffer buffer
|
||||||
|
;; with-current-buffer required here because gac-automatically-pull-p
|
||||||
|
;; is buffer-local
|
||||||
|
(when gac-automatically-pull-p
|
||||||
|
(gac-pull buffer))))
|
||||||
|
(remhash buffer gac--debounce-timers)))
|
||||||
|
|
||||||
(defun gac-kill-buffer-hook ()
|
(defun gac-kill-buffer-hook ()
|
||||||
(when (and gac-debounce-interval
|
(when (and gac-debounce-interval
|
||||||
gac--debounce-timers
|
gac--debounce-timers
|
||||||
(gethash (current-buffer) gac--debounce-timers))
|
(gethash (current-buffer) gac--debounce-timers))
|
||||||
|
(gac--before-save (current-buffer))
|
||||||
(gac--after-save (current-buffer))))
|
(gac--after-save (current-buffer))))
|
||||||
|
|
||||||
(add-hook 'kill-buffer-hook #'gac-kill-buffer-hook)
|
(add-hook 'kill-buffer-hook #'gac-kill-buffer-hook)
|
||||||
|
@ -285,21 +297,29 @@ should already have been set up."
|
||||||
(defun gac-after-save-func ()
|
(defun gac-after-save-func ()
|
||||||
"Commit the current file.
|
"Commit the current file.
|
||||||
|
|
||||||
When `gac-automatically-pull-p' is non-nil also pull.
|
|
||||||
|
|
||||||
When `gac-automatically-push-p' is non-nil also push."
|
When `gac-automatically-push-p' is non-nil also push."
|
||||||
(if gac-debounce-interval
|
(if gac-debounce-interval
|
||||||
(gac--debounced-save)
|
(gac--debounced-save)
|
||||||
(gac--after-save (current-buffer))))
|
(gac--after-save (current-buffer))))
|
||||||
|
|
||||||
|
(defun gac-before-save-func ()
|
||||||
|
"Commit the current file.
|
||||||
|
|
||||||
|
When `gac-automatically-pull-p' is non-nil also pull."
|
||||||
|
(gac--before-save (current-buffer)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode git-auto-commit-mode
|
(define-minor-mode git-auto-commit-mode
|
||||||
"Automatically commit any changes made when saving with this
|
"Automatically commit any changes made when saving with this
|
||||||
mode turned on, optionally pull and push them too."
|
mode turned on, optionally pull and push them too."
|
||||||
:lighter " ga"
|
:lighter " ga"
|
||||||
(if git-auto-commit-mode
|
(if git-auto-commit-mode
|
||||||
(add-hook 'after-save-hook 'gac-after-save-func t t)
|
(progn
|
||||||
(remove-hook 'after-save-hook 'gac-after-save-func t)))
|
(add-hook 'before-save-hook 'gac-before-save-func t t)
|
||||||
|
(add-hook 'after-save-hook 'gac-after-save-func t t))
|
||||||
|
(progn
|
||||||
|
(remove-hook 'before-save-hook 'gac-before-save-func t)
|
||||||
|
(remove-hook 'after-save-hook 'gac-after-save-func t))))
|
||||||
|
|
||||||
(provide 'git-auto-commit-mode)
|
(provide 'git-auto-commit-mode)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue