aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-08-23 20:03:23 -0400
committerKyle Meyer <kyle@kyleam.com>2015-08-24 09:48:44 -0400
commitb640c6f50e0a80d41e3fef4eb036e5124bc2a2e7 (patch)
treeb0432c09b697d86308f6af546e30da120d72840e /lisp
parentd7115bc65590d6ea45556998554316f9cc0d23b1 (diff)
magit-blame: fix calls from indirect buffers
Make sure that default-directory stays set at the top-level directory. When magit-blame is called from an indirect buffer, the find-file call sets default-directory to the file's directory, so the downstream git call (now from the file's directory) fails when given a path relative to the top-level directory. This isn't an issue when magit-blame is called from a buffer visiting a file. The call to find-file does not override the default-directory let-bound by magit-with-toplevel because the file is already being visited by the current buffer. Fix this by let-binding the find-file call separately. While this makes it possible call magit-blame from an indirect buffer, point is not placed appropriately in the base buffer. This probably isn't worth taking the time to fix given that calling magit-blame from indirect buffer isn't very common (since the above error has yet to be reported).
Diffstat (limited to 'lisp')
-rw-r--r--lisp/magit-blame.el83
1 files changed, 43 insertions, 40 deletions
diff --git a/lisp/magit-blame.el b/lisp/magit-blame.el
index c188aaf..b1c6439 100644
--- a/lisp/magit-blame.el
+++ b/lisp/magit-blame.el
@@ -219,49 +219,52 @@ only arguments available from `magit-blame-popup' should be used.
(if buffer-file-name
(user-error "Buffer isn't visiting a tracked file")
(user-error "Buffer isn't visiting a file"))))))
- (magit-with-toplevel
+ (let ((toplevel (or (magit-toplevel)
+ (user-error "Not in git repository"))))
(if revision
(magit-find-file revision file)
- (find-file (expand-file-name file)))
+ (let ((default-directory toplevel))
+ (find-file file)))
(widen)
- (when line
- (setq magit-blame-recursive-p t)
- (goto-char (point-min))
- (forward-line (1- line)))
- (unless magit-blame-mode
- (setq magit-blame-cache (make-hash-table :test 'equal))
- (let ((show-headings magit-blame-show-headings))
- (magit-blame-mode 1)
- (setq-local magit-blame-show-headings show-headings))
- (message "Blaming...")
- (let ((magit-process-popup-time -1)
- (inhibit-magit-refresh t))
- (magit-run-git-async
- "blame" "--incremental" args
- "-L" (format "%s,%s"
- (line-number-at-pos (window-start))
- (line-number-at-pos (1- (window-end))))
- revision "--" file))
- (setq magit-blame-process magit-this-process)
- (set-process-filter magit-this-process 'magit-blame-process-filter)
- (set-process-sentinel
- magit-this-process
- `(lambda (process event)
- (when (memq (process-status process) '(exit signal))
- (magit-process-sentinel process event)
- (magit-blame-assert-buffer process)
- (with-current-buffer (process-get process 'command-buf)
- (when magit-blame-mode
- (let ((magit-process-popup-time -1)
- (inhibit-magit-refresh t)
- (default-directory ,default-directory))
- (magit-run-git-async "blame" "--incremental" ,@args
- ,revision "--" ,file))
- (setq magit-blame-process magit-this-process)
- (set-process-filter
- magit-this-process 'magit-blame-process-filter)
- (set-process-sentinel
- magit-this-process 'magit-blame-process-sentinel)))))))))
+ (let ((default-directory toplevel))
+ (when line
+ (setq magit-blame-recursive-p t)
+ (goto-char (point-min))
+ (forward-line (1- line)))
+ (unless magit-blame-mode
+ (setq magit-blame-cache (make-hash-table :test 'equal))
+ (let ((show-headings magit-blame-show-headings))
+ (magit-blame-mode 1)
+ (setq-local magit-blame-show-headings show-headings))
+ (message "Blaming...")
+ (let ((magit-process-popup-time -1)
+ (inhibit-magit-refresh t))
+ (magit-run-git-async
+ "blame" "--incremental" args
+ "-L" (format "%s,%s"
+ (line-number-at-pos (window-start))
+ (line-number-at-pos (1- (window-end))))
+ revision "--" file))
+ (setq magit-blame-process magit-this-process)
+ (set-process-filter magit-this-process 'magit-blame-process-filter)
+ (set-process-sentinel
+ magit-this-process
+ `(lambda (process event)
+ (when (memq (process-status process) '(exit signal))
+ (magit-process-sentinel process event)
+ (magit-blame-assert-buffer process)
+ (with-current-buffer (process-get process 'command-buf)
+ (when magit-blame-mode
+ (let ((magit-process-popup-time -1)
+ (inhibit-magit-refresh t)
+ (default-directory ,default-directory))
+ (magit-run-git-async "blame" "--incremental" ,@args
+ ,revision "--" ,file))
+ (setq magit-blame-process magit-this-process)
+ (set-process-filter
+ magit-this-process 'magit-blame-process-filter)
+ (set-process-sentinel
+ magit-this-process 'magit-blame-process-sentinel))))))))))
(defun magit-blame-process-sentinel (process event)
(let ((status (process-status process)))