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 10test -f".git/refs/tags/$_tag"|| error "tag:\"$_tag\"does not exist" 11cat".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 19shift2 20echo"$_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 27test -n"$_tag"|| error "usage: save_tag tag commit-args ..." 28shift1 29"$@">".git/refs/tags/$_tag" 30 31echo"s/$(tag $_tag)/$_tag/g">sed.script.tmp 32cat sed.script>>sed.script.tmp 33rm sed.script 34mv sed.script.tmp sed.script 35} 36 37# Replace unhelpful sha1 hashses with their symbolic equivalents 38entag () { 39sed-fsed.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 46shift1 47 _save=$GIT_AUTHOR_EMAIL 48 49 GIT_AUTHOR_EMAIL="$_author" 50export GIT_AUTHOR_EMAIL 51"$@" 52iftest -z"$_save" 53then 54unset GIT_AUTHOR_EMAIL 55else 56 GIT_AUTHOR_EMAIL="$_save" 57export GIT_AUTHOR_EMAIL 58fi 59} 60 61commit_date () { 62 _commit=$1 63 git cat-file commit $_commit| 64sed-n"s/^committer .*> \([0-9]*\) .*/\1/p" 65} 66 67# Assign the value of fake date to a variable, but 68# allow fairly common "1971-08-16 00:00" to be omittd 69assign_fake_date () { 70case"$2"in 71 ??:??:??)eval"$1='1971-08-16$2'";; 72 ??:??)eval"$1='1971-08-16 00:$2'";; 73 ??)eval"$1='1971-08-16 00:00:$2'";; 74*)eval"$1='$2'";; 75esac 76} 77 78on_committer_date () { 79 assign_fake_date GIT_COMMITTER_DATE "$1" 80export GIT_COMMITTER_DATE 81shift1 82"$@" 83} 84 85on_dates () { 86 assign_fake_date GIT_COMMITTER_DATE "$1" 87 assign_fake_date GIT_AUTHOR_DATE "$2" 88export GIT_COMMITTER_DATE GIT_AUTHOR_DATE 89shift2 90"$@" 91} 92 93# Execute a command and suppress any error output. 94hide_error () { 95"$@"2>/dev/null 96} 97 98check_output () { 99 _name=$1 100shift1 101ifeval"$*"| entag >"$_name.actual" 102then 103 test_cmp "$_name.expected""$_name.actual" 104else 105return1 106fi 107} 108 109# Turn a reasonable test description into a reasonable test name. 110# All alphanums translated into -'s which are then compressed and stripped 111# from front and back. 112name_from_description () { 113 perl -pe' 114 s/[^A-Za-z0-9.]/-/g; 115 s/-+/-/g; 116 s/-$//; 117 s/^-//; 118 y/A-Z/a-z/; 119 ' 120} 121 122 123# Execute the test described by the first argument, by eval'ing 124# command line specified in the 2nd argument. Check the status code 125# is zero and that the output matches the stream read from 126# stdin. 127test_output_expect_success() 128{ 129 _description=$1 130 _test=$2 131test$#-eq2|| 132 error "usage: test_output_expect_success description test <<EOF ... EOF" 133 134 _name=$(echo $_description | name_from_description) 135cat>"$_name.expected" 136 test_expect_success "$_description""check_output$_name\"$_test\"" 137}