Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
update-bash: git related improvement
Browse files Browse the repository at this point in the history
* 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 <xucheng@me.com>
  • Loading branch information
xu-cheng committed Jan 28, 2016
1 parent 2774b98 commit e942726
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions Library/Homebrew/cmd/update-bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e942726

Please sign in to comment.