#!/bin/sh # Copyright (c) 2005 Linus Torvalds setglobal USAGE = ''[-n []] -l [] | [-a | -s | -u ] [-f | -d | -v] [-m ] []'' setglobal SUBDIRECTORY_OK = ''Yes'' source git-sh-setup setglobal message_given = '' setglobal annotate = '' setglobal signed = '' setglobal force = '' setglobal message = '' setglobal username = '' setglobal list = '' setglobal verify = '' setglobal LINES = '0' while test $# != 0 { match $1 { with -a setglobal annotate = '1' shift with -s setglobal annotate = '1' setglobal signed = '1' shift with -f setglobal force = '1' shift with -n match "$Argc,$2" { with 1,* | *,-* setglobal LINES = '1' # no argument with * shift setglobal LINES = $[expr $1 : '\([0-9]*\)] test -z $LINES && setglobal LINES = '1' # 1 line is default when -n is used } shift with -l setglobal list = '1' shift match $Argc { with 0 setglobal PATTERN = '' with * setglobal PATTERN = $1 # select tags by shell pattern, not re shift } git rev-parse --symbolic --tags | sort | while read TAG { match $TAG { with *$PATTERN* with * continue } test $LINES -le 0 && do { echo $TAG; continue ;} setglobal OBJTYPE = $[git cat-file -t $TAG] match $OBJTYPE { with tag setglobal 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 with * echo $TAG } } with -m setglobal annotate = '1' shift setglobal message = $1 if test "$Argc" = "0" { die "error: option -m needs an argument" } else { setglobal message = $1 setglobal message_given = '1' shift } with -F setglobal annotate = '1' shift if test "$Argc" = "0" { die "error: option -F needs an argument" } else { setglobal message = $[cat $1] setglobal message_given = '1' shift } with -u setglobal annotate = '1' setglobal signed = '1' shift if test "$Argc" = "0" { die "error: option -u needs an argument" } else { setglobal username = $1 shift } with -d shift setglobal had_error = '0'for tag in @Argv { setglobal cur = $[git show-ref --verify --hash -- "refs/tags/$tag] || do { echo >&2 "Seriously, what tag are you talking about?> !2 "Seriously, what tag are you talking about?" setglobal had_error = '1' continue } git update-ref -m 'tag: delete' -d "refs/tags/$tag" $cur || do { setglobal had_error = '1' continue } echo "Deleted tag $tag." } exit $had_error with -v shift setglobal tag_name = $1 setglobal tag = $[git show-ref --verify --hash -- "refs/tags/$tag_name] || die "Seriously, what tag are you talking about?" git-verify-tag -v $tag exit $? with -* usage with * break } } test -n $list && exit 0 setglobal name = $1 test $name || usage setglobal prev = '0000000000000000000000000000000000000000' if git show-ref --verify --quiet -- "refs/tags/$name" { test -n $force || die "tag '$name' already exists" setglobal prev = $[git rev-parse "refs/tags/$name] } shift git check-ref-format "tags/$name" || die "we do not like '$name' as a tag name." setglobal object = $[git rev-parse --verify --default HEAD @Argv] || exit 1 setglobal type = $[git cat-file -t $object] || exit 1 setglobal tagger = $[git var GIT_COMMITTER_IDENT] || exit 1 test -n $username || setglobal username = $[git config user.signingkey] || setglobal username = $[expr "z$tagger" : 'z\(.*>\)] trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0 if test $annotate { if test -z $message_given { shell { echo "#" echo "# Write a tag message" echo "#" } > "$GIT_DIR"/TAG_EDITMSG git_editor "$GIT_DIR"/TAG_EDITMSG || exit } else { printf '%s\n' $message >"$GIT_DIR"/TAG_EDITMSG } grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG | git stripspace >"$GIT_DIR"/TAG_FINALMSG test -s "$GIT_DIR"/TAG_FINALMSG -o -n $message_given || do { echo >&2 "No tag message?> !2 "No tag message?" exit 1 } shell { printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \ $object $type $name $tagger; cat "$GIT_DIR"/TAG_FINALMSG } >"$GIT_DIR"/TAG_TMP rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG if test $signed { gpg -bsa -u $username "$GIT_DIR"/TAG_TMP && cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP || die "failed to sign the tag with GPG." } setglobal object = $[git-mktag < "$GIT_DIR"/TAG_TMP] } git update-ref "refs/tags/$name" $object $prev