102d5678151d5b1fcca731724efb2bd1ad0647d6
   1: included from 6002 and others
   2
   3mkdir -p .git/refs/tags
   4
   5>sed.script
   6
   7# Answer the sha1 has associated with the tag. The tag must exist in .git/refs/tags
   8tag () {
   9        _tag=$1
  10        test -f ".git/refs/tags/$_tag" || error "tag: \"$_tag\" does not exist"
  11        cat ".git/refs/tags/$_tag"
  12}
  13
  14# Generate a commit using the text specified to make it unique and the tree
  15# named by the tag specified.
  16unique_commit () {
  17        _text=$1
  18        _tree=$2
  19        shift 2
  20        echo "$_text" | git commit-tree $(tag "$_tree") "$@"
  21}
  22
  23# Save the output of a command into the tag specified. Prepend
  24# a substitution script for the tag onto the front of sed.script
  25save_tag () {
  26        _tag=$1
  27        test -n "$_tag" || error "usage: save_tag tag commit-args ..."
  28        shift 1
  29        "$@" >".git/refs/tags/$_tag"
  30
  31        echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp
  32        cat sed.script >>sed.script.tmp
  33        rm sed.script
  34        mv sed.script.tmp sed.script
  35}
  36
  37# Replace unhelpful sha1 hashses with their symbolic equivalents
  38entag () {
  39        sed -f sed.script
  40}
  41
  42# Execute a command after first saving, then setting the GIT_AUTHOR_EMAIL
  43# tag to a specified value. Restore the original value on return.
  44as_author () {
  45        _author=$1
  46        shift 1
  47        _save=$GIT_AUTHOR_EMAIL
  48
  49        GIT_AUTHOR_EMAIL="$_author"
  50        export GIT_AUTHOR_EMAIL
  51        "$@"
  52        if test -z "$_save"
  53        then
  54                unset GIT_AUTHOR_EMAIL
  55        else
  56                GIT_AUTHOR_EMAIL="$_save"
  57                export GIT_AUTHOR_EMAIL
  58        fi
  59}
  60
  61commit_date () {
  62        _commit=$1
  63        git cat-file commit $_commit |
  64        sed -n "s/^committer .*> \([0-9]*\) .*/\1/p"
  65}
  66
  67on_committer_date () {
  68        _date=$1
  69        shift 1
  70        GIT_COMMITTER_DATE="$_date"
  71        export GIT_COMMITTER_DATE
  72        "$@"
  73        unset GIT_COMMITTER_DATE
  74}
  75
  76# Execute a command and suppress any error output.
  77hide_error () {
  78        "$@" 2>/dev/null
  79}
  80
  81check_output () {
  82        _name=$1
  83        shift 1
  84        if eval "$*" | entag >"$_name.actual"
  85        then
  86                test_cmp "$_name.expected" "$_name.actual"
  87        else
  88                return 1
  89        fi
  90}
  91
  92# Turn a reasonable test description into a reasonable test name.
  93# All alphanums translated into -'s which are then compressed and stripped
  94# from front and back.
  95name_from_description () {
  96        perl -pe '
  97                s/[^A-Za-z0-9.]/-/g;
  98                s/-+/-/g;
  99                s/-$//;
 100                s/^-//;
 101                y/A-Z/a-z/;
 102        '
 103}
 104
 105
 106# Execute the test described by the first argument, by eval'ing
 107# command line specified in the 2nd argument. Check the status code
 108# is zero and that the output matches the stream read from
 109# stdin.
 110test_output_expect_success()
 111{
 112        _description=$1
 113        _test=$2
 114        test $# -eq 2 ||
 115        error "usage: test_output_expect_success description test <<EOF ... EOF"
 116
 117        _name=$(echo $_description | name_from_description)
 118        cat >"$_name.expected"
 119        test_expect_success "$_description" "check_output $_name \"$_test\""
 120}