dotemacs

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

magit-pull.el (6323B)


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