update packages

This commit is contained in:
2025-02-26 20:16:44 +01:00
parent 59db017445
commit 45d49daef0
291 changed files with 16240 additions and 522600 deletions

View File

@@ -1,9 +1,9 @@
;;; magit-stash.el --- Stash support for Magit -*- lexical-binding:t -*-
;; Copyright (C) 2008-2023 The Magit Project Contributors
;; Copyright (C) 2008-2025 The Magit Project Contributors
;; Author: Jonas Bernoulli <jonas@bernoul.li>
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
;; Author: Jonas Bernoulli <emacs.magit@jonas.bernoulli.dev>
;; Maintainer: Jonas Bernoulli <emacs.magit@jonas.bernoulli.dev>
;; SPDX-License-Identifier: GPL-3.0-or-later
@@ -39,10 +39,10 @@
;;;; Diff options
(defcustom magit-stash-sections-hook
'(magit-insert-stash-notes
magit-insert-stash-worktree
magit-insert-stash-index
magit-insert-stash-untracked)
(list #'magit-insert-stash-notes
#'magit-insert-stash-worktree
#'magit-insert-stash-index
#'magit-insert-stash-untracked)
"Hook run to insert sections into stash diff buffers."
:package-version '(magit . "2.1.0")
:group 'magit-stash
@@ -129,8 +129,8 @@ while two prefix arguments are equivalent to `--all'."
(interactive
(progn (when (and (magit-merge-in-progress-p)
(not (magit-y-or-n-p "\
Stashing and resetting during a merge conflict. \
Applying the resulting stash won't restore the merge state. \
Stashing and resetting during a merge conflict. \
Applying the resulting stash won't restore the merge state. \
Proceed anyway? ")))
(user-error "Abort"))
(magit-stash-read-args)))
@@ -143,7 +143,7 @@ Unstaged and untracked changes are not stashed. The stashed
changes are applied in reverse to both the index and the
worktree. This command can fail when the worktree is not clean.
Applying the resulting stash has the inverse effect."
(interactive (list (magit-stash-read-message)))
(interactive (list (funcall magit-stash-read-message-function)))
(magit-stash-save message t nil nil t 'worktree))
;;;###autoload
@@ -256,27 +256,30 @@ specifying a list of files to be stashed."
(list t)))
(if transient
(transient-setup 'magit-stash-push)
(magit-run-git "stash" "push" args)))
(magit-run-git "stash" "push"
(seq-filter #'atom args)
(assoc "--" args))))
;;;###autoload
(defun magit-stash-apply (stash)
"Apply a stash to the working tree.
First try \"git stash apply --index\", which tries to preserve
the index stored in the stash, if any. This may fail because
applying the stash could result in conflicts and those have to
be stored in the index, making it impossible to also store the
stash's index there as well.
When using a Git release before v2.38.0, simply run \"git stash
apply\" or with a prefix argument \"git stash apply --index\".
If the above failed, then try \"git stash apply\". This fails
\(with or without \"--index\") if there are any uncommitted
changes to files that are also modified in the stash.
When using Git v2.38.0 or later, behave more intelligently:
If both of the above failed, then apply using \"git apply\".
If there are no conflicting files, use \"--3way\". If there are
conflicting files, then using \"--3way\" requires that those
files are staged first, which may be undesirable, so prompt
the user whether to use \"--3way\" or \"--reject\"."
First try \"git stash apply --index\", which tries to preserve the
index stored in the stash, if any. This may fail because applying
the stash could result in conflicts and those have to be stored in
the index, making it impossible to also store the stash's index
there.
If \"git stash\" fails, then potentially fall back to using \"git
apply\". If the stash does not touch any unstaged files, then pass
\"--3way\" to that command. Otherwise ask the user whether to use
that argument or \"--reject\". Customize `magit-no-confirm' if you
want to fall back to using \"--3way\", without being prompted."
(interactive (list (magit-read-stash "Apply stash")))
(magit-stash--apply "apply" stash))
@@ -284,48 +287,82 @@ the user whether to use \"--3way\" or \"--reject\"."
(defun magit-stash-pop (stash)
"Apply a stash to the working tree, on success remove it from stash list.
First try \"git stash pop --index\", which tries to preserve
the index stored in the stash, if any. This may fail because
applying the stash could result in conflicts and those have to
be stored in the index, making it impossible to also store the
stash's index there as well.
When using a Git release before v2.38.0, simply run \"git stash
pop\" or with a prefix argument \"git stash pop --index\".
If the above failed, then try \"git stash apply\". This fails
\(with or without \"--index\") if there are any uncommitted
changes to files that are also modified in the stash.
When using Git v2.38.0 or later, behave more intelligently:
If both of the above failed, then apply using \"git apply\".
If there are no conflicting files, use \"--3way\". If there are
conflicting files, then using \"--3way\" requires that those
files are staged first, which may be undesirable, so prompt
the user whether to use \"--3way\" or \"--reject\"."
First try \"git stash apply --index\", which tries to preserve the
index stored in the stash, if any. This may fail because applying
the stash could result in conflicts and those have to be stored in
the index, making it impossible to also store the stash's index
there.
If \"git stash\" fails, then potentially fall back to using \"git
apply\". If the stash does not touch any unstaged files, then pass
\"--3way\" to that command. Otherwise ask the user whether to use
that argument or \"--reject\". Customize `magit-no-confirm' if you
want to fall back to using \"--3way\", without being prompted."
(interactive (list (magit-read-stash "Pop stash")))
(magit-stash--apply "pop" stash))
(defun magit-stash--apply (action stash)
(or (= (magit-call-git "stash" action "--index" stash) 0)
;; The stash's index could not be applied, so always keep the stash.
(= (magit-call-git "stash" "apply" stash) 0)
(let* ((range (format "%s^..%s" stash stash))
(stashed (magit-git-items "diff" "-z" "--name-only" range "--"))
(conflicts (cl-sort (cl-union (magit-unstaged-files t stashed)
(magit-untracked-files t stashed)
:test #'equal)
#'string<))
(arg (cond
((not conflicts) "--3way")
((magit-confirm-files
'stash-apply-3way conflicts
"Apply stash using `--3way', which requires first staging"
"(else use `--reject')"
t)
(magit-stage-1 nil conflicts)
"--3way")
("--reject"))))
(with-temp-buffer
(magit-git-insert "diff" range)
(magit-run-git-with-input "apply" arg "-"))))
(magit-refresh))
(if (magit-git-version< "2.38.0")
(magit-run-git "stash" action stash (and current-prefix-arg "--index"))
(magit-stash--apply-1 action stash)
(magit-refresh)))
(defun magit-stash--apply-1 (action stash)
(or
(magit--run-git-stash action "--index" stash)
;; The stash's index could not be applied, so always keep the stash.
(magit--run-git-stash "apply" stash)
(let* ((range (format "%s^..%s" stash stash))
(stashed (magit-git-items "diff" "-z" "--name-only" range "--"))
(conflicts (cl-sort (cl-union (magit-unstaged-files t stashed)
(magit-untracked-files t stashed)
:test #'equal)
#'string<))
(arg (if (or (not conflicts)
(memq 'stash-apply-3way magit-no-confirm))
"--3way"
(magit-read-char-case
(concat
"Could not apply stash because of unstaged changes.\n\n"
"To do a tree-way merge, these files have to be staged\n"
(mapconcat (lambda (f) (format " %s" f)) conflicts "\n")
"\n")
nil
(?s (format
"\n[s] stage file%s and apply with \"git apply --3way\""
(if (length> conflicts 1) "s" ""))
"--3way")
(?r "\n[r] apply with \"git apply --reject\"" "--reject")
(?c "\n[c] cancel" nil)))))
(when arg
(when (and (equal arg "--3way") conflicts)
(magit-stage-1 nil conflicts))
(with-temp-buffer
(magit-git-insert "diff" range)
(magit-run-git-with-input "apply" arg "-"))))))
(defun magit--run-git-stash (&rest args)
(magit--with-temp-process-buffer
(let ((exit (save-excursion
(with-environment-variables (("LC_ALL" "en_US.utf8"))
(magit-process-git t "stash" args))))
(buffer (current-buffer))
(failed (looking-at "\\`error: ")))
(with-current-buffer (magit-process-buffer t)
(magit-process-finish-section
(magit-process-insert-section default-directory magit-git-executable
(magit-process-git-arguments args)
exit buffer)
exit))
(pcase (list exit failed)
(`(0 ,_) t) ; no conflict
(`(1 nil) t) ; successfully installed conflict
(_ nil))))) ; could not install conflict, or genuine error
;;;###autoload
(defun magit-stash-drop (stash)
@@ -348,7 +385,7 @@ When the region is active offer to drop all contained stashes."
(defun magit-stash-clear (ref)
"Remove all stashes saved in REF's reflog by deleting REF."
(interactive (let ((ref (or (magit-section-value-if 'stashes) "refs/stash")))
(magit-confirm t (format "Drop all stashes in %s" ref))
(magit-confirm t (list "Drop all stashes in %s" ref))
(list ref)))
(magit-run-git "update-ref" "-d" ref))
@@ -375,7 +412,7 @@ Then apply STASH, dropping it if it applies cleanly."
;;;###autoload
(defun magit-stash-format-patch (stash)
"Create a patch from STASH"
"Create a patch from STASH."
(interactive (list (magit-read-stash "Create patch from stash")))
(with-temp-file (magit-rev-format "0001-%f.patch" stash)
(magit-git-insert "stash" "show" "-p" stash))
@@ -413,7 +450,7 @@ Then apply STASH, dropping it if it applies cleanly."
(t "local"))))))
(defun magit-stash-store (message ref commit)
(magit-update-ref ref message commit t))
(magit-update-ref ref message commit))
(defun magit-stash-create (message index worktree untracked)
(unless (magit-rev-parse "--verify" "HEAD")
@@ -467,7 +504,7 @@ Then apply STASH, dropping it if it applies cleanly."
"<1>" (magit-menu-item "Visit %v" #'magit-stash-show))
(magit-define-section-jumper magit-jump-to-stashes
"Stashes" stashes "refs/stash")
"Stashes" stashes "refs/stash" magit-insert-stashes)
(cl-defun magit-insert-stashes (&optional (ref "refs/stash")
(heading "Stashes:"))
@@ -511,8 +548,9 @@ instead of \"Stashes:\"."
(define-derived-mode magit-stashes-mode magit-reflog-mode "Magit Stashes"
"Mode for looking at lists of stashes."
:interactive nil
:group 'magit-log
(hack-dir-local-variables-non-file-buffer))
(magit-hack-dir-local-variables))
(defun magit-stashes-setup-buffer ()
(magit-setup-buffer #'magit-stashes-mode nil
@@ -520,9 +558,10 @@ instead of \"Stashes:\"."
(defun magit-stashes-refresh-buffer ()
(magit-insert-section (stashesbuf)
(magit-insert-heading (if (equal magit-buffer-refname "refs/stash")
"Stashes:"
(format "Stashes [%s]:" magit-buffer-refname)))
(magit-insert-heading t
(if (equal magit-buffer-refname "refs/stash")
"Stashes"
(format "Stashes [%s]" magit-buffer-refname)))
(magit-git-wash (apply-partially #'magit-log-wash-log 'stash)
"reflog" "--format=%gd%x00%aN%x00%at%x00%gs" magit-buffer-refname)))
@@ -571,10 +610,14 @@ If there is no stash buffer in the same frame, then do nothing."
(define-derived-mode magit-stash-mode magit-diff-mode "Magit Stash"
"Mode for looking at individual stashes."
:interactive nil
:group 'magit-diff
(hack-dir-local-variables-non-file-buffer)
(magit-hack-dir-local-variables)
(setq magit--imenu-group-types '(commit)))
(put 'magit-stash-mode 'magit-diff-default-arguments
'("--no-ext-diff"))
(defun magit-stash-setup-buffer (stash args files)
(magit-setup-buffer #'magit-stash-mode nil
(magit-buffer-revision stash)
@@ -607,13 +650,11 @@ If there is no stash buffer in the same frame, then do nothing."
"Insert section showing notes for a stash.
This shows the notes for stash@{N} but not for the other commits
that make up the stash."
(magit-insert-section section (note)
(magit-insert-heading "Notes")
(magit-insert-section (note)
(magit-insert-heading t "Notes")
(magit-git-insert "notes" "show" magit-buffer-revision)
(if (= (point)
(oref section content))
(magit-cancel-section)
(insert "\n"))))
(magit-cancel-section 'if-empty)
(insert "\n")))
(defun magit-insert-stash-index ()
"Insert section showing staged changes of the stash."