2005-04-26 00:23:53 +02:00
|
|
|
#!/bin/sh
|
2005-05-10 07:57:58 +02:00
|
|
|
# Copyright (c) 2005 Linus Torvalds
|
|
|
|
|
2007-06-03 02:05:39 +02:00
|
|
|
USAGE='[-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
|
2005-12-13 23:30:31 +01:00
|
|
|
SUBDIRECTORY_OK='Yes'
|
|
|
|
. git-sh-setup
|
2005-11-28 08:33:54 +01:00
|
|
|
|
2006-11-26 17:42:49 +01:00
|
|
|
message_given=
|
2005-07-26 00:18:35 +02:00
|
|
|
annotate=
|
2005-07-24 00:21:22 +02:00
|
|
|
signed=
|
|
|
|
force=
|
2005-08-09 02:04:42 +02:00
|
|
|
message=
|
2005-10-06 23:10:39 +02:00
|
|
|
username=
|
2006-02-17 13:04:39 +01:00
|
|
|
list=
|
2007-01-03 13:59:00 +01:00
|
|
|
verify=
|
2007-06-03 02:05:39 +02:00
|
|
|
LINES=0
|
2007-09-23 22:42:08 +02:00
|
|
|
while test $# != 0
|
2005-07-24 00:21:22 +02:00
|
|
|
do
|
|
|
|
case "$1" in
|
2005-07-26 00:18:35 +02:00
|
|
|
-a)
|
|
|
|
annotate=1
|
2007-06-28 18:56:57 +02:00
|
|
|
shift
|
2005-07-26 00:18:35 +02:00
|
|
|
;;
|
2005-07-24 00:21:22 +02:00
|
|
|
-s)
|
2005-07-26 00:18:35 +02:00
|
|
|
annotate=1
|
2005-07-24 00:21:22 +02:00
|
|
|
signed=1
|
2007-06-28 18:56:57 +02:00
|
|
|
shift
|
2005-07-24 00:21:22 +02:00
|
|
|
;;
|
|
|
|
-f)
|
|
|
|
force=1
|
2007-06-28 18:56:57 +02:00
|
|
|
shift
|
2005-07-24 00:21:22 +02:00
|
|
|
;;
|
2007-06-03 02:05:39 +02:00
|
|
|
-n)
|
2007-06-28 18:56:57 +02:00
|
|
|
case "$#,$2" in
|
|
|
|
1,* | *,-*)
|
|
|
|
LINES=1 # no argument
|
2007-06-03 02:05:39 +02:00
|
|
|
;;
|
|
|
|
*) shift
|
|
|
|
LINES=$(expr "$1" : '\([0-9]*\)')
|
|
|
|
[ -z "$LINES" ] && LINES=1 # 1 line is default when -n is used
|
|
|
|
;;
|
2006-02-17 13:04:39 +01:00
|
|
|
esac
|
2007-06-28 18:56:57 +02:00
|
|
|
shift
|
2007-06-03 02:05:39 +02:00
|
|
|
;;
|
|
|
|
-l)
|
|
|
|
list=1
|
2006-05-15 02:07:39 +02:00
|
|
|
shift
|
2007-06-28 18:56:57 +02:00
|
|
|
case $# in
|
|
|
|
0) PATTERN=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
PATTERN="$1" # select tags by shell pattern, not re
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
2007-06-03 02:05:39 +02:00
|
|
|
git rev-parse --symbolic --tags | sort |
|
|
|
|
while read TAG
|
|
|
|
do
|
|
|
|
case "$TAG" in
|
|
|
|
*$PATTERN*) ;;
|
|
|
|
*) continue ;;
|
|
|
|
esac
|
|
|
|
[ "$LINES" -le 0 ] && { echo "$TAG"; continue ;}
|
|
|
|
OBJTYPE=$(git cat-file -t "$TAG")
|
|
|
|
case $OBJTYPE in
|
2007-06-30 08:42:47 +02:00
|
|
|
tag)
|
|
|
|
ANNOTATION=$(git cat-file tag "$TAG" |
|
|
|
|
sed -e '1,/^$/d' |
|
|
|
|
sed -n -e "
|
|
|
|
/^-----BEGIN PGP SIGNATURE-----\$/q
|
|
|
|
2,\$s/^/ /
|
|
|
|
p
|
|
|
|
${LINES}q
|
|
|
|
")
|
|
|
|
printf "%-15s %s\n" "$TAG" "$ANNOTATION"
|
2007-06-03 02:05:39 +02:00
|
|
|
;;
|
|
|
|
*) echo "$TAG"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2006-02-17 13:04:39 +01:00
|
|
|
;;
|
2005-08-09 02:04:42 +02:00
|
|
|
-m)
|
2007-06-07 09:04:01 +02:00
|
|
|
annotate=1
|
2005-08-09 02:04:42 +02:00
|
|
|
shift
|
|
|
|
message="$1"
|
2006-11-26 17:42:49 +01:00
|
|
|
if test "$#" = "0"; then
|
|
|
|
die "error: option -m needs an argument"
|
|
|
|
else
|
2007-06-28 18:56:57 +02:00
|
|
|
message="$1"
|
2006-11-26 17:42:49 +01:00
|
|
|
message_given=1
|
2007-06-28 18:56:57 +02:00
|
|
|
shift
|
2006-11-26 17:42:49 +01:00
|
|
|
fi
|
2005-08-09 02:04:42 +02:00
|
|
|
;;
|
2006-12-21 15:13:02 +01:00
|
|
|
-F)
|
|
|
|
annotate=1
|
|
|
|
shift
|
|
|
|
if test "$#" = "0"; then
|
|
|
|
die "error: option -F needs an argument"
|
|
|
|
else
|
|
|
|
message="$(cat "$1")"
|
|
|
|
message_given=1
|
2007-06-28 18:56:57 +02:00
|
|
|
shift
|
2006-12-21 15:13:02 +01:00
|
|
|
fi
|
|
|
|
;;
|
2005-10-06 23:10:39 +02:00
|
|
|
-u)
|
|
|
|
annotate=1
|
|
|
|
signed=1
|
|
|
|
shift
|
2007-06-28 18:56:57 +02:00
|
|
|
if test "$#" = "0"; then
|
|
|
|
die "error: option -u needs an argument"
|
|
|
|
else
|
|
|
|
username="$1"
|
|
|
|
shift
|
|
|
|
fi
|
2005-10-06 23:10:39 +02:00
|
|
|
;;
|
2005-11-08 11:44:33 +01:00
|
|
|
-d)
|
2007-06-07 09:04:01 +02:00
|
|
|
shift
|
2007-01-20 19:47:41 +01:00
|
|
|
had_error=0
|
|
|
|
for tag
|
|
|
|
do
|
2007-07-03 07:52:14 +02:00
|
|
|
cur=$(git show-ref --verify --hash -- "refs/tags/$tag") || {
|
2007-01-20 19:47:41 +01:00
|
|
|
echo >&2 "Seriously, what tag are you talking about?"
|
|
|
|
had_error=1
|
|
|
|
continue
|
|
|
|
}
|
2007-07-03 07:52:14 +02:00
|
|
|
git update-ref -m 'tag: delete' -d "refs/tags/$tag" "$cur" || {
|
2007-01-20 19:47:41 +01:00
|
|
|
had_error=1
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
echo "Deleted tag $tag."
|
|
|
|
done
|
|
|
|
exit $had_error
|
2005-11-08 11:44:33 +01:00
|
|
|
;;
|
2007-01-03 13:59:00 +01:00
|
|
|
-v)
|
|
|
|
shift
|
|
|
|
tag_name="$1"
|
2007-07-03 07:52:14 +02:00
|
|
|
tag=$(git show-ref --verify --hash -- "refs/tags/$tag_name") ||
|
2007-01-03 13:59:00 +01:00
|
|
|
die "Seriously, what tag are you talking about?"
|
|
|
|
git-verify-tag -v "$tag"
|
|
|
|
exit $?
|
|
|
|
;;
|
2005-07-26 00:18:35 +02:00
|
|
|
-*)
|
|
|
|
usage
|
|
|
|
;;
|
2005-07-24 00:21:22 +02:00
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2007-06-03 02:05:39 +02:00
|
|
|
[ -n "$list" ] && exit 0
|
|
|
|
|
2005-07-09 03:23:06 +02:00
|
|
|
name="$1"
|
2005-07-26 00:18:35 +02:00
|
|
|
[ "$name" ] || usage
|
2006-09-27 11:06:31 +02:00
|
|
|
prev=0000000000000000000000000000000000000000
|
2007-07-03 07:52:14 +02:00
|
|
|
if git show-ref --verify --quiet -- "refs/tags/$name"
|
2006-09-27 11:06:31 +02:00
|
|
|
then
|
|
|
|
test -n "$force" || die "tag '$name' already exists"
|
|
|
|
prev=`git rev-parse "refs/tags/$name"`
|
2005-07-26 00:18:35 +02:00
|
|
|
fi
|
2005-07-24 00:21:22 +02:00
|
|
|
shift
|
2007-07-03 07:52:14 +02:00
|
|
|
git check-ref-format "tags/$name" ||
|
2005-10-14 03:57:39 +02:00
|
|
|
die "we do not like '$name' as a tag name."
|
2005-05-10 07:57:58 +02:00
|
|
|
|
2007-07-03 07:52:14 +02:00
|
|
|
object=$(git rev-parse --verify --default HEAD "$@") || exit 1
|
|
|
|
type=$(git cat-file -t $object) || exit 1
|
2008-07-30 19:48:33 +02:00
|
|
|
tagger=$(git var GIT_COMMITTER_IDENT) || exit 1
|
2007-01-26 15:13:46 +01:00
|
|
|
|
2007-01-31 06:03:11 +01:00
|
|
|
test -n "$username" ||
|
2008-01-18 07:52:40 +01:00
|
|
|
username=$(git config user.signingkey) ||
|
2007-01-31 06:03:11 +01:00
|
|
|
username=$(expr "z$tagger" : 'z\(.*>\)')
|
2005-07-09 03:23:06 +02:00
|
|
|
|
2005-11-04 00:26:43 +01:00
|
|
|
trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
|
2005-07-26 00:18:35 +02:00
|
|
|
|
|
|
|
if [ "$annotate" ]; then
|
2006-11-26 17:42:49 +01:00
|
|
|
if [ -z "$message_given" ]; then
|
2005-08-09 02:04:42 +02:00
|
|
|
( echo "#"
|
|
|
|
echo "# Write a tag message"
|
2005-11-04 00:26:43 +01:00
|
|
|
echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
|
2007-07-20 07:09:35 +02:00
|
|
|
git_editor "$GIT_DIR"/TAG_EDITMSG || exit
|
2005-08-09 02:04:42 +02:00
|
|
|
else
|
2007-05-26 09:33:03 +02:00
|
|
|
printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG
|
2005-08-09 02:04:42 +02:00
|
|
|
fi
|
2005-07-24 00:21:22 +02:00
|
|
|
|
2005-11-04 00:26:43 +01:00
|
|
|
grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
|
2007-07-03 07:52:14 +02:00
|
|
|
git stripspace >"$GIT_DIR"/TAG_FINALMSG
|
2005-07-09 03:23:06 +02:00
|
|
|
|
2006-11-26 17:42:49 +01:00
|
|
|
[ -s "$GIT_DIR"/TAG_FINALMSG -o -n "$message_given" ] || {
|
2005-10-06 23:10:39 +02:00
|
|
|
echo >&2 "No tag message?"
|
|
|
|
exit 1
|
|
|
|
}
|
2005-07-09 03:23:06 +02:00
|
|
|
|
2006-02-12 19:05:34 +01:00
|
|
|
( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
|
|
|
|
"$object" "$type" "$name" "$tagger";
|
2005-11-04 00:26:43 +01:00
|
|
|
cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
|
|
|
|
rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
|
2005-07-26 00:18:35 +02:00
|
|
|
if [ "$signed" ]; then
|
2007-01-31 06:03:11 +01:00
|
|
|
gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
|
2005-11-04 00:26:43 +01:00
|
|
|
cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
|
2005-07-26 00:18:35 +02:00
|
|
|
die "failed to sign the tag with GPG."
|
|
|
|
fi
|
2005-11-04 00:26:43 +01:00
|
|
|
object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
|
2005-07-24 00:21:22 +02:00
|
|
|
fi
|
2005-07-09 03:23:06 +02:00
|
|
|
|
2006-10-02 06:36:15 +02:00
|
|
|
git update-ref "refs/tags/$name" "$object" "$prev"
|