summaryrefslogtreecommitdiff
path: root/lisp/vc/vc-git.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-09-24 15:17:23 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-09-24 15:19:03 +0200
commit8dacd8cd914fdbe0f6f17ca57915611d48e9124d (patch)
tree287c2bf8dd3d837962cbf09e0281be76a4454943 /lisp/vc/vc-git.el
parent3ce322efef3c57b83d0f243c6f0d4f560d50fe7a (diff)
downloademacs-8dacd8cd914fdbe0f6f17ca57915611d48e9124d.tar.gz
emacs-8dacd8cd914fdbe0f6f17ca57915611d48e9124d.tar.bz2
emacs-8dacd8cd914fdbe0f6f17ca57915611d48e9124d.zip
Add a new command vc-pull-and-push
* lisp/vc/vc-svn.el (vc-exec-after): * lisp/vc/vc-hg.el (vc-exec-after): * lisp/vc/vc-git.el (vc-exec-after): * lisp/vc/vc-cvs.el (vc-exec-after): * lisp/vc/vc-bzr.el (vc-exec-after): * lisp/org/org-macro.el (vc-exec-after): * lisp/obsolete/vc-mtn.el (vc-exec-after): * lisp/obsolete/vc-arch.el (vc-exec-after): Update declaration. * lisp/vc/vc-dispatcher.el (vc--process-sentinel): Allow running code only on success. (vc-exec-after): Ditto. (vc--inhibit-change-window-start): New variable. (vc-do-async-command): Use it to allow chaining commands without moving window point. Return the process instead of the buffer, since the process may have exited already, and then we can't get at the process. * lisp/vc/vc-git.el (vc-git--pushpull): Return the process object. (vc-git-pull-and-push): New function. * lisp/vc/vc.el (vc-pull-and-push): New command (bug#51964).
Diffstat (limited to 'lisp/vc/vc-git.el')
-rw-r--r--lisp/vc/vc-git.el31
1 files changed, 26 insertions, 5 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 3816d323e6f..18cc4a66adc 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -624,7 +624,7 @@ or an empty string if none."
;; Follows vc-git-command (or vc-do-async-command), which uses vc-do-command
;; from vc-dispatcher.
-(declare-function vc-exec-after "vc-dispatcher" (code))
+(declare-function vc-exec-after "vc-dispatcher" (code &optional success))
;; Follows vc-exec-after.
(declare-function vc-set-async-update "vc-dispatcher" (process-buffer))
@@ -1098,7 +1098,8 @@ If PROMPT is non-nil, prompt for the Git command to run."
(buffer (format "*vc-git : %s*" (expand-file-name root)))
(git-program vc-git-program)
;; TODO if pushing, prompt if no default push location - cf bzr.
- (vc-want-edit-command-p prompt))
+ (vc-want-edit-command-p prompt)
+ proc)
(require 'vc-dispatcher)
(when vc-want-edit-command-p
(with-current-buffer (get-buffer-create buffer)
@@ -1108,8 +1109,8 @@ If PROMPT is non-nil, prompt for the Git command to run."
command (caaddr args)
extra-args (cdaddr args)))
nil t)))
- (apply #'vc-do-async-command
- buffer root git-program command extra-args)
+ (setq proc (apply #'vc-do-async-command
+ buffer root git-program command extra-args))
(with-current-buffer buffer
(vc-run-delayed
(vc-compilation-mode 'git)
@@ -1124,7 +1125,8 @@ If PROMPT is non-nil, prompt for the Git command to run."
(list compile-command nil
(lambda (_name-of-mode) buffer)
nil))))
- (vc-set-async-update buffer)))
+ (vc-set-async-update buffer)
+ proc))
(defun vc-git-pull (prompt)
"Pull changes into the current Git branch.
@@ -1138,6 +1140,25 @@ Normally, this runs \"git push\". If PROMPT is non-nil, prompt
for the Git command to run."
(vc-git--pushpull "push" prompt nil))
+(defun vc-git-pull-and-push (prompt)
+ "Pull changes into the current Git branch, and then push.
+The push will only be performed if the pull was successful.
+
+Normally, this runs \"git pull\". If PROMPT is non-nil, prompt
+for the Git command to run."
+ (let ((proc (vc-git--pushpull "pull" prompt '("--stat"))))
+ (when (process-buffer proc)
+ (with-current-buffer (process-buffer proc)
+ (if (and (eq (process-status proc) 'exit)
+ (zerop (process-exit-status proc)))
+ (let ((vc--inhibit-change-window-start t))
+ (vc-git-push nil))
+ (vc-exec-after
+ (lambda ()
+ (let ((vc--inhibit-change-window-start t))
+ (vc-git-push nil)))
+ proc))))))
+
(defun vc-git-merge-branch ()
"Merge changes into the current Git branch.
This prompts for a branch to merge from."