From e942726f10d313a0aa4746fe54a14a490d8bf43f Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Thu, 28 Jan 2016 18:48:44 +0800 Subject: [PATCH] update-bash: git related improvement * Use git function instead of refreshing bash cache on `git` path. * Better `which_git`: * Take user's setting of `HOMEBREW_GIT` and `GIT` env variable into account. * Always expand git path. * Only check Xcode installation for OS X. Closes #48508. Signed-off-by: Xu Cheng --- Library/Homebrew/cmd/update-bash.sh | 40 ++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cmd/update-bash.sh b/Library/Homebrew/cmd/update-bash.sh index 8c0c0e3ef5ce..3b67d7f42339 100644 --- a/Library/Homebrew/cmd/update-bash.sh +++ b/Library/Homebrew/cmd/update-bash.sh @@ -2,22 +2,43 @@ brew() { "$HOMEBREW_BREW_FILE" "$@" } +git() { + [[ -n "$HOMEBREW_GIT" ]] || odie "HOMEBREW_GIT is unset!" + "$HOMEBREW_GIT" "$@" +} + which_git() { - local which_git + local git_path local active_developer_dir - which_git="$(which git 2>/dev/null)" - if [[ -n "$which_git" && "/usr/bin/git" = "$which_git" ]] + if [[ -n "$HOMEBREW_GIT" ]] + then + git_path="$HOMEBREW_GIT" + elif [[ -n "$GIT" ]] + then + git_path="$GIT" + else + git_path="git" + fi + + git_path="$(which "$git_path" 2>/dev/null)" + + if [[ -n "$git_path" ]] + then + git_path="$(chdir "${git_path%/*}" && pwd -P)/${git_path##*/}" + fi + + if [[ -n "$HOMEBREW_OSX" && "$git_path" = "/usr/bin/git" ]] then active_developer_dir="$('/usr/bin/xcode-select' -print-path 2>/dev/null)" if [[ -n "$active_developer_dir" && -x "$active_developer_dir/usr/bin/git" ]] then - which_git="$active_developer_dir/usr/bin/git" + git_path="$active_developer_dir/usr/bin/git" else - which_git="" + git_path="" fi fi - echo "$which_git" + echo "$git_path" } git_init_if_necessary() { @@ -272,15 +293,16 @@ EOS odie "$HOMEBREW_REPOSITORY must be writable!" fi - if [[ -z "$(which_git)" ]] + HOMEBREW_GIT="$(which_git)" + if [[ -z "$HOMEBREW_GIT" ]] then brew install git - if [[ -z "$(which_git)" ]] + HOMEBREW_GIT="$(which_git)" + if [[ -z "$HOMEBREW_GIT" ]] then odie "Git must be installed and in your PATH!" fi fi - hash -p "$(cd "$(dirname "$(which_git)")" && pwd -P)/git" git if [[ -z "$HOMEBREW_VERBOSE" ]] then