]>
Commit | Line | Data |
---|---|---|
38b9197a JX |
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" && | |
10 | if ! parent=$(git -C "$repo" rev-parse HEAD^{} --) | |
11 | then | |
12 | parent= | |
13 | fi && | |
14 | T=$(git -C "$repo" write-tree) && | |
15 | shift && | |
16 | while test $# -gt 0 | |
17 | do | |
18 | name=$1 && | |
19 | test_tick && | |
20 | if test -z "$parent" | |
21 | then | |
22 | oid=$(echo $name | git -C "$repo" commit-tree $T) | |
23 | else | |
24 | oid=$(echo $name | git -C "$repo" commit-tree -p $parent $T) | |
25 | fi && | |
26 | eval $name=$oid && | |
27 | parent=$oid && | |
28 | shift || | |
29 | return 1 | |
30 | done && | |
a9568dba | 31 | git -C "$repo" update-ref refs/heads/main $oid |
38b9197a JX |
32 | } |
33 | ||
34 | # Format the output of git-push, git-show-ref and other commands to make a | |
35 | # user-friendly and stable text. We can easily prepare the expect text | |
36 | # without having to worry about future changes of the commit ID and spaces | |
37 | # of the output. Single quotes are replaced with double quotes, because | |
38 | # it is boring to prepare unquoted single quotes in expect text. We also | |
73c01d25 ÆAB |
39 | # remove some locale error messages. The emitted human-readable errors are |
40 | # redundant to the more machine-readable output the tests already assert. | |
38b9197a JX |
41 | make_user_friendly_and_stable_output () { |
42 | sed \ | |
43 | -e "s/ *\$//" \ | |
cf3d868f | 44 | -e "s/ */ /g" \ |
38b9197a JX |
45 | -e "s/'/\"/g" \ |
46 | -e "s/ / /g" \ | |
47 | -e "s/$A/<COMMIT-A>/g" \ | |
48 | -e "s/$B/<COMMIT-B>/g" \ | |
49 | -e "s/$TAG/<TAG-v123>/g" \ | |
50 | -e "s/$ZERO_OID/<ZERO-OID>/g" \ | |
51 | -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \ | |
52 | -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \ | |
53 | -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \ | |
54 | -e "/^error: / d" | |
55 | } | |
cf3d868f JX |
56 | |
57 | filter_out_user_friendly_and_stable_output () { | |
58 | make_user_friendly_and_stable_output | | |
59 | sed -n ${1+"$@"} | |
60 | } |