summaryrefslogtreecommitdiff
path: root/lisp/vc/vc-git.el
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-09-18 14:47:23 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-09-21 12:31:05 -0700
commit101f3cf5b9b5600147d4406c3be8daf174e1a543 (patch)
tree2b1c2c04359ada4948958695236a129bddb0fcfb /lisp/vc/vc-git.el
parent447ff572be1019249afb2c67411d4a5bdb0a4407 (diff)
downloademacs-101f3cf5b9b5600147d4406c3be8daf174e1a543.tar.gz
emacs-101f3cf5b9b5600147d4406c3be8daf174e1a543.tar.bz2
emacs-101f3cf5b9b5600147d4406c3be8daf174e1a543.zip
Add support for user edits to VC command arguments
* lisp/vc/vc-dispatcher.el (vc-pre-command-functions): New hook. (vc-want-edit-command-p): New variable. (vc-do-command): If vc-want-edit-command-p is non-nil, prompt the user to edit the VC command & arguments before execution. Run the new hook. (vc-do-async-command): Use the new hook to insert into BUFFER the command that's next to be run. * lisp/vc/vc-git.el (vc-git--pushpull): Drop prompting code. Bind vc-want-edit-command-p so that vc-do-command handles the prompting. Use the new hook to update compile-command with the edited command. * lisp/vc/vc.el (vc-print-branch-log): A non-nil prefix argument now means vc-want-edit-command-p is bound to a non-nil value (bug#57807).
Diffstat (limited to 'lisp/vc/vc-git.el')
-rw-r--r--lisp/vc/vc-git.el31
1 files changed, 13 insertions, 18 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index a5d12f03bcf..2228cf86659 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1089,35 +1089,30 @@ It is based on `log-edit-mode', and has Git-specific extensions."
(declare-function vc-compilation-mode "vc-dispatcher" (backend))
(defvar compilation-directory)
(defvar compilation-arguments)
+(defvar vc-want-edit-command-p)
(defun vc-git--pushpull (command prompt extra-args)
"Run COMMAND (a string; either push or pull) on the current Git branch.
If PROMPT is non-nil, prompt for the Git command to run."
(let* ((root (vc-git-root default-directory))
(buffer (format "*vc-git : %s*" (expand-file-name root)))
- (git-program vc-git-program)
- args)
- ;; If necessary, prompt for the exact command.
- ;; TODO if pushing, prompt if no default push location - cf bzr.
- (when prompt
- (setq args (split-string
- (read-shell-command
- (format "Git %s command: " command)
- (format "%s %s" git-program command)
- 'vc-git-history)
- " " t))
- (setq git-program (car args)
- command (cadr args)
- args (cddr args)))
- (setq args (nconc args extra-args))
+ ;; TODO if pushing, prompt if no default push location - cf bzr.
+ (vc-want-edit-command-p prompt))
(require 'vc-dispatcher)
- (apply #'vc-do-async-command buffer root git-program command args)
+ (when vc-want-edit-command-p
+ (with-current-buffer (get-buffer-create buffer)
+ (add-hook 'vc-pre-command-functions
+ (pcase-lambda (_ _ `(,new-command . ,new-args))
+ (setq command new-command extra-args new-args))
+ nil t)))
+ (apply #'vc-do-async-command
+ buffer root vc-git-program command extra-args)
(with-current-buffer buffer
(vc-run-delayed
(vc-compilation-mode 'git)
(setq-local compile-command
- (concat git-program " " command " "
- (mapconcat #'identity args " ")))
+ (concat vc-git-program " " command " "
+ (mapconcat #'identity extra-args " ")))
(setq-local compilation-directory root)
;; Either set `compilation-buffer-name-function' locally to nil
;; or use `compilation-arguments' to set `name-function'.