1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-21 06:55:39 +00:00

VC Git: Use vc-deduce-fileset to determine what to stash

* lisp/vc/vc-git.el (vc-git--deduce-files-for-stash): New function.
(vc-git-stash, vc-git-stash-snapshot): Use it to determine what
to stash.  Update and expand docstrings.
(vc-git-stash-snapshot): No longer unconditionally snapshot all
uncommitted changes across the whole working tree.
This commit is contained in:
Sean Whitton 2024-10-29 19:25:31 +08:00
parent 9aa1865926
commit 4a49c50a4c

View File

@ -2179,14 +2179,24 @@ This command shares argument histories with \\[rgrep] and \\[grep]."
(autoload 'vc-dir-marked-files "vc-dir")
(defun vc-git--deduce-files-for-stash ()
;; In *vc-dir*, if nothing is marked, act on the whole working tree
;; regardless of the position of point. This preserves historical
;; behavior and is also probably more useful.
(if (derived-mode-p 'vc-dir-mode)
(vc-dir-marked-files)
(cadr (vc-deduce-fileset))))
(defun vc-git-stash (name)
"Create a stash given the name NAME."
"Create a stash named NAME.
In `vc-dir-mode', if there are files marked, stash the changes to those.
If no files are marked, stash all uncommitted changes to tracked files.
In other modes, call `vc-deduce-fileset' to determine files to stash."
(interactive "sStash name: ")
(let ((root (vc-git-root default-directory)))
(when root
(apply #'vc-git--call nil "stash" "push" "-m" name
(when (derived-mode-p 'vc-dir-mode)
(vc-dir-marked-files)))
(vc-git--deduce-files-for-stash))
(vc-resynch-buffer root t t))))
(defvar vc-git-stash-read-history nil
@ -2234,10 +2244,14 @@ This command shares argument histories with \\[rgrep] and \\[grep]."
(vc-resynch-buffer (vc-git-root default-directory) t t))
(defun vc-git-stash-snapshot ()
"Create a stash with the current tree state."
"Create a stash with the current uncommitted changes.
In `vc-dir-mode', if there are files marked, stash the changes to those.
If no files are marked, stash all uncommitted changes to tracked files.
In other modes, call `vc-deduce-fileset' to determine files to stash."
(interactive)
(vc-git--call nil "stash" "save"
(format-time-string "Snapshot on %Y-%m-%d at %H:%M"))
(apply #'vc-git--call nil "stash" "push" "-m"
(format-time-string "Snapshot on %Y-%m-%d at %H:%M")
(vc-git--deduce-files-for-stash))
(vc-git-command "*vc-git-stash*" 0 nil "stash" "apply" "-q" "stash@{0}")
(vc-resynch-buffer (vc-git-root default-directory) t t))