commit | author | age
|
5cb5f7
|
1 |
;;; magit-tag.el --- tag functionality -*- lexical-binding: t -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2010-2018 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 |
;; Magit is free software; you can redistribute it and/or modify it |
|
12 |
;; under the terms of the GNU General Public License as published by |
|
13 |
;; the Free Software Foundation; either version 3, or (at your option) |
|
14 |
;; any later version. |
|
15 |
;; |
|
16 |
;; Magit is distributed in the hope that it will be useful, but WITHOUT |
|
17 |
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
18 |
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
|
19 |
;; License for more details. |
|
20 |
;; |
|
21 |
;; You should have received a copy of the GNU General Public License |
|
22 |
;; along with Magit. If not, see http://www.gnu.org/licenses. |
|
23 |
|
|
24 |
;;; Commentary: |
|
25 |
|
|
26 |
;; This library implements tag commands. |
|
27 |
|
|
28 |
;;; Code: |
|
29 |
|
|
30 |
(require 'magit) |
|
31 |
|
|
32 |
;;;###autoload (autoload 'magit-tag-popup "magit" nil t) |
|
33 |
(magit-define-popup magit-tag-popup |
|
34 |
"Popup console for tag commands." |
|
35 |
:man-page "git-tag" |
|
36 |
:switches '((?a "Annotate" "--annotate") |
|
37 |
(?f "Force" "--force") |
|
38 |
(?s "Sign" "--sign")) |
|
39 |
:options '((?f "Sign" "--local-user=" magit-read-gpg-secret-key)) |
|
40 |
:actions '((?t "Create" magit-tag-create) |
|
41 |
(?k "Delete" magit-tag-delete) |
|
42 |
(?p "Prune" magit-tag-prune)) |
|
43 |
:default-action 'magit-tag-create) |
|
44 |
|
|
45 |
;;;###autoload |
|
46 |
(defun magit-tag-create (name rev &optional args) |
|
47 |
"Create a new tag with the given NAME at REV. |
|
48 |
With a prefix argument annotate the tag. |
|
49 |
\n(git tag [--annotate] NAME REV)" |
|
50 |
(interactive (list (magit-read-tag "Tag name") |
|
51 |
(magit-read-branch-or-commit "Place tag on") |
|
52 |
(let ((args (magit-tag-arguments))) |
|
53 |
(when current-prefix-arg |
|
54 |
(cl-pushnew "--annotate" args)) |
|
55 |
args))) |
|
56 |
(magit-run-git-with-editor "tag" args name rev)) |
|
57 |
|
|
58 |
;;;###autoload |
|
59 |
(defun magit-tag-delete (tags) |
|
60 |
"Delete one or more tags. |
|
61 |
If the region marks multiple tags (and nothing else), then offer |
|
62 |
to delete those, otherwise prompt for a single tag to be deleted, |
|
63 |
defaulting to the tag at point. |
|
64 |
\n(git tag -d TAGS)" |
|
65 |
(interactive (list (--if-let (magit-region-values 'tag) |
|
66 |
(magit-confirm t nil "Delete %i tags" nil it) |
|
67 |
(magit-read-tag "Delete tag" t)))) |
|
68 |
(magit-run-git "tag" "-d" tags)) |
|
69 |
|
|
70 |
;;;###autoload |
|
71 |
(defun magit-tag-prune (tags remote-tags remote) |
|
72 |
"Offer to delete tags missing locally from REMOTE, and vice versa." |
|
73 |
(interactive |
|
74 |
(let* ((remote (magit-read-remote "Prune tags using remote")) |
|
75 |
(tags (magit-list-tags)) |
|
76 |
(rtags (prog2 (message "Determining remote tags...") |
|
77 |
(magit-remote-list-tags remote) |
|
78 |
(message "Determining remote tags...done"))) |
|
79 |
(ltags (-difference tags rtags)) |
|
80 |
(rtags (-difference rtags tags))) |
|
81 |
(unless (or ltags rtags) |
|
82 |
(message "Same tags exist locally and remotely")) |
|
83 |
(unless (magit-confirm t |
|
84 |
"Delete %s locally" |
|
85 |
"Delete %i tags locally" |
|
86 |
'noabort ltags) |
|
87 |
(setq ltags nil)) |
|
88 |
(unless (magit-confirm t |
|
89 |
"Delete %s from remote" |
|
90 |
"Delete %i tags from remote" |
|
91 |
'noabort rtags) |
|
92 |
(setq rtags nil)) |
|
93 |
(list ltags rtags remote))) |
|
94 |
(when tags |
|
95 |
(magit-call-git "tag" "-d" tags)) |
|
96 |
(when remote-tags |
|
97 |
(magit-run-git-async "push" remote (--map (concat ":" it) remote-tags)))) |
|
98 |
|
|
99 |
;;;###autoload |
|
100 |
(defun magit-tag-release (tag) |
|
101 |
"Create an opinionated release tag. |
|
102 |
|
|
103 |
Assume version tags that match \"\\\\`v?[0-9]\\\\(\\\\.[0-9]\\\\)*\\\\'\". |
|
104 |
Prompt for the name of the new tag using the highest existing tag |
|
105 |
as initial input and call \"git tag --annotate --sign -m MSG\" TAG, |
|
106 |
regardless of whether these arguments are enabled in the popup. |
|
107 |
Given a TAG \"v1.2.3\" and a repository \"/path/to/foo-bar\", the |
|
108 |
MESSAGE would be \"Foo-Bar 1.2.3\". |
|
109 |
|
|
110 |
Because it is so opinionated, this command is not available from |
|
111 |
the tag popup by default." |
|
112 |
(interactive |
|
113 |
(list (read-string "Create tag: " |
|
114 |
(car (nreverse |
|
115 |
(cl-sort (magit-list-tags) #'version< |
|
116 |
:key (lambda (tag) |
|
117 |
(if (string-prefix-p "v" tag) |
|
118 |
(substring tag 1) |
|
119 |
tag)))))))) |
|
120 |
(magit-run-git |
|
121 |
"tag" "--annotate" "--sign" |
|
122 |
"-m" (format "%s %s" |
|
123 |
(capitalize (file-name-nondirectory |
|
124 |
(directory-file-name (magit-toplevel)))) |
|
125 |
(if (string-prefix-p "v" tag) |
|
126 |
(substring tag 1) |
|
127 |
tag)) |
|
128 |
tag) |
|
129 |
(magit-show-refs)) |
|
130 |
|
|
131 |
;;; _ |
|
132 |
(provide 'magit-tag) |
|
133 |
;;; magit-tag.el ends here |