aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Whitton2024-10-29 19:55:08 +0800
committerSean Whitton2024-10-29 20:06:48 +0800
commit90ffe8a36b16801eaf0ca9b0ffca07156cf3c26d (patch)
treee8506f14490498692c809bcb321e399ad1feb8d5
parent4a49c50a4c351503a94c223da05888e5fd3d4fa1 (diff)
downloademacs-90ffe8a36b16801eaf0ca9b0ffca07156cf3c26d.tar.gz
emacs-90ffe8a36b16801eaf0ca9b0ffca07156cf3c26d.zip
Improve prompting for git stashes
* lisp/vc/vc-git.el (vc-git-stash-read): New DEFAULT-MOST-RECENT optional argument. Use format-prompt. Signal user-error immediately if there are no stashes. Rewrite docstring. (vc-git-stash-show, vc-git-stash-apply, vc-git-stash-pop) (vc-git-stash-delete): Drop trailing ": " from prompts. (vc-git-stash-pop): Pass non-nil DEFAULT-MOST-RECENT to vc-git-stash-read.
-rw-r--r--lisp/vc/vc-git.el40
1 files changed, 25 insertions, 15 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index b751ead3f1d..d7fc833a2ec 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -2202,21 +2202,29 @@ In other modes, call `vc-deduce-fileset' to determine files to stash."
2202(defvar vc-git-stash-read-history nil 2202(defvar vc-git-stash-read-history nil
2203 "History for `vc-git-stash-read'.") 2203 "History for `vc-git-stash-read'.")
2204 2204
2205(defun vc-git-stash-read (prompt) 2205(defun vc-git-stash-read (prompt &optional default-most-recent)
2206 "Read a Git stash. PROMPT is a string to prompt with." 2206 "Prompt the user, with PROMPT, to select a git stash.
2207 (let ((stash (completing-read 2207PROMPT is passed to `format-prompt'. If DEFAULT-MOST-RECENT is non-nil,
2208 prompt 2208then the most recently pushed stash is the default selection."
2209 (split-string 2209 (if-let* ((stashes
2210 (or (vc-git--run-command-string nil "stash" "list") "") "\n" t) 2210 (split-string (vc-git--run-command-string nil
2211 nil :require-match nil 'vc-git-stash-read-history))) 2211 "stash" "list")
2212 (if (string-equal stash "") 2212 "\n" t)))
2213 (user-error "Not a stash") 2213 (let* ((default (and default-most-recent (car stashes)))
2214 (string-match "^stash@{[[:digit:]]+}" stash) 2214 (prompt (format-prompt prompt default))
2215 (match-string 0 stash)))) 2215 (stash (completing-read prompt stashes
2216 nil :require-match nil
2217 'vc-git-stash-read-history
2218 default)))
2219 (if (string-equal stash "")
2220 (user-error "Not a stash")
2221 (string-match "^stash@{[[:digit:]]+}" stash)
2222 (match-string 0 stash)))
2223 (user-error "No stashes")))
2216 2224
2217(defun vc-git-stash-show (name) 2225(defun vc-git-stash-show (name)
2218 "Show the contents of stash NAME." 2226 "Show the contents of stash NAME."
2219 (interactive (list (vc-git-stash-read "Show stash: "))) 2227 (interactive (list (vc-git-stash-read "Show stash")))
2220 (vc-setup-buffer "*vc-git-stash*") 2228 (vc-setup-buffer "*vc-git-stash*")
2221 (vc-git-command "*vc-git-stash*" 'async nil 2229 (vc-git-command "*vc-git-stash*" 'async nil
2222 "stash" "show" "--color=never" "-p" name) 2230 "stash" "show" "--color=never" "-p" name)
@@ -2227,19 +2235,21 @@ In other modes, call `vc-deduce-fileset' to determine files to stash."
2227 2235
2228(defun vc-git-stash-apply (name) 2236(defun vc-git-stash-apply (name)
2229 "Apply stash NAME." 2237 "Apply stash NAME."
2230 (interactive (list (vc-git-stash-read "Apply stash: "))) 2238 (interactive (list (vc-git-stash-read "Apply stash")))
2231 (vc-git-command "*vc-git-stash*" 0 nil "stash" "apply" "-q" name) 2239 (vc-git-command "*vc-git-stash*" 0 nil "stash" "apply" "-q" name)
2232 (vc-resynch-buffer (vc-git-root default-directory) t t)) 2240 (vc-resynch-buffer (vc-git-root default-directory) t t))
2233 2241
2234(defun vc-git-stash-pop (name) 2242(defun vc-git-stash-pop (name)
2235 "Pop stash NAME." 2243 "Pop stash NAME."
2236 (interactive (list (vc-git-stash-read "Pop stash: "))) 2244 ;; Stashes are commonly popped off in reverse order, so pass non-nil
2245 ;; DEFAULT-MOST-RECENT to `vc-git-stash-read'.
2246 (interactive (list (vc-git-stash-read "Pop stash" t)))
2237 (vc-git-command "*vc-git-stash*" 0 nil "stash" "pop" "-q" name) 2247 (vc-git-command "*vc-git-stash*" 0 nil "stash" "pop" "-q" name)
2238 (vc-resynch-buffer (vc-git-root default-directory) t t)) 2248 (vc-resynch-buffer (vc-git-root default-directory) t t))
2239 2249
2240(defun vc-git-stash-delete (name) 2250(defun vc-git-stash-delete (name)
2241 "Delete stash NAME." 2251 "Delete stash NAME."
2242 (interactive (list (vc-git-stash-read "Delete stash: "))) 2252 (interactive (list (vc-git-stash-read "Delete stash")))
2243 (vc-git-command "*vc-git-stash*" 0 nil "stash" "drop" "-q" name) 2253 (vc-git-command "*vc-git-stash*" 0 nil "stash" "drop" "-q" name)
2244 (vc-resynch-buffer (vc-git-root default-directory) t t)) 2254 (vc-resynch-buffer (vc-git-root default-directory) t t))
2245 2255