Merge in xdiff cleanup pieces
[git/mingw/4msysgit/kblees.git] / git-tag.sh
blob76e51ed174c3f8e752d221374ec83b1f1db7fde5
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 cd "$GIT_DIR/refs" &&
29 case "$#" in
31 find tags -type f -print ;;
33 shift
34 find tags -type f -print | grep "$@" ;;
35 esac
36 exit $?
38 -m)
39 annotate=1
40 shift
41 message="$1"
43 -u)
44 annotate=1
45 signed=1
46 shift
47 username="$1"
49 -d)
50 shift
51 tag_name="$1"
52 rm "$GIT_DIR/refs/tags/$tag_name" && \
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 if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
69 die "tag '$name' already exists"
71 shift
72 git-check-ref-format "tags/$name" ||
73 die "we do not like '$name' as a tag name."
75 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
76 type=$(git-cat-file -t $object) || exit 1
77 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
78 : ${username:=$(expr "$tagger" : '\(.*>\)')}
80 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
82 if [ "$annotate" ]; then
83 if [ -z "$message" ]; then
84 ( echo "#"
85 echo "# Write a tag message"
86 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
87 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
88 else
89 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
92 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
93 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
95 [ -s "$GIT_DIR"/TAG_FINALMSG ] || {
96 echo >&2 "No tag message?"
97 exit 1
100 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
101 "$object" "$type" "$name" "$tagger";
102 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
103 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
104 if [ "$signed" ]; then
105 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
106 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
107 die "failed to sign the tag with GPG."
109 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
112 leading=`expr "refs/tags/$name" : '\(.*\)/'` &&
113 mkdir -p "$GIT_DIR/$leading" &&
114 echo $object > "$GIT_DIR/refs/tags/$name"