blob: 76c1bcd8c9b5a42d4dedab2f3ea7261d91427538 [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 Hamano215a7ad2005-09-07 17:26:23 -07004. git-sh-setup || die "Not a git archive"
Linus Torvaldsd7277822005-07-23 15:21:22 -07005
Junio C Hamano0fad0fd2005-07-25 15:18:35 -07006usage () {
Junio C Hamano215a7ad2005-09-07 17:26:23 -07007 echo >&2 "Usage: git-tag [-a | -s] [-f] [-m "tag message"] tagname"
Junio C Hamano0fad0fd2005-07-25 15:18:35 -07008 exit 1
9}
10
11annotate=
Linus Torvaldsd7277822005-07-23 15:21:22 -070012signed=
13force=
Chris Wrightc882bc92005-08-08 17:04:42 -070014message=
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 ;;
Chris Wrightc882bc92005-08-08 17:04:42 -070028 -m)
29 annotate=1
30 shift
31 message="$1"
32 ;;
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070033 -*)
34 usage
35 ;;
Linus Torvaldsd7277822005-07-23 15:21:22 -070036 *)
37 break
38 ;;
39 esac
40 shift
41done
42
Linus Torvalds918c05f2005-07-08 18:23:06 -070043name="$1"
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070044[ "$name" ] || usage
45if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
46 die "tag '$name' already exists"
47fi
Linus Torvaldsd7277822005-07-23 15:21:22 -070048shift
Junio C Hamano8ac069a2005-05-09 22:57:58 -070049
Junio C Hamano2ad77e62005-08-15 15:37:37 -070050object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
Junio C Hamano0fc65a42005-04-29 16:25:05 -070051type=$(git-cat-file -t $object) || exit 1
Eric W. Biedermanc8185662005-07-14 19:02:10 -060052tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
Linus Torvalds918c05f2005-07-08 18:23:06 -070053
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070054trap 'rm -f .tmp-tag* .tagmsg .editmsg' 0
55
56if [ "$annotate" ]; then
Chris Wrightc882bc92005-08-08 17:04:42 -070057 if [ -z "$message" ]; then
58 ( echo "#"
59 echo "# Write a tag message"
60 echo "#" ) > .editmsg
61 ${VISUAL:-${EDITOR:-vi}} .editmsg || exit
62 else
63 echo "$message" > .editmsg
64 fi
Linus Torvalds918c05f2005-07-08 18:23:06 -070065
Linus Torvaldsd7277822005-07-23 15:21:22 -070066 grep -v '^#' < .editmsg | git-stripspace > .tagmsg
Linus Torvalds918c05f2005-07-08 18:23:06 -070067
Linus Torvaldsd7277822005-07-23 15:21:22 -070068 [ -s .tagmsg ] || exit
Linus Torvalds918c05f2005-07-08 18:23:06 -070069
Linus Torvaldsd7277822005-07-23 15:21:22 -070070 ( echo -e "object $object\ntype $type\ntag $name\ntagger $tagger\n"; cat .tagmsg ) > .tmp-tag
71 rm -f .tmp-tag.asc .tagmsg
Junio C Hamano0fad0fd2005-07-25 15:18:35 -070072 if [ "$signed" ]; then
73 me=$(expr "$tagger" : '\(.*>\)') &&
74 gpg -bsa -u "$me" .tmp-tag &&
75 cat .tmp-tag.asc >>.tmp-tag ||
76 die "failed to sign the tag with GPG."
77 fi
Linus Torvaldsd7277822005-07-23 15:21:22 -070078 object=$(git-mktag < .tmp-tag)
Linus Torvaldsd7277822005-07-23 15:21:22 -070079fi
80
Eric W. Biedermanec3f5a42005-07-14 19:00:15 -060081mkdir -p "$GIT_DIR/refs/tags"
Linus Torvaldsd7277822005-07-23 15:21:22 -070082echo $object > "$GIT_DIR/refs/tags/$name"