Re: [PATCH] Makefile: Fix CDPATH problem

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] Makefile: Fix CDPATH problem

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:48:27

Jonathan Nieder [off-list ref] writes:
CDPATH takes scripts to unexpected places.  For example, with a CDPATH
including a blt directory:

 make -C templates DESTDIR='' install
 make[1]: Entering directory `/users/e477610/exptool/src/git-1.7.0.2/templates'
 install -d -m 755 '/home/e477610/exptool/share/git-core/templates'
 (cd blt && gtar cf - .) | \
	(cd '/home/e477610/exptool/share/git-core/templates' && umask 022 && gtar xof -)
 gtar: This does not look like a tar archive

The CDPATH mechanism does not implicitly add "." at the beginning of
CDPATH, which is the most irritating part.

Most git scripts already protect against use of CDPATH through
git-sh-setup, but the Makefile doesn’t.
Eh, the rationale and the in-code comment need to be fixed.  The issue is
not "taking us to random places", but "reporting the name of the random
place in its standard output".

But other than that, this is something we have seen on the list a few
times, and I think it is about time to do this.

Thanks.

[PATCH v2] Makefile: Fix CDPATH problem

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:48:27

If CDPATH is set, "cd" prints its destination to stdout, causing
the common (cd a && tar cf - .) | (cd b && tar xf -) idiom to fail.
For example:

 make -C templates DESTDIR='' install
 make[1]: Entering directory `/users/e477610/exptool/src/git-1.7.0.2/templates'
 install -d -m 755 '/home/e477610/exptool/share/git-core/templates'
 (cd blt && gtar cf - .) | \
	(cd '/home/e477610/exptool/share/git-core/templates' && umask 022 && gtar xof -)
 gtar: This does not look like a tar archive

Most git scripts already protect against use of CDPATH through
git-sh-setup, but the Makefile doesn’t.

Reported-by: Michael Cox <redacted>
Signed-off-by: Jonathan Nieder <redacted>
---
Eh, the rationale and the in-code comment need to be fixed.  The issue is
not "taking us to random places", but "reporting the name of the random
place in its standard output".
That makes more sense.  Thanks.
But other than that, this is something we have seen on the list a few
times, and I think it is about time to do this.
Here’s an updated patch.

 Makefile |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
index 4387d42..98372eb 100644
--- a/Makefile
+++ b/Makefile
@@ -317,6 +317,12 @@ SCRIPT_PYTHON =
 SCRIPT_SH =
 TEST_PROGRAMS =
 
+# Having this variable in your environment would break pipelines because
+# you cause "cd" to echo its destination to stdout.  It can also take
+# scripts to unexpected places.  If you like CDPATH, define it for your
+# interactive shell sessions without exporting it.
+unexport CDPATH
+
 SCRIPT_SH += git-am.sh
 SCRIPT_SH += git-bisect.sh
 SCRIPT_SH += git-difftool--helper.sh
-- 
1.7.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help