Jim Meyering wrote: > Mike Frysinger wrote: >> the current git-version-gen script and its usage in packages such as >> coreutils >> is causing me headaches wrt distros. it currently assumes one of two states: >> - the current tree is a valid git repo belonging to the related project >> - the current tree is not a git repo (all the way back to the root) >> >> the reports i'm getting are that some people like to maintain some of the >> higher directories in git (perhaps even /), and so when you unpack a >> coreutils >> release and attempt to compile/install it, this script is triggered since git >> will walk back from $PWD to / to find a .git dir. >> >> this results either in incorrect warnings (during install), or incorrect >> forcing of autotools to be regenerated (during maintainer/dist targets). >> >> further, some of the commands used in git-version-gen require write access to >> the .git repo (i.e. git update-index --refresh), which our package management >> tools flag as a violation (after all, building/installing packages in $PWD >> generally should not be updating files outside of $PWD). > > Thanks for the report. > > I've included a patch below that makes the script skip the -dirty > check (index-updating part) when appropriate. If that's not enough, > please demonstrate precisely what's going wrong.
Here's a complete patch: >From 4d90f397add9b98c536a1e75405badb923af9bcb Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyer...@redhat.com> Date: Sat, 19 Feb 2011 20:48:36 +0100 Subject: [PATCH] git-version-gen: skip "-dirty" check when appropriate * build-aux/git-version-gen: Don't run any git commands when the version comes from .tarball-version. Prior to this, we would run git update-index --refresh even from a just-unpacked tarball directory, and that could affect a .git/ directory in a parent of the build directory. Reported by Mike Frysinger. --- ChangeLog | 9 +++++++++ build-aux/git-version-gen | 31 +++++++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index d6fd3c6..0630db0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-02-19 Jim Meyering <meyer...@redhat.com> + + git-version-gen: skip "-dirty" check when appropriate + * build-aux/git-version-gen: Don't run any git commands + when the version comes from .tarball-version. Prior to this, + we would run git update-index --refresh even from a just-unpacked + tarball directory, and that could affect a .git/ directory in a + parent of the build directory. Reported by Mike Frysinger. + 2011-02-19 Bruno Haible <br...@clisp.org> unictype/property-byname: Reduce the size of the 'data' segment. diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen index 68c7d64..686f703 100755 --- a/build-aux/git-version-gen +++ b/build-aux/git-version-gen @@ -1,6 +1,6 @@ #!/bin/sh # Print a version string. -scriptversion=2011-01-04.17; # UTC +scriptversion=2011-02-19.19; # UTC # Copyright (C) 2007-2011 Free Software Foundation, Inc. # @@ -80,6 +80,7 @@ nl=' # Avoid meddling by environment variable of the same name. v= +v_from_git= # First see if there is a tarball-only version file. # then try "git describe", then default. @@ -134,24 +135,30 @@ then # Change the first '-' to a '.', so version-comparing tools work properly. # Remove the "g" in git describe's output string, to save a byte. v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`; + v_from_git=1 else v=UNKNOWN fi v=`echo "$v" |sed 's/^v//'` -# Don't declare a version "dirty" merely because a time stamp has changed. -git update-index --refresh > /dev/null 2>&1 +# Test whether to append the "-dirty" suffix only if the version +# string we're using came from git. I.e., skip the test if it's "UNKNOWN" +# or if it came from .tarball-version. +if test -n "$v_from_git"; then + # Don't declare a version "dirty" merely because a time stamp has changed. + git update-index --refresh > /dev/null 2>&1 -dirty=`exec 2>/dev/null;git diff-index --name-only HEAD` || dirty= -case "$dirty" in - '') ;; - *) # Append the suffix only if there isn't one already. - case $v in - *-dirty) ;; - *) v="$v-dirty" ;; - esac ;; -esac + dirty=`exec 2>/dev/null;git diff-index --name-only HEAD` || dirty= + case "$dirty" in + '') ;; + *) # Append the suffix only if there isn't one already. + case $v in + *-dirty) ;; + *) v="$v-dirty" ;; + esac ;; + esac +fi # Omit the trailing newline, so that m4_esyscmd can use the result directly. echo "$v" | tr -d "$nl" -- 1.7.4.1.16.g759e8