blob: ac269e3277d9b8c844e8c43b95695375dd829746 [file] [log] [blame]
Linus Torvalds65f0d0e2005-04-25 15:23:53 -07001#!/bin/sh
Junio C Hamano8ac069a2005-05-09 22:57:58 -07002# Copyright (c) 2005 Linus Torvalds
3
Junio C Hamanob867c7c2006-02-17 04:04:39 -08004USAGE='-l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]'
freku045@student.liu.se806f36d2005-12-13 23:30:31 +01005SUBDIRECTORY_OK='Yes'
6. git-sh-setup
Junio C Hamanod165fa12005-11-27 23:33:54 -08007
Junio C Hamano0fad0fd2005-07-25 15:18:35 -07008annotate=
Linus Torvaldsd7277822005-07-23 15:21:22 -07009signed=
10force=
Chris Wrightc882bc92005-08-08 17:04:42 -070011message=
Linus Torvaldsbc162e42005-10-06 14:10:39 -070012username=
Junio C Hamanob867c7c2006-02-17 04:04:39 -080013list=
Linus Torvaldsd7277822005-07-23 15:21:22 -070014while case "$#" in 0) break ;; esac
15do
16 case "$1" in
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070017 -a)
18 annotate=1
19 ;;
Linus Torvaldsd7277822005-07-23 15:21:22 -070020 -s)
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070021 annotate=1
Linus Torvaldsd7277822005-07-23 15:21:22 -070022 signed=1
23 ;;
24 -f)
25 force=1
26 ;;
Junio C Hamanob867c7c2006-02-17 04:04:39 -080027 -l)
Junio C Hamanob867c7c2006-02-17 04:04:39 -080028 case "$#" in
29 1)
Seane6ebb8a2006-05-14 20:07:39 -040030 set x . ;;
Junio C Hamanob867c7c2006-02-17 04:04:39 -080031 esac
Seane6ebb8a2006-05-14 20:07:39 -040032 shift
33 git rev-parse --symbolic --tags | sort | grep "$@"
Junio C Hamanob867c7c2006-02-17 04:04:39 -080034 exit $?
35 ;;
Chris Wrightc882bc92005-08-08 17:04:42 -070036 -m)
37 annotate=1
38 shift
39 message="$1"
40 ;;
Linus Torvaldsbc162e42005-10-06 14:10:39 -070041 -u)
42 annotate=1
43 signed=1
44 shift
45 username="$1"
46 ;;
Kai Ruemmler61f81512005-11-08 11:44:33 +010047 -d)
48 shift
49 tag_name="$1"
Christian Couderd3d00132006-10-01 22:16:22 +020050 tag=$(git-show-ref --verify --hash -- "refs/tags/$tag_name") ||
51 die "Seriously, what tag are you talking about?"
52 git-update-ref -m 'tag: delete' -d "refs/tags/$tag_name" "$tag" &&
53 echo "Deleted tag $tag_name."
Kai Ruemmler61f81512005-11-08 11:44:33 +010054 exit $?
55 ;;
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070056 -*)
57 usage
58 ;;
Linus Torvaldsd7277822005-07-23 15:21:22 -070059 *)
60 break
61 ;;
62 esac
63 shift
64done
65
Linus Torvalds918c05f2005-07-08 18:23:06 -070066name="$1"
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070067[ "$name" ] || usage
Junio C Hamanocede7522006-09-27 02:06:31 -070068prev=0000000000000000000000000000000000000000
Christian Couderb431b282006-10-01 22:33:04 +020069if git-show-ref --verify --quiet -- "refs/tags/$name"
Junio C Hamanocede7522006-09-27 02:06:31 -070070then
71 test -n "$force" || die "tag '$name' already exists"
72 prev=`git rev-parse "refs/tags/$name"`
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070073fi
Linus Torvaldsd7277822005-07-23 15:21:22 -070074shift
Junio C Hamano03feddd2005-10-13 18:57:39 -070075git-check-ref-format "tags/$name" ||
76 die "we do not like '$name' as a tag name."
Junio C Hamano8ac069a2005-05-09 22:57:58 -070077
Junio C Hamano2ad77e62005-08-15 15:37:37 -070078object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
Junio C Hamano0fc65a42005-04-29 16:25:05 -070079type=$(git-cat-file -t $object) || exit 1
Eric W. Biedermanc8185662005-07-14 19:02:10 -060080tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
Mark Woodingf327dbc2006-04-13 22:01:24 +000081: ${username:=$(expr "z$tagger" : 'z\(.*>\)')}
Linus Torvalds918c05f2005-07-08 18:23:06 -070082
Junio C Hamanoa10aad62005-11-03 15:26:43 -080083trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070084
85if [ "$annotate" ]; then
Chris Wrightc882bc92005-08-08 17:04:42 -070086 if [ -z "$message" ]; then
87 ( echo "#"
88 echo "# Write a tag message"
Junio C Hamanoa10aad62005-11-03 15:26:43 -080089 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
90 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
Chris Wrightc882bc92005-08-08 17:04:42 -070091 else
Junio C Hamanoa10aad62005-11-03 15:26:43 -080092 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
Chris Wrightc882bc92005-08-08 17:04:42 -070093 fi
Linus Torvalds918c05f2005-07-08 18:23:06 -070094
Junio C Hamanoa10aad62005-11-03 15:26:43 -080095 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
96 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
Linus Torvalds918c05f2005-07-08 18:23:06 -070097
Junio C Hamanoa10aad62005-11-03 15:26:43 -080098 [ -s "$GIT_DIR"/TAG_FINALMSG ] || {
Linus Torvaldsbc162e42005-10-06 14:10:39 -070099 echo >&2 "No tag message?"
100 exit 1
101 }
Linus Torvalds918c05f2005-07-08 18:23:06 -0700102
Alex Riesen0dbc4e82006-02-12 19:05:34 +0100103 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
104 "$object" "$type" "$name" "$tagger";
Junio C Hamanoa10aad62005-11-03 15:26:43 -0800105 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
106 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
Junio C Hamano0fad0fd2005-07-25 15:18:35 -0700107 if [ "$signed" ]; then
Junio C Hamanoa10aad62005-11-03 15:26:43 -0800108 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
109 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
Junio C Hamano0fad0fd2005-07-25 15:18:35 -0700110 die "failed to sign the tag with GPG."
111 fi
Junio C Hamanoa10aad62005-11-03 15:26:43 -0800112 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
Linus Torvaldsd7277822005-07-23 15:21:22 -0700113fi
114
Christian Couder36733702006-10-02 06:36:15 +0200115git update-ref "refs/tags/$name" "$object" "$prev"
116