X Tutup
Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 73a2e75

Browse files
committed
shims/scm: move to same path as Homebrew/brew.
1 parent dde20cd commit 73a2e75

File tree

7 files changed

+124
-63
lines changed

7 files changed

+124
-63
lines changed

Library/ENV/scm/git

Lines changed: 0 additions & 60 deletions
This file was deleted.

Library/Homebrew/cmd/update.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ brew() {
33
}
44

55
git() {
6-
"$HOMEBREW_LIBRARY/ENV/scm/git" "$@"
6+
"$HOMEBREW_LIBRARY/Homebrew/shims/scm/git" "$@"
77
}
88

99
git_init_if_necessary() {

Library/Homebrew/config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def mkpath
4040

4141
HOMEBREW_LIBRARY = Pathname.new(ENV["HOMEBREW_LIBRARY"])
4242
HOMEBREW_ENV_PATH = HOMEBREW_LIBRARY/"ENV"
43+
HOMEBREW_SHIMS_PATH = HOMEBREW_LIBRARY/"Homebrew/shims"
4344
HOMEBREW_CONTRIB = HOMEBREW_REPOSITORY/"Library/Contributions"
4445

4546
# Where we store built products

Library/Homebrew/shims/scm/git

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/bin/bash
2+
3+
# This script because we support $GIT, $HOMEBREW_SVN, etc., Xcode-only and
4+
# no Xcode/CLT configurations. Order is careful to be what the user would want.
5+
6+
set +o posix
7+
8+
quiet_safe_cd() {
9+
cd "$1" >/dev/null || { echo "Error: failed to cd to $1" >&2; exit 1; }
10+
}
11+
12+
realpath() {
13+
local path="$1"
14+
local dir
15+
local base
16+
local dest
17+
18+
dir="$(quiet_safe_cd "${path%/*}/" && pwd -P)"
19+
base="${path##*/}"
20+
path="$dir/$base"
21+
22+
while [[ -L "$path" ]]
23+
do
24+
dest="$(readlink "$path")"
25+
if [[ "$dest" = "/"* ]]
26+
then
27+
path="$dest"
28+
else
29+
path="$dir/$dest"
30+
fi
31+
dir="$(quiet_safe_cd "${path%/*}/" && pwd -P)"
32+
base="${path##*/}"
33+
path="$dir/$base"
34+
done
35+
36+
echo "$path"
37+
}
38+
39+
executable() {
40+
local file="$1"
41+
[[ -f "$file" && -x "$file" ]]
42+
}
43+
44+
lowercase() {
45+
echo "$1" | tr '[:upper:]' '[:lower:]'
46+
}
47+
48+
safe_exec() {
49+
local arg0="$1"
50+
if ! executable "$arg0"
51+
then
52+
return
53+
fi
54+
# prevent fork-bombs
55+
if [[ "$(lowercase "$arg0")" = "$SCM_FILE" || "$(realpath "$arg0")" = "$SCM_REAL" ]]
56+
then
57+
return
58+
fi
59+
if [[ "$HOMEBREW" = "print-path" ]]
60+
then
61+
echo "$arg0"
62+
exit
63+
fi
64+
exec "$@"
65+
}
66+
67+
SCM_FILE="${0##*/}"
68+
SCM_REAL="$(realpath "$0")"
69+
SCM_DIR="$(quiet_safe_cd "${SCM_REAL%/*}/" && pwd -P)"
70+
71+
if [[ "$1" = --homebrew=* ]]
72+
then
73+
HOMEBREW="${1:11}"
74+
shift
75+
fi
76+
77+
case "$(lowercase "$SCM_FILE")" in
78+
git)
79+
[[ -n "$HOMEBREW_GIT" ]] && safe_exec "$(which "$HOMEBREW_GIT")" "$@"
80+
[[ -n "$GIT" ]] && safe_exec "$(which "$GIT")" "$@"
81+
;;
82+
svn)
83+
[[ -n "$HOMEBREW_SVN" ]] && safe_exec "$(which "$HOMEBREW_SVN")" "$@"
84+
;;
85+
esac
86+
87+
brew_version="$(quiet_safe_cd "$SCM_DIR/../../../../bin" && pwd -P)/$SCM_FILE"
88+
safe_exec "$brew_version" "$@"
89+
90+
IFS=$'\n'
91+
for path in $(/usr/bin/which -a "$SCM_FILE" 2>/dev/null)
92+
do
93+
if [[ "$path" != "/usr/bin/$SCM_FILE" ]]
94+
then
95+
safe_exec "$path" "$@"
96+
fi
97+
done
98+
99+
if executable "/usr/bin/xcode-select"
100+
then
101+
# xcode-select will return empty on no Xcode/CLT configuration.
102+
# /usr/bin/<tool> will be a popup stub under such configuration.
103+
# xcrun hangs if xcode-select is set to "/"
104+
xcode_path="$(/usr/bin/xcode-select -print-path 2>/dev/null)"
105+
[[ -n "$xcode_path" ]] || popup_stub=1
106+
if [[ -z "$popup_stub" && "$xcode_path" != "/" ]]
107+
then
108+
path="$(/usr/bin/xcrun -find "$SCM_FILE" 2>/dev/null)"
109+
safe_exec "$path" "$@"
110+
fi
111+
fi
112+
113+
path="/Applications/Xcode.app/Contents/Developer/usr/bin/$SCM_FILE"
114+
safe_exec "$path" "$@"
115+
116+
path="/usr/bin/$SCM_FILE"
117+
[[ -z "$popup_stub" ]] && safe_exec "$path" "$@"
118+
119+
echo "You must: brew install $SCM_FILE" >&2
120+
exit 1

Library/Homebrew/utils/git.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Utils
22
def self.git_available?
33
return @git if instance_variable_defined?(:@git)
4-
@git = quiet_system HOMEBREW_ENV_PATH/"scm/git", "--version"
4+
@git = quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version"
55
end
66

77
def self.ensure_git_installed!

Library/brew.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def require?(path)
5151
end
5252

5353
# Add SCM wrappers.
54-
ENV["PATH"] += "#{File::PATH_SEPARATOR}#{HOMEBREW_ENV_PATH}/scm"
54+
ENV["PATH"] += "#{File::PATH_SEPARATOR}#{HOMEBREW_SHIMS_PATH}/scm"
5555

5656
if cmd
5757
internal_cmd = require? HOMEBREW_LIBRARY_PATH.join("cmd", cmd)

0 commit comments

Comments
 (0)
X Tutup