diff options
context:
space:
mode:
Diffstat (limited to 'tests/t0001-git-version.sh')
-rwxr-xr-xtests/t0001-git-version.sh53
1 file changed, 53 insertions, 0 deletions
diff --git a/tests/t0001-git-version.sh b/tests/t0001-git-version.sh
new file mode 100755
index 0000000..2117764
--- /dev/null
+++ b/tests/t0001-git-version.sh
@@ -0,0 +1,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