On Mon, Oct 28, 2013 at 8:45 AM, Bruce Korb <bk...@gnu.org> wrote:
> On 10/27/13 17:46, Pádraig Brady wrote:
>>>
>>>   gnulib_dir ?= $(srcdir)/gnulib
>>> -gnulib-version = $$(cd $(gnulib_dir) && git describe)
>>> +gnulib-version = $$(cd $(gnulib_dir) && git rev-parse --short HEAD)
>>>   bootstrap-tools ?= autoconf,automake,gnulib
>
> ...
>
>> This would change the announce message from:
>>    Gnulib v0.0-7848-g4a82904
>> to:
>>    Gnulib 4a82904
>
>
> That, or "/path/to/gnulib\nGnulib 4a82904"
> I'd suggest:
>   gnulib-version = $$(cd $(gnulib_dir) >/dev/null && git rev-parse --short
> HEAD)

Thanks for the suggestion, Bruce.
However, I prefer not to change every use of
"cd"-in-subshell-where-stdout-matters.
That is too hard to maintain.  Instead, I'll do this:
From efe41e732a29e21bfe88c791c221d5c38e827f1e Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyer...@fb.com>
Date: Mon, 28 Oct 2013 16:08:16 -0700
Subject: [PATCH] gnulib-tool: protect against CDPATH

* gnulib-tool: Some "cd" built-in functions print a directory name
to stdout when CDPATH is set, e.g.,
  $ bash -c 'CDPATH=/; cd tmp'
  /tmp
Unset that envvar, when possible.
Prompted by a comment from Bruce Korb.
---
 ChangeLog   | 8 ++++++++
 gnulib-tool | 3 +++
 2 files changed, 11 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 6fca0c7..b64d8c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2013-10-28  Jim Meyering  <meyer...@fb.com>

+       gnulib-tool: protect against CDPATH
+       * gnulib-tool: Some "cd" built-in functions print a directory name
+       to stdout when CDPATH is set, e.g.,
+         $ bash -c 'CDPATH=/; cd tmp'
+         /tmp
+       Unset that envvar, when possible.
+       Prompted by a comment from Bruce Korb.
+
        maint.mk: restore functionality removed by recent change...
        Sunday's change, v0.0-8062-g6b24f60, may have appeared correct from
        the context of a shallow-cloned gnulib repository: "git describe"
diff --git a/gnulib-tool b/gnulib-tool
index ed693e0..152de86 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -898,6 +898,9 @@ if test "X$1" = "X--no-reexec"; then
   shift
 fi

+# Unset CDPATH.  Otherwise, output from the 'cd dir' can surprise callers.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
 # Command-line option processing.
 # Removes the OPTIONS from the arguments. Sets the variables:
 # - mode            one of: list, find, import, add-import, remove-import,
-- 
1.8.4.1.559.gdb9bdfb

Reply via email to