]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5411/common-functions.sh
Merge branch 'jx/t5411-flake-fix'
[thirdparty/git.git] / t / t5411 / common-functions.sh
CommitLineData
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.
8create_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
39# remove some locale error messages, which break test if we turn on
40# `GIT_TEST_GETTEXT_POISON=true` in order to test unintentional translations
41# on plumbing commands.
42make_user_friendly_and_stable_output () {
43 sed \
44 -e "s/ *\$//" \
cf3d868f 45 -e "s/ */ /g" \
38b9197a
JX
46 -e "s/'/\"/g" \
47 -e "s/ / /g" \
48 -e "s/$A/<COMMIT-A>/g" \
49 -e "s/$B/<COMMIT-B>/g" \
50 -e "s/$TAG/<TAG-v123>/g" \
51 -e "s/$ZERO_OID/<ZERO-OID>/g" \
52 -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
53 -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \
54 -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
55 -e "/^error: / d"
56}
cf3d868f
JX
57
58filter_out_user_friendly_and_stable_output () {
59 make_user_friendly_and_stable_output |
60 sed -n ${1+"$@"}
61}