blob: 2117764cb13dfbc45c055c3876190e55ea889514 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh

# Checks that the Git version cgit says it is built for is the one it is
# actually built against. The top-level Makefile names a version, the tree
# under vendor/git records its own, and the submodule is pinned to a tag, so
# all three have to agree or cgit is being built on something other than what
# it claims. Set CGIT_TEST_NO_GIT_VERSION to YesPlease when Git comes from
# elsewhere and the comparison has nothing to say.

if [ "${CGIT_TEST_NO_GIT_VERSION}" = "YesPlease" ]; then
	exit 0
fi

test_description='Check Git version is correct'
CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh

test_expect_success 'extract Git version from Makefile' '
	sed -n -e "/^GIT_VERSION[ 	]*=/ {
		s/^GIT_VERSION[ 	]*=[ 	]*//
		p
	}" ../../Makefile >makefile_version
'

# Git's GIT-VERSION-GEN script applies "s/-/./g" to the version string on its
# way into the GIT-VERSION-FILE, so the same has to be done to the version in
# the Makefile before the two can be compared.
test_expect_success 'test Git version matches Makefile' '
	( cat ../../vendor/git/GIT-VERSION-FILE || echo "No GIT-VERSION-FILE" ) |
	sed -e "s/GIT_VERSION[ 	]*=[ 	]*//" -e "s/\\.dirty$//" >git_version &&
	sed -e "s/-/./g" makefile_version >makefile_git_version &&
	test_cmp git_version makefile_git_version
'

# A tree unpacked from a tarball has no submodule pin to describe, so there is
# nothing to compare against and the test says so rather than failing.
test_expect_success 'test submodule version matches Makefile' '
	if ! test -e ../../vendor/git/.git
	then
		echo "vendor/git/ is not a Git repository" >&2
	else
		(
			cd ../.. &&
			submodule_oid=$(git ls-files --stage -- vendor/git |
				sed -e "s/^[0-9]* \\([0-9a-f]*\\) [0-9]	.*$/\\1/") &&
			cd vendor/git &&
			git describe --match "v[0-9]*" $submodule_oid
		) | sed -e "s/^v//" -e "s/-/./" >submodule_version &&
		test_cmp submodule_version makefile_version
	fi
'

test_done