2005-04-26 02:23:53 +04:00
|
|
|
#!/bin/sh
|
2005-05-10 09:57:58 +04:00
|
|
|
# Copyright (c) 2005 Linus Torvalds
|
|
|
|
|
2006-02-17 15:04:39 +03:00
|
|
|
USAGE='-l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]'
|
2005-12-14 01:30:31 +03:00
|
|
|
SUBDIRECTORY_OK='Yes'
|
|
|
|
. git-sh-setup
|
2005-11-28 10:33:54 +03:00
|
|
|
|
2005-07-26 02:18:35 +04:00
|
|
|
annotate=
|
2005-07-24 02:21:22 +04:00
|
|
|
signed=
|
|
|
|
force=
|
2005-08-09 04:04:42 +04:00
|
|
|
message=
|
2005-10-07 01:10:39 +04:00
|
|
|
username=
|
2006-02-17 15:04:39 +03:00
|
|
|
list=
|
2005-07-24 02:21:22 +04:00
|
|
|
while case "$#" in 0) break ;; esac
|
|
|
|
do
|
|
|
|
case "$1" in
|
2005-07-26 02:18:35 +04:00
|
|
|
-a)
|
|
|
|
annotate=1
|
|
|
|
;;
|
2005-07-24 02:21:22 +04:00
|
|
|
-s)
|
2005-07-26 02:18:35 +04:00
|
|
|
annotate=1
|
2005-07-24 02:21:22 +04:00
|
|
|
signed=1
|
|
|
|
;;
|
|
|
|
-f)
|
|
|
|
force=1
|
|
|
|
;;
|
2006-02-17 15:04:39 +03:00
|
|
|
-l)
|
|
|
|
cd "$GIT_DIR/refs" &&
|
|
|
|
case "$#" in
|
|
|
|
1)
|
|
|
|
find tags -type f -print ;;
|
|
|
|
*)
|
|
|
|
shift
|
|
|
|
find tags -type f -print | grep "$@" ;;
|
|
|
|
esac
|
|
|
|
exit $?
|
|
|
|
;;
|
2005-08-09 04:04:42 +04:00
|
|
|
-m)
|
|
|
|
annotate=1
|
|
|
|
shift
|
|
|
|
message="$1"
|
|
|
|
;;
|
2005-10-07 01:10:39 +04:00
|
|
|
-u)
|
|
|
|
annotate=1
|
|
|
|
signed=1
|
|
|
|
shift
|
|
|
|
username="$1"
|
|
|
|
;;
|
2005-11-08 13:44:33 +03:00
|
|
|
-d)
|
|
|
|
shift
|
|
|
|
tag_name="$1"
|
|
|
|
rm "$GIT_DIR/refs/tags/$tag_name" && \
|
|
|
|
echo "Deleted tag $tag_name."
|
|
|
|
exit $?
|
|
|
|
;;
|
2005-07-26 02:18:35 +04:00
|
|
|
-*)
|
|
|
|
usage
|
|
|
|
;;
|
2005-07-24 02:21:22 +04:00
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2005-07-09 05:23:06 +04:00
|
|
|
name="$1"
|
2005-07-26 02:18:35 +04:00
|
|
|
[ "$name" ] || usage
|
|
|
|
if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
|
|
|
|
die "tag '$name' already exists"
|
|
|
|
fi
|
2005-07-24 02:21:22 +04:00
|
|
|
shift
|
2005-10-14 05:57:39 +04:00
|
|
|
git-check-ref-format "tags/$name" ||
|
|
|
|
die "we do not like '$name' as a tag name."
|
2005-05-10 09:57:58 +04:00
|
|
|
|
2005-08-16 02:37:37 +04:00
|
|
|
object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
|
2005-04-30 03:25:05 +04:00
|
|
|
type=$(git-cat-file -t $object) || exit 1
|
2005-07-15 05:02:10 +04:00
|
|
|
tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
|
2005-10-07 01:10:39 +04:00
|
|
|
: ${username:=$(expr "$tagger" : '\(.*>\)')}
|
2005-07-09 05:23:06 +04:00
|
|
|
|
2005-11-04 02:26:43 +03:00
|
|
|
trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
|
2005-07-26 02:18:35 +04:00
|
|
|
|
|
|
|
if [ "$annotate" ]; then
|
2005-08-09 04:04:42 +04:00
|
|
|
if [ -z "$message" ]; then
|
|
|
|
( echo "#"
|
|
|
|
echo "# Write a tag message"
|
2005-11-04 02:26:43 +03:00
|
|
|
echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
|
|
|
|
${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
|
2005-08-09 04:04:42 +04:00
|
|
|
else
|
2005-11-04 02:26:43 +03:00
|
|
|
echo "$message" >"$GIT_DIR"/TAG_EDITMSG
|
2005-08-09 04:04:42 +04:00
|
|
|
fi
|
2005-07-24 02:21:22 +04:00
|
|
|
|
2005-11-04 02:26:43 +03:00
|
|
|
grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
|
|
|
|
git-stripspace >"$GIT_DIR"/TAG_FINALMSG
|
2005-07-09 05:23:06 +04:00
|
|
|
|
2005-11-04 02:26:43 +03:00
|
|
|
[ -s "$GIT_DIR"/TAG_FINALMSG ] || {
|
2005-10-07 01:10:39 +04:00
|
|
|
echo >&2 "No tag message?"
|
|
|
|
exit 1
|
|
|
|
}
|
2005-07-09 05:23:06 +04:00
|
|
|
|
2006-02-12 21:05:34 +03:00
|
|
|
( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
|
|
|
|
"$object" "$type" "$name" "$tagger";
|
2005-11-04 02:26:43 +03:00
|
|
|
cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
|
|
|
|
rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
|
2005-07-26 02:18:35 +04:00
|
|
|
if [ "$signed" ]; then
|
2005-11-04 02:26:43 +03:00
|
|
|
gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
|
|
|
|
cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
|
2005-07-26 02:18:35 +04:00
|
|
|
die "failed to sign the tag with GPG."
|
|
|
|
fi
|
2005-11-04 02:26:43 +03:00
|
|
|
object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
|
2005-07-24 02:21:22 +04:00
|
|
|
fi
|
2005-07-09 05:23:06 +04:00
|
|
|
|
2005-11-08 03:22:34 +03:00
|
|
|
leading=`expr "refs/tags/$name" : '\(.*\)/'` &&
|
|
|
|
mkdir -p "$GIT_DIR/$leading" &&
|
2005-07-24 02:21:22 +04:00
|
|
|
echo $object > "$GIT_DIR/refs/tags/$name"
|