1# Interoperability testing framework. Each script should source
2# this after setting default $VERSION_A and $VERSION_B variables.
3
4. ../../GIT-BUILD-OPTIONS
5INTEROP_ROOT=$(pwd)
6BUILD_ROOT=$INTEROP_ROOT/build
7
8build_version () {
9 if test -z "$1"
10 then
11 echo >&2 "error: test script did not set default versions"
12 return 1
13 fi
14
15 if test "$1" = "."
16 then
17 git rev-parse --show-toplevel
18 return 0
19 fi
20
21 sha1=$(git rev-parse "$1^{tree}") || return 1
22 dir=$BUILD_ROOT/$sha1
23
24 if test -e "$dir/.built"
25 then
26 echo "$dir"
27 return 0
28 fi
29
30 echo >&2 "==> Building $1..."
31
32 mkdir -p "$dir" || return 1
33
34 (cd "$(git rev-parse --show-cdup)" && git archive --format=tar "$sha1") |
35 (cd "$dir" && tar x) ||
36 return 1
37
38 for config in config.mak config.mak.autogen config.status
39 do
40 if test -e "$INTEROP_ROOT/../../$config"
41 then
42 cp "$INTEROP_ROOT/../../$config" "$dir/" || return 1
43 fi
44 done
45
46 (
47 cd "$dir" &&
48 make $GIT_INTEROP_MAKE_OPTS >&2 &&
49 touch .built
50 ) || return 1
51
52 echo "$dir"
53}
54
55# Old versions of git don't have bin-wrappers, so let's give a rough emulation.
56wrap_git () {
57 write_script "$1" <<-EOF
58 GIT_EXEC_PATH="$2"
59 export GIT_EXEC_PATH
60 PATH="$2:\$PATH"
61 export GIT_EXEC_PATH
62 exec git "\$@"
63 EOF
64}
65
66generate_wrappers () {
67 mkdir -p .bin &&
68 wrap_git .bin/git.a "$DIR_A" &&
69 wrap_git .bin/git.b "$DIR_B" &&
70 write_script .bin/git <<-\EOF &&
71 echo >&2 fatal: test tried to run generic git
72 exit 1
73 EOF
74 PATH=$(pwd)/.bin:$PATH
75}
76
77VERSION_A=${GIT_TEST_VERSION_A:-$VERSION_A}
78VERSION_B=${GIT_TEST_VERSION_B:-$VERSION_B}
79
80if ! DIR_A=$(build_version "$VERSION_A") ||
81 ! DIR_B=$(build_version "$VERSION_B")
82then
83 echo >&2 "fatal: unable to build git versions"
84 exit 1
85fi
86
87TEST_DIRECTORY=$INTEROP_ROOT/..
88TEST_OUTPUT_DIRECTORY=$INTEROP_ROOT
89TEST_NO_CREATE_REPO=t
90. "$TEST_DIRECTORY"/test-lib.sh
91
92generate_wrappers || die "unable to set up interop test environment"