From 2343a067c3de65a7e7b85b1ca4d83147b8f6b647 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sun, 22 Jan 2023 19:27:10 +0200 Subject: [PATCH] Generalize vc-pull-and-push to support more backends (bug#60569) * lisp/vc/vc-git.el (vc-git-pull-and-push): Remove and move its logic to vc-pull-and-push. * lisp/vc/vc.el (vc-pull-and-push): Add code from vc-git-pull-and-push. --- lisp/vc/vc-git.el | 19 ------------------- lisp/vc/vc.el | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 06bf927831d..04aa37d6400 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -1182,25 +1182,6 @@ 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-async-window t)) - (vc-git-push nil)) - (vc-exec-after - (lambda () - (let ((vc--inhibit-async-window 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." diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index f105461b210..d4a3280f1bd 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -3071,9 +3071,20 @@ It also signals an error in a Bazaar bound branch." (interactive "P") (let* ((vc-fileset (vc-deduce-fileset t)) (backend (car vc-fileset))) - (if (vc-find-backend-function backend 'pull-and-push) - (vc-call-backend backend 'pull-and-push arg) - (user-error "VC pull-and-push is unsupported for `%s'" backend)))) + (if (vc-find-backend-function backend 'pull) + (let ((proc (vc-call-backend backend 'pull arg))) + (when (and (processp proc) (process-buffer proc)) + (with-current-buffer (process-buffer proc) + (if (and (eq (process-status proc) 'exit) + (zerop (process-exit-status proc))) + (let ((vc--inhibit-async-window t)) + (vc-push arg)) + (vc-exec-after + (lambda () + (let ((vc--inhibit-async-window t)) + (vc-push arg))) + proc))))) + (user-error "VC pull is unsupported for `%s'" backend)))) (defun vc-version-backup-file (file &optional rev) "Return name of backup file for revision REV of FILE. -- 2.39.2