diff options
author | Kyle Meyer <kyle@kyleam.com> | 2015-07-17 01:37:39 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2015-07-17 01:37:39 -0400 |
commit | da15682eab022a043a01b1ec8a44e1fb0d975586 (patch) | |
tree | d6f9d56bdbf1c38849250c8d54f2ef4d1925f318 | |
parent | 8a97fb0da663592fed45f75350e04621818572a5 (diff) | |
download | emacs.d-da15682eab022a043a01b1ec8a44e1fb0d975586.tar.gz |
magit-pin-file: Allow toggling with working tree
Also, try to go to position even when OTHER-REV is non-nil.
-rw-r--r-- | lisp/init-git.el | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/lisp/init-git.el b/lisp/init-git.el index 24c4d8d..a20cb9a 100644 --- a/lisp/init-git.el +++ b/lisp/init-git.el @@ -233,19 +233,24 @@ changed since the current commit. If OTHER-REV is non-nil, prompt for another revision instead of the current. In this case, keep point at the beginning of the -buffer." +buffer. + +If buffer is already a revision buffer, then find the working +tree copy instead." (interactive "P") - (let ((pos (point)) - (rev (if other-rev - (magit-read-branch-or-commit "Find file from revision") - (or (magit-get-current-branch) - (magit-rev-parse "HEAD")))) - (fname (and (or buffer-file-name - (user-error "Buffer not visiting file")) - (file-relative-name buffer-file-name - (magit-toplevel))))) - (magit-find-file rev fname) - (unless other-rev (goto-char pos)))) + (magit-with-toplevel + (let* ((pos (point)) + (rev (cond (other-rev + (magit-read-branch-or-commit "Find file from revision")) + ((not magit-buffer-file-name) + (or (magit-get-current-branch) + (magit-rev-parse "HEAD"))))) + (fname (file-relative-name + (or buffer-file-name + magit-buffer-file-name + (user-error "Buffer not visiting file"))))) + (if rev (magit-find-file rev fname) (find-file fname)) + (goto-char pos)))) (defun km/magit-revfile-reset (&optional checkout) "Reset to revision from current revfile. |