]>
Commit | Line | Data |
---|---|---|
ce11895d JS |
1 | [ -d .git/refs/tags ] || mkdir -p .git/refs/tags |
2 | ||
28346d2d | 3 | :> sed.script |
ce11895d JS |
4 | |
5 | # Answer the sha1 has associated with the tag. The tag must exist in .git or .git/refs/tags | |
6 | tag() | |
7 | { | |
8 | _tag=$1 | |
9 | [ -f .git/refs/tags/$_tag ] || error "tag: \"$_tag\" does not exist" | |
10 | cat .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. | |
15 | unique_commit() | |
16 | { | |
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 | |
28346d2d | 24 | # a substitution script for the tag onto the front of sed.script |
ce11895d JS |
25 | save_tag() |
26 | { | |
27 | _tag=$1 | |
28 | [ -n "$_tag" ] || error "usage: save_tag tag commit-args ..." | |
29 | shift 1 | |
30 | "$@" >.git/refs/tags/$_tag | |
f6069c59 | 31 | |
28346d2d JS |
32 | echo "s/$(tag $_tag)/$_tag/g" > sed.script.tmp |
33 | cat sed.script >> sed.script.tmp | |
34 | rm sed.script | |
35 | mv sed.script.tmp sed.script | |
ce11895d JS |
36 | } |
37 | ||
38 | # Replace unhelpful sha1 hashses with their symbolic equivalents | |
39 | entag() | |
40 | { | |
28346d2d | 41 | sed -f sed.script |
ce11895d JS |
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. | |
46 | as_author() | |
47 | { | |
48 | _author=$1 | |
49 | shift 1 | |
50 | _save=$GIT_AUTHOR_EMAIL | |
51 | ||
52 | export GIT_AUTHOR_EMAIL="$_author" | |
53 | "$@" | |
54 | export GIT_AUTHOR_EMAIL="$_save" | |
55 | } | |
56 | ||
57 | commit_date() | |
58 | { | |
59 | _commit=$1 | |
60 | git-cat-file commit $_commit | sed -n "s/^committer .*> \([0-9]*\) .*/\1/p" | |
61 | } | |
62 | ||
63 | on_committer_date() | |
64 | { | |
65 | _date=$1 | |
66 | shift 1 | |
67 | GIT_COMMITTER_DATE=$_date "$@" | |
68 | } | |
69 | ||
70 | # Execute a command and suppress any error output. | |
71 | hide_error() | |
72 | { | |
73 | "$@" 2>/dev/null | |
74 | } | |
75 | ||
76 | check_output() | |
77 | { | |
78 | _name=$1 | |
79 | shift 1 | |
80 | if eval "$*" | entag > $_name.actual | |
81 | then | |
82 | diff $_name.expected $_name.actual | |
83 | else | |
84 | return 1; | |
85 | fi | |
86 | } | |
87 | ||
88 | # Turn a reasonable test description into a reasonable test name. | |
89 | # All alphanums translated into -'s which are then compressed and stripped | |
90 | # from front and back. | |
91 | name_from_description() | |
92 | { | |
93 | tr "'" '-' | tr '~`!@#$%^&*()_+={}[]|\;:"<>,/? ' '-' | tr -s '-' | tr '[A-Z]' '[a-z]' | sed "s/^-*//;s/-*\$//" | |
94 | } | |
95 | ||
96 | ||
97 | # Execute the test described by the first argument, by eval'ing | |
98 | # command line specified in the 2nd argument. Check the status code | |
99 | # is zero and that the output matches the stream read from | |
100 | # stdin. | |
101 | test_output_expect_success() | |
102 | { | |
103 | _description=$1 | |
104 | _test=$2 | |
105 | [ $# -eq 2 ] || error "usage: test_output_expect_success description test <<EOF ... EOF" | |
106 | _name=$(echo $_description | name_from_description) | |
107 | cat > $_name.expected | |
108 | test_expect_success "$_description" "check_output $_name \"$_test\"" | |
109 | } |