Bug #476

git version check in configure / is broken for non-GNU test

Added by Christoph Junghans about 10 years ago. Updated about 10 years ago.

Target version:
Affected version - extra info:
Affected version:


+ test git version < git version 1.5.3
./genversion.sh16: <: 0403-012 A test command parameter is not valid.

I do not know a easy way to fix that, maybe

git --version | sed -e 's/[^0-9]//g' -e 's/^...$/&0/'

The problem is mainly that some version are 1.X.X and some are 1.X.X.X


#1 Updated by Teemu Murtola about 10 years ago

The proposed fix is really obscure. :) Even if it may work for now, it can easily break at some point... It seems that test a < b is not POSIX-compatible, although it works on GNU and BSD implementations, so some kind of a workaround would be necessary. A similar test is used in to test whether the git version is 1.5.1 or greater, and that should be fixed as well. To enable compilation on systems that do not support that test, we could change the test around such that is not run if that test does not work, but that is only a temporary workaround.

A proper fix for would be to test whether "git rev-list --pretty=format:%ci" works or not (or "git rev-list --pretty=format:%cd --date=short") , and something like that should be easy to implement if one has access to older git versions to see how they actually behave if invoked with those flags. The test in could probably also be changed to test for the actual features used... I think the main reason for the test in is that we just haven't tested the scripts with older versions, so it might be completely unnecessary. We might also do all the tests in if that is easier, and then just pass the result into the script.

I don't have an easy access to older git versions, so I can't fix it quickly, but I can try to take a look at this after my holidays if no one else has time.

#2 Updated by Christoph Junghans about 10 years ago

I think the solution is to test the git command used.
You never know maybe it will fail with newer version of git again ;-)

#3 Updated by Teemu Murtola about 10 years ago

The main problem with testing the git command is that one has to check what really happens with older versions of git (preferably several...), and that takes some effort if/when one has to compile those: for example, the problematic command with pre-1.5.3 git is
git rev-list -n1 --pretty=format:%ci
If I remember correctly, the command actually does not fail on older git, it just prints %ci instead of a date...

#4 Updated by Erik Lindahl about 10 years ago

Hi Christoph,

To look into this I think we need access to an example of a test command that actually fails - my mac (BSD?) version seems to pass the test.

The bug report has 'Linux' as the OS; which Linux versions use a non-GNU test?



#5 Updated by Erik Lindahl about 10 years ago

PS Teemu: I would prefer to test the actual command, and think it works if we do something like

if ~/git-1.5/bin/git rev-list -n1 --pretty=format:%cd HEAD | grep '[0-9]\{4\}'  > /dev/null 2>&1; then echo "Good version" ; fi

...but the problem is that this only works if it is executed in a git repository, and I have no idea what will happen with normal out-of-tree builds.

For now I think the easiest option is to hack the version test, but we need to be a bit careful with things like -rc3 suffixes.

#6 Updated by Teemu Murtola about 10 years ago

I also think that the best solution is to test the actual command and get rid of the version tests altogether, and if you now anyway have a git compiled that doesn't support these, this shouldn't be too hard. The command you pasted probably does the trick (with --git-dir added, see below). In that case, we need to change both and the scripts. configure should check that --pretty=format:%cd works, and whether --pretty=format:%ci works.

For out-of-tree builds, it is possible to provide the repository location with --git-dir=$srcdir/.git. If there's something wrong with the repository, git will exit with a non-zero error code in configure, which should result in never calling the script.

#7 Updated by Erik Lindahl about 10 years ago

Fixed in commit commit 491695653409d057aeda9ddf157bed30dadc3f31. We not test for git features.

#8 Updated by Erik Lindahl about 10 years ago

Forgot to change status.

#9 Updated by Christoph Junghans about 10 years ago

Just for the records, it is IBM's version of test coming with AIX 5.3 and AIX 6.1

$/bin/test 'git version' \> 'git version 1.5.3'; echo $?
test: 0402-154 An operator is missing or is not valid.

Btw the bash/sh/ksh93 internal test works:
$test 'git version' \> 'git version 1.5.3'; echo $?

I am not sure why configure is using /bin/test and not the shell build-in.

Also available in: Atom PDF