magit-fetch.el (6851B)
1 ;;; magit-fetch.el --- Download objects and refs -*- lexical-binding:t -*- 2 3 ;; Copyright (C) 2008-2024 The Magit Project Contributors 4 5 ;; Author: Jonas Bernoulli <emacs.magit@jonas.bernoulli.dev> 6 ;; Maintainer: Jonas Bernoulli <emacs.magit@jonas.bernoulli.dev> 7 8 ;; SPDX-License-Identifier: GPL-3.0-or-later 9 10 ;; Magit is free software: you can redistribute it and/or modify it 11 ;; under the terms of the GNU General Public License as published by 12 ;; the Free Software Foundation, either version 3 of the License, or 13 ;; (at your option) any later version. 14 ;; 15 ;; Magit is distributed in the hope that it will be useful, but WITHOUT 16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 18 ;; License for more details. 19 ;; 20 ;; You should have received a copy of the GNU General Public License 21 ;; along with Magit. If not, see <https://www.gnu.org/licenses/>. 22 23 ;;; Commentary: 24 25 ;; This library implements fetch commands. 26 27 ;;; Code: 28 29 (require 'magit) 30 31 ;;; Commands 32 33 ;;;###autoload (autoload 'magit-fetch "magit-fetch" nil t) 34 (transient-define-prefix magit-fetch () 35 "Fetch from another repository." 36 :man-page "git-fetch" 37 ["Arguments" 38 ("-p" "Prune deleted branches" ("-p" "--prune")) 39 ("-t" "Fetch all tags" ("-t" "--tags")) 40 ("-u" "Fetch full history" "--unshallow" :level 7) 41 ("-F" "Force" ("-f" "--force"))] 42 ["Fetch from" 43 ("p" magit-fetch-from-pushremote) 44 ("u" magit-fetch-from-upstream) 45 ("e" "elsewhere" magit-fetch-other) 46 ("a" "all remotes" magit-fetch-all)] 47 ["Fetch" 48 ("o" "another branch" magit-fetch-branch) 49 ("r" "explicit refspec" magit-fetch-refspec) 50 ("m" "submodules" magit-fetch-modules)] 51 ["Configure" 52 ("C" "variables..." magit-branch-configure)]) 53 54 (defun magit-fetch-arguments () 55 (transient-args 'magit-fetch)) 56 57 (defun magit-git-fetch (remote args) 58 (run-hooks 'magit-credential-hook) 59 (magit-run-git-async "fetch" remote args)) 60 61 ;;;###autoload (autoload 'magit-fetch-from-pushremote "magit-fetch" nil t) 62 (transient-define-suffix magit-fetch-from-pushremote (args) 63 "Fetch from the current push-remote. 64 65 With a prefix argument or when the push-remote is either not 66 configured or unusable, then let the user first configure the 67 push-remote." 68 :description #'magit-fetch--pushremote-description 69 (interactive (list (magit-fetch-arguments))) 70 (let ((remote (magit-get-push-remote))) 71 (when (or current-prefix-arg 72 (not (member remote (magit-list-remotes)))) 73 (let ((var (magit--push-remote-variable))) 74 (setq remote 75 (magit-read-remote (format "Set %s and fetch from there" var))) 76 (magit-set remote var))) 77 (magit-git-fetch remote args))) 78 79 (defun magit-fetch--pushremote-description () 80 (let* ((branch (magit-get-current-branch)) 81 (remote (magit-get-push-remote branch)) 82 (v (magit--push-remote-variable branch t))) 83 (cond 84 ((member remote (magit-list-remotes)) remote) 85 (remote 86 (format "%s, replacing invalid" v)) 87 (t 88 (format "%s, setting that" v))))) 89 90 ;;;###autoload (autoload 'magit-fetch-from-upstream "magit-fetch" nil t) 91 (transient-define-suffix magit-fetch-from-upstream (remote args) 92 "Fetch from the \"current\" remote, usually the upstream. 93 94 If the upstream is configured for the current branch and names 95 an existing remote, then use that. Otherwise try to use another 96 remote: If only a single remote is configured, then use that. 97 Otherwise if a remote named \"origin\" exists, then use that. 98 99 If no remote can be determined, then this command is not available 100 from the `magit-fetch' transient prefix and invoking it directly 101 results in an error." 102 :if (lambda () (magit-get-current-remote t)) 103 :description (lambda () (magit-get-current-remote t)) 104 (interactive (list (magit-get-current-remote t) 105 (magit-fetch-arguments))) 106 (unless remote 107 (error "The \"current\" remote could not be determined")) 108 (magit-git-fetch remote args)) 109 110 ;;;###autoload 111 (defun magit-fetch-other (remote args) 112 "Fetch from another repository." 113 (interactive (list (magit-read-remote "Fetch remote") 114 (magit-fetch-arguments))) 115 (magit-git-fetch remote args)) 116 117 ;;;###autoload 118 (defun magit-fetch-branch (remote branch args) 119 "Fetch a BRANCH from a REMOTE." 120 (interactive 121 (let ((remote (magit-read-remote-or-url "Fetch from remote or url"))) 122 (list remote 123 (magit-read-remote-branch "Fetch branch" remote) 124 (magit-fetch-arguments)))) 125 (magit-git-fetch remote (cons branch args))) 126 127 ;;;###autoload 128 (defun magit-fetch-refspec (remote refspec args) 129 "Fetch a REFSPEC from a REMOTE." 130 (interactive 131 (let ((remote (magit-read-remote-or-url "Fetch from remote or url"))) 132 (list remote 133 (magit-read-refspec "Fetch using refspec" remote) 134 (magit-fetch-arguments)))) 135 (magit-git-fetch remote (cons refspec args))) 136 137 ;;;###autoload 138 (defun magit-fetch-all (args) 139 "Fetch from all remotes." 140 (interactive (list (magit-fetch-arguments))) 141 (magit-git-fetch nil (cons "--all" args))) 142 143 ;;;###autoload 144 (defun magit-fetch-all-prune () 145 "Fetch from all remotes, and prune. 146 Prune remote tracking branches for branches that have been 147 removed on the respective remote." 148 (interactive) 149 (run-hooks 'magit-credential-hook) 150 (magit-run-git-async "remote" "update" "--prune")) 151 152 ;;;###autoload 153 (defun magit-fetch-all-no-prune () 154 "Fetch from all remotes." 155 (interactive) 156 (run-hooks 'magit-credential-hook) 157 (magit-run-git-async "remote" "update")) 158 159 ;;;###autoload (autoload 'magit-fetch-modules "magit-fetch" nil t) 160 (transient-define-prefix magit-fetch-modules (&optional transient args) 161 "Fetch all populated submodules. 162 163 Fetching is done using \"git fetch --recurse-submodules\", which 164 means that the super-repository and recursively all submodules 165 are also fetched. 166 167 To set and potentially save other arguments invoke this command 168 with a prefix argument." 169 :man-page "git-fetch" 170 :value (list "--verbose" "--jobs=4") 171 ["Arguments" 172 ("-v" "verbose" "--verbose") 173 ("-j" "number of jobs" "--jobs=" :reader transient-read-number-N+)] 174 ["Action" 175 ("m" "fetch modules" magit-fetch-modules)] 176 (interactive (if current-prefix-arg 177 (list t) 178 (list nil (transient-args 'magit-fetch-modules)))) 179 (if transient 180 (transient-setup 'magit-fetch-modules) 181 (when-let (((magit-git-version< "2.8.0")) 182 (value (transient-arg-value "--jobs=" args))) 183 (message "Dropping --jobs; not supported by Git v%s" 184 (magit-git-version)) 185 (setq args (remove (format "--jobs=%s" value) args))) 186 (magit-with-toplevel 187 (magit-run-git-async "fetch" "--recurse-submodules" args)))) 188 189 ;;; _ 190 (provide 'magit-fetch) 191 ;;; magit-fetch.el ends here