summaryrefslogtreecommitdiff
path: root/lisp/init-git.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-02-20 23:54:50 -0500
committerKyle Meyer <kyle@kyleam.com>2015-02-28 00:29:49 -0500
commit8f738061dfff16eebdc47bfa2072559accac3e4a (patch)
tree0a16bbe5468daa3cdf1aca3a1ead63ed5bbd2933 /lisp/init-git.el
parent6d5108aead381ed7f11becc6a44e78e3fd2f53fa (diff)
downloademacs.d-8f738061dfff16eebdc47bfa2072559accac3e4a.tar.gz
Add command magit-pin-file
Diffstat (limited to 'lisp/init-git.el')
-rw-r--r--lisp/init-git.el25
1 files changed, 25 insertions, 0 deletions
diff --git a/lisp/init-git.el b/lisp/init-git.el
index 9735181..98be191 100644
--- a/lisp/init-git.el
+++ b/lisp/init-git.el
@@ -174,6 +174,30 @@ and 'squash!' titles."
(goto-char (apply #'max commit-pts))
(message "No matching commits found"))))
+(defun km/magit-pin-file (&optional other-rev)
+ "Pin this file to the current revision.
+
+Visit the current file and current revision with
+`magit-find-file'. Position point as in the original buffer.
+This may not correspond to same content if text before point has
+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."
+ (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-get-top-dir)))))
+ (magit-find-file rev fname)
+ (unless other-rev (goto-char pos))))
+
(defun km/git-rebase-show-commit ()
"Show the commit on the current line if any.
Unlike `git-rebase-show-commit', display (but don't switch to)
@@ -208,6 +232,7 @@ the commit buffer. And no dinging."
(define-key km/git-map "c" 'km/magit-show-commit-under-point)
(define-key km/git-map "C" 'km/magit-show-project-commit-under-point)
(define-key km/git-map "e" 'km/magit-commit-extend-all)
+ (define-key km/git-map "p" 'km/magit-pin-file)
(define-key km/git-map "u" 'km/magit-auto-commit))
(after 'magit-log