#!/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. if test "$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[[:space:]]*=/ { s/^GIT_VERSION[[:space:]]*=[[:space:]]*// p }" "$TEST_OUTPUT_DIRECTORY/../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 "$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 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 "$TEST_OUTPUT_DIRECTORY/../vendor/git/.git" then echo "vendor/git/ is not a Git repository" >&2 else ( cd "$TEST_OUTPUT_DIRECTORY/.." && submodule_oid=$(git ls-files --stage -- vendor/git | sed -e "s/^[0-9]* \\([0-9a-f]*\\) [0-9][[:space:]].*$/\\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