]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5411/common-functions.sh
Merge branch 'jx/remote-archive-over-smart-http'
[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 () {
3c06a583
JX
9 repo="$1" && test -d "$repo" ||
10 error "Repository $repo does not exist."
38b9197a
JX
11 shift &&
12 while test $# -gt 0
13 do
14 name=$1 &&
3c06a583
JX
15 shift &&
16 test_commit -C "$repo" --no-tag "$name" &&
17 eval $name=$(git -C "$repo" rev-parse HEAD)
18 done
38b9197a
JX
19}
20
12d6991c
JX
21get_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
38b9197a
JX
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
2bafb3d7 35# without having to worry about changes of the commit ID (full or abbrev.)
38b9197a
JX
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
73c01d25
ÆAB
38# remove some locale error messages. The emitted human-readable errors are
39# redundant to the more machine-readable output the tests already assert.
38b9197a
JX
40make_user_friendly_and_stable_output () {
41 sed \
38b9197a 42 -e "s/'/\"/g" \
12d6991c
JX
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" \
38b9197a 46 -e "s/$ZERO_OID/<ZERO-OID>/g" \
38b9197a
JX
47 -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
48 -e "/^error: / d"
49}
cf3d868f
JX
50
51filter_out_user_friendly_and_stable_output () {
52 make_user_friendly_and_stable_output |
53 sed -n ${1+"$@"}
54}
822ee894 55
2bafb3d7
JX
56format_and_save_expect () {
57 sed -e 's/^> //' -e 's/Z$//' >expect
58}
59
822ee894
JX
60test_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}