Add option to prevent new files from being added to git

Setting ‘gac-automatically-add-new-files-p’ to t will tell git-auto-commit-mode
not to try adding new files to the git repository.
This commit is contained in:
Tom Willemse 2019-12-10 21:39:06 -08:00
parent b0db5b841b
commit d8d9dab5d2
4 changed files with 49 additions and 16 deletions

2
NEWS
View file

@ -6,6 +6,8 @@
- Only try to commit when changes have been discovered in the file. By - 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 extension git-auto-commit-mode won't ask for a summary to a commit that it
won't make. won't make.
- Add option to prevent new (untracked) files from being added to the git
repository automatically, =gac-automatically-add-new-files-p=.
* v4.5.0 * v4.5.0

View file

@ -76,6 +76,10 @@
repository's ~HEAD~ to its default upstream. Setting up the repository's ~HEAD~ to its default upstream. Setting up the
upstream is the user's responsibility. 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.
- =gac-ask-for-summary-p= :: A boolean value indicating whether or not - =gac-ask-for-summary-p= :: A boolean value indicating whether or not
git-auto-commit-mode should ask the user for a commit message every time git-auto-commit-mode should ask the user for a commit message every time
a commit is made. *Note*: Since the summary is asked for before the commit, a commit is made. *Note*: Since the summary is asked for before the commit,

View file

@ -50,6 +50,12 @@ If non-nil a git push will be executed after each commit."
:risky t) :risky t)
(make-variable-buffer-local 'gac-automatically-push-p) (make-variable-buffer-local 'gac-automatically-push-p)
(defcustom gac-automatically-add-new-files-p t
"Should new (untracked) files automatically be committed to the repo?"
:tag "Automatically add new files"
:group 'git-auto-commit-mode
:type 'boolean)
(defcustom gac-ask-for-summary-p nil (defcustom gac-ask-for-summary-p nil
"Ask the user for a short summary each time a file is committed?" "Ask the user for a short summary each time a file is committed?"
:tag "Ask for a summary on each commit" :tag "Ask for a summary on each commit"
@ -185,7 +191,8 @@ should already have been set up."
(defun gac--after-save (buffer) (defun gac--after-save (buffer)
(unwind-protect (unwind-protect
(when (and (buffer-live-p buffer) (when (and (buffer-live-p buffer)
(or (not (gac--buffer-is-tracked buffer)) (or (and gac-automatically-add-new-files-p
(not (gac--buffer-is-tracked buffer)))
(gac--buffer-has-changes buffer))) (gac--buffer-has-changes buffer)))
(gac-commit buffer) (gac-commit buffer)
(with-current-buffer buffer (with-current-buffer buffer

View file

@ -28,21 +28,41 @@
(require 'git-auto-commit-mode) (require 'git-auto-commit-mode)
(describe "New files" (describe "New files"
(it "Should be added to git" (describe "When gac-automatically-add-new-files is t"
(let* ((temp-dir (make-temp-file "gac-" t)) (it "Should be added to git"
(temp-file (expand-file-name "test" temp-dir)) (let* ((gac-automatically-add-new-files-p t)
(default-directory temp-dir)) (temp-dir (make-temp-file "gac-" t))
(unwind-protect (temp-file (expand-file-name "test" temp-dir))
(progn (default-directory temp-dir))
(shell-command "git init") (unwind-protect
(let ((buffer (find-file-noselect temp-file))) (progn
(with-current-buffer buffer (shell-command "git init")
(git-auto-commit-mode) (let ((buffer (find-file-noselect temp-file)))
(insert "test") (with-current-buffer buffer
(save-buffer))) (git-auto-commit-mode)
(expect (shell-command-to-string "git log --format=format:%s") (insert "test")
:to-match (rx string-start "test" string-end))) (save-buffer)))
(delete-directory temp-dir t))))) (expect (shell-command-to-string "git log --format=format:%s")
:to-match (rx string-start "test" string-end)))
(delete-directory temp-dir t)))))
(describe "When gac-automatically-add-new-files is nil"
(it "Shouldnt be added to git"
(let* ((gac-automatically-add-new-files-p nil)
(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")
:not :to-match (rx string-start "test" string-end)))
(delete-directory temp-dir t))))))
(provide 'git-auto-commit-mode-tests) (provide 'git-auto-commit-mode-tests)
;;; git-auto-commit-mode-tests.el ends here ;;; git-auto-commit-mode-tests.el ends here