Jim Meyering wrote: > Giuseppe Scrivano wrote: > >> Hello, >> >> Jim Meyering <j...@meyering.net> writes: >> >>> Not sure about more "elegant", but here's a lower cost method: >> >> Thanks for the patch but I think the problem you have reported here: >> >> http://article.gmane.org/gmane.comp.lib.gnulib.bugs/21845 >> >> persists. >> >> >> Here an example, where /tmp/foo is a git repository. >> >> /tmp/foo$ mkdir bar && cd bar && git rev-parse --verify HEAD >> eed6a47d30bff7fd268411ae8a0d893c3827edc1 >> /tmp/foo/bar$ >> >> >> Instead, using the more expensive "git log", you are sure the directory >> is controlled by git: >> >> /tmp/foo$ (test -n "$(git log -z -n1 .)") > /dev/null 2>&1 && echo FOO >> FOO >> >> /tmp/foo$ mkdir bar && cd bar \ >> && (test -n "$(git log -z -n1 .)") > /dev/null 2>&1 && echo BAR >> /tmp/foo/bar$ > > Hi Giuseppe, > > Thanks for pointing that out. > > In that case, this should be a little better: > [I didn't see a need for your -z, and --pretty=format:x > simply avoids printing out unnecessary information. > Also, I didn't see a need for the outer subshell, so removed it. ] > > test -n "$(git log -1 --pretty=format:x . 2>/dev/null)" > >>> * build-aux/git-version-gen: Adjust this script so that it works >>> when run from any working directory beneath the top-level .git/- >>> containing directory. Inspired by a patch from Giusseppe Scrivano, >>> http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/21843/focus=21847 >> >> oops, typo in my name. > > Sorry about that. > I'll correct the ChangeLog entry.
Thanks again for the quick corrections. Here's a better version. I'll wait for review this time ;-) >From b917191d0d7c5588852be7825575e543bc40dd9e Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyer...@redhat.com> Date: Wed, 13 Oct 2010 22:11:31 +0200 Subject: [PATCH] git-version-gen: do require git-VC'd files in cwd * build-aux/git-version-gen: Reject a git version string if there are no commits associated with the current directory. This avoids an unlikely false-positive (unrelated dir whose parent repository also contains a tag matching v*), as pointed out by Giuseppe Scrivano in http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/21843/focus=23664 --- ChangeLog | 10 +++++++++- build-aux/git-version-gen | 9 +++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9a4ed57..7b358af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,17 @@ 2010-10-13 Jim Meyering <meyer...@redhat.com> + git-version-gen: do require git-VC'd files in cwd + * build-aux/git-version-gen: Reject a git version string + if there are no commits associated with the current directory. + This avoids an unlikely false-positive (unrelated dir whose parent + repository also contains a tag matching v*), as pointed out + by Giuseppe Scrivano in + http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/21843/focus=23664 + git-version-gen: don't require that .git/ be in the current dir * build-aux/git-version-gen: Adjust this script so that it works when run from any working directory beneath the top-level .git/- - containing directory. Inspired by a patch from Giusseppe Scrivano, + containing directory. Inspired by a patch from Giuseppe Scrivano, http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/21843/focus=21847 test-select: avoid warn_unused_result warnings diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen index 6262775..795a98b 100755 --- a/build-aux/git-version-gen +++ b/build-aux/git-version-gen @@ -1,6 +1,6 @@ #!/bin/sh # Print a version string. -scriptversion=2010-10-13.14; # UTC +scriptversion=2010-10-13.20; # UTC # Copyright (C) 2007-2010 Free Software Foundation, Inc. # @@ -98,9 +98,10 @@ fi if test -n "$v" then : # use $v -# Otherwise, if we're anywhere beneath a .git directory, and "git describe" -# output looks sensible, use that to derive a version string. -elif git rev-parse --verify HEAD > /dev/null 2>&1 \ +# Otherwise, if there is at least one git commit involving the working +# directory, and "git describe" output looks sensible, use that to +# derive a version string. +elif test "`git log -1 --pretty=format:x . 2>&1`" = x \ && v=`git describe --abbrev=4 --match='v*' HEAD 2>/dev/null \ || git describe --abbrev=4 HEAD 2>/dev/null` \ && v=`printf '%s\n' "$v" | sed "$tag_sed_script"` \ -- 1.7.3.1.104.gc752e