Compare commits

...

5 commits

Author SHA1 Message Date
a7b59acea6 Add newer Emacs versions to tests 2022-12-07 08:47:52 -08:00
50cb58b11d Make git a little quieter
On my system whenever I run the tests without specifying an initial branch name,
I get a lot of messages about setting the default branch name globally. This is
just noise for these tests, so this specifies a branch name manually to make it
go away.

The name ‘gac-test’ was chosen to make it clear that we're dealing with a
repository created specifically for ‘git-auto-commit-mode’ in case somehow a
repository gets left behind.
2022-12-07 08:38:01 -08:00
97d9392d51 Extract getting the latest commit message into a function
If the way to get the commit message ever changes, or needs more
post-processing, it's easy to be able to change it in just one place instead of
everywhere.
2022-12-07 07:28:22 -08:00
7b628c0ce0 Add a few tests for the ‘gac-default-message’ variable 2022-12-07 07:23:51 -08:00
a6b6e0fa18 Add note about how to set the customization options 2020-11-17 18:27:41 -08:00
3 changed files with 68 additions and 4 deletions

View file

@ -10,6 +10,8 @@ jobs:
matrix:
emacs_version:
- '26.3'
- '27.2'
- '28.2'
- 'snapshot'
include:
- emacs_version: 'snapshot'

View file

@ -114,3 +114,23 @@
A boolean value indicating whether to display the commit summary message,
which is usually displayed in the minibuffer. The default is ~nil~, meaning
that the summary would be displayed on every commit.
To set any of these options, you can:
- Use the customization interface (~M-x customize-group git-auto-commit-mode~).
- Set the defaults in your Emacs initialization file using:
#+begin_src emacs-lisp
(setq-default gac-ask-for-summary-p t)
#+end_src
- Set values in a hook:
#+begin_src emacs-lisp
(defun set-my-settings ()
(setq gac-automatically-push-p t))
(add-hook 'org-mode-hook 'set-my-settings)
#+end_src
- Set values in a ~.dir-locals.el~ (see [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html#Directory-Variables][Per-Directory Local Variables]]):
#+begin_src emacs-lisp
((nil . ((gac-shell-and . " ; and "))))
#+end_src

View file

@ -27,6 +27,10 @@
(require 'buttercup)
(require 'git-auto-commit-mode)
(defun git-auto-commit-mode-tests--get-last-commit-message ()
"Get the last commit message from git."
(shell-command-to-string "git log --format=format:%s"))
(describe "In a git repository"
:var (temp-dir current-directory)
@ -34,7 +38,7 @@
(setq temp-dir (make-temp-file "gac-" t)
current-directory default-directory
default-directory temp-dir)
(shell-command "git init")
(shell-command "git init --initial-branch=gac-test")
(shell-command "git config user.email user@example.com")
(shell-command "git config user.name \"User Example\""))
@ -55,7 +59,7 @@
(insert "test")
(save-buffer))
(expect (shell-command-to-string "git log --format=format:%s")
(expect (git-auto-commit-mode-tests--get-last-commit-message)
:to-match (rx string-start "test" string-end)))))
(describe "When gac-automatically-add-new-files is nil"
@ -68,7 +72,7 @@
(insert "test")
(save-buffer))
(expect (shell-command-to-string "git log --format=format:%s")
(expect (git-auto-commit-mode-tests--get-last-commit-message)
:not :to-match (rx string-start "test" string-end))))))
(describe "Getting a relative path"
@ -140,7 +144,45 @@
(save-buffer))
(expect (gac-relative-file-name temp-file)
:to-equal "[test-test.txt")))))
:to-equal "[test-test.txt"))))
(describe "Getting a commit message"
(it "should default to the relative file name"
(let* ((temp-file (expand-file-name "test.txt" temp-dir))
(buffer (find-file-noselect temp-file)))
(with-current-buffer buffer
(git-auto-commit-mode)
(insert "test")
(save-buffer))
(expect (git-auto-commit-mode-tests--get-last-commit-message)
:to-equal "test.txt")))
(it "should use the message specified in gac-default-message"
(let* ((temp-file (expand-file-name "test.txt" temp-dir))
(buffer (find-file-noselect temp-file))
(gac-default-message "I made a commit!"))
(with-current-buffer buffer
(git-auto-commit-mode)
(insert "test")
(save-buffer))
(expect (git-auto-commit-mode-tests--get-last-commit-message)
:to-equal "I made a commit!")))
(it "should use the function result if gac-default-message is a function"
(let* ((temp-file (expand-file-name "test.txt" temp-dir))
(buffer (find-file-noselect temp-file))
(gac-default-message
(lambda (f)
(concat "wip " (gac-relative-file-name f)))))
(with-current-buffer buffer
(git-auto-commit-mode)
(insert "test")
(save-buffer))
(expect (git-auto-commit-mode-tests--get-last-commit-message)
:to-equal "wip test.txt")))))
(provide 'git-auto-commit-mode-tests)
;;; git-auto-commit-mode-tests.el ends here