Commit 7a3bb7f2 authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit-fetch-{branch,refspec}: new commands

Also add the functions `magit-read-remote-or-url', `magit-read-refspec',
and `magit-remote-list-refs', which are required by these new commands.
parent 8324592c
......@@ -15,6 +15,8 @@ Updates since v2.5.0
one or more comma-separated and refspecs, which are explicitly typed
in the minibuffer.
* Added new commands `magit-fetch-refspec' and `magit-fetch-branch'.
* Added new command `magit-reset-popup' featuring all the available
reset variants.
......
......@@ -1016,6 +1016,11 @@ where COMMITS is the number of commits in TAG but not in REV."
(substring it 52))
(magit-git-lines "ls-remote" "--heads" remote)))
(defun magit-remote-list-refs (remote)
(--keep (and (not (string-match-p "\\^{}$" it))
(substring it 41))
(magit-git-lines "ls-remote" remote)))
(defun magit-get-submodules ()
(--mapcat (and (string-match "^160000 [0-9a-z]\\{40\\} 0\t\\(.+\\)$" it)
(list (match-string 1 it)))
......@@ -1271,6 +1276,12 @@ Return a list of two integers: (A>B B>A)."
choice
(user-error "`%s' doesn't have the form REMOTE/BRANCH" choice))))
(defun magit-read-refspec (prompt remote)
(magit-completing-read prompt
(prog2 (message "Determining available refs...")
(magit-remote-list-refs remote)
(message "Determining available refs...done"))))
(defun magit-read-local-branch (prompt &optional secondary-default)
(magit-completing-read prompt (magit-list-local-branch-names)
nil t nil 'magit-revision-history
......@@ -1376,6 +1387,15 @@ Return a list of two integers: (A>B B>A)."
(magit-remote-at-point)
(magit-get-remote))))))
(defun magit-read-remote-or-url (prompt &optional default)
(magit-completing-read prompt
(nconc (magit-list-remotes)
(list "https://" "git://" "git@"))
nil nil nil nil
(or default
(magit-remote-at-point)
(magit-get-remote))))
;;; Variables
(defun magit-get (&rest keys)
......
......@@ -184,6 +184,8 @@ Delete the symbolic-ref \"refs/remotes/<remote>/HEAD\"."
(?e "elsewhere" magit-fetch)
(?a "all remotes" magit-fetch-all)
"Fetch"
(?o "another branch" magit-fetch-branch)
(?r "explicit refspec" magit-fetch-refspec)
(?m "submodules" magit-submodule-fetch))
:default-action 'magit-fetch
:max-action-columns 1)
......@@ -219,6 +221,26 @@ Delete the symbolic-ref \"refs/remotes/<remote>/HEAD\"."
(magit-fetch-arguments)))
(magit-git-fetch remote args))
;;;###autoload
(defun magit-fetch-branch (remote branch args)
"Fetch a BRANCH from a REMOTE."
(interactive
(let ((remote (magit-read-remote-or-url "Fetch from remote or url")))
(list remote
(magit-read-remote-branch "Fetch branch" remote)
(magit-fetch-arguments))))
(magit-git-fetch remote (cons branch args)))
;;;###autoload
(defun magit-fetch-refspec (remote refspec args)
"Fetch a REFSPEC from a REMOTE."
(interactive
(let ((remote (magit-read-remote-or-url "Fetch from remote or url")))
(list remote
(magit-read-refspec "Fetch using refspec" remote)
(magit-fetch-arguments))))
(magit-git-fetch remote (cons refspec args)))
;;;###autoload
(defun magit-fetch-all (args)
"Fetch from all remotes."
......@@ -312,6 +334,8 @@ missing. To add them use something like:
(?f "remotes" magit-fetch-all-no-prune)
(?F "remotes and prune" magit-fetch-all-prune)
"Fetch"
(?o "another branch" magit-fetch-branch)
(?r "explicit refspec" magit-fetch-refspec)
(?m "submodules" magit-submodule-fetch))
:default-action 'magit-fetch
:max-action-columns 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment