commit | author | age
|
5cb5f7
|
1 |
;;; magit-fetch.el --- download objects and refs -*- lexical-binding: t -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2008-2018 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 |
;; Magit is free software; you can redistribute it and/or modify it |
|
12 |
;; under the terms of the GNU General Public License as published by |
|
13 |
;; the Free Software Foundation; either version 3, or (at your option) |
|
14 |
;; any later version. |
|
15 |
;; |
|
16 |
;; Magit is distributed in the hope that it will be useful, but WITHOUT |
|
17 |
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
18 |
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
|
19 |
;; License for more details. |
|
20 |
;; |
|
21 |
;; You should have received a copy of the GNU General Public License |
|
22 |
;; along with Magit. If not, see http://www.gnu.org/licenses. |
|
23 |
|
|
24 |
;;; Commentary: |
|
25 |
|
|
26 |
;; This library implements fetch commands. |
|
27 |
|
|
28 |
;;; Code: |
|
29 |
|
|
30 |
(require 'magit) |
|
31 |
|
|
32 |
;;; Options |
|
33 |
|
|
34 |
(defcustom magit-fetch-modules-jobs 4 |
|
35 |
"Number of submodules to fetch in parallel. |
|
36 |
Ignored for Git versions before v2.8.0." |
|
37 |
:package-version '(magit . "2.12.0") |
|
38 |
:group 'magit-commands |
|
39 |
:type '(choice (const :tag "one at a time" nil) number)) |
|
40 |
|
|
41 |
;;; Commands |
|
42 |
|
|
43 |
;;;###autoload (autoload 'magit-fetch-popup "magit-fetch" nil t) |
|
44 |
(magit-define-popup magit-fetch-popup |
|
45 |
"Popup console for fetch commands." |
|
46 |
:man-page "git-fetch" |
|
47 |
:switches '((?p "Prune deleted branches" "--prune")) |
|
48 |
:actions '("Configure" |
|
49 |
(?C "variables..." magit-branch-config-popup) |
|
50 |
"Fetch from" |
|
51 |
(?p magit-get-push-remote magit-fetch-from-pushremote) |
|
52 |
(?u magit-get-remote magit-fetch-from-upstream) |
|
53 |
(?e "elsewhere" magit-fetch-other) |
|
54 |
(?a "all remotes" magit-fetch-all) |
|
55 |
"Fetch" |
|
56 |
(?o "another branch" magit-fetch-branch) |
|
57 |
(?r "explicit refspec" magit-fetch-refspec) |
|
58 |
(?m "submodules" magit-fetch-modules)) |
|
59 |
:default-action 'magit-fetch |
|
60 |
:max-action-columns 1) |
|
61 |
|
|
62 |
(defun magit-git-fetch (remote args) |
|
63 |
(run-hooks 'magit-credential-hook) |
|
64 |
(magit-run-git-async "fetch" remote args)) |
|
65 |
|
|
66 |
;;;###autoload |
|
67 |
(defun magit-fetch-from-pushremote (args) |
|
68 |
"Fetch from the push-remote of the current branch." |
|
69 |
(interactive (list (magit-fetch-arguments))) |
|
70 |
(--if-let (magit-get-push-remote) |
|
71 |
(magit-git-fetch it args) |
|
72 |
(--if-let (magit-get-current-branch) |
|
73 |
(user-error "No push-remote is configured for %s" it) |
|
74 |
(user-error "No branch is checked out")))) |
|
75 |
|
|
76 |
;;;###autoload |
|
77 |
(defun magit-fetch-from-upstream (args) |
|
78 |
"Fetch from the upstream repository of the current branch." |
|
79 |
(interactive (list (magit-fetch-arguments))) |
|
80 |
(--if-let (magit-get-remote) |
|
81 |
(magit-git-fetch it args) |
|
82 |
(--if-let (magit-get-current-branch) |
|
83 |
(user-error "No upstream is configured for %s" it) |
|
84 |
(user-error "No branch is checked out")))) |
|
85 |
|
|
86 |
;;;###autoload |
|
87 |
(defun magit-fetch-other (remote args) |
|
88 |
"Fetch from another repository." |
|
89 |
(interactive (list (magit-read-remote "Fetch remote") |
|
90 |
(magit-fetch-arguments))) |
|
91 |
(magit-git-fetch remote args)) |
|
92 |
|
|
93 |
;;;###autoload |
|
94 |
(defun magit-fetch-branch (remote branch args) |
|
95 |
"Fetch a BRANCH from a REMOTE." |
|
96 |
(interactive |
|
97 |
(let ((remote (magit-read-remote-or-url "Fetch from remote or url"))) |
|
98 |
(list remote |
|
99 |
(magit-read-remote-branch "Fetch branch" remote) |
|
100 |
(magit-fetch-arguments)))) |
|
101 |
(magit-git-fetch remote (cons branch args))) |
|
102 |
|
|
103 |
;;;###autoload |
|
104 |
(defun magit-fetch-refspec (remote refspec args) |
|
105 |
"Fetch a REFSPEC from a REMOTE." |
|
106 |
(interactive |
|
107 |
(let ((remote (magit-read-remote-or-url "Fetch from remote or url"))) |
|
108 |
(list remote |
|
109 |
(magit-read-refspec "Fetch using refspec" remote) |
|
110 |
(magit-fetch-arguments)))) |
|
111 |
(magit-git-fetch remote (cons refspec args))) |
|
112 |
|
|
113 |
;;;###autoload |
|
114 |
(defun magit-fetch-all (args) |
|
115 |
"Fetch from all remotes." |
|
116 |
(interactive (list (cl-intersection (magit-fetch-arguments) |
|
117 |
(list "--verbose" "--prune") |
|
118 |
:test #'equal))) |
|
119 |
(run-hooks 'magit-credential-hook) |
|
120 |
(magit-run-git-async "remote" "update" args)) |
|
121 |
|
|
122 |
;;;###autoload |
|
123 |
(defun magit-fetch-all-prune () |
|
124 |
"Fetch from all remotes, and prune. |
|
125 |
Prune remote tracking branches for branches that have been |
|
126 |
removed on the respective remote." |
|
127 |
(interactive) |
|
128 |
(run-hooks 'magit-credential-hook) |
|
129 |
(magit-run-git-async "remote" "update" "--prune")) |
|
130 |
|
|
131 |
;;;###autoload |
|
132 |
(defun magit-fetch-all-no-prune () |
|
133 |
"Fetch from all remotes." |
|
134 |
(interactive) |
|
135 |
(run-hooks 'magit-credential-hook) |
|
136 |
(magit-run-git-async "remote" "update")) |
|
137 |
|
|
138 |
;;;###autoload |
|
139 |
(defun magit-fetch-modules (&optional all) |
|
140 |
"Fetch all submodules. |
|
141 |
|
|
142 |
Option `magit-fetch-modules-jobs' controls how many submodules |
|
143 |
are being fetched in parallel. Also fetch the super-repository, |
|
144 |
because `git-fetch' does not support not doing that. With a |
|
145 |
prefix argument fetch all remotes." |
|
146 |
(interactive "P") |
|
147 |
(magit-with-toplevel |
|
148 |
(magit-run-git-async |
|
149 |
"fetch" "--verbose" "--recurse-submodules" |
|
150 |
(and magit-fetch-modules-jobs |
|
151 |
(version<= "2.8.0" (magit-git-version)) |
|
152 |
(list "-j" (number-to-string magit-fetch-modules-jobs))) |
|
153 |
(and all "--all")))) |
|
154 |
|
|
155 |
;;; _ |
|
156 |
(provide 'magit-fetch) |
|
157 |
;;; magit-fetch.el ends here |