git-tag-scripton commit (revert local fix) (200e7fb)
   1#!/bin/sh
   2# Copyright (c) 2005 Linus Torvalds
   3
   4. git-sh-setup-script || die "Not a git archive"
   5
   6usage () {
   7    echo >&2 "Usage: git-tag-script [-a | -s] [-f] tagname"
   8    exit 1
   9}
  10
  11annotate=
  12signed=
  13force=
  14while case "$#" in 0) break ;; esac
  15do
  16    case "$1" in
  17    -a)
  18        annotate=1
  19        ;;
  20    -s)
  21        annotate=1
  22        signed=1
  23        ;;
  24    -f)
  25        force=1
  26        ;;
  27    -*)
  28        usage
  29        ;;
  30    *)
  31        break
  32        ;;
  33    esac
  34    shift
  35done
  36
  37name="$1"
  38[ "$name" ] || usage
  39if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
  40    die "tag '$name' already exists"
  41fi
  42shift
  43
  44object=$(git-rev-parse --verify --revs-only --default HEAD "$@") || exit 1
  45type=$(git-cat-file -t $object) || exit 1
  46tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
  47
  48trap 'rm -f .tmp-tag* .tagmsg .editmsg' 0
  49
  50if [ "$annotate" ]; then
  51    ( echo "#"
  52      echo "# Write a tag message"
  53      echo "#" ) > .editmsg
  54    ${VISUAL:-${EDITOR:-vi}} .editmsg || exit
  55
  56    grep -v '^#' < .editmsg | git-stripspace > .tagmsg
  57
  58    [ -s .tagmsg ] || exit
  59
  60    ( echo -e "object $object\ntype $type\ntag $name\ntagger $tagger\n"; cat .tagmsg ) > .tmp-tag
  61    rm -f .tmp-tag.asc .tagmsg
  62    if [ "$signed" ]; then
  63        me=$(expr "$tagger" : '\(.*>\)') &&
  64        gpg -bsa -u "$me" .tmp-tag &&
  65        cat .tmp-tag.asc >>.tmp-tag ||
  66        die "failed to sign the tag with GPG."
  67    fi
  68    object=$(git-mktag < .tmp-tag)
  69fi
  70
  71mkdir -p "$GIT_DIR/refs/tags"
  72echo $object > "$GIT_DIR/refs/tags/$name"