From 5bb26c63843381d9b3dad7708970a93494d20b26 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 7 Oct 2019 21:29:12 -0700 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20commit=20when=20there=20are=20n?= =?UTF-8?q?o=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before trying to commit, run a ‘git diff’ to make sure there are any changes to commit. If this turns up empty no commit is attempted. --- NEWS | 6 ++++++ git-auto-commit-mode.el | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) 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