tests/t0001-validate-git-versions.sh (view raw)
1#!/bin/sh
2
3if [ "${CGIT_TEST_NO_GIT_VERSION}" = "YesPlease" ]; then
4 exit 0
5fi
6
7test_description='Check Git version is correct'
8CGIT_TEST_NO_CREATE_REPOS=YesPlease
9. ./setup.sh
10
11test_expect_success 'extract Git version from Makefile' '
12 sed -n -e "/^GIT_VER[ ]*=/ {
13 s/^GIT_VER[ ]*=[ ]*//
14 p
15 }" ../../Makefile >makefile_version
16'
17
18# Note that Git's GIT-VERSION-GEN script applies "s/-/./g" to the version
19# string to produce the internal version in the GIT-VERSION-FILE, so we
20# must apply the same transformation to the version in the Makefile before
21# comparing them.
22test_expect_success 'test Git version matches Makefile' '
23 ( cat ../../git/GIT-VERSION-FILE || echo "No GIT-VERSION-FILE" ) |
24 sed -e "s/GIT_VERSION[ ]*=[ ]*//" -e "s/\\.dirty$//" >git_version &&
25 sed -e "s/-/./g" makefile_version >makefile_git_version &&
26 test_cmp git_version makefile_git_version
27'
28
29test_expect_success 'test submodule version matches Makefile' '
30 if ! test -e ../../git/.git
31 then
32 echo "git/ is not a Git repository" >&2
33 else
34 (
35 cd ../.. &&
36 sm_oid=$(git ls-files --stage -- git |
37 sed -e "s/^[0-9]* \\([0-9a-f]*\\) [0-9] .*$/\\1/") &&
38 cd git &&
39 git describe --match "v[0-9]*" $sm_oid
40 ) | sed -e "s/^v//" -e "s/-/./" >sm_version &&
41 test_cmp sm_version makefile_version
42 fi
43'
44
45test_done