2012-01-10 21:32:50 +01:00
|
|
|
(defun git-auto-commit-relative-file-name (filename)
|
|
|
|
"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-01-09 23:58:28 +01:00
|
|
|
(defun git-auto-commit ()
|
|
|
|
"Commit `buffer-file-name` to git"
|
2012-01-10 21:32:50 +01:00
|
|
|
(let* ((filename (buffer-file-name))
|
|
|
|
(relative-filename
|
|
|
|
(git-auto-commit-relative-file-name filename)))
|
|
|
|
(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
|
|
|
|
"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
|
|
|
|
(add-hook 'after-save-hook 'git-auto-commit t t)
|
|
|
|
(remove-hook 'after-save-hook 'git-auto-commit t)))
|