]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6000lib.sh
git-commit.txt: Add missing long/short options
[thirdparty/git.git] / t / t6000lib.sh
CommitLineData
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
6tag()
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.
15unique_commit()
16{
17 _text=$1
18 _tree=$2
19 shift 2
5be60078 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
ce11895d
JS
25save_tag()
26{
a6080a0a 27 _tag=$1
ce11895d
JS
28 [ -n "$_tag" ] || error "usage: save_tag tag commit-args ..."
29 shift 1
a6080a0a 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
a6080a0a 38# Replace unhelpful sha1 hashses with their symbolic equivalents
ce11895d
JS
39entag()
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.
46as_author()
47{
48 _author=$1
49 shift 1
50 _save=$GIT_AUTHOR_EMAIL
51
0e46e704
BD
52 GIT_AUTHOR_EMAIL="$_author"
53 export GIT_AUTHOR_EMAIL
ce11895d 54 "$@"
47e013f9
JH
55 if test -z "$_save"
56 then
57 unset GIT_AUTHOR_EMAIL
58 else
0e46e704
BD
59 GIT_AUTHOR_EMAIL="$_save"
60 export GIT_AUTHOR_EMAIL
47e013f9 61 fi
ce11895d
JS
62}
63
64commit_date()
65{
66 _commit=$1
5be60078 67 git cat-file commit $_commit | sed -n "s/^committer .*> \([0-9]*\) .*/\1/p"
ce11895d
JS
68}
69
70on_committer_date()
71{
72 _date=$1
73 shift 1
0e46e704
BD
74 GIT_COMMITTER_DATE="$_date"
75 export GIT_COMMITTER_DATE
933e4f09
EW
76 "$@"
77 unset GIT_COMMITTER_DATE
ce11895d
JS
78}
79
80# Execute a command and suppress any error output.
81hide_error()
82{
83 "$@" 2>/dev/null
84}
85
86check_output()
87{
88 _name=$1
89 shift 1
90 if eval "$*" | entag > $_name.actual
91 then
92 diff $_name.expected $_name.actual
93 else
94 return 1;
95 fi
96}
97
98# Turn a reasonable test description into a reasonable test name.
99# All alphanums translated into -'s which are then compressed and stripped
100# from front and back.
101name_from_description()
102{
aab0abf7
JK
103 perl -pe '
104 s/[^A-Za-z0-9.]/-/g;
105 s/-+/-/g;
106 s/-$//;
107 s/^-//;
108 y/A-Z/a-z/;
109 '
ce11895d
JS
110}
111
112
113# Execute the test described by the first argument, by eval'ing
114# command line specified in the 2nd argument. Check the status code
a6080a0a 115# is zero and that the output matches the stream read from
ce11895d
JS
116# stdin.
117test_output_expect_success()
a6080a0a 118{
ce11895d
JS
119 _description=$1
120 _test=$2
121 [ $# -eq 2 ] || error "usage: test_output_expect_success description test <<EOF ... EOF"
122 _name=$(echo $_description | name_from_description)
123 cat > $_name.expected
a6080a0a 124 test_expect_success "$_description" "check_output $_name \"$_test\""
ce11895d 125}