Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

* NAME

git-auto-commit-mode - Emacs minor mode to automatically commit (and
git-auto-commit-mode - Emacs minor mode to automatically commit (and pull and
push) a git repository.

[[http://melpa.org/#/git-auto-commit-mode][file:http://melpa.org/packages/git-auto-commit-mode-badge.svg]]
Expand All @@ -26,6 +26,8 @@
When enabled, git-auto-commit-mode uses the =after-save-hook= to
commit changes to git each time. If =gac-automatically-push-p= is
non-nil it also tries to push the ~HEAD~ to the current upstream.
If =gac-automatically-pull-p= is
non-nil it also tries to pull the ~HEAD~ to the current upstream.
Making sure that upstream is properly set is the responsibility of
the user.

Expand Down Expand Up @@ -82,6 +84,11 @@
push the git repository's ~HEAD~ to its default upstream. Setting up the
upstream is the user's responsibility.

- =gac-automatically-pull-p= ::
A boolean value indicating whether or not git-auto-commit-mode should try to
pull the git repository's ~HEAD~ from its default upstream. Setting up the
upstream is the user's responsibility.

- =gac-automatically-add-new-files-p= ::
A boolean value indicating whether or not git-auto-commit-mode should add
new (untracked) files to the repository.
Expand Down
52 changes: 43 additions & 9 deletions git-auto-commit-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
;; Keywords: vc
;; URL: https://github.com/ryuslash/git-auto-commit-mode

;; Updates by: Kyle Harrington <[email protected]>
;; Updated: Sept 22, 2021

;; This file is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
Expand All @@ -29,6 +32,9 @@
;; When `gac-automatically-push-p' is non-nil, it also tries to push
;; to the current upstream.

;; When `gac-automatically-pull-p' is non-nil, it also tries to pull
;; from the current upstream.

;; When `gac-debounce-interval' is non-nil and set to a number
;; representing seconds, it will only perform Git actions at that
;; interval. That way, repeatedly saving a file will not hammer the
Expand All @@ -52,6 +58,16 @@ If non-nil a git push will be executed after each commit."
:risky t)
(make-variable-buffer-local 'gac-automatically-push-p)

(defcustom gac-automatically-pull-p nil
"Automatically pull before each commit.

If non-nil a git pull will be executed before each commit."
:tag "Automatically pull"
:group 'git-auto-commit-mode
:type 'boolean
:risky t)
(make-variable-buffer-local 'gac-automatically-pull-p)

(defcustom gac-automatically-add-new-files-p t
"Should new (untracked) files automatically be committed to the repo?"
:tag "Automatically add new files"
Expand Down Expand Up @@ -193,9 +209,21 @@ should already have been set up."
;; default-directory. The explicit binding here is defensive, in case gac-push
;; starts being used elsewhere.
(let ((default-directory (file-name-directory (buffer-file-name buffer))))
(let ((proc (start-process "git" "*git-auto-push*" "git" "push")))
(set-process-sentinel proc 'gac-process-sentinel)
(set-process-filter proc 'gac-process-filter))))
(call-process "git" nil "*git-auto-push*" nil "push")))

(defun gac-pull (buffer)
"Pull commits from the current upstream.
This doesn't check or ask for a remote, so the correct remote
should already have been set up."
;; gac-pull is currently only called from gac--after-save, where it is wrapped
;; in with-current-buffer, which should already take care of
;; default-directory. The explicit binding here is defensive, in case gac-pull
;; starts being used elsewhere.
(let ((default-directory (file-name-directory (buffer-file-name buffer))))
(call-process "git" nil "*git-auto-pull*" nil "merge" "--squash")
(call-process "git" nil "*git-auto-pull*" nil "commit" "--no-edit")
(call-process "git" nil "*git-auto-pull*" nil "pull" "--rebase")))


(defvar gac--debounce-timers (make-hash-table :test #'equal))

Expand Down Expand Up @@ -234,11 +262,17 @@ should already have been set up."
(not (gac--buffer-is-tracked buffer)))
(gac--buffer-has-changes buffer)))
(gac-commit buffer)
(with-current-buffer buffer
;; with-current-buffer required here because gac-automatically-push-p
;; is buffer-local
(when gac-automatically-push-p
(gac-push buffer))))
(make-thread
(lambda ()
(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))
;; with-current-buffer required here because gac-automatically-push-p
;; is buffer-local
(when gac-automatically-push-p
(gac-push buffer))))))
(remhash buffer gac--debounce-timers)))

(defun gac-kill-buffer-hook ()
Expand All @@ -260,7 +294,7 @@ When `gac-automatically-push-p' is non-nil also push."
;;;###autoload
(define-minor-mode git-auto-commit-mode
"Automatically commit any changes made when saving with this
mode turned on and optionally push them too."
mode turned on, optionally pull and push them too."
:lighter " ga"
(if git-auto-commit-mode
(add-hook 'after-save-hook 'gac-after-save-func t t)
Expand Down