git-tag.shon commit Format tweaks for asciidoc. (b0d08a5)
   1#!/bin/sh
   2# Copyright (c) 2005 Linus Torvalds
   3
   4USAGE='-l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]'
   5SUBDIRECTORY_OK='Yes'
   6. git-sh-setup
   7
   8annotate=
   9signed=
  10force=
  11message=
  12username=
  13list=
  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    -l)
  28        cd "$GIT_DIR/refs" &&
  29        case "$#" in
  30        1)
  31                find tags -type f -print ;;
  32        *)
  33                shift
  34                find tags -type f -print | grep "$@" ;;
  35        esac
  36        exit $?
  37        ;;
  38    -m)
  39        annotate=1
  40        shift
  41        message="$1"
  42        ;;
  43    -u)
  44        annotate=1
  45        signed=1
  46        shift
  47        username="$1"
  48        ;;
  49    -d)
  50        shift
  51        tag_name="$1"
  52        rm "$GIT_DIR/refs/tags/$tag_name" && \
  53                echo "Deleted tag $tag_name."
  54        exit $?
  55        ;;
  56    -*)
  57        usage
  58        ;;
  59    *)
  60        break
  61        ;;
  62    esac
  63    shift
  64done
  65
  66name="$1"
  67[ "$name" ] || usage
  68if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
  69    die "tag '$name' already exists"
  70fi
  71shift
  72git-check-ref-format "tags/$name" ||
  73        die "we do not like '$name' as a tag name."
  74
  75object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
  76type=$(git-cat-file -t $object) || exit 1
  77tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
  78: ${username:=$(expr "$tagger" : '\(.*>\)')}
  79
  80trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
  81
  82if [ "$annotate" ]; then
  83    if [ -z "$message" ]; then
  84        ( echo "#"
  85          echo "# Write a tag message"
  86          echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
  87        ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
  88    else
  89        echo "$message" >"$GIT_DIR"/TAG_EDITMSG
  90    fi
  91
  92    grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
  93    git-stripspace >"$GIT_DIR"/TAG_FINALMSG
  94
  95    [ -s "$GIT_DIR"/TAG_FINALMSG ] || {
  96        echo >&2 "No tag message?"
  97        exit 1
  98    }
  99
 100    ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
 101        "$object" "$type" "$name" "$tagger";
 102      cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
 103    rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
 104    if [ "$signed" ]; then
 105        gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
 106        cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
 107        die "failed to sign the tag with GPG."
 108    fi
 109    object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
 110fi
 111
 112leading=`expr "refs/tags/$name" : '\(.*\)/'` &&
 113mkdir -p "$GIT_DIR/$leading" &&
 114echo $object > "$GIT_DIR/refs/tags/$name"