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)
23 suffix=${oid#???????} &&
33 # Format the output of git-push, git-show-ref and other commands to make a
34 # user-friendly and stable text. We can easily prepare the expect text
35 # without having to worry about changes of the commit ID (full or abbrev.)
36 # of the output. Single quotes are replaced with double quotes, because
37 # it is boring to prepare unquoted single quotes in expect text. We also
38 # remove some locale error messages. The emitted human-readable errors are
39 # redundant to the more machine-readable output the tests already assert.
40 make_user_friendly_and_stable_output () {
43 -e "s/$(get_abbrev_oid $A)[0-9a-f]*/<COMMIT-A>/g" \
44 -e "s/$(get_abbrev_oid $B)[0-9a-f]*/<COMMIT-B>/g" \
45 -e "s/$(get_abbrev_oid $TAG)[0-9a-f]*/<TAG-v123>/g" \
46 -e "s/$ZERO_OID/<ZERO-OID>/g" \
47 -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
51 filter_out_user_friendly_and_stable_output () {
52 make_user_friendly_and_stable_output |
56 format_and_save_expect () {
57 sed -e 's/^> //' -e 's/Z$//' >expect
68 indir=${indir:+"$indir"/}
69 cat >show-ref.expect &&
70 git ${indir:+ -C "$indir"} show-ref >show-ref.pristine &&
71 make_user_friendly_and_stable_output <show-ref.pristine >show-ref.filtered &&
72 test_cmp show-ref.expect show-ref.filtered