From 51c2c7349fa9d17e7474dcfbde1138135bba9ded Mon Sep 17 00:00:00 2001 From: Syohei YOSHIDA Date: Mon, 28 Jul 2014 19:44:35 +0900 Subject: [PATCH] Add validation - Buffer is related to file - File is git tracked --- git-timemachine.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/git-timemachine.el b/git-timemachine.el index ceabf24..65182e1 100644 --- a/git-timemachine.el +++ b/git-timemachine.el @@ -97,10 +97,18 @@ ("w" . git-timemachine-kill-revision)) :group 'git-timemachine) +(defun git-timemachine-validate (file) + (unless file + (error "This buffer is not related to file.")) + (with-temp-buffer + (unless (zerop (call-process "git" nil nil nil "ls-files" "--error-unmatch" file)) + (error "This file is not git tracked.")))) + ;;;###autoload (defun git-timemachine () "Enable git timemachine for file of current buffer." (interactive) + (git-timemachine-validate (buffer-file-name)) (let ((git-directory (file-name-as-directory (car (process-lines "git" "rev-parse" "--show-toplevel")))) (file-name (buffer-file-name)) (timemachine-buffer (format "timemachine:%s" (buffer-name)))