#!/bin/sh # Checks that the Git version cgit says it is built for is the one it is # built against, so the Makefile, vendor/git and the submodule pin must name # the same version. Set CGIT_TEST_NO_GIT_VERSION to YesPlease when Git comes # from elsewhere. test_description='Check Git version is correct' CGIT_TEST_NO_CREATE_REPOS=YesPlease . ./setup.sh if test "$CGIT_TEST_NO_GIT_VERSION" = "YesPlease" then skip_all='Skipping the Git version checks: CGIT_TEST_NO_GIT_VERSION is set' test_done fi test_expect_success 'extract Git version from Makefile' ' sed -n -e "/^GIT_VERSION[[:space:]]*=/ { s/^GIT_VERSION[[:space:]]*=[[:space:]]*// p }" "$TEST_OUTPUT_DIRECTORY/../Makefile" >makefile_version && test -s 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 "$TEST_OUTPUT_DIRECTORY/../vendor/git/GIT-VERSION-FILE" || echo "No GIT-VERSION-FILE" ) | sed -e "s/GIT_VERSION[[:space:]]*=[[:space:]]*//" -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 history to describe the submodule pin # with, so the check is skipped there rather than passed. test_lazy_prereq SUBMODULE 'test -e "$TEST_OUTPUT_DIRECTORY/../vendor/git/.git"' test_expect_success SUBMODULE 'test submodule version matches Makefile' ' git -C "$TEST_OUTPUT_DIRECTORY/.." ls-files --stage -- vendor/git >gitlink && submodule_oid=$(sed -n "s/^160000 \\([0-9a-f]*\\) .*/\\1/p" gitlink) && test -n "$submodule_oid" && git -C "$TEST_OUTPUT_DIRECTORY/../vendor/git" \ describe --match "v[0-9]*" "$submodule_oid" >submodule_tag && sed -e "s/^v//" -e "s/-/./" submodule_tag >submodule_version && test_cmp makefile_version submodule_version ' test_done