[PATCH] Fix bisection terminating condition
[git/dscho.git] / git-tag-script
blob39c3c53987bf647d2b15127c7fa8cedcc5befd35
1 #!/bin/sh
2 # Copyright (c) 2005 Linus Torvalds
4 . git-sh-setup-script || die "Not a git archive"
6 usage () {
7 echo >&2 "Usage: git-tag-script [-a | -s] [-f] [-m "tag message"] tagname"
8 exit 1
11 annotate=
12 signed=
13 force=
14 message=
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 -m)
29 annotate=1
30 shift
31 message="$1"
33 -*)
34 usage
37 break
39 esac
40 shift
41 done
43 name="$1"
44 [ "$name" ] || usage
45 if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
46 die "tag '$name' already exists"
48 shift
50 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
51 type=$(git-cat-file -t $object) || exit 1
52 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
54 trap 'rm -f .tmp-tag* .tagmsg .editmsg' 0
56 if [ "$annotate" ]; then
57 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
66 grep -v '^#' < .editmsg | git-stripspace > .tagmsg
68 [ -s .tagmsg ] || exit
70 ( echo -e "object $object\ntype $type\ntag $name\ntagger $tagger\n"; cat .tagmsg ) > .tmp-tag
71 rm -f .tmp-tag.asc .tagmsg
72 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."
78 object=$(git-mktag < .tmp-tag)
81 mkdir -p "$GIT_DIR/refs/tags"
82 echo $object > "$GIT_DIR/refs/tags/$name"