Klimi's new dotfiles with stow.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

163 rader
6.1 KiB

4 år sedan
  1. ;;; magit-pull.el --- update local 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 pull commands.
  22. ;;; Code:
  23. (require 'magit)
  24. ;;; Options
  25. (defcustom magit-pull-or-fetch nil
  26. "Whether `magit-pull' also offers some fetch suffixes."
  27. :package-version '(magit . "2.91.0")
  28. :group 'magit-commands
  29. :type 'boolean)
  30. ;;; Commands
  31. ;;;###autoload (autoload 'magit-pull "magit-pull" nil t)
  32. (define-transient-command magit-pull ()
  33. "Pull from another repository."
  34. :man-page "git-pull"
  35. [:description
  36. (lambda () (if magit-pull-or-fetch "Pull arguments" "Arguments"))
  37. ("-r" "Rebase local commits" ("-r" "--rebase"))]
  38. [:description
  39. (lambda ()
  40. (if-let ((branch (magit-get-current-branch)))
  41. (concat
  42. (propertize "Pull into " 'face 'transient-heading)
  43. (propertize branch 'face 'magit-branch-local)
  44. (propertize " from" 'face 'transient-heading))
  45. (propertize "Pull from" 'face 'transient-heading)))
  46. ("p" magit-pull-from-pushremote)
  47. ("u" magit-pull-from-upstream)
  48. ("e" "elsewhere" magit-pull-branch)]
  49. ["Fetch from"
  50. :if-non-nil magit-pull-or-fetch
  51. ("f" "remotes" magit-fetch-all-no-prune)
  52. ("F" "remotes and prune" magit-fetch-all-prune)]
  53. ["Fetch"
  54. :if-non-nil magit-pull-or-fetch
  55. ("o" "another branch" magit-fetch-branch)
  56. ("s" "explicit refspec" magit-fetch-refspec)
  57. ("m" "submodules" magit-fetch-modules)]
  58. ["Configure"
  59. ("r" magit-branch.<branch>.rebase :if magit-get-current-branch)
  60. ("C" "variables..." magit-branch-configure)]
  61. (interactive)
  62. (transient-setup 'magit-pull nil nil :scope (magit-get-current-branch)))
  63. (defun magit-pull-arguments ()
  64. (transient-args 'magit-pull))
  65. ;;;###autoload (autoload 'magit-pull-from-pushremote "magit-pull" nil t)
  66. (define-suffix-command magit-pull-from-pushremote (args)
  67. "Pull from the push-remote of the current branch.
  68. When the push-remote is not configured, then read the push-remote
  69. from the user, set it, and then pull from it. With a prefix
  70. argument the push-remote can be changed before pulling from it."
  71. :if 'magit-get-current-branch
  72. :description 'magit-pull--pushbranch-description
  73. (interactive (list (magit-pull-arguments)))
  74. (pcase-let ((`(,branch ,remote)
  75. (magit--select-push-remote "pull from there")))
  76. (run-hooks 'magit-credential-hook)
  77. (magit-run-git-async "pull" args remote branch)))
  78. (defun magit-pull--pushbranch-description ()
  79. ;; Also used by `magit-rebase-onto-pushremote'.
  80. (let* ((branch (magit-get-current-branch))
  81. (target (magit-get-push-branch branch t))
  82. (remote (magit-get-push-remote branch))
  83. (v (magit--push-remote-variable branch t)))
  84. (cond
  85. (target)
  86. ((member remote (magit-list-remotes))
  87. (format "%s, replacing non-existent" v))
  88. (remote
  89. (format "%s, replacing invalid" v))
  90. (t
  91. (format "%s, setting that" v)))))
  92. ;;;###autoload (autoload 'magit-pull-from-upstream "magit-pull" nil t)
  93. (define-suffix-command magit-pull-from-upstream (args)
  94. "Pull from the upstream of the current branch.
  95. With a prefix argument or when the upstream is either not
  96. configured or unusable, then let the user first configure
  97. the upstream."
  98. :if 'magit-get-current-branch
  99. :description 'magit-pull--upstream-description
  100. (interactive (list (magit-pull-arguments)))
  101. (let* ((branch (or (magit-get-current-branch)
  102. (user-error "No branch is checked out")))
  103. (remote (magit-get "branch" branch "remote"))
  104. (merge (magit-get "branch" branch "merge")))
  105. (when (or current-prefix-arg
  106. (not (or (magit-get-upstream-branch branch)
  107. (magit--unnamed-upstream-p remote merge))))
  108. (magit-set-upstream-branch
  109. branch (magit-read-upstream-branch
  110. branch (format "Set upstream of %s and pull from there" branch)))
  111. (setq remote (magit-get "branch" branch "remote"))
  112. (setq merge (magit-get "branch" branch "merge")))
  113. (run-hooks 'magit-credential-hook)
  114. (magit-run-git-with-editor "pull" args remote merge)))
  115. (defun magit-pull--upstream-description ()
  116. (when-let ((branch (magit-get-current-branch)))
  117. (or (magit-get-upstream-branch branch)
  118. (let ((remote (magit-get "branch" branch "remote"))
  119. (merge (magit-get "branch" branch "merge"))
  120. (u (magit--propertize-face "@{upstream}" 'bold)))
  121. (cond
  122. ((magit--unnamed-upstream-p remote merge)
  123. (format "%s of %s"
  124. (magit--propertize-face merge 'magit-branch-remote)
  125. (magit--propertize-face remote 'bold)))
  126. ((magit--valid-upstream-p remote merge)
  127. (concat u ", replacing non-existent"))
  128. ((or remote merge)
  129. (concat u ", replacing invalid"))
  130. (t
  131. (concat u ", setting that")))))))
  132. ;;;###autoload
  133. (defun magit-pull-branch (source args)
  134. "Pull from a branch read in the minibuffer."
  135. (interactive (list (magit-read-remote-branch "Pull" nil nil nil t)
  136. (magit-pull-arguments)))
  137. (run-hooks 'magit-credential-hook)
  138. (pcase-let ((`(,remote . ,branch)
  139. (magit-get-tracked source)))
  140. (magit-run-git-with-editor "pull" args remote branch)))
  141. ;;; _
  142. (provide 'magit-pull)
  143. ;;; magit-pull.el ends here