Merge branch 'master' into jc/combine
[git/jnareb-git.git] / t / t6000lib.sh
blobc6752af48e04993e3ed3efebf288ffa86d02633a
1 [ -d .git/refs/tags ] || mkdir -p .git/refs/tags
3 :> sed.script
5 # Answer the sha1 has associated with the tag. The tag must exist in .git or .git/refs/tags
6 tag()
8 _tag=$1
9 [ -f .git/refs/tags/$_tag ] || error "tag: \"$_tag\" does not exist"
10 cat .git/refs/tags/$_tag
13 # Generate a commit using the text specified to make it unique and the tree
14 # named by the tag specified.
15 unique_commit()
17 _text=$1
18 _tree=$2
19 shift 2
20 echo $_text | git-commit-tree $(tag $_tree) "$@"
23 # Save the output of a command into the tag specified. Prepend
24 # a substitution script for the tag onto the front of sed.script
25 save_tag()
27 _tag=$1
28 [ -n "$_tag" ] || error "usage: save_tag tag commit-args ..."
29 shift 1
30 "$@" >.git/refs/tags/$_tag
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
38 # Replace unhelpful sha1 hashses with their symbolic equivalents
39 entag()
41 sed -f sed.script
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()
48 _author=$1
49 shift 1
50 _save=$GIT_AUTHOR_EMAIL
52 export GIT_AUTHOR_EMAIL="$_author"
53 "$@"
54 if test -z "$_save"
55 then
56 unset GIT_AUTHOR_EMAIL
57 else
58 export GIT_AUTHOR_EMAIL="$_save"
62 commit_date()
64 _commit=$1
65 git-cat-file commit $_commit | sed -n "s/^committer .*> \([0-9]*\) .*/\1/p"
68 on_committer_date()
70 _date=$1
71 shift 1
72 GIT_COMMITTER_DATE=$_date "$@"
75 # Execute a command and suppress any error output.
76 hide_error()
78 "$@" 2>/dev/null
81 check_output()
83 _name=$1
84 shift 1
85 if eval "$*" | entag > $_name.actual
86 then
87 diff $_name.expected $_name.actual
88 else
89 return 1;
93 # Turn a reasonable test description into a reasonable test name.
94 # All alphanums translated into -'s which are then compressed and stripped
95 # from front and back.
96 name_from_description()
98 tr "'" '-' | tr '~`!@#$%^&*()_+={}[]|\;:"<>,/? ' '-' | tr -s '-' | tr '[A-Z]' '[a-z]' | sed "s/^-*//;s/-*\$//"
102 # Execute the test described by the first argument, by eval'ing
103 # command line specified in the 2nd argument. Check the status code
104 # is zero and that the output matches the stream read from
105 # stdin.
106 test_output_expect_success()
108 _description=$1
109 _test=$2
110 [ $# -eq 2 ] || error "usage: test_output_expect_success description test <<EOF ... EOF"
111 _name=$(echo $_description | name_from_description)
112 cat > $_name.expected
113 test_expect_success "$_description" "check_output $_name \"$_test\""