diff options
| author | Mike McQuaid | 2016-07-15 19:03:45 +0100 |
|---|---|---|
| committer | GitHub | 2016-07-15 19:03:45 +0100 |
| commit | a02be9eea204264ce48827ac365c8b53b986d66a (patch) | |
| tree | cf85e35e0992204cb9f1f938b831161433ca8fd4 /Library/Homebrew/shims/scm/git | |
| parent | de366f71b9c9fded0b5578bb4fef14139834038a (diff) | |
| download | brew-a02be9eea204264ce48827ac365c8b53b986d66a.tar.bz2 | |
ENV: move to new paths. (#507)
Move some stuff formerly in `Library/ENV` around:
- Move `Library/ENV/$XCODE_VERSION` to `Library/Homebrew/env/super` as they are
all superenv wrappers and all symlinks to the same version. We never needed
the "separate shims for separate versions" functionality and it just adds
confusion.
- Move `Library/ENV/pkgconfig` to `Library/Homebrew/env/pkgconfig` to get more
things under `Library/Homebrew`
- Move `Library/ENV/scm` to `Library/scm` as these wrappers are not actually
used by or related to superenv (or stdenv) in any way.
Diffstat (limited to 'Library/Homebrew/shims/scm/git')
| -rwxr-xr-x | Library/Homebrew/shims/scm/git | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/Library/Homebrew/shims/scm/git b/Library/Homebrew/shims/scm/git new file mode 100755 index 000000000..10950ef07 --- /dev/null +++ b/Library/Homebrew/shims/scm/git @@ -0,0 +1,120 @@ +#!/bin/bash + +# This script because we support $GIT, $HOMEBREW_SVN, etc., Xcode-only and +# no Xcode/CLT configurations. Order is careful to be what the user would want. + +set +o posix + +quiet_safe_cd() { + cd "$1" >/dev/null || { echo "Error: failed to cd to $1" >&2; exit 1; } +} + +realpath() { + local path="$1" + local dir + local base + local dest + + dir="$(quiet_safe_cd "${path%/*}/" && pwd -P)" + base="${path##*/}" + path="$dir/$base" + + while [[ -L "$path" ]] + do + dest="$(readlink "$path")" + if [[ "$dest" = "/"* ]] + then + path="$dest" + else + path="$dir/$dest" + fi + dir="$(quiet_safe_cd "${path%/*}/" && pwd -P)" + base="${path##*/}" + path="$dir/$base" + done + + echo "$path" +} + +executable() { + local file="$1" + [[ -f "$file" && -x "$file" ]] +} + +lowercase() { + echo "$1" | tr '[:upper:]' '[:lower:]' +} + +safe_exec() { + local arg0="$1" + if ! executable "$arg0" + then + return + fi + # prevent fork-bombs + if [[ "$(lowercase "$arg0")" = "$SCM_FILE" || "$(realpath "$arg0")" = "$SCM_REAL" ]] + then + return + fi + if [[ "$HOMEBREW" = "print-path" ]] + then + echo "$arg0" + exit + fi + exec "$@" +} + +SCM_FILE="${0##*/}" +SCM_REAL="$(realpath "$0")" +SCM_DIR="$(quiet_safe_cd "${SCM_REAL%/*}/" && pwd -P)" + +if [[ "$1" = --homebrew=* ]] +then + HOMEBREW="${1:11}" + shift +fi + +case "$(lowercase "$SCM_FILE")" in + git) + [[ -n "$HOMEBREW_GIT" ]] && safe_exec "$(which "$HOMEBREW_GIT")" "$@" + [[ -n "$GIT" ]] && safe_exec "$(which "$GIT")" "$@" + ;; + svn) + [[ -n "$HOMEBREW_SVN" ]] && safe_exec "$(which "$HOMEBREW_SVN")" "$@" + ;; +esac + +brew_version="$(quiet_safe_cd "$SCM_DIR/../../../../bin" && pwd -P)/$SCM_FILE" +safe_exec "$brew_version" "$@" + +IFS=$'\n' +for path in $(/usr/bin/which -a "$SCM_FILE" 2>/dev/null) +do + if [[ "$path" != "/usr/bin/$SCM_FILE" ]] + then + safe_exec "$path" "$@" + fi +done + +if executable "/usr/bin/xcode-select" +then + # xcode-select will return empty on no Xcode/CLT configuration. + # /usr/bin/<tool> will be a popup stub under such configuration. + # xcrun hangs if xcode-select is set to "/" + xcode_path="$(/usr/bin/xcode-select -print-path 2>/dev/null)" + [[ -n "$xcode_path" ]] || popup_stub=1 + if [[ -z "$popup_stub" && "$xcode_path" != "/" ]] + then + path="$(/usr/bin/xcrun -find "$SCM_FILE" 2>/dev/null)" + safe_exec "$path" "$@" + fi +fi + +path="/Applications/Xcode.app/Contents/Developer/usr/bin/$SCM_FILE" +safe_exec "$path" "$@" + +path="/usr/bin/$SCM_FILE" +[[ -z "$popup_stub" ]] && safe_exec "$path" "$@" + +echo "You must: brew install $SCM_FILE" >&2 +exit 1 |
