blob: d53f94cd9c618e9c2032d3e6ad7af9f3866e7707 [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
Han-Wen Nienhuysaabd7692006-11-26 17:42:49 +01008message_given=
Junio C Hamano0fad0fd2005-07-25 15:18:35 -07009annotate=
Linus Torvaldsd7277822005-07-23 15:21:22 -070010signed=
11force=
Chris Wrightc882bc92005-08-08 17:04:42 -070012message=
Linus Torvaldsbc162e42005-10-06 14:10:39 -070013username=
Junio C Hamanob867c7c2006-02-17 04:04:39 -080014list=
Linus Torvaldsd7277822005-07-23 15:21:22 -070015while case "$#" in 0) break ;; esac
16do
17 case "$1" in
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070018 -a)
19 annotate=1
20 ;;
Linus Torvaldsd7277822005-07-23 15:21:22 -070021 -s)
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070022 annotate=1
Linus Torvaldsd7277822005-07-23 15:21:22 -070023 signed=1
24 ;;
25 -f)
26 force=1
27 ;;
Junio C Hamanob867c7c2006-02-17 04:04:39 -080028 -l)
Junio C Hamanob867c7c2006-02-17 04:04:39 -080029 case "$#" in
30 1)
Seane6ebb8a2006-05-14 20:07:39 -040031 set x . ;;
Junio C Hamanob867c7c2006-02-17 04:04:39 -080032 esac
Seane6ebb8a2006-05-14 20:07:39 -040033 shift
34 git rev-parse --symbolic --tags | sort | grep "$@"
Junio C Hamanob867c7c2006-02-17 04:04:39 -080035 exit $?
36 ;;
Chris Wrightc882bc92005-08-08 17:04:42 -070037 -m)
38 annotate=1
39 shift
40 message="$1"
Han-Wen Nienhuysaabd7692006-11-26 17:42:49 +010041 if test "$#" = "0"; then
42 die "error: option -m needs an argument"
43 exit 2
44 else
45 message_given=1
46 fi
Chris Wrightc882bc92005-08-08 17:04:42 -070047 ;;
Linus Torvaldsbc162e42005-10-06 14:10:39 -070048 -u)
49 annotate=1
50 signed=1
51 shift
52 username="$1"
53 ;;
Kai Ruemmler61f81512005-11-08 11:44:33 +010054 -d)
55 shift
56 tag_name="$1"
Christian Couderd3d00132006-10-01 22:16:22 +020057 tag=$(git-show-ref --verify --hash -- "refs/tags/$tag_name") ||
58 die "Seriously, what tag are you talking about?"
59 git-update-ref -m 'tag: delete' -d "refs/tags/$tag_name" "$tag" &&
60 echo "Deleted tag $tag_name."
Kai Ruemmler61f81512005-11-08 11:44:33 +010061 exit $?
62 ;;
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070063 -*)
64 usage
65 ;;
Linus Torvaldsd7277822005-07-23 15:21:22 -070066 *)
67 break
68 ;;
69 esac
70 shift
71done
72
Linus Torvalds918c05f2005-07-08 18:23:06 -070073name="$1"
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070074[ "$name" ] || usage
Junio C Hamanocede7522006-09-27 02:06:31 -070075prev=0000000000000000000000000000000000000000
Christian Couderb431b282006-10-01 22:33:04 +020076if git-show-ref --verify --quiet -- "refs/tags/$name"
Junio C Hamanocede7522006-09-27 02:06:31 -070077then
78 test -n "$force" || die "tag '$name' already exists"
79 prev=`git rev-parse "refs/tags/$name"`
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070080fi
Linus Torvaldsd7277822005-07-23 15:21:22 -070081shift
Junio C Hamano03feddd2005-10-13 18:57:39 -070082git-check-ref-format "tags/$name" ||
83 die "we do not like '$name' as a tag name."
Junio C Hamano8ac069a2005-05-09 22:57:58 -070084
Junio C Hamano2ad77e62005-08-15 15:37:37 -070085object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
Junio C Hamano0fc65a42005-04-29 16:25:05 -070086type=$(git-cat-file -t $object) || exit 1
Eric W. Biedermanc8185662005-07-14 19:02:10 -060087tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
Mark Woodingf327dbc2006-04-13 22:01:24 +000088: ${username:=$(expr "z$tagger" : 'z\(.*>\)')}
Linus Torvalds918c05f2005-07-08 18:23:06 -070089
Junio C Hamanoa10aad62005-11-03 15:26:43 -080090trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070091
92if [ "$annotate" ]; then
Han-Wen Nienhuysaabd7692006-11-26 17:42:49 +010093 if [ -z "$message_given" ]; then
Chris Wrightc882bc92005-08-08 17:04:42 -070094 ( echo "#"
95 echo "# Write a tag message"
Junio C Hamanoa10aad62005-11-03 15:26:43 -080096 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
97 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
Chris Wrightc882bc92005-08-08 17:04:42 -070098 else
Junio C Hamanoa10aad62005-11-03 15:26:43 -080099 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
Chris Wrightc882bc92005-08-08 17:04:42 -0700100 fi
Linus Torvalds918c05f2005-07-08 18:23:06 -0700101
Junio C Hamanoa10aad62005-11-03 15:26:43 -0800102 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
103 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
Linus Torvalds918c05f2005-07-08 18:23:06 -0700104
Han-Wen Nienhuysaabd7692006-11-26 17:42:49 +0100105 [ -s "$GIT_DIR"/TAG_FINALMSG -o -n "$message_given" ] || {
Linus Torvaldsbc162e42005-10-06 14:10:39 -0700106 echo >&2 "No tag message?"
107 exit 1
108 }
Linus Torvalds918c05f2005-07-08 18:23:06 -0700109
Alex Riesen0dbc4e82006-02-12 19:05:34 +0100110 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
111 "$object" "$type" "$name" "$tagger";
Junio C Hamanoa10aad62005-11-03 15:26:43 -0800112 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
113 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
Junio C Hamano0fad0fd2005-07-25 15:18:35 -0700114 if [ "$signed" ]; then
Junio C Hamanoa10aad62005-11-03 15:26:43 -0800115 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
116 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
Junio C Hamano0fad0fd2005-07-25 15:18:35 -0700117 die "failed to sign the tag with GPG."
118 fi
Junio C Hamanoa10aad62005-11-03 15:26:43 -0800119 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
Linus Torvaldsd7277822005-07-23 15:21:22 -0700120fi
121
Christian Couder36733702006-10-02 06:36:15 +0200122git update-ref "refs/tags/$name" "$object" "$prev"
123