]>
Commit | Line | Data |
---|---|---|
b9b727dd JH |
1 | : included from 6002 and others |
2 | ||
50e5a252 | 3 | mkdir -p .git/refs/tags |
ce11895d | 4 | |
50e5a252 | 5 | >sed.script |
ce11895d | 6 | |
cbc5cf7c | 7 | # Answer the sha1 has associated with the tag. The tag must exist under refs/tags |
50e5a252 | 8 | tag () { |
ce11895d | 9 | _tag=$1 |
cbc5cf7c DT |
10 | git rev-parse --verify "refs/tags/$_tag" || |
11 | error "tag: \"$_tag\" does not exist" | |
ce11895d JS |
12 | } |
13 | ||
14 | # Generate a commit using the text specified to make it unique and the tree | |
15 | # named by the tag specified. | |
50e5a252 | 16 | unique_commit () { |
ce11895d | 17 | _text=$1 |
50e5a252 | 18 | _tree=$2 |
ce11895d | 19 | shift 2 |
50e5a252 | 20 | echo "$_text" | git commit-tree $(tag "$_tree") "$@" |
ce11895d JS |
21 | } |
22 | ||
23 | # Save the output of a command into the tag specified. Prepend | |
28346d2d | 24 | # a substitution script for the tag onto the front of sed.script |
50e5a252 | 25 | save_tag () { |
a6080a0a | 26 | _tag=$1 |
50e5a252 | 27 | test -n "$_tag" || error "usage: save_tag tag commit-args ..." |
ce11895d | 28 | shift 1 |
50e5a252 | 29 | "$@" >".git/refs/tags/$_tag" |
f6069c59 | 30 | |
50e5a252 JH |
31 | echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp |
32 | cat sed.script >>sed.script.tmp | |
28346d2d JS |
33 | rm sed.script |
34 | mv sed.script.tmp sed.script | |
ce11895d JS |
35 | } |
36 | ||
98e023de | 37 | # Replace unhelpful sha1 hashes with their symbolic equivalents |
50e5a252 | 38 | entag () { |
28346d2d | 39 | sed -f sed.script |
ce11895d JS |
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. | |
50e5a252 | 44 | as_author () { |
ce11895d JS |
45 | _author=$1 |
46 | shift 1 | |
50e5a252 | 47 | _save=$GIT_AUTHOR_EMAIL |
ce11895d | 48 | |
0e46e704 BD |
49 | GIT_AUTHOR_EMAIL="$_author" |
50 | export GIT_AUTHOR_EMAIL | |
ce11895d | 51 | "$@" |
47e013f9 JH |
52 | if test -z "$_save" |
53 | then | |
54 | unset GIT_AUTHOR_EMAIL | |
55 | else | |
0e46e704 BD |
56 | GIT_AUTHOR_EMAIL="$_save" |
57 | export GIT_AUTHOR_EMAIL | |
47e013f9 | 58 | fi |
ce11895d JS |
59 | } |
60 | ||
50e5a252 JH |
61 | commit_date () { |
62 | _commit=$1 | |
63 | git cat-file commit $_commit | | |
64 | sed -n "s/^committer .*> \([0-9]*\) .*/\1/p" | |
ce11895d JS |
65 | } |
66 | ||
841dc693 JH |
67 | # Assign the value of fake date to a variable, but |
68 | # allow fairly common "1971-08-16 00:00" to be omittd | |
69 | assign_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 | ||
50e5a252 | 78 | on_committer_date () { |
841dc693 | 79 | assign_fake_date GIT_COMMITTER_DATE "$1" |
50e5a252 | 80 | export GIT_COMMITTER_DATE |
841dc693 | 81 | shift 1 |
50e5a252 | 82 | "$@" |
11667316 JH |
83 | } |
84 | ||
85 | on_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 | "$@" | |
ce11895d JS |
91 | } |
92 | ||
93 | # Execute a command and suppress any error output. | |
50e5a252 | 94 | hide_error () { |
ce11895d JS |
95 | "$@" 2>/dev/null |
96 | } | |
97 | ||
50e5a252 | 98 | check_output () { |
ce11895d JS |
99 | _name=$1 |
100 | shift 1 | |
50e5a252 | 101 | if eval "$*" | entag >"$_name.actual" |
ce11895d | 102 | then |
50e5a252 | 103 | test_cmp "$_name.expected" "$_name.actual" |
ce11895d | 104 | else |
50e5a252 | 105 | return 1 |
ce11895d JS |
106 | 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. | |
50e5a252 | 112 | name_from_description () { |
aab0abf7 JK |
113 | perl -pe ' |
114 | s/[^A-Za-z0-9.]/-/g; | |
115 | s/-+/-/g; | |
116 | s/-$//; | |
117 | s/^-//; | |
118 | y/A-Z/a-z/; | |
119 | ' | |
ce11895d JS |
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 | |
a6080a0a | 125 | # is zero and that the output matches the stream read from |
ce11895d JS |
126 | # stdin. |
127 | test_output_expect_success() | |
a6080a0a | 128 | { |
ce11895d | 129 | _description=$1 |
50e5a252 JH |
130 | _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" | |
a6080a0a | 136 | test_expect_success "$_description" "check_output $_name \"$_test\"" |
ce11895d | 137 | } |