| 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.: |
| 3 | # |
| 4 | # create_commits_in <repo> A B C |
| 5 | # |
| 6 | # NOTE: Never calling this function from a subshell since variable |
| 7 | # assignments will disappear when subshell exits. |
| 8 | create_commits_in () { |
| 9 | repo="$1" && test -d "$repo" || |
| 10 | error "Repository $repo does not exist." |
| 11 | shift && |
| 12 | while test $# -gt 0 |
| 13 | do |
| 14 | name=$1 && |
| 15 | shift && |
| 16 | test_commit -C "$repo" --no-tag "$name" && |
| 17 | eval $name=$(git -C "$repo" rev-parse HEAD) |
| 18 | done |
| 19 | } |
| 20 | |
| 21 | get_abbrev_oid () { |
| 22 | oid=$1 && |
| 23 | suffix=${oid#???????} && |
| 24 | oid=${oid%$suffix} && |
| 25 | if test -n "$oid" |
| 26 | then |
| 27 | echo "$oid" |
| 28 | else |
| 29 | echo "undefined-oid" |
| 30 | fi |
| 31 | } |
| 32 | |
| 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 () { |
| 41 | sed \ |
| 42 | -e "s/'/\"/g" \ |
| 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>#" \ |
| 48 | -e "/^error: / d" |
| 49 | } |
| 50 | |
| 51 | filter_out_user_friendly_and_stable_output () { |
| 52 | make_user_friendly_and_stable_output | |
| 53 | sed -n ${1+"$@"} |
| 54 | } |
| 55 | |
| 56 | format_and_save_expect () { |
| 57 | sed -e 's/^> //' -e 's/Z$//' >expect |
| 58 | } |
| 59 | |
| 60 | test_cmp_refs () { |
| 61 | indir= |
| 62 | if test "$1" = "-C" |
| 63 | then |
| 64 | shift |
| 65 | indir="$1" |
| 66 | shift |
| 67 | fi |
| 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 |
| 73 | } |