1 # Create commits in <repo> and assign each commit's oid to shell variables
2 # given in the arguments (A, B, and C). E.g.:
4 # create_commits_in <repo> A B C
6 # NOTE: Never calling this function from a subshell since variable
7 # assignments will disappear when subshell exits.
9 repo="$1" && test -d "$repo" ||
10 error "Repository $repo does not exist."
16 test_commit -C "$repo" --no-tag "$name" &&
17 eval $name=$(git -C "$repo" rev-parse HEAD)
21 # Format the output of git-push, git-show-ref and other commands to make a
22 # user-friendly and stable text. We can easily prepare the expect text
23 # without having to worry about changes of the commit ID (full or abbrev.)
24 # of the output. Single quotes are replaced with double quotes, because
25 # it is boring to prepare unquoted single quotes in expect text. We also
26 # remove some locale error messages. The emitted human-readable errors are
27 # redundant to the more machine-readable output the tests already assert.
28 make_user_friendly_and_stable_output () {
31 -e "s/$A/<COMMIT-A>/g" \
32 -e "s/$B/<COMMIT-B>/g" \
33 -e "s/$TAG/<TAG-v123>/g" \
34 -e "s/$ZERO_OID/<ZERO-OID>/g" \
35 -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
36 -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \
37 -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
41 filter_out_user_friendly_and_stable_output () {
42 make_user_friendly_and_stable_output |
46 format_and_save_expect () {
47 sed -e 's/^> //' -e 's/Z$//' >expect
58 indir=${indir:+"$indir"/}
59 cat >show-ref.expect &&
60 git ${indir:+ -C "$indir"} show-ref >show-ref.pristine &&
61 make_user_friendly_and_stable_output <show-ref.pristine >show-ref.filtered &&
62 test_cmp show-ref.expect show-ref.filtered