commit | author | age
|
5cb5f7
|
1 |
;;; magit-pull.el --- update local 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 pull commands. |
|
27 |
|
|
28 |
;;; Code: |
|
29 |
|
|
30 |
(require 'magit) |
|
31 |
|
|
32 |
;;; Commands |
|
33 |
|
|
34 |
;;;###autoload (autoload 'magit-pull-popup "magit-pull" nil t) |
|
35 |
(magit-define-popup magit-pull-popup |
|
36 |
"Popup console for pull commands." |
|
37 |
:man-page "git-pull" |
|
38 |
:variables '("Configure" |
|
39 |
(?r "branch.%s.rebase" |
|
40 |
magit-cycle-branch*rebase |
|
41 |
magit-pull-format-branch*rebase) |
|
42 |
(?C "variables..." magit-branch-config-popup)) |
|
43 |
:actions '((lambda () |
|
44 |
(--if-let (magit-get-current-branch) |
|
45 |
(concat |
|
46 |
(propertize "Pull into " 'face 'magit-popup-heading) |
|
47 |
(propertize it 'face 'magit-branch-local) |
|
48 |
(propertize " from" 'face 'magit-popup-heading)) |
|
49 |
(propertize "Pull from" 'face 'magit-popup-heading))) |
|
50 |
(?p magit-get-push-branch magit-pull-from-pushremote) |
|
51 |
(?u magit-get-upstream-branch magit-pull-from-upstream) |
|
52 |
(?e "elsewhere" magit-pull-branch)) |
|
53 |
:default-action 'magit-pull |
|
54 |
:max-action-columns 1) |
|
55 |
|
|
56 |
;;;###autoload (autoload 'magit-pull-and-fetch-popup "magit-pull" nil t) |
|
57 |
(magit-define-popup magit-pull-and-fetch-popup |
|
58 |
"Popup console for pull and fetch commands. |
|
59 |
|
|
60 |
This popup is intended as a replacement for the separate popups |
|
61 |
`magit-pull-popup' and `magit-fetch-popup'. To use it, add this |
|
62 |
to your init file: |
|
63 |
|
|
64 |
(with-eval-after-load \\='magit-remote |
|
65 |
(define-key magit-mode-map \"f\" \\='magit-pull-and-fetch-popup) |
|
66 |
(define-key magit-mode-map \"F\" nil)) |
|
67 |
|
|
68 |
The combined popup does not offer all commands and arguments |
|
69 |
available from the individual popups. Instead of the argument |
|
70 |
`--prune' and the command `magit-fetch-all' it uses two commands |
|
71 |
`magit-fetch-prune' and `magit-fetch-no-prune'. And the commands |
|
72 |
`magit-fetch-from-pushremote' and `magit-fetch-from-upstream' are |
|
73 |
missing. To add them use something like: |
|
74 |
|
|
75 |
(with-eval-after-load \\='magit-remote |
|
76 |
(magit-define-popup-action \\='magit-pull-and-fetch-popup ?U |
|
77 |
\\='magit-get-upstream-branch |
|
78 |
\\='magit-fetch-from-upstream-remote ?F) |
|
79 |
(magit-define-popup-action \\='magit-pull-and-fetch-popup ?P |
|
80 |
\\='magit-get-push-branch |
|
81 |
\\='magit-fetch-from-push-remote ?F))" |
|
82 |
:man-page "git-pull" |
|
83 |
:variables '("Configure" |
|
84 |
(?r "branch.%s.rebase" |
|
85 |
magit-cycle-branch*rebase |
|
86 |
magit-pull-format-branch*rebase) |
|
87 |
(?C "variables..." magit-branch-config-popup)) |
|
88 |
:actions '((lambda () |
|
89 |
(--if-let (magit-get-current-branch) |
|
90 |
(concat |
|
91 |
(propertize "Pull into " 'face 'magit-popup-heading) |
|
92 |
(propertize it 'face 'magit-branch-local) |
|
93 |
(propertize " from" 'face 'magit-popup-heading)) |
|
94 |
(propertize "Pull from" 'face 'magit-popup-heading))) |
|
95 |
(?p magit-get-push-branch magit-pull-from-pushremote) |
|
96 |
(?u magit-get-upstream-branch magit-pull-from-upstream) |
|
97 |
(?e "elsewhere" magit-pull-branch) |
|
98 |
"Fetch from" |
|
99 |
(?f "remotes" magit-fetch-all-no-prune) |
|
100 |
(?F "remotes and prune" magit-fetch-all-prune) |
|
101 |
"Fetch" |
|
102 |
(?o "another branch" magit-fetch-branch) |
|
103 |
(?s "explicit refspec" magit-fetch-refspec) |
|
104 |
(?m "submodules" magit-fetch-modules)) |
|
105 |
:default-action 'magit-fetch |
|
106 |
:max-action-columns 1) |
|
107 |
|
|
108 |
(defun magit-pull-format-branch*rebase () |
|
109 |
(magit--format-popup-variable:choices |
|
110 |
(format "branch.%s.rebase" (or (magit-get-current-branch) "<name>")) |
|
111 |
'("true" "false") |
|
112 |
"false" "pull.rebase")) |
|
113 |
|
|
114 |
(defun magit-git-pull (source args) |
|
115 |
(run-hooks 'magit-credential-hook) |
|
116 |
(pcase-let ((`(,remote . ,branch) |
|
117 |
(magit-split-branch-name source))) |
|
118 |
(magit-run-git-with-editor "pull" args remote branch))) |
|
119 |
|
|
120 |
;;;###autoload |
|
121 |
(defun magit-pull-from-pushremote (args) |
|
122 |
"Pull from the push-remote of the current branch." |
|
123 |
(interactive (list (magit-pull-arguments))) |
|
124 |
(--if-let (magit-get-push-branch) |
|
125 |
(magit-git-pull it args) |
|
126 |
(--if-let (magit-get-current-branch) |
|
127 |
(user-error "No push-remote is configured for %s" it) |
|
128 |
(user-error "No branch is checked out")))) |
|
129 |
|
|
130 |
;;;###autoload |
|
131 |
(defun magit-pull-from-upstream (args) |
|
132 |
"Pull from the upstream of the current branch." |
|
133 |
(interactive (list (magit-pull-arguments))) |
|
134 |
(--if-let (magit-get-upstream-branch) |
|
135 |
(progn (run-hooks 'magit-credential-hook) |
|
136 |
(magit-run-git-with-editor |
|
137 |
"pull" args (car (magit-split-branch-name it)))) |
|
138 |
(--if-let (magit-get-current-branch) |
|
139 |
(user-error "No upstream is configured for %s" it) |
|
140 |
(user-error "No branch is checked out")))) |
|
141 |
|
|
142 |
;;;###autoload |
|
143 |
(defun magit-pull-branch (source args) |
|
144 |
"Pull from a branch read in the minibuffer." |
|
145 |
(interactive (list (magit-read-remote-branch "Pull" nil nil nil t) |
|
146 |
(magit-pull-arguments))) |
|
147 |
(magit-git-pull source args)) |
|
148 |
|
|
149 |
;;; _ |
|
150 |
(provide 'magit-pull) |
|
151 |
;;; magit-pull.el ends here |