Update clone/fetch documentation with --depth (shallow clone) option
[git/git-svn.git] / git-tag.sh
blobe1bfa82f1ea1213fad8ff8c4b6ad2b17e6ca1f7e
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 else
44 message_given=1
47 -F)
48 annotate=1
49 shift
50 if test "$#" = "0"; then
51 die "error: option -F needs an argument"
52 else
53 message="$(cat "$1")"
54 message_given=1
57 -u)
58 annotate=1
59 signed=1
60 shift
61 username="$1"
63 -d)
64 shift
65 tag_name="$1"
66 tag=$(git-show-ref --verify --hash -- "refs/tags/$tag_name") ||
67 die "Seriously, what tag are you talking about?"
68 git-update-ref -m 'tag: delete' -d "refs/tags/$tag_name" "$tag" &&
69 echo "Deleted tag $tag_name."
70 exit $?
72 -*)
73 usage
76 break
78 esac
79 shift
80 done
82 name="$1"
83 [ "$name" ] || usage
84 prev=0000000000000000000000000000000000000000
85 if git-show-ref --verify --quiet -- "refs/tags/$name"
86 then
87 test -n "$force" || die "tag '$name' already exists"
88 prev=`git rev-parse "refs/tags/$name"`
90 shift
91 git-check-ref-format "tags/$name" ||
92 die "we do not like '$name' as a tag name."
94 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
95 type=$(git-cat-file -t $object) || exit 1
96 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
97 : ${username:=$(expr "z$tagger" : 'z\(.*>\)')}
99 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
101 if [ "$annotate" ]; then
102 if [ -z "$message_given" ]; then
103 ( echo "#"
104 echo "# Write a tag message"
105 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
106 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
107 else
108 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
111 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
112 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
114 [ -s "$GIT_DIR"/TAG_FINALMSG -o -n "$message_given" ] || {
115 echo >&2 "No tag message?"
116 exit 1
119 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
120 "$object" "$type" "$name" "$tagger";
121 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
122 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
123 if [ "$signed" ]; then
124 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
125 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
126 die "failed to sign the tag with GPG."
128 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
131 git update-ref "refs/tags/$name" "$object" "$prev"