dotemacs

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

magit-bundle.el (5404B)


      1 ;;; magit-bundle.el --- bundle support for Magit   -*- lexical-binding: t -*-
      2 
      3 ;; Copyright (C) 2011-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 ;;; Code:
     27 
     28 (require 'magit)
     29 
     30 ;;; Commands
     31 
     32 ;;;###autoload (autoload 'magit-bundle "magit-bundle" nil t)
     33 (transient-define-prefix magit-bundle ()
     34   "Create or verify Git bundles."
     35   :man-page "git-bundle"
     36   ["Actions"
     37    ("c" "create"     magit-bundle-create)
     38    ("v" "verify"     magit-bundle-verify)
     39    ("l" "list-heads" magit-bundle-list-heads)])
     40 
     41 ;;;###autoload (autoload 'magit-bundle-import "magit-bundle" nil t)
     42 (transient-define-prefix magit-bundle-create (&optional file refs args)
     43   "Create a bundle."
     44   :man-page "git-bundle"
     45   ["Arguments"
     46    ("-a" "Include all refs" "--all")
     47    ("-b" "Include branches" "--branches=" :allow-empty t)
     48    ("-t" "Include tags"     "--tags="     :allow-empty t)
     49    ("-r" "Include remotes"  "--remotes="  :allow-empty t)
     50    ("-g" "Include refs"     "--glob=")
     51    ("-e" "Exclude refs"     "--exclude=")
     52    (magit-log:-n)
     53    (magit-log:--since)
     54    (magit-log:--until)]
     55   ["Actions"
     56    ("c" "create regular bundle" magit-bundle-create)
     57    ("t" "create tracked bundle" magit-bundle-create-tracked)
     58    ("u" "update tracked bundle" magit-bundle-update-tracked)]
     59   (interactive
     60    (and (eq transient-current-command 'magit-bundle-create)
     61         (list (read-file-name "Create bundle: " nil nil nil
     62                               (concat (file-name-nondirectory
     63                                        (directory-file-name (magit-toplevel)))
     64                                       ".bundle"))
     65               (magit-completing-read-multiple* "Refnames (zero or more): "
     66                                                (magit-list-refnames))
     67               (transient-args 'magit-bundle-create))))
     68   (if file
     69       (magit-git-bundle "create" file refs args)
     70     (transient-setup 'magit-bundle-create)))
     71 
     72 ;;;###autoload
     73 (defun magit-bundle-create-tracked (file tag branch refs args)
     74   "Create and track a new bundle."
     75   (interactive
     76    (let ((tag    (magit-read-tag "Track bundle using tag"))
     77          (branch (magit-read-branch "Bundle branch"))
     78          (refs   (magit-completing-read-multiple*
     79                   "Additional refnames (zero or more): "
     80                   (magit-list-refnames))))
     81      (list (read-file-name "File: " nil nil nil (concat tag ".bundle"))
     82            tag branch
     83            (if (equal branch (magit-get-current-branch))
     84                (cons "HEAD" refs)
     85              refs)
     86            (transient-args 'magit-bundle-create))))
     87   (magit-git-bundle "create" file (cons branch refs) args)
     88   (magit-git "tag" "--force" tag branch
     89              "-m" (concat ";; git-bundle tracking\n"
     90                           (pp-to-string `((file   . ,file)
     91                                           (branch . ,branch)
     92                                           (refs   . ,refs)
     93                                           (args   . ,args))))))
     94 
     95 ;;;###autoload
     96 (defun magit-bundle-update-tracked (tag)
     97   "Update a bundle that is being tracked using TAG."
     98   (interactive (list (magit-read-tag "Update bundle tracked by tag" t)))
     99   (let (msg)
    100     (let-alist (magit--with-temp-process-buffer
    101                  (save-excursion
    102                    (magit-git-insert "for-each-ref" "--format=%(contents)"
    103                                      (concat "refs/tags/" tag)))
    104                  (setq msg (buffer-string))
    105                  (ignore-errors (read (current-buffer))))
    106       (unless (and .file .branch)
    107         (error "Tag %s does not appear to track a bundle" tag))
    108       (magit-git-bundle "create" .file
    109                         (cons (concat tag ".." .branch) .refs)
    110                         .args)
    111       (magit-git "tag" "--force" tag .branch "-m" msg))))
    112 
    113 ;;;###autoload
    114 (defun magit-bundle-verify (file)
    115   "Check whether FILE is valid and applies to the current repository."
    116   (interactive (list (magit-bundle--read-file-name "Verify bundle: ")))
    117   (magit-process-buffer)
    118   (magit-git-bundle "verify" file))
    119 
    120 ;;;###autoload
    121 (defun magit-bundle-list-heads (file)
    122   "List the refs in FILE."
    123   (interactive (list (magit-bundle--read-file-name "List heads of bundle: ")))
    124   (magit-process-buffer)
    125   (magit-git-bundle "list-heads" file))
    126 
    127 (defun magit-bundle--read-file-name (prompt)
    128   (read-file-name prompt nil nil t (magit-file-at-point) #'file-regular-p))
    129 
    130 (defun magit-git-bundle (command file &optional refs args)
    131   (magit-git "bundle" command (magit-convert-filename-for-git file) refs args))
    132 
    133 ;;; _
    134 (provide 'magit-bundle)
    135 ;;; magit-bundle.el ends here