[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/git-commit bdade489ea 1/2: magit-stash-{apply, pop}: Fix c
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/git-commit bdade489ea 1/2: magit-stash-{apply, pop}: Fix case when there are staged changes |
Date: |
Sun, 23 Jul 2023 15:59:33 -0400 (EDT) |
branch: elpa/git-commit
commit bdade489ead0ffd1de0709042d5166837efea4e8
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
magit-stash-{apply,pop}: Fix case when there are staged changes
It is not possible to preserve a stash index when applying it and
there are staged changes. Previously we just always tried to preserve
it anyway, using the `--index' argument, and only failed we fell back
to applying without that argument.
That used to work, but due to a change/regression in Git that stopped
working quite some time ago. The futile attempt to use `--index'
causes the staged changes to be unstaged and when there are unstaged
changes (to files also touched by the stash), then it is not possible
to apply a stash at all.
(Users still have to be aware that they might have to stage before
being able to apply a stash, despite the presence of uncommitted
changes.)
---
lisp/magit-stash.el | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/lisp/magit-stash.el b/lisp/magit-stash.el
index c3efef167a..4e202025ea 100644
--- a/lisp/magit-stash.el
+++ b/lisp/magit-stash.el
@@ -237,23 +237,23 @@ specifying a list of files to be stashed."
;;;###autoload
(defun magit-stash-apply (stash)
"Apply a stash to the working tree.
-Try to preserve the stash index. If that fails because there
-are staged changes, apply without preserving the stash index."
+If nothing is staged, then try to reinstate the stashed index.
+Doing so is not possible if there are staged changes."
(interactive (list (magit-read-stash "Apply stash")))
- (if (= (magit-call-git "stash" "apply" "--index" stash) 0)
- (magit-refresh)
- (magit-run-git "stash" "apply" stash)))
+ (magit-run-git "stash" "apply" stash
+ (and (not (magit-anything-staged-p))
+ "--index")))
;;;###autoload
(defun magit-stash-pop (stash)
"Apply a stash to the working tree and remove it from stash list.
-Try to preserve the stash index. If that fails because there
-are staged changes, apply without preserving the stash index
-and forgo removing the stash."
+If nothing is staged, then try to reinstate the stashed index.
+Doing so is not possible if there are staged changes. Do not
+remove the stash, if it cannot be applied."
(interactive (list (magit-read-stash "Pop stash")))
- (if (= (magit-call-git "stash" "apply" "--index" stash) 0)
- (magit-stash-drop stash)
- (magit-run-git "stash" "apply" stash)))
+ (magit-run-git "stash" "apply" stash
+ (and (not (magit-anything-staged-p))
+ "--index")))
;;;###autoload
(defun magit-stash-drop (stash)