diff --git a/NEWS b/NEWS index 1409bfb..dc790b5 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ - 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. + - Add option to prevent new (untracked) files from being added to the git + repository automatically, =gac-automatically-add-new-files-p=. * v4.5.0 diff --git a/README.org b/README.org index 4fd5782..fc6a6e7 100644 --- a/README.org +++ b/README.org @@ -76,6 +76,10 @@ repository's ~HEAD~ to its default upstream. Setting up the 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 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, diff --git a/git-auto-commit-mode.el b/git-auto-commit-mode.el index 4fc6315..0bfdd6f 100644 --- a/git-auto-commit-mode.el +++ b/git-auto-commit-mode.el @@ -50,6 +50,12 @@ If non-nil a git push will be executed after each commit." :risky t) (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 "Ask the user for a short summary each time a file is committed?" :tag "Ask for a summary on each commit" @@ -185,7 +191,8 @@ should already have been set up." (defun gac--after-save (buffer) (unwind-protect (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-commit buffer) (with-current-buffer buffer diff --git a/tests/git-auto-commit-mode-tests.el b/tests/git-auto-commit-mode-tests.el index 8e7c291..fd40dce 100644 --- a/tests/git-auto-commit-mode-tests.el +++ b/tests/git-auto-commit-mode-tests.el @@ -28,21 +28,41 @@ (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))))) + (describe "When ‘gac-automatically-add-new-files’ is t" + (it "Should be added to git" + (let* ((gac-automatically-add-new-files-p t) + (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))))) + + (describe "When ‘gac-automatically-add-new-files’ is nil" + (it "Shouldn’t 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) ;;; git-auto-commit-mode-tests.el ends here