From: Jim Meyering <meyering@redhat.com>
Date: Wed, 13 Oct 2010 20:11:31 +0000 (+0200)
Subject: git-version-gen: do require git-VC'd files in cwd
X-Git-Tag: v0.1~3684
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=49e38169beb576f18a11b1858bd3601a999092dc;p=gnulib.git

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
---

diff --git a/ChangeLog b/ChangeLog
index 8bd4153bb7..14b10e8b57 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-10-13  Jim Meyering  <meyering@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
+
 2010-10-13  Paul Eggert  <eggert@cs.ucla.edu>
 
 	argv-iter: omit nonconforming declaration
@@ -21,7 +31,7 @@
 	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 6262775876..795a98b323 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"` \