Compare commits
61 commits
Author | SHA1 | Date | |
---|---|---|---|
a7b59acea6 | |||
50cb58b11d | |||
97d9392d51 | |||
7b628c0ce0 | |||
a6b6e0fa18 | |||
df07899acd | |||
d4fd943206 | |||
e2c939cb8e | |||
23abaff792 | |||
|
2d48b8296d | ||
5755d36c03 | |||
|
14e4def248 | ||
|
2c0488869a | ||
|
dd0c2441de | ||
ae69e61233 | |||
106fc3c8b4 | |||
6f7b58f866 | |||
|
aff67aa36d | ||
4cfc906cb4 | |||
3e5fab83a5 | |||
d8d9dab5d2 | |||
b0db5b841b | |||
|
24c8e7b0fe | ||
|
ea3b5c0d91 | ||
|
392ca73178 | ||
|
a597d6920a | ||
|
4a8a7e0271 | ||
2f05046731 | |||
fc94d0df93 | |||
5bb26c6384 | |||
3db70af7d3 | |||
23a0224a00 | |||
|
e533166a22 | ||
|
fa8865bf49 | ||
|
0ac5025766 | ||
|
074739d78f | ||
|
2c8197e5d7 | ||
075e5f9ded | |||
b151584256 | |||
fa4e042f8d | |||
7b370eeb37 | |||
9edaf8243d | |||
858dc816f1 | |||
|
acf6a60578 | ||
|
344667ee75 | ||
|
ca96589764 | ||
e7b3a146b8 | |||
4685b7ee16 | |||
c3f42d0635 | |||
|
e11eb392c0 | ||
7e4ed5f07a | |||
0e8c5e8d3f | |||
b36909ab64 | |||
058c55cf2a | |||
cbc62b2a88 | |||
17f8fa22a3 | |||
dbe05bed93 | |||
6d8c914b24 | |||
995293de8f | |||
|
8401b45a4f | ||
3ccf3fb624 |
13 changed files with 537 additions and 177 deletions
27
.github/workflows/test.yml
vendored
Normal file
27
.github/workflows/test.yml
vendored
Normal 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
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
.cask/
|
||||
git-auto-commit-mode.elc
|
||||
|
|
19
CONTRIBUTING
19
CONTRIBUTING
|
@ -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
5
Cask
Normal file
|
@ -0,0 +1,5 @@
|
|||
(source gnu)
|
||||
(source melpa)
|
||||
|
||||
(development
|
||||
(depends-on "buttercup"))
|
48
NEWS
48
NEWS
|
@ -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
|
||||
|
||||
|
|
68
README.org
68
README.org
|
@ -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
|
||||
- =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
|
||||
|
|
|
@ -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."
|
||||
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)))
|
||||
(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 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
|
||||
(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
1
site/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
_publish/
|
|
@ -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
|
|
@ -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
|
|
@ -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"))))
|
|
@ -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;
|
||||
}
|
188
tests/git-auto-commit-mode-tests.el
Normal file
188
tests/git-auto-commit-mode-tests.el
Normal 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 "Shouldn’t 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
|
Loading…
Add table
Reference in a new issue