diff --git a/NEWS b/NEWS index cd903a6..1409bfb 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,12 @@ # -*- mode: org; -*- #+STARTUP: showall +* Unreleased + + - Only try to commit when changes have been discovered in the file. By + extension git-auto-commit-mode won't ask for a summary to a commit that it + won't make. + * v4.5.0 - Support the fish shell through the ~gac-shell-and~ option. diff --git a/git-auto-commit-mode.el b/git-auto-commit-mode.el index 917b748..33ffa1a 100644 --- a/git-auto-commit-mode.el +++ b/git-auto-commit-mode.el @@ -164,9 +164,19 @@ should already have been set up." actual-buffer) gac--debounce-timers)))) +(defun gac--buffer-has-changes (buffer) + "Check to see if there is any change in BUFFER." + (let ((file-name (convert-standard-filename + (file-name-nondirectory + (buffer-file-name buffer))))) + (not (string= + (shell-command-to-string (concat "git diff " file-name)) + "")))) + (defun gac--after-save (buffer) (unwind-protect - (when (buffer-live-p buffer) + (when (and (buffer-live-p buffer) + (gac--buffer-has-changes buffer)) (gac-commit buffer) (with-current-buffer buffer ;; with-current-buffer required here because gac-automatically-push-p