Add a prefix arg to magit-remote-update to prompt for a remote.

This commit is contained in:
Nathan Weizenbaum 2010-06-06 16:44:47 -07:00 committed by Phil Jackson
parent bcdfc155ae
commit fe7656731b
2 changed files with 35 additions and 14 deletions

View file

@ -499,6 +499,14 @@ Many Magit faces inherit from this one by default."
(substring head 11) (substring head 11)
nil))) nil)))
(defun magit-get-current-remote ()
"Return the name of the remote for the current branch.
If there is no current branch, or no remote for that branch,
return nil."
(let* ((branch (magit-get-current-branch))
(remote (and branch (magit-get "branch" branch "remote"))))
(if (string= remote "") nil remote)))
(defun magit-ref-exists-p (ref) (defun magit-ref-exists-p (ref)
(= (magit-git-exit-code "show-ref" "--verify" ref) 0)) (= (magit-git-exit-code "show-ref" "--verify" ref) 0))
@ -651,6 +659,19 @@ Many Magit faces inherit from this one by default."
(match-string 1 branch) (match-string 1 branch)
branch))))) branch)))))
(defun magit-read-remote (&optional prompt def)
"Read the name of a remote.
PROMPT is used as the prompt, and defaults to \"Remote\".
DEF is the default value, and defaults to the value of `magit-get-current-branch'."
(let* ((prompt (or prompt "Remote"))
(def (or def (magit-get-current-remote)))
(prompt (if def
(format "%s (default %s): " prompt def)
(format "%s: " prompt)))
(remotes (magit-git-lines "remote"))
(reply (funcall magit-completing-read prompt remotes
nil nil nil nil def)))
(if (string= reply "") nil reply)))
;;; Sections ;;; Sections
@ -2963,11 +2984,17 @@ Uncomitted changes in both working tree and staging area are lost.
;;; Updating, pull, and push ;;; Updating, pull, and push
(defun magit-remote-update () (defun magit-remote-update (&optional remote)
(interactive) "Update REMOTE. If nil, update all remotes.
(if (magit-svn-enabled)
(magit-run-git-async "svn" "fetch") When called interactively, update the current remote unless a
(magit-run-git-async "remote" "update"))) prefix arg is given. With prefix arg, prompt for a remote and
update it."
(interactive (list (when current-prefix-arg (magit-read-remote))))
(cond
((magit-svn-enabled) (magit-run-git-async "svn" "fetch"))
(remote (magit-run-git-async "fetch" remote))
(t (magit-run-git-async "remote" "update"))))
(defun magit-pull () (defun magit-pull ()
(interactive) (interactive)
@ -3008,13 +3035,6 @@ typing and automatically refreshes the status buffer."
args) args)
nil nil nil t)))) nil nil nil t))))
(defun magit-read-remote (prompt def)
(funcall magit-completing-read (if def
(format "%s (default %s): " prompt def)
(format "%s: " prompt))
(magit-git-lines "remote")
nil nil nil nil def))
(defun magit-push () (defun magit-push ()
(interactive) (interactive)
(let* ((branch (or (magit-get-current-branch) (let* ((branch (or (magit-get-current-branch)

View file

@ -654,8 +654,9 @@ the current branch, you will be prompted as well. Typing @kbd{P} will
only push the current branch to the remote. In other words, it will only push the current branch to the remote. In other words, it will
run @code{git push <remote> <branch>}. run @code{git push <remote> <branch>}.
Typing @kbd{f} will run @code{git remote update} and @kbd{F} will run Typing @kbd{f} will run @code{git remote update}. With a prefix arg, it
@code{git pull}. When you don't have a default branch configured to will prompt for the name of the remote to update. Typing @kbd{F} will
run @code{git pull}. When you don't have a default branch configured to
be pulled into the current one, you will be asked for it. be pulled into the current one, you will be asked for it.
If there is a default remote repository for the current branch, Magit If there is a default remote repository for the current branch, Magit