Clarify fetch error for missing objects.
[git/spearce.git] / git-tag.sh
blobac269e3277d9b8c844e8c43b95695375dd829746
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 annotate=
9 signed=
10 force=
11 message=
12 username=
13 list=
14 while case "$#" in 0) break ;; esac
16 case "$1" in
17 -a)
18 annotate=1
20 -s)
21 annotate=1
22 signed=1
24 -f)
25 force=1
27 -l)
28 case "$#" in
30 set x . ;;
31 esac
32 shift
33 git rev-parse --symbolic --tags | sort | grep "$@"
34 exit $?
36 -m)
37 annotate=1
38 shift
39 message="$1"
41 -u)
42 annotate=1
43 signed=1
44 shift
45 username="$1"
47 -d)
48 shift
49 tag_name="$1"
50 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."
54 exit $?
56 -*)
57 usage
60 break
62 esac
63 shift
64 done
66 name="$1"
67 [ "$name" ] || usage
68 prev=0000000000000000000000000000000000000000
69 if git-show-ref --verify --quiet -- "refs/tags/$name"
70 then
71 test -n "$force" || die "tag '$name' already exists"
72 prev=`git rev-parse "refs/tags/$name"`
74 shift
75 git-check-ref-format "tags/$name" ||
76 die "we do not like '$name' as a tag name."
78 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
79 type=$(git-cat-file -t $object) || exit 1
80 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
81 : ${username:=$(expr "z$tagger" : 'z\(.*>\)')}
83 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
85 if [ "$annotate" ]; then
86 if [ -z "$message" ]; then
87 ( echo "#"
88 echo "# Write a tag message"
89 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
90 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
91 else
92 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
95 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
96 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
98 [ -s "$GIT_DIR"/TAG_FINALMSG ] || {
99 echo >&2 "No tag message?"
100 exit 1
103 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
104 "$object" "$type" "$name" "$tagger";
105 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
106 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
107 if [ "$signed" ]; then
108 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
109 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
110 die "failed to sign the tag with GPG."
112 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
115 git update-ref "refs/tags/$name" "$object" "$prev"