[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/git-commit c92dee94e9: magit-save-repository-buffers: Hand
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/git-commit c92dee94e9: magit-save-repository-buffers: Handle let-bound default-directory |
Date: |
Fri, 16 Sep 2022 13:58:48 -0400 (EDT) |
branch: elpa/git-commit
commit c92dee94e916db0dfc7cc37b745ef3989017a838
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
magit-save-repository-buffers: Handle let-bound default-directory
When `default-directory' is let-bound around a call to git, then that
binding is still in effect when `save-some-repositories' (and thus
this function) process the current buffer. (For other buffers that is
not the case because `default-directory' is a buffer-local variable.)
As a result, if the current buffer is modified and visits a file in
another repository, then this function wrongly concluded that the file
is located in the repository specified by `default-directory'.
If the wip modes are enabled, then saving a tracked file causes wip
refs to be updated. When that happens, the let-binding is still in
effect, so an attempt is made to stage the visited file in the wrong
repository, which results in an error being raised, about the file
being outside the repository.
Counter this by internally let-binding `default-directory' based on
`buffer-file-name'.
---
lisp/magit-mode.el | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 73718c0dbf..af3097e3bc 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -1189,18 +1189,26 @@ argument (the prefix) non-nil means save all with no
questions."
(save-some-buffers
arg (lambda ()
(and buffer-file-name
- ;; - Check whether refreshing is disabled.
- (not magit-inhibit-refresh-save)
- ;; - Check whether the visited file is either on the
- ;; same remote as the repository, or both are on
- ;; the local system.
- (equal (file-remote-p buffer-file-name) remote)
- ;; Delayed checks that are more expensive for remote
- ;; repositories, due to the required network access.
- ;; - Check whether the file is inside the repository.
- (equal (magit-rev-parse-safe "--show-toplevel") topdir)
- ;; - Check whether the file is actually writable.
- (file-writable-p buffer-file-name)))))))
+ ;; If the current file is modified and resides inside
+ ;; a repository, and a let-binding is in effect, which
+ ;; places us in another repository, then the below
+ ;; let-binding is needed to prevent that file from
+ ;; being saved.
+ (let ((default-directory
+ (file-name-directory buffer-file-name)))
+ (and
+ ;; - Check whether refreshing is disabled.
+ (not magit-inhibit-refresh-save)
+ ;; - Check whether the visited file is either on the
+ ;; same remote as the repository, or both are on
+ ;; the local system.
+ (equal (file-remote-p buffer-file-name) remote)
+ ;; Delayed checks that are more expensive for remote
+ ;; repositories, due to the required network access.
+ ;; - Check whether the file is inside the repository.
+ (equal (magit-rev-parse-safe "--show-toplevel") topdir)
+ ;; - Check whether the file is actually writable.
+ (file-writable-p buffer-file-name)))))))))
;;; Restore Window Configuration
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/git-commit c92dee94e9: magit-save-repository-buffers: Handle let-bound default-directory,
ELPA Syncer <=