interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / lib-t6000.sh

135 lines · 3028 bytes Raw Blame History
1: included from 6002 and others
2
3>sed.script
4
5# Answer the sha1 has associated with the tag. The tag must exist under refs/tags
6tag () {
7 _tag=$1
8 git rev-parse --verify "refs/tags/$_tag" ||
9 error "tag: \"$_tag\" does not exist"
10}
11
12# Generate a commit using the text specified to make it unique and the tree
13# named by the tag specified.
14unique_commit () {
15 _text=$1
16 _tree=$2
17 shift 2
18 echo "$_text" | git commit-tree $(tag "$_tree") "$@"
19}
20
21# Save the output of a command into the tag specified. Prepend
22# a substitution script for the tag onto the front of sed.script
23save_tag () {
24 _tag=$1
25 test -n "$_tag" || error "usage: save_tag tag commit-args ..."
26 shift 1
27
28 git update-ref "refs/tags/$_tag" $("$@")
29
30 echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp
31 cat sed.script >>sed.script.tmp
32 rm sed.script
33 mv sed.script.tmp sed.script
34}
35
36# Replace unhelpful sha1 hashes with their symbolic equivalents
37entag () {
38 sed -f sed.script
39}
40
41# Execute a command after first saving, then setting the GIT_AUTHOR_EMAIL
42# tag to a specified value. Restore the original value on return.
43as_author () {
44 _author=$1
45 shift 1
46 _save=$GIT_AUTHOR_EMAIL
47
48 GIT_AUTHOR_EMAIL="$_author"
49 export GIT_AUTHOR_EMAIL
50 "$@"
51 if test -z "$_save"
52 then
53 unset GIT_AUTHOR_EMAIL
54 else
55 GIT_AUTHOR_EMAIL="$_save"
56 export GIT_AUTHOR_EMAIL
57 fi
58}
59
60commit_date () {
61 _commit=$1
62 git cat-file commit $_commit |
63 sed -n "s/^committer .*> \([0-9]*\) .*/\1/p"
64}
65
66# Assign the value of fake date to a variable, but
67# allow fairly common "1971-08-16 00:00" to be omittd
68assign_fake_date () {
69 case "$2" in
70 ??:??:??) eval "$1='1971-08-16 $2'" ;;
71 ??:??) eval "$1='1971-08-16 00:$2'" ;;
72 ??) eval "$1='1971-08-16 00:00:$2'" ;;
73 *) eval "$1='$2'" ;;
74 esac
75}
76
77on_committer_date () {
78 assign_fake_date GIT_COMMITTER_DATE "$1"
79 export GIT_COMMITTER_DATE
80 shift 1
81 "$@"
82}
83
84on_dates () {
85 assign_fake_date GIT_COMMITTER_DATE "$1"
86 assign_fake_date GIT_AUTHOR_DATE "$2"
87 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
88 shift 2
89 "$@"
90}
91
92# Execute a command and suppress any error output.
93hide_error () {
94 "$@" 2>/dev/null
95}
96
97check_output () {
98 _name=$1
99 shift 1
100 if eval "$*" | entag >"$_name.actual"
101 then
102 test_cmp "$_name.expected" "$_name.actual"
103 else
104 return 1
105 fi
106}
107
108# Turn a reasonable test description into a reasonable test name.
109# All alphanums translated into -'s which are then compressed and stripped
110# from front and back.
111name_from_description () {
112 sed \
113 -e 's/[^A-Za-z0-9.]/-/g' \
114 -e 's/--*/-/g' \
115 -e 's/-$//' \
116 -e 's/^-//' \
117 -e 'y/A-Z/a-z/'
118}
119
120
121# Execute the test described by the first argument, by eval'ing
122# command line specified in the 2nd argument. Check the status code
123# is zero and that the output matches the stream read from
124# stdin.
125test_output_expect_success()
126{
127 _description=$1
128 _test=$2
129 test $# -eq 2 ||
130 error "usage: test_output_expect_success description test <<EOF ... EOF"
131
132 _name=$(echo $_description | name_from_description)
133 cat >"$_name.expected"
134 test_expect_success "$_description" "check_output $_name \"$_test\""
135}