2012-01-10 21:44:05 +01:00
|
|
|
;;; git-auto-commit-mode.el --- Emacs Minor mode to automatically commit
|
|
|
|
|
|
|
|
;; Copyright (C) 2012 Tom Willemsen <tom@ryuslash.org>
|
|
|
|
|
2012-05-20 14:14:59 +02:00
|
|
|
;; Author: Tom Willemsen <tom@ryuslash.org>
|
2012-01-10 21:44:05 +01:00
|
|
|
;; Created: Jan 9, 2012
|
|
|
|
;; Version: 1
|
2012-05-20 14:14:59 +02:00
|
|
|
;; Keywords: vc
|
|
|
|
;; URL: http://ryuslash.org/git-auto-commit-mode/
|
2012-01-10 21:44:05 +01:00
|
|
|
|
|
|
|
;; This file 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 file 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
|
2012-05-20 14:14:59 +02:00
|
|
|
;; along with this file; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; git-auto-commit-mode is an Emacs minor mode that tries to commit
|
|
|
|
;; changes to a file after every save.
|
|
|
|
|
|
|
|
;;; Change Log:
|
|
|
|
|
|
|
|
;; 1 - Initial release.
|
2012-01-10 21:44:05 +01:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2012-05-20 14:18:03 +02:00
|
|
|
(defun gac-relative-file-name (filename)
|
2012-01-10 21:32:50 +01:00
|
|
|
"Find the path to the 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))
|
|
|
|
|
2012-05-20 14:18:03 +02:00
|
|
|
(defun gac-commit ()
|
2012-05-20 14:15:46 +02:00
|
|
|
"Commit `buffer-file-name' to git"
|
2012-01-10 21:32:50 +01:00
|
|
|
(let* ((filename (buffer-file-name))
|
|
|
|
(relative-filename
|
2012-05-20 14:18:03 +02:00
|
|
|
(gac-relative-file-name filename)))
|
2012-01-10 21:32:50 +01:00
|
|
|
(shell-command
|
|
|
|
(concat "git add " filename
|
|
|
|
" && git commit -m '" relative-filename "'"))))
|
2012-01-09 23:58:28 +01:00
|
|
|
|
|
|
|
(define-minor-mode git-auto-commit-mode
|
2012-05-20 14:15:46 +02:00
|
|
|
"Automatically commit any changes made when saving with this
|
|
|
|
mode turned on"
|
2012-01-10 00:08:10 +01:00
|
|
|
:lighter " ga"
|
2012-01-09 23:58:28 +01:00
|
|
|
(if git-auto-commit-mode
|
2012-05-20 14:18:03 +02:00
|
|
|
(add-hook 'after-save-hook 'gac-commit t t)
|
|
|
|
(remove-hook 'after-save-hook 'gac-commit t)))
|
2012-05-20 14:14:59 +02:00
|
|
|
|
|
|
|
;;; git-auto-commit-mode.el ends here
|