config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

magit-bundle.el (5315B)


      1 ;;; magit-bundle.el --- Bundle support for Magit  -*- lexical-binding:t -*-
      2 
      3 ;; Copyright (C) 2008-2024 The Magit Project Contributors
      4 
      5 ;; Author: Jonas Bernoulli <emacs.magit@jonas.bernoulli.dev>
      6 ;; Maintainer: Jonas Bernoulli <emacs.magit@jonas.bernoulli.dev>
      7 
      8 ;; SPDX-License-Identifier: GPL-3.0-or-later
      9 
     10 ;; Magit is free software: you can redistribute it and/or modify it
     11 ;; under the terms of the GNU General Public License as published by
     12 ;; the Free Software Foundation, either version 3 of the License, or
     13 ;; (at your option) any later version.
     14 ;;
     15 ;; Magit is distributed in the hope that it will be useful, but WITHOUT
     16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     17 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
     18 ;; License for more details.
     19 ;;
     20 ;; You should have received a copy of the GNU General Public License
     21 ;; along with Magit.  If not, see <https://www.gnu.org/licenses/>.
     22 
     23 ;;; Code:
     24 
     25 (require 'magit)
     26 
     27 ;;; Commands
     28 
     29 ;;;###autoload (autoload 'magit-bundle "magit-bundle" nil t)
     30 (transient-define-prefix magit-bundle ()
     31   "Create or verify Git bundles."
     32   :man-page "git-bundle"
     33   ["Actions"
     34    ("c" "create"     magit-bundle-create)
     35    ("v" "verify"     magit-bundle-verify)
     36    ("l" "list-heads" magit-bundle-list-heads)])
     37 
     38 ;;;###autoload (autoload 'magit-bundle-import "magit-bundle" nil t)
     39 (transient-define-prefix magit-bundle-create (&optional file refs args)
     40   "Create a bundle."
     41   :man-page "git-bundle"
     42   ["Arguments"
     43    ("-a" "Include all refs" "--all")
     44    ("-b" "Include branches" "--branches=" :allow-empty t)
     45    ("-t" "Include tags"     "--tags="     :allow-empty t)
     46    ("-r" "Include remotes"  "--remotes="  :allow-empty t)
     47    ("-g" "Include refs"     "--glob=")
     48    ("-e" "Exclude refs"     "--exclude=")
     49    (magit-log:-n)
     50    (magit-log:--since)
     51    (magit-log:--until)]
     52   ["Actions"
     53    ("c" "create regular bundle" magit-bundle-create)
     54    ("t" "create tracked bundle" magit-bundle-create-tracked)
     55    ("u" "update tracked bundle" magit-bundle-update-tracked)]
     56   (interactive
     57    (and (eq transient-current-command 'magit-bundle-create)
     58         (list (read-file-name "Create bundle: " nil nil nil
     59                               (concat (file-name-nondirectory
     60                                        (directory-file-name (magit-toplevel)))
     61                                       ".bundle"))
     62               (magit-completing-read-multiple "Refnames (zero or more): "
     63                                               (magit-list-refnames))
     64               (transient-args 'magit-bundle-create))))
     65   (if file
     66       (magit-git-bundle "create" file refs args)
     67     (transient-setup 'magit-bundle-create)))
     68 
     69 ;;;###autoload
     70 (defun magit-bundle-create-tracked (file tag branch refs args)
     71   "Create and track a new bundle."
     72   (interactive
     73    (let ((tag    (magit-read-tag "Track bundle using tag"))
     74          (branch (magit-read-branch "Bundle branch"))
     75          (refs   (magit-completing-read-multiple
     76                   "Additional refnames (zero or more): "
     77                   (magit-list-refnames))))
     78      (list (read-file-name "File: " nil nil nil (concat tag ".bundle"))
     79            tag branch
     80            (if (equal branch (magit-get-current-branch))
     81                (cons "HEAD" refs)
     82              refs)
     83            (transient-args 'magit-bundle-create))))
     84   (magit-git-bundle "create" file (cons branch refs) args)
     85   (magit-git "tag" "--force" tag branch
     86              "-m" (concat ";; git-bundle tracking\n"
     87                           (pp-to-string `((file   . ,file)
     88                                           (branch . ,branch)
     89                                           (refs   . ,refs)
     90                                           (args   . ,args))))))
     91 
     92 ;;;###autoload
     93 (defun magit-bundle-update-tracked (tag)
     94   "Update a bundle that is being tracked using TAG."
     95   (interactive (list (magit-read-tag "Update bundle tracked by tag" t)))
     96   (let (msg)
     97     (let-alist (magit--with-temp-process-buffer
     98                  (save-excursion
     99                    (magit-git-insert "for-each-ref" "--format=%(contents)"
    100                                      (concat "refs/tags/" tag)))
    101                  (setq msg (buffer-string))
    102                  (ignore-errors (read (current-buffer))))
    103       (unless (and .file .branch)
    104         (error "Tag %s does not appear to track a bundle" tag))
    105       (magit-git-bundle "create" .file
    106                         (cons (concat tag ".." .branch) .refs)
    107                         .args)
    108       (magit-git "tag" "--force" tag .branch "-m" msg))))
    109 
    110 ;;;###autoload
    111 (defun magit-bundle-verify (file)
    112   "Check whether FILE is valid and applies to the current repository."
    113   (interactive (list (magit-bundle--read-file-name "Verify bundle: ")))
    114   (magit-process-buffer)
    115   (magit-git-bundle "verify" file))
    116 
    117 ;;;###autoload
    118 (defun magit-bundle-list-heads (file)
    119   "List the refs in FILE."
    120   (interactive (list (magit-bundle--read-file-name "List heads of bundle: ")))
    121   (magit-process-buffer)
    122   (magit-git-bundle "list-heads" file))
    123 
    124 (defun magit-bundle--read-file-name (prompt)
    125   (read-file-name prompt nil nil t (magit-file-at-point) #'file-regular-p))
    126 
    127 (defun magit-git-bundle (command file &optional refs args)
    128   (magit-git "bundle" command (magit-convert-filename-for-git file) refs args))
    129 
    130 ;;; _
    131 (provide 'magit-bundle)
    132 ;;; magit-bundle.el ends here