Documentation(tutorial): adjust merge example to the new merge world order.
[git/jnareb-git.git] / git-tag.sh
blob2435a75f7a9414bdceb1cef308a99918784f5421
1 #!/bin/sh
2 # Copyright (c) 2005 Linus Torvalds
4 GIT_DIR=`git-rev-parse --git-dir` || exit $?
6 usage () {
7 echo >&2 "Usage: git-tag [-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]"
8 exit 1
11 die () {
12 echo >&2 "$*"
13 exit 1
16 annotate=
17 signed=
18 force=
19 message=
20 username=
21 while case "$#" in 0) break ;; esac
23 case "$1" in
24 -a)
25 annotate=1
27 -s)
28 annotate=1
29 signed=1
31 -f)
32 force=1
34 -m)
35 annotate=1
36 shift
37 message="$1"
39 -u)
40 annotate=1
41 signed=1
42 shift
43 username="$1"
45 -d)
46 shift
47 tag_name="$1"
48 rm "$GIT_DIR/refs/tags/$tag_name" && \
49 echo "Deleted tag $tag_name."
50 exit $?
52 -*)
53 usage
56 break
58 esac
59 shift
60 done
62 name="$1"
63 [ "$name" ] || usage
64 if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
65 die "tag '$name' already exists"
67 shift
68 git-check-ref-format "tags/$name" ||
69 die "we do not like '$name' as a tag name."
71 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
72 type=$(git-cat-file -t $object) || exit 1
73 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
74 : ${username:=$(expr "$tagger" : '\(.*>\)')}
76 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
78 if [ "$annotate" ]; then
79 if [ -z "$message" ]; then
80 ( echo "#"
81 echo "# Write a tag message"
82 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
83 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
84 else
85 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
88 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
89 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
91 [ -s "$GIT_DIR"/TAG_FINALMSG ] || {
92 echo >&2 "No tag message?"
93 exit 1
96 ( echo -e "object $object\ntype $type\ntag $name\ntagger $tagger\n";
97 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
98 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
99 if [ "$signed" ]; then
100 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
101 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
102 die "failed to sign the tag with GPG."
104 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
107 leading=`expr "refs/tags/$name" : '\(.*\)/'` &&
108 mkdir -p "$GIT_DIR/$leading" &&
109 echo $object > "$GIT_DIR/refs/tags/$name"