diff options
| author | Xu Cheng | 2016-01-28 18:48:44 +0800 |
|---|---|---|
| committer | Xu Cheng | 2016-01-28 19:03:38 +0800 |
| commit | 0ec5fec801e1a365f64e73ce3e613300c25ea7bc (patch) | |
| tree | 527217e998b763596bbba3e454e1b7cb9270a27d /Library/Homebrew/cmd | |
| parent | d1b7c91787066d22068f65696fdd5d700fb1dde1 (diff) | |
| download | brew-0ec5fec801e1a365f64e73ce3e613300c25ea7bc.tar.bz2 | |
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 Homebrew/homebrew#48508.
Signed-off-by: Xu Cheng <xucheng@me.com>
Diffstat (limited to 'Library/Homebrew/cmd')
| -rw-r--r-- | Library/Homebrew/cmd/update-bash.sh | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/Library/Homebrew/cmd/update-bash.sh b/Library/Homebrew/cmd/update-bash.sh index 8c0c0e3ef..3b67d7f42 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 |
