blob: 3f2d873fec9ed9e98b787cd708cd9e8e816e7573 [file] [log] [blame]
Junio C Hamanob9b727d2010-01-30 15:59:09 -08001: included from 6002 and others
2
Junio C Hamano50e5a252013-06-21 10:12:48 -07003mkdir -p .git/refs/tags
Jon Seymource118952005-07-06 20:11:24 +10004
Junio C Hamano50e5a252013-06-21 10:12:48 -07005>sed.script
Jon Seymource118952005-07-06 20:11:24 +10006
Junio C Hamano50e5a252013-06-21 10:12:48 -07007# Answer the sha1 has associated with the tag. The tag must exist in .git/refs/tags
8tag () {
Jon Seymource118952005-07-06 20:11:24 +10009 _tag=$1
Junio C Hamano50e5a252013-06-21 10:12:48 -070010 test -f ".git/refs/tags/$_tag" || error "tag: \"$_tag\" does not exist"
11 cat ".git/refs/tags/$_tag"
Jon Seymource118952005-07-06 20:11:24 +100012}
13
14# Generate a commit using the text specified to make it unique and the tree
15# named by the tag specified.
Junio C Hamano50e5a252013-06-21 10:12:48 -070016unique_commit () {
Jon Seymource118952005-07-06 20:11:24 +100017 _text=$1
Junio C Hamano50e5a252013-06-21 10:12:48 -070018 _tree=$2
Jon Seymource118952005-07-06 20:11:24 +100019 shift 2
Junio C Hamano50e5a252013-06-21 10:12:48 -070020 echo "$_text" | git commit-tree $(tag "$_tree") "$@"
Jon Seymource118952005-07-06 20:11:24 +100021}
22
23# Save the output of a command into the tag specified. Prepend
Jon Seymour28346d22005-07-07 10:50:07 +100024# a substitution script for the tag onto the front of sed.script
Junio C Hamano50e5a252013-06-21 10:12:48 -070025save_tag () {
Junio C Hamanoa6080a02007-06-07 00:04:01 -070026 _tag=$1
Junio C Hamano50e5a252013-06-21 10:12:48 -070027 test -n "$_tag" || error "usage: save_tag tag commit-args ..."
Jon Seymource118952005-07-06 20:11:24 +100028 shift 1
Junio C Hamano50e5a252013-06-21 10:12:48 -070029 "$@" >".git/refs/tags/$_tag"
Jon Seymourf6069c52005-07-06 20:11:29 +100030
Junio C Hamano50e5a252013-06-21 10:12:48 -070031 echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp
32 cat sed.script >>sed.script.tmp
Jon Seymour28346d22005-07-07 10:50:07 +100033 rm sed.script
34 mv sed.script.tmp sed.script
Jon Seymource118952005-07-06 20:11:24 +100035}
36
Ondřej Bílka98e023d2013-07-29 10:18:21 +020037# Replace unhelpful sha1 hashes with their symbolic equivalents
Junio C Hamano50e5a252013-06-21 10:12:48 -070038entag () {
Jon Seymour28346d22005-07-07 10:50:07 +100039 sed -f sed.script
Jon Seymource118952005-07-06 20:11:24 +100040}
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.
Junio C Hamano50e5a252013-06-21 10:12:48 -070044as_author () {
Jon Seymource118952005-07-06 20:11:24 +100045 _author=$1
46 shift 1
Junio C Hamano50e5a252013-06-21 10:12:48 -070047 _save=$GIT_AUTHOR_EMAIL
Jon Seymource118952005-07-06 20:11:24 +100048
Bryan Donlan0e46e702008-05-04 01:37:58 -040049 GIT_AUTHOR_EMAIL="$_author"
50 export GIT_AUTHOR_EMAIL
Jon Seymource118952005-07-06 20:11:24 +100051 "$@"
Junio C Hamano47e013f2006-02-07 15:35:46 -080052 if test -z "$_save"
53 then
54 unset GIT_AUTHOR_EMAIL
55 else
Bryan Donlan0e46e702008-05-04 01:37:58 -040056 GIT_AUTHOR_EMAIL="$_save"
57 export GIT_AUTHOR_EMAIL
Junio C Hamano47e013f2006-02-07 15:35:46 -080058 fi
Jon Seymource118952005-07-06 20:11:24 +100059}
60
Junio C Hamano50e5a252013-06-21 10:12:48 -070061commit_date () {
62 _commit=$1
63 git cat-file commit $_commit |
64 sed -n "s/^committer .*> \([0-9]*\) .*/\1/p"
Jon Seymource118952005-07-06 20:11:24 +100065}
66
Junio C Hamano841dc692013-06-21 10:29:59 -070067# 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 () {
70 case "$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'" ;;
75 esac
76}
77
Junio C Hamano50e5a252013-06-21 10:12:48 -070078on_committer_date () {
Junio C Hamano841dc692013-06-21 10:29:59 -070079 assign_fake_date GIT_COMMITTER_DATE "$1"
Junio C Hamano50e5a252013-06-21 10:12:48 -070080 export GIT_COMMITTER_DATE
Junio C Hamano841dc692013-06-21 10:29:59 -070081 shift 1
Junio C Hamano50e5a252013-06-21 10:12:48 -070082 "$@"
Jon Seymource118952005-07-06 20:11:24 +100083}
84
Junio C Hamano11667312013-06-21 11:03:32 -070085on_dates () {
86 assign_fake_date GIT_COMMITTER_DATE "$1"
87 assign_fake_date GIT_AUTHOR_DATE "$2"
88 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
89 shift 2
90 "$@"
91}
92
Jon Seymource118952005-07-06 20:11:24 +100093# Execute a command and suppress any error output.
Junio C Hamano50e5a252013-06-21 10:12:48 -070094hide_error () {
Jon Seymource118952005-07-06 20:11:24 +100095 "$@" 2>/dev/null
96}
97
Junio C Hamano50e5a252013-06-21 10:12:48 -070098check_output () {
Jon Seymource118952005-07-06 20:11:24 +100099 _name=$1
100 shift 1
Junio C Hamano50e5a252013-06-21 10:12:48 -0700101 if eval "$*" | entag >"$_name.actual"
Jon Seymource118952005-07-06 20:11:24 +1000102 then
Junio C Hamano50e5a252013-06-21 10:12:48 -0700103 test_cmp "$_name.expected" "$_name.actual"
Jon Seymource118952005-07-06 20:11:24 +1000104 else
Junio C Hamano50e5a252013-06-21 10:12:48 -0700105 return 1
Jon Seymource118952005-07-06 20:11:24 +1000106 fi
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.
Junio C Hamano50e5a252013-06-21 10:12:48 -0700112name_from_description () {
Jeff Kingaab0abf2008-03-14 20:32:33 -0400113 perl -pe '
114 s/[^A-Za-z0-9.]/-/g;
115 s/-+/-/g;
116 s/-$//;
117 s/^-//;
118 y/A-Z/a-z/;
119 '
Jon Seymource118952005-07-06 20:11:24 +1000120}
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
Junio C Hamanoa6080a02007-06-07 00:04:01 -0700125# is zero and that the output matches the stream read from
Jon Seymource118952005-07-06 20:11:24 +1000126# stdin.
127test_output_expect_success()
Junio C Hamanoa6080a02007-06-07 00:04:01 -0700128{
Jon Seymource118952005-07-06 20:11:24 +1000129 _description=$1
Junio C Hamano50e5a252013-06-21 10:12:48 -0700130 _test=$2
131 test $# -eq 2 ||
132 error "usage: test_output_expect_success description test <<EOF ... EOF"
133
134 _name=$(echo $_description | name_from_description)
135 cat >"$_name.expected"
Junio C Hamanoa6080a02007-06-07 00:04:01 -0700136 test_expect_success "$_description" "check_output $_name \"$_test\""
Jon Seymource118952005-07-06 20:11:24 +1000137}