Compare commits

...

61 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
df07899acd Bump version, update news 2020-08-27 23:53:52 -07:00
d4fd943206 Make use of the ‘:var’ and ‘before|after-each’ forms of buttercup
This removes a bit of boiler-plate code from the tests, hopefully making them
easier to read and write.
2020-08-18 23:54:59 -07:00
e2c939cb8e Rename test setup function
I’d like to rename other functions as well, but especially with the commands and
variables I’m afraid of breaking configurations. I don’t have to worry about
that so much yet with the test functions.
2020-08-18 23:32:07 -07:00
23abaff792 Add github workflow that runs buttercup on push and pull requests 2020-08-18 22:08:58 -07:00
Oleg Pykhalov
2d48b8296d
Configure Git in tests 2020-08-18 22:05:01 +03:00
5755d36c03 Fix issue with having ‘[’ in the path
Having a ‘[’ messed up the regular expression used because it wasn’t being
properly escaped.
2020-08-01 00:48:44 -07:00
Adel Qalieh
14e4def248 Add option to have it be completely silent when committing 2020-07-05 10:28:19 -04:00
Adel Qalieh
2c0488869a Add config to add flags for git commit command and document both 2020-07-05 10:23:45 -04:00
Matthew McClure
dd0c2441de
Replace 404 URL with github.com page 2020-03-22 16:07:48 -04:00
ae69e61233 Bump version 2020-02-17 15:48:12 -08:00
106fc3c8b4 Update contributing instructions 2020-01-12 17:56:17 -08:00
6f7b58f866 Merge remote-tracking branch 'ThibautVerron/Commit-msg' 2019-12-14 02:21:35 -08:00
Holger Wenzel
aff67aa36d added flag for git add command 2019-12-14 02:10:38 -08:00
4cfc906cb4 Expand explanation of directory-local variables 2019-12-10 21:46:05 -08:00
3e5fab83a5 Update README.org to follow new org-mode indentation
org-mode 9.3 started indenting description lists as normal, this commit makes
the README.org follow that indentation.
2019-12-10 21:41:51 -08:00
d8d9dab5d2 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.
2019-12-10 21:39:06 -08:00
b0db5b841b 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.
2019-12-10 21:18:17 -08:00
Thibaut Verron
24c8e7b0fe Add setting for changing the default message 2019-11-21 13:10:05 +01:00
Thibaut Verron
ea3b5c0d91 Auto commit: /home/guests/verron/Development/git-auto-commit-mode/git-auto-commit-mode.el 2019-11-21 13:08:30 +01:00
Thibaut Verron
392ca73178 Auto commit: /home/guests/verron/Development/git-auto-commit-mode/git-auto-commit-mode.el 2019-11-21 13:07:48 +01:00
Thibaut Verron
a597d6920a git-auto-commit-mode.el 2019-11-21 13:04:33 +01:00
Thibaut Verron
4a8a7e0271 git-auto-commit-mode.el 2019-11-21 13:02:03 +01:00
2f05046731 Consistently apply the code markup to customization options 2019-10-07 21:34:53 -07:00
fc94d0df93 Document the behaviour of ‘C-g’ in the summary entry 2019-10-07 21:33:09 -07:00
5bb26c6384 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.
2019-10-07 21:29:12 -07:00
3db70af7d3 Update version to v4.5.0 2019-10-07 20:40:04 -07:00
23a0224a00 Update README 2019-10-07 20:37:02 -07:00
Constantine Vetoshev
e533166a22 Fix automatic Git push when used with debouncing. 2019-07-16 12:36:37 -07:00
Constantine Vetoshev
fa8865bf49 Fix whitespace. 2019-07-11 09:30:01 -07:00
Constantine Vetoshev
0ac5025766 Code review fixes. 2019-07-11 09:24:58 -07:00
Constantine Vetoshev
074739d78f Add support for commit debouncing.
This patch prevents frequent saves from making an excessively large number of
commits. With gac-debounce-interval (a buffer-specific variable) set to a number
representing seconds, buffers with git-auto-commit-mode active will only make
Git commits at the end of the given interval after a save. So with
gac-debounce-interval set to 300, a buffer will commit changes accumulated over
5 minutes, rather than at every save. It will also commit if the buffer is
killed.

This mode of operation can be made default with, e.g.:

    (setq-default gac-debounce-interval 300)
2018-06-22 21:57:16 -07:00
Stig Brautaset
2c8197e5d7 Support fish which uses "; and" rather than "&&" to join commands 2016-12-29 16:17:29 +00:00
075e5f9ded Bump version 2015-04-04 16:51:09 +02:00
b151584256 Update copyright and url headers 2015-04-04 16:49:15 +02:00
fa4e042f8d Update NEWS 2015-04-04 16:49:03 +02:00
7b370eeb37 Update README 2015-04-04 16:46:43 +02:00
9edaf8243d Cleanup git-commit slightly 2015-04-03 09:48:51 +02:00
858dc816f1 Merge remote-tracking branch 'owengriffin/windows-support' 2015-04-03 09:42:29 +02:00
Owen Griffin
acf6a60578 Wrap git commit message in shell-quote-argument 2015-04-02 22:52:31 +01:00
Owen Griffin
344667ee75 Use default-directory for git commit
- Uses double-quotes for commit message to support filenames with spaces
  on Windows
- file-name-nondirectory is necessary for Windows support, otherwise the
  drive name (C:\) is included in the path
2015-04-02 21:20:34 +01:00
Owen Griffin
ca96589764 Support Windows paths
- Changes the current directory before commit
- Quotes the filename arguments using shell-quote-argument
2015-04-01 21:30:21 +01:00
e7b3a146b8 Show MELPA badges in README 2015-03-21 15:19:02 +01:00
4685b7ee16 Bump version 2015-03-21 15:12:50 +01:00
c3f42d0635 Merge remote-tracking branch 'mbreit/quote-filename' 2015-03-21 15:04:15 +01:00
Moritz Breit
e11eb392c0 Quote filename for git add
Fixes git-auto-commit-mode for files with spaces in the filename.
2015-03-20 21:13:15 +01:00
7e4ed5f07a Bump version 2014-12-29 20:42:15 +01:00
0e8c5e8d3f Update NEWS 2014-12-29 20:39:28 +01:00
b36909ab64 Update copyright years 2014-12-29 20:38:59 +01:00
058c55cf2a Add option to ask for a summary
When this option is enabled, whenever a commit is about to be made a
summary of the commit's changes is asked of the user. If no summary is
given, or if the option is nil, use the relative file-name.
2014-12-29 20:33:50 +01:00
cbc62b2a88 Remove site-related files
New script generates site automatically.
2013-10-10 02:46:38 +02:00
17f8fa22a3 Update docstrings to fix checkdoc warnings 2013-10-07 23:59:21 +02:00
dbe05bed93 Change name 2013-10-07 23:59:05 +02:00
6d8c914b24 Bump version 2013-10-07 23:23:13 +02:00
995293de8f Merge branch 'geerds/provide-feature' 2013-10-07 23:19:24 +02:00
Jascha Geerds
8401b45a4f Provide "git-auto-commit-mode" feature 2013-10-07 21:03:19 +02:00
3ccf3fb624 Update version info
Should have been done before the last tag.
2013-04-10 01:57:21 +02:00
13 changed files with 537 additions and 177 deletions

27
.github/workflows/test.yml vendored Normal file
View file

@ -0,0 +1,27 @@
name: test
on:
push: {branches: [master]}
pull_request: {branches: [master]}
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
emacs_version:
- '26.3'
- '27.2'
- '28.2'
- 'snapshot'
include:
- emacs_version: 'snapshot'
allow_failure: true
steps:
- uses: actions/checkout@v2
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs_version }}
- uses: conao3/setup-cask@master
- name: Run tests
run: "cask && cask exec buttercup -L . || ${{ matrix.allow_failure == true }}"

1
.gitignore vendored
View file

@ -1 +1,2 @@
.cask/
git-auto-commit-mode.elc

View file

@ -1,25 +1,24 @@
# -*- mode: org; -*-
#+STARTUP: showall
If you wish to contribute you can use either the sources located on
[[http://code.ryuslash.org/cgit.cgi/emacs/git-auto-commit-mode/][ryuslash.org]] or the [[https://github.com/ryuslash/git-auto-commit-mode][github]] sources.
Please feel free to contribute. I welcome any help that you may offer. Whether
it's fixing typo's, updating the documentation, or fixing bugs or adding new
features.
* Getting the source
If you wish to work on git-auto-commit-mode you can get the sources
by cloning the repository:
If you wish to work on git-auto-commit-mode you can get the sources by cloning
the repository:
#+BEGIN_EXAMPLE
git clone git://ryuslash.org/emacs/git-auto-commit-mode.org
#+END_EXAMPLE
* Style
Use spaces, don't use tabs. If you can, keep lines shorter than 80
characters. Other than that, Emacs can handle indentation pretty
well.
Use spaces, don't use tabs. If you can, keep lines shorter than 80 characters.
Other than that, Emacs can handle indentation pretty well.
* Patches
If you want to send any patches I prefer an email with the output
generated by =git request-pull=, possibly with =-p=, over things like
github pull requests.
If you want to send any patches I'd be more than happy to merge them. Please
feel free to use Github pull requests, or any other means preferred by you.

5
Cask Normal file
View file

@ -0,0 +1,5 @@
(source gnu)
(source melpa)
(development
(depends-on "buttercup"))

48
NEWS
View file

@ -1,4 +1,52 @@
# -*- mode: org; -*-
#+STARTUP: showall
* v4.7.0
- Fix the URL package header, it was pointing at a non-existent page.
- Add user options =gac-commit-additional-flags=, and =gac-silent-message-p=.
- Fix an issue with having the =[= character somewhere in the path of the file.
* v4.6.0
- 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
- Support the fish shell through the ~gac-shell-and~ option.
- Support buffering commits within a certain time interval using the
~gac-debounce-interval~.
* v4.4.0
- Support Windows paths using =convert-standard-filename=.
- Properly escape command-line arguments when calling git with
=shell-quote-argument=.
- Explicitly bind =default-directory= when calling git.
* v4.3.2
- Bump version, oops I forgot to do this for 4.3.1.
* v4.3.1
- Fix committing files with spaces in their name.
* v4.3.0
- Add user option =gac-ask-for-summary-p=.
* v4.2.2
- =provide= a ~git-auto-commit-mode~ feature. (Thanks Jascha Geerds!)
* v4.2.1
- Fix some version number mistakes.
* v4.2.0

View file

@ -6,6 +6,9 @@
git-auto-commit-mode - Emacs minor mode to automatically commit (and
push) a git repository.
[[http://melpa.org/#/git-auto-commit-mode][file:http://melpa.org/packages/git-auto-commit-mode-badge.svg]]
[[http://stable.melpa.org/#/git-auto-commit-mode][file:http://stable.melpa.org/packages/git-auto-commit-mode-badge.svg]]
* SYNOPSIS
=M-x git-auto-commit-mode <RET>=
@ -46,6 +49,12 @@
*** As a directory-local variable
Create a ~.dir-locals.el~ file in the directory where you want
git-auto-commit-mode to be enabled. This will also apply to any
subdirectories, so be careful. For more information see the [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html#Directory-Variables][Per-Directory
Local Variables]] section in the Emacs manual. Then put one of the following
snippets of code in there:
If you're using Emacs 24 or newer you should set an =eval= variable:
#+BEGIN_EXAMPLE
((nil . ((eval git-auto-commit-mode 1))))
@ -68,7 +77,60 @@
git-auto-commit-mode is a simple mode, as such it offers little
customization.
- =gac-automatically-push-p= :: A boolean value indicating whether or
not git-auto-commit-mode should try to push the git
repository's ~HEAD~ to its default upstream. Setting up the
upstream is the user's responsibility.
- =gac-automatically-push-p= ::
A boolean value indicating whether or not git-auto-commit-mode should try to
push the git 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, but /after/ the file has been saved,
pressing ~C-g~ while entering the Summary will stop the commit from being
made, but not the file from being saved.
- =gac-shell-and= ::
A string that can be used to change how the shell combines commands. The
default " && " is good for bash-like shells, but " ; and " would be used for
fish, for example.
- =gac-debounce-interval= ::
A number specifying a buffer between automatic commits in seconds. Wait with
making an actual commit until this number of seconds elapses.
- =gac-add-additional-flag= ::
A string that can be used to add additional command line flags to the ~git
add~ command.
- =gac-commit-additional-flag= ::
A string that can be used to add additional command line flags to the ~git
commit~ command.
- =gac-silent-message-p= ::
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

@ -1,12 +1,12 @@
;;; git-auto-commit-mode.el --- Emacs Minor mode to automatically commit and push
;;; git-auto-commit-mode.el --- Emacs Minor mode to automatically commit and push -*- lexical-binding: t -*-
;; Copyright (C) 2012,2013 Tom Willemsen <tom@ryuslash.org>
;; Copyright (C) 2012, 2013, 2014, 2015 Tom Willemse <tom@ryuslash.org>
;; Author: Tom Willemsen <tom@ryuslash.org>
;; Author: Tom Willemse <tom@ryuslash.org>
;; Created: Jan 9, 2012
;; Version: 4.1
;; Version: 4.7.0
;; Keywords: vc
;; URL: http://org.ryuslash.org/projects/git-auto-commit-mode.html
;; URL: https://github.com/ryuslash/git-auto-commit-mode
;; This file is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
@ -29,35 +29,106 @@
;; When `gac-automatically-push-p' is non-nil, it also tries to push
;; to the current upstream.
;; When `gac-debounce-interval' is non-nil and set to a number
;; representing seconds, it will only perform Git actions at that
;; interval. That way, repeatedly saving a file will not hammer the
;; Git repository.
;;; Code:
(require 'subr-x)
(defgroup git-auto-commit-mode nil
"Customization options for `git-auto-commit-mode'."
:group 'external)
(defcustom gac-automatically-push-p nil
"Control whether or not `git-auto-commit-mode' should also
automatically push the changes committed after each save."
"Automatically push after each commit.
If non-nil a git push will be executed after each commit."
:tag "Automatically push"
:group 'git-auto-commit-mode
:type 'boolean
: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"
:group 'git-auto-commit-mode
:type 'boolean)
(defcustom gac-shell-and " && "
"How to join commands together in the shell. For fish shell,
you want to customise this to: \" ; and \" instead of the default."
:tag "Join shell commands"
:group 'git-auto-commit-mode
:type 'string)
(defcustom gac-add-additional-flag ""
"Flag to add to the git add command."
:tag "git add flag"
:group 'git-auto-commit-mode
:type 'string)
(defcustom gac-commit-additional-flag ""
"Flag to add to the git commit command."
:tag "git commit flag"
:group 'git-auto-commit-mode
:type 'string)
(defcustom gac-silent-message-p nil
"Should git output be output to the message area?"
:tag "Quiet message output"
:group 'git-auto-commit-mode
:type 'boolean)
(defcustom gac-debounce-interval nil
"Debounce automatic commits to avoid hammering Git.
If non-nil a commit will be scheduled to occur that many seconds
in the future. Note that this uses Emacs timer functionality, and
is subject to its limitations."
:tag "Debounce interval"
:group 'git-auto-commit-mode
:type '(choice (number :tag "Interval in seconds")
(const :tag "Off" nil)))
(make-variable-buffer-local 'gac-debounce-interval)
(defcustom gac-default-message nil
"Default message for automatic commits.
It can be:
- nil to use the default FILENAME
- a string which is used
- a function returning a string, called with FILENAME as
argument, in which case the result is used as commit message
"
:tag "Default commit message"
:group 'git-auto-commit-mode
:type '(choice (string :tag "Commit message")
(const :tag "Default: FILENAME" nil)
(function :tag "Function")))
(defun gac-relative-file-name (filename)
"Find the path to the filename relative to the git directory"
"Find the path to FILENAME relative to the git directory."
(let* ((git-dir
(replace-regexp-in-string
"\n+$" "" (shell-command-to-string
"git rev-parse --show-toplevel")))
(relative-file-name
(replace-regexp-in-string
"^/" "" (replace-regexp-in-string
git-dir "" filename))))
relative-file-name))
(string-trim-right
(shell-command-to-string "git rev-parse --show-toplevel"))))
(file-relative-name filename git-dir)))
(defun gac-password (proc string)
"Ask the user for a password when necessary."
"Ask the user for a password when necessary.
PROC is the process running git. STRING is the line that was
output by PROC."
(let (ask)
(cond
((or
@ -71,40 +142,120 @@
(process-send-string proc (concat (read-passwd ask nil) "\n")))))
(defun gac-process-filter (proc string)
"Checks if the process is asking for a password and asks the
user for one when it does."
"Check if PROC is asking for a password and promps the user if so.
STRING is the output line from PROC."
(save-current-buffer
(set-buffer (process-buffer proc))
(let ((inhibit-read-only t))
(gac-password proc string))))
(defun gac-process-sentinel (proc status)
"Report the process' status change."
"Report PROC change to STATUS."
(message "git %s" (substring status 0 -1)))
(defun gac-commit ()
"Commit `buffer-file-name' to git"
(let* ((filename (buffer-file-name))
(relative-filename
(gac-relative-file-name filename)))
(shell-command
(concat "git add " filename
" && git commit -m '" relative-filename "'"))))
(defun gac--commit-msg (filename)
"Get a commit message.
(defun gac-push ()
"Push changes to the repository to the current upstream. This
doesn't check or ask for a remote, so the correct remote should
already have been set up."
(let ((proc (start-process "git" "*git-auto-push*" "git" "push")))
(set-process-sentinel proc 'gac-process-sentinel)
(set-process-filter proc 'gac-process-filter)))
Default to FILENAME."
(let ((relative-filename (gac-relative-file-name filename)))
(if (not gac-ask-for-summary-p)
(if gac-default-message
(if (functionp gac-default-message)
(funcall gac-default-message filename)
gac-default-message)
relative-filename)
(or gac-default-message relative-filename)
(read-string "Summary: " nil nil relative-filename))))
(defun gac-commit (buffer)
"Commit the current buffer's file to git."
(let* ((buffer-file (buffer-file-name buffer))
(filename (convert-standard-filename
(file-name-nondirectory buffer-file)))
(commit-msg (gac--commit-msg buffer-file))
(default-directory (file-name-directory buffer-file)))
(funcall (if gac-silent-message-p
#'call-process-shell-command
#'shell-command)
(concat "git add " gac-add-additional-flag " " (shell-quote-argument filename)
gac-shell-and
"git commit -m " (shell-quote-argument commit-msg)
" " gac-commit-additional-flag))))
(defun gac-push (buffer)
"Push commits to the current upstream.
This doesn't check or ask for a remote, so the correct remote
should already have been set up."
;; gac-push is currently only called from gac--after-save, where it is wrapped
;; in with-current-buffer, which should already take care of
;; default-directory. The explicit binding here is defensive, in case gac-push
;; starts being used elsewhere.
(let ((default-directory (file-name-directory (buffer-file-name buffer))))
(let ((proc (start-process "git" "*git-auto-push*" "git" "push")))
(set-process-sentinel proc 'gac-process-sentinel)
(set-process-filter proc 'gac-process-filter))))
(defvar gac--debounce-timers (make-hash-table :test #'equal))
(defun gac--debounced-save ()
(let* ((actual-buffer (current-buffer))
(current-buffer-debounce-timer (gethash actual-buffer gac--debounce-timers)))
(unless current-buffer-debounce-timer
(puthash actual-buffer
(run-at-time gac-debounce-interval nil
#'gac--after-save
actual-buffer)
gac--debounce-timers))))
(defun gac--buffer-is-tracked (buffer)
"Check to see if BUFFERs 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
(file-name-nondirectory
(buffer-file-name buffer)))))
(not (string=
(shell-command-to-string (concat "git diff " file-name))
""))))
(defun gac--after-save (buffer)
(unwind-protect
(when (and (buffer-live-p 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
;; with-current-buffer required here because gac-automatically-push-p
;; is buffer-local
(when gac-automatically-push-p
(gac-push buffer))))
(remhash buffer gac--debounce-timers)))
(defun gac-kill-buffer-hook ()
(when (and gac-debounce-interval
gac--debounce-timers
(gethash (current-buffer) gac--debounce-timers))
(gac--after-save (current-buffer))))
(add-hook 'kill-buffer-hook #'gac-kill-buffer-hook)
(defun gac-after-save-func ()
"Commit the changes to the current file, and when
`gac-automatically-push-p' is not `nil', push."
(gac-commit)
(when gac-automatically-push-p
(gac-push)))
"Commit the current file.
When `gac-automatically-push-p' is non-nil also push."
(if gac-debounce-interval
(gac--debounced-save)
(gac--after-save (current-buffer))))
;;;###autoload
(define-minor-mode git-auto-commit-mode
@ -115,4 +266,6 @@ mode turned on and optionally push them too."
(add-hook 'after-save-hook 'gac-after-save-func t t)
(remove-hook 'after-save-hook 'gac-after-save-func t)))
(provide 'git-auto-commit-mode)
;;; git-auto-commit-mode.el ends here

1
site/.gitignore vendored
View file

@ -1 +0,0 @@
_publish/

View file

@ -1,10 +0,0 @@
.PHONY: export publish
all:
export:
emacs -batch -l project.el -f org-publish-all
publish: export
scp _publish/* \
ryuslash.org:public_html/orgweb/projects/git-auto-commit-mode

View file

@ -1,26 +0,0 @@
#+TITLE: git-auto-commit-mode
#+LINK_HOME: http://ryuslash.org/
#+OPTIONS: num:nil toc:nil author:nil
#+STARTUP: showall
#+STYLE: <link rel="stylesheet" type="text/css" href="stylesheet.css" />
#+MACRO: ver 0.4.2
#+BEGIN_CENTER
[[http://code.ryuslash.org/cgit.cgi/emacs/git-auto-commit-mode/][Browse source]]
[[http://blog.ryuslash.org/tags/git-auto-commit-mode][Read posts]]
Download: [[http://code.ryuslash.org/cgit.cgi/emacs/git-auto-commit-mode/snapshot/git-auto-commit-mode-{{{ver}}}.tar.gz][TAR.GZ]], [[http://code.ryuslash.org/cgit.cgi/emacs/git-auto-commit-mode/snapshot/git-auto-commit-mode-{{{ver}}}.zip][ZIP]]
#+END_CENTER
#+INCLUDE: "../README.org"
* INSTALLING
#+INCLUDE: "../INSTALL" :minlevel 2
* CONTRIBUTING
#+INCLUDE: "../CONTRIBUTING" :minlevel 2
* NEWS
#+INCLUDE: "../NEWS" :minlevel 2

View file

@ -1,18 +0,0 @@
(require 'org-publish)
(setq org-publish-project-alist
'(("git-auto-commit-mode-files"
:base-directory "./"
:publishing-directory "_publish/"
:recursive nil
:base-extension "css"
:publishing-function org-publish-attachment)
("git-auto-commit-mode-org"
:base-directory "./"
:publishing-directory "_publish/"
:recursive nil
:base-extension "org"
:publishing-function org-publish-org-to-html)
("git-auto-commit-mode-site"
:components ("git-auto-commit-mode-org"
"git-auto-commit-mode-files"))))

View file

@ -1,68 +0,0 @@
a
{
color: #6d97bf;
}
a:visited
{
color: #b27dbf;
}
body
{
font-family: "DejaVu Sans", sans-serif;
background-color: #222224;
color: #eeeeec;
}
code,
pre
{
font-family: "Envy Code R", monospace;
}
h3, h4,
.outline-text-2,
.outline-text-3,
.outline-text-4
{
margin-left: 20px;
}
pre
{
background-color: #111113;
color: #eeeeec;
border: 1px solid #a5a5a4;
border-radius: 2px;
}
ul
{
margin-left: -20px;
}
#content
{
width: 700px;
}
#org-div-home-and-up
{
width: 750px;
}
#postamble
{
font-size: 12px;
padding: 3px 5px;
border: 1px solid #a5a5a4;
width: 690px;
}
#postamble p
{
margin: 0;
padding: 0;
line-height: 1.3em;
}

View file

@ -0,0 +1,188 @@
;;; 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)
(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)
(before-each
(setq temp-dir (make-temp-file "gac-" t)
current-directory default-directory
default-directory temp-dir)
(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\""))
(after-each
(delete-directory temp-dir t)
(setq temp-dir nil
default-directory current-directory
current-directory nil))
(describe "New files"
(describe "When gac-automatically-add-new-files is t"
(it "Should be added to git"
(let* ((gac-automatically-add-new-files-p t)
(temp-file (expand-file-name "test" 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-match (rx string-start "test" string-end)))))
(describe "When gac-automatically-add-new-files is nil"
(it "Shouldnt be added to git"
(let* ((gac-automatically-add-new-files-p nil)
(temp-file (expand-file-name "test" 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)
:not :to-match (rx string-start "test" string-end))))))
(describe "Getting a relative path"
(it "should return the file name for files in the project root"
(let* ((temp-file (expand-file-name "test" temp-dir))
(buffer (find-file-noselect temp-file)))
(with-current-buffer buffer
(git-auto-commit-mode)
(insert "test")
(save-buffer))
(expect (gac-relative-file-name temp-file)
:to-equal "test")))
(it "should return the file name and directory name for nested files"
(mkdir (expand-file-name "test" temp-dir))
(let* ((temp-file (expand-file-name "test/test.txt" temp-dir))
(buffer (find-file-noselect temp-file)))
(with-current-buffer buffer
(git-auto-commit-mode)
(insert "test")
(save-buffer))
(expect (gac-relative-file-name temp-file)
:to-equal "test/test.txt")))
(it "should handle [] in the filename"
(let* ((temp-file (expand-file-name "[test]-test.txt" temp-dir))
(buffer (find-file-noselect temp-file)))
(with-current-buffer buffer
(git-auto-commit-mode)
(insert "test")
(save-buffer))
(expect (gac-relative-file-name temp-file)
:to-equal "[test]-test.txt")))
(it "should handle [] in the directory name"
(mkdir (expand-file-name "[test]-test" temp-dir))
(let* ((temp-file (expand-file-name "[test]-test/testing.txt" temp-dir))
(buffer (find-file-noselect temp-file)))
(with-current-buffer buffer
(git-auto-commit-mode)
(insert "test")
(save-buffer))
(expect (gac-relative-file-name temp-file)
:to-equal "[test]-test/testing.txt")))
(it "should handle [ in the directory name"
(let* ((temp-file (expand-file-name "testing.txt" temp-dir))
(buffer (find-file-noselect temp-file)))
(with-current-buffer buffer
(git-auto-commit-mode)
(insert "test")
(save-buffer))
(expect (gac-relative-file-name temp-file)
:to-equal "testing.txt")))
(it "should handle [ in the file name"
(let* ((temp-file (expand-file-name "[test-test.txt" temp-dir))
(buffer (find-file-noselect temp-file)))
(with-current-buffer buffer
(git-auto-commit-mode)
(insert "test")
(save-buffer))
(expect (gac-relative-file-name temp-file)
: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