update of packages
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
;;; magit-stash.el --- Stash support for Magit -*- lexical-binding:t -*-
|
||||
|
||||
;; Copyright (C) 2008-2022 The Magit Project Contributors
|
||||
;; Copyright (C) 2008-2023 The Magit Project Contributors
|
||||
|
||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
||||
@@ -80,6 +80,11 @@ AUTHOR-WIDTH has to be an integer. When the name of the author
|
||||
:set-after '(magit-log-margin)
|
||||
:set (apply-partially #'magit-margin-set-variable 'magit-stashes-mode))
|
||||
|
||||
;;;; Variables
|
||||
|
||||
(defvar magit-stash-read-message-function #'magit-stash-read-message
|
||||
"Function used to read the message when creating a stash.")
|
||||
|
||||
;;; Commands
|
||||
|
||||
;;;###autoload (autoload 'magit-stash "magit-stash" nil t)
|
||||
@@ -160,16 +165,29 @@ while two prefix arguments are equivalent to `--all'."
|
||||
(magit-stash-save message t t include-untracked t 'index))
|
||||
|
||||
(defun magit-stash-read-args ()
|
||||
(list (magit-stash-read-message)
|
||||
(list (funcall magit-stash-read-message-function)
|
||||
(magit-stash-read-untracked)))
|
||||
|
||||
(defun magit-stash-read-untracked ()
|
||||
(let ((prefix (prefix-numeric-value current-prefix-arg))
|
||||
(args (magit-stash-arguments)))
|
||||
(cond ((or (= prefix 16) (member "--all" args)) 'all)
|
||||
((or (= prefix 4) (member "--include-untracked" args)) t))))
|
||||
|
||||
(defun magit-stash-read-message ()
|
||||
"Read a message from the minibuffer, to be used for a stash.
|
||||
|
||||
The message that Git would have picked, is available as the
|
||||
default (used when the user enters the empty string) and as
|
||||
the next history element (which can be accessed with \
|
||||
\\<minibuffer-local-map>\\[next-history-element])."
|
||||
(read-string (format "Stash message (default: On%s:%s): "
|
||||
(magit--ellipsis) (magit--ellipsis))
|
||||
nil nil
|
||||
(format "On %s: %s"
|
||||
(or (magit-get-current-branch) "(no branch)")
|
||||
(magit-rev-format "%h %s"))))
|
||||
|
||||
(defun magit-stash-read-message-traditional ()
|
||||
"Read a message from the minibuffer, to be used for a stash.
|
||||
|
||||
If the user confirms the initial-input unmodified, then the
|
||||
abbreviated commit hash and commit summary are appended.
|
||||
The resulting message is what Git would have used."
|
||||
(let* ((default (format "On %s: "
|
||||
(or (magit-get-current-branch) "(no branch)")))
|
||||
(input (magit-read-string "Stash message" default)))
|
||||
@@ -177,6 +195,12 @@ while two prefix arguments are equivalent to `--all'."
|
||||
(concat default (magit-rev-format "%h %s"))
|
||||
input)))
|
||||
|
||||
(defun magit-stash-read-untracked ()
|
||||
(let ((prefix (prefix-numeric-value current-prefix-arg))
|
||||
(args (magit-stash-arguments)))
|
||||
(cond ((or (= prefix 16) (member "--all" args)) 'all)
|
||||
((or (= prefix 4) (member "--include-untracked" args)) t))))
|
||||
|
||||
;;;###autoload
|
||||
(defun magit-snapshot-both (&optional include-untracked)
|
||||
"Create a snapshot of the index and working tree.
|
||||
@@ -237,31 +261,79 @@ 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."
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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\"."
|
||||
(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-stash--apply "apply" stash))
|
||||
|
||||
;;;###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."
|
||||
"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.
|
||||
|
||||
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.
|
||||
|
||||
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\"."
|
||||
(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-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))
|
||||
|
||||
;;;###autoload
|
||||
(defun magit-stash-drop (stash)
|
||||
"Remove a stash from the stash list.
|
||||
When the region is active offer to drop all contained stashes."
|
||||
(interactive
|
||||
(list (--if-let (magit-region-values 'stash)
|
||||
(magit-confirm 'drop-stashes nil "Drop %i stashes" nil it)
|
||||
(list (if-let ((values (magit-region-values 'stash)))
|
||||
(magit-confirm 'drop-stashes nil "Drop %d stashes" nil values)
|
||||
(magit-read-stash "Drop stash"))))
|
||||
(dolist (stash (if (listp stash)
|
||||
(nreverse (prog1 stash (setq stash (car stash))))
|
||||
@@ -282,20 +354,23 @@ When the region is active offer to drop all contained stashes."
|
||||
|
||||
;;;###autoload
|
||||
(defun magit-stash-branch (stash branch)
|
||||
"Create and checkout a new BRANCH from STASH."
|
||||
"Create and checkout a new BRANCH from an existing STASH.
|
||||
The new branch starts at the commit that was current when the
|
||||
stash was created. If the stash applies cleanly, then drop it."
|
||||
(interactive (list (magit-read-stash "Branch stash")
|
||||
(magit-read-string-ns "Branch name")))
|
||||
(magit-run-git "stash" "branch" branch stash))
|
||||
|
||||
;;;###autoload
|
||||
(defun magit-stash-branch-here (stash branch)
|
||||
"Create and checkout a new BRANCH and apply STASH.
|
||||
The branch is created using `magit-branch-and-checkout', using the
|
||||
current branch or `HEAD' as the start-point."
|
||||
"Create and checkout a new BRANCH from an existing STASH.
|
||||
Use the current branch or `HEAD' as the starting-point of BRANCH.
|
||||
Then apply STASH, dropping it if it applies cleanly."
|
||||
(interactive (list (magit-read-stash "Branch stash")
|
||||
(magit-read-string-ns "Branch name")))
|
||||
(let ((magit-inhibit-refresh t))
|
||||
(magit-branch-and-checkout branch (or (magit-get-current-branch) "HEAD")))
|
||||
(let ((start-point (or (magit-get-current-branch) "HEAD")))
|
||||
(magit-call-git "checkout" "-b" branch start-point)
|
||||
(magit-branch-maybe-adjust-upstream branch start-point))
|
||||
(magit-stash-apply stash))
|
||||
|
||||
;;;###autoload
|
||||
@@ -373,21 +448,23 @@ current branch or `HEAD' as the start-point."
|
||||
|
||||
;;; Sections
|
||||
|
||||
(defvar magit-stashes-section-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(magit-menu-set map [magit-visit-thing] #'magit-stash-list "List %t")
|
||||
(magit-menu-set map [magit-delete-thing] #'magit-stash-clear "Clear %t")
|
||||
map)
|
||||
"Keymap for `stashes' section.")
|
||||
(defvar-keymap magit-stashes-section-map
|
||||
:doc "Keymap for `stashes' section."
|
||||
"<remap> <magit-delete-thing>" #'magit-stash-clear
|
||||
"<remap> <magit-visit-thing>" #'magit-stash-list
|
||||
"<2>" (magit-menu-item "Clear %t" #'magit-stash-clear)
|
||||
"<1>" (magit-menu-item "List %t" #'magit-stash-list))
|
||||
|
||||
(defvar magit-stash-section-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(magit-menu-set map [magit-visit-thing] #'magit-stash-show "Visit %v")
|
||||
(magit-menu-set map [magit-delete-thing] #'magit-stash-drop "Delete %M")
|
||||
(magit-menu-set map [magit-cherry-apply] #'magit-stash-apply "Apply %M")
|
||||
(magit-menu-set map [magit-cherry-pick] #'magit-stash-pop "Pop %M")
|
||||
map)
|
||||
"Keymap for `stash' sections.")
|
||||
(defvar-keymap magit-stash-section-map
|
||||
:doc "Keymap for `stash' sections."
|
||||
"<remap> <magit-cherry-pick>" #'magit-stash-pop
|
||||
"<remap> <magit-cherry-apply>" #'magit-stash-apply
|
||||
"<remap> <magit-delete-thing>" #'magit-stash-drop
|
||||
"<remap> <magit-visit-thing>" #'magit-stash-show
|
||||
"<4>" (magit-menu-item "Pop %M" #'magit-stash-pop)
|
||||
"<3>" (magit-menu-item "Apply %M" #'magit-stash-apply)
|
||||
"<2>" (magit-menu-item "Delete %M" #'magit-stash-drop)
|
||||
"<1>" (magit-menu-item "Visit %v" #'magit-stash-show))
|
||||
|
||||
(magit-define-section-jumper magit-jump-to-stashes
|
||||
"Stashes" stashes "refs/stash")
|
||||
@@ -522,8 +599,9 @@ If there is no stash buffer in the same frame, then do nothing."
|
||||
(defun magit-stash-insert-section (commit range message &optional files)
|
||||
(magit-insert-section (commit commit)
|
||||
(magit-insert-heading message)
|
||||
(magit--insert-diff "diff" range "-p" "--no-prefix" magit-buffer-diff-args
|
||||
"--" (or files magit-buffer-diff-files))))
|
||||
(magit--insert-diff nil
|
||||
"diff" range "-p" "--no-prefix" magit-buffer-diff-args
|
||||
"--" (or files magit-buffer-diff-files))))
|
||||
|
||||
(defun magit-insert-stash-notes ()
|
||||
"Insert section showing notes for a stash.
|
||||
|
||||
Reference in New Issue
Block a user