aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemsen2012-01-10 21:32:50 +0100
committerGravatar Tom Willemsen2012-01-10 21:32:50 +0100
commitd3ddb34bdc2eb5529d98d4b9f9413a04494b2415 (patch)
tree3693e425336532d5d33ee5d5a7cc8337441017fa
parent563c1daaf41301ceb5386c91f1a50032793b16a7 (diff)
downloadgit-auto-commit-mode-d3ddb34bdc2eb5529d98d4b9f9413a04494b2415.tar.gz
git-auto-commit-mode-d3ddb34bdc2eb5529d98d4b9f9413a04494b2415.zip
Use relative path for commit message
-rw-r--r--git-auto-commit-mode.el21
1 files changed, 18 insertions, 3 deletions
diff --git a/git-auto-commit-mode.el b/git-auto-commit-mode.el
index 5d2b840..d3bb5e7 100644
--- a/git-auto-commit-mode.el
+++ b/git-auto-commit-mode.el
@@ -1,8 +1,23 @@
+(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))
+
(defun git-auto-commit ()
"Commit `buffer-file-name` to git"
- (let ((filename (buffer-file-name)))
- (shell-command (concat "git add " filename
- " && git commit -m '" filename "'"))))
+ (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 "'"))))
(define-minor-mode git-auto-commit-mode
"Automatically commit any changes made when saving with this mode