Don’t commit when there are no changes
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.
This commit is contained in:
parent
3db70af7d3
commit
5bb26c6384
2 changed files with 17 additions and 1 deletions
6
NEWS
6
NEWS
|
@ -1,6 +1,12 @@
|
||||||
# -*- mode: org; -*-
|
# -*- mode: org; -*-
|
||||||
#+STARTUP: showall
|
#+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
|
* v4.5.0
|
||||||
|
|
||||||
- Support the fish shell through the ~gac-shell-and~ option.
|
- Support the fish shell through the ~gac-shell-and~ option.
|
||||||
|
|
|
@ -164,9 +164,19 @@ should already have been set up."
|
||||||
actual-buffer)
|
actual-buffer)
|
||||||
gac--debounce-timers))))
|
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)
|
(defun gac--after-save (buffer)
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(when (buffer-live-p buffer)
|
(when (and (buffer-live-p buffer)
|
||||||
|
(gac--buffer-has-changes 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
|
||||||
|
|
Loading…
Reference in a new issue