dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

magit-fetch.el (6552B)


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