Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 regels
6.4 KiB

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