Fix new files not being committed
When deciding if a file should be committed or not, also check to see if the file has been committed before.
This commit is contained in:
parent
2f05046731
commit
b0db5b841b
4 changed files with 65 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
.cask/
|
||||
git-auto-commit-mode.elc
|
||||
|
|
5
Cask
Normal file
5
Cask
Normal file
|
@ -0,0 +1,5 @@
|
|||
(source gnu)
|
||||
(source melpa)
|
||||
|
||||
(development
|
||||
(depends-on "buttercup"))
|
|
@ -164,6 +164,15 @@ should already have been set up."
|
|||
actual-buffer)
|
||||
gac--debounce-timers))))
|
||||
|
||||
(defun gac--buffer-is-tracked (buffer)
|
||||
"Check to see if BUFFER’s file is tracked in git."
|
||||
(let ((file-name (convert-standard-filename
|
||||
(file-name-nondirectory
|
||||
(buffer-file-name buffer)))))
|
||||
(not (string=
|
||||
(shell-command-to-string (concat "git ls-files " file-name))
|
||||
""))))
|
||||
|
||||
(defun gac--buffer-has-changes (buffer)
|
||||
"Check to see if there is any change in BUFFER."
|
||||
(let ((file-name (convert-standard-filename
|
||||
|
@ -176,7 +185,8 @@ should already have been set up."
|
|||
(defun gac--after-save (buffer)
|
||||
(unwind-protect
|
||||
(when (and (buffer-live-p buffer)
|
||||
(gac--buffer-has-changes buffer))
|
||||
(or (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
|
||||
|
|
48
tests/git-auto-commit-mode-tests.el
Normal file
48
tests/git-auto-commit-mode-tests.el
Normal file
|
@ -0,0 +1,48 @@
|
|||
;;; git-auto-commit-mode-tests.el --- Tests for git-auto-commit-mode -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2019 Tom Willemse
|
||||
|
||||
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||
;; Keywords:
|
||||
|
||||
;; This program 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 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'buttercup)
|
||||
(require 'git-auto-commit-mode)
|
||||
|
||||
(describe "New files"
|
||||
(it "Should be added to git"
|
||||
(let* ((temp-dir (make-temp-file "gac-" t))
|
||||
(temp-file (expand-file-name "test" temp-dir))
|
||||
(default-directory temp-dir))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(shell-command "git init")
|
||||
(let ((buffer (find-file-noselect temp-file)))
|
||||
(with-current-buffer buffer
|
||||
(git-auto-commit-mode)
|
||||
(insert "test")
|
||||
(save-buffer)))
|
||||
(expect (shell-command-to-string "git log --format=format:%s")
|
||||
:to-match (rx string-start "test" string-end)))
|
||||
(delete-directory temp-dir t)))))
|
||||
|
||||
(provide 'git-auto-commit-mode-tests)
|
||||
;;; git-auto-commit-mode-tests.el ends here
|
Loading…
Reference in a new issue