bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Do not limit git-version-gen to work only under the reposito


From: Jim Meyering
Subject: Re: [PATCH] Do not limit git-version-gen to work only under the repository root.
Date: Wed, 13 Oct 2010 16:15:55 +0200

Giuseppe Scrivano wrote:

> Bruno, Jim,
>
> thanks for your comments.
>
>
> Jim Meyering <address@hidden> writes:
>
>> What is your use case?
>
> I have the git repository in myserver/, but the top_srcdir is in
> myserver/myserver/.
>
>
>> Won't this proposal cause trouble when
>> running git-version-gen in a non-version-controlled
>> pkg-top-level-directory that has a parent containing an
>> unrelated .git/ directory?
>>
>> That would happen to me when building under $HOME,
>> since I have $HOME/.git.
>>
>> I think you would have to add something more to ensure that the
>> repository used is in fact associated with the project at hand.
>
> I wasn't aware of this git behaviour.
>
> I couldn't find anything better than the check:
>
>   test -n "$(git log -z -n1 .)"
>
> I am not sure if there is a more "elegant" way to do it.

Hi Giuseppe,

Thanks for the suggestion.
And thanks to Bruno for resurrecting this thread.

> Subject: [PATCH] Do not limit git-version-gen to work only under the 
> repository root.
>
> * build-aux/git-version-gen: Modify check whether directory is
> controlled by git or not.
...
> -elif test -d .git \
> +# Check that the current directory is controlled by git.
> +elif (test -n "$(git log -z -n1 .)") > /dev/null 2>&1 \
>      && v=`git describe --abbrev=4 --match='v*' HEAD 2>/dev/null \
>         || git describe --abbrev=4 HEAD 2>/dev/null` \
>      && case $v in

Not sure about more "elegant", but here's a lower cost method:

>From 932cfeb12ac1a06cd8abdad7ed6eb65e6aeb602d Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 13 Oct 2010 16:08:36 +0200
Subject: [PATCH] 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,
http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/21843/focus=21847
---
 ChangeLog                 |    6 ++++++
 build-aux/git-version-gen |    6 ++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e7838e1..9a4ed57 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2010-10-13  Jim Meyering  <address@hidden>

+       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,
+       http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/21843/focus=21847
+
        test-select: avoid warn_unused_result warnings
        * tests/test-select.c: Include "macros.h".
        ASSERT that each call to read, write, and pipe succeeds.
diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen
index 5617eb8..6262775 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-06-14.19; # UTC
+scriptversion=2010-10-13.14; # UTC

 # Copyright (C) 2007-2010 Free Software Foundation, Inc.
 #
@@ -98,7 +98,9 @@ fi
 if test -n "$v"
 then
     : # use $v
-elif test -d .git \
+# 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 \
     && 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]