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