Teach all of log family --left-right output.
[git/dscho.git] / git-tag.sh
blobd53f94cd9c618e9c2032d3e6ad7af9f3866e7707
1 #!/bin/sh
2 # Copyright (c) 2005 Linus Torvalds
4 USAGE='-l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]'
5 SUBDIRECTORY_OK='Yes'
6 . git-sh-setup
8 message_given=
9 annotate=
10 signed=
11 force=
12 message=
13 username=
14 list=
15 while case "$#" in 0) break ;; esac
17 case "$1" in
18 -a)
19 annotate=1
21 -s)
22 annotate=1
23 signed=1
25 -f)
26 force=1
28 -l)
29 case "$#" in
31 set x . ;;
32 esac
33 shift
34 git rev-parse --symbolic --tags | sort | grep "$@"
35 exit $?
37 -m)
38 annotate=1
39 shift
40 message="$1"
41 if test "$#" = "0"; then
42 die "error: option -m needs an argument"
43 exit 2
44 else
45 message_given=1
48 -u)
49 annotate=1
50 signed=1
51 shift
52 username="$1"
54 -d)
55 shift
56 tag_name="$1"
57 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."
61 exit $?
63 -*)
64 usage
67 break
69 esac
70 shift
71 done
73 name="$1"
74 [ "$name" ] || usage
75 prev=0000000000000000000000000000000000000000
76 if git-show-ref --verify --quiet -- "refs/tags/$name"
77 then
78 test -n "$force" || die "tag '$name' already exists"
79 prev=`git rev-parse "refs/tags/$name"`
81 shift
82 git-check-ref-format "tags/$name" ||
83 die "we do not like '$name' as a tag name."
85 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
86 type=$(git-cat-file -t $object) || exit 1
87 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
88 : ${username:=$(expr "z$tagger" : 'z\(.*>\)')}
90 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
92 if [ "$annotate" ]; then
93 if [ -z "$message_given" ]; then
94 ( echo "#"
95 echo "# Write a tag message"
96 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
97 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
98 else
99 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
102 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
103 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
105 [ -s "$GIT_DIR"/TAG_FINALMSG -o -n "$message_given" ] || {
106 echo >&2 "No tag message?"
107 exit 1
110 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
111 "$object" "$type" "$name" "$tagger";
112 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
113 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
114 if [ "$signed" ]; then
115 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
116 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
117 die "failed to sign the tag with GPG."
119 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
122 git update-ref "refs/tags/$name" "$object" "$prev"