fordon_greeman / voidfiles

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