Skip to content

Commit 61dbb3c

Browse files
committed
Makefile: insert SANE_TOOL_PATH to PATH before /bin or /usr/bin
In an earlier patch, we introduced SANE_TOOL_PATH that is prepended to user's PATH. This had an unintended consequence of overriding user's private binary directory that typically comes earlier in the PATH to holds even saner commands than whatever comes with the system. For example, a user may have ~/bin that is early in the path and contains a shell script "vi" that launches system's /bin/vi with specific options. Prepending SANE_TOOL_PATH to the PATH that happens to have "vi" in it defeats such customization. This fixes the issue by inserting SANE_TOOL_PATH just before /bin or /usr/bin appears on the PATH. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 203ee91 commit 61dbb3c

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -881,10 +881,11 @@ endif
881881
-include config.mak
882882

883883
ifdef SANE_TOOL_PATH
884-
BROKEN_PATH_FIX = s|^. @@PATH@@|PATH=$(SANE_TOOL_PATH)|
884+
SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH))
885+
BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|'
885886
PATH := $(SANE_TOOL_PATH):${PATH}
886887
else
887-
BROKEN_PATH_FIX = d
888+
BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
888889
endif
889890

890891
ifeq ($(uname_S),Darwin)
@@ -1288,7 +1289,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
12881289
-e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
12891290
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
12901291
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
1291-
-e '/^# @@PATH@@/$(BROKEN_PATH_FIX)' \
1292+
-e $(BROKEN_PATH_FIX) \
12921293
$@.sh >$@+ && \
12931294
chmod +x $@+ && \
12941295
mv $@+ $@

git-sh-setup.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,33 @@
1111
# exporting it.
1212
unset CDPATH
1313

14-
# @@PATH@@:$PATH
14+
git_broken_path_fix () {
15+
case ":$PATH:" in
16+
*:$1:*) : ok ;;
17+
*)
18+
PATH=$(
19+
SANE_TOOL_PATH="$1"
20+
IFS=: path= sep=
21+
set x $PATH
22+
shift
23+
for elem
24+
do
25+
case "$SANE_TOOL_PATH:$elem" in
26+
(?*:/bin | ?*:/usr/bin)
27+
path="$path$sep$SANE_TOOL_PATH"
28+
sep=:
29+
SANE_TOOL_PATH=
30+
esac
31+
path="$path$sep$elem"
32+
sep=:
33+
done
34+
echo "$path"
35+
)
36+
;;
37+
esac
38+
}
39+
40+
# @@BROKEN_PATH_FIX@@
1541
1642
die() {
1743
echo >&2 "$@"

0 commit comments

Comments
 (0)