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>
This commit is contained in:
parent
d1b7c91787
commit
0ec5fec801
@ -2,22 +2,43 @@ brew() {
|
|||||||
"$HOMEBREW_BREW_FILE" "$@"
|
"$HOMEBREW_BREW_FILE" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
git() {
|
||||||
|
[[ -n "$HOMEBREW_GIT" ]] || odie "HOMEBREW_GIT is unset!"
|
||||||
|
"$HOMEBREW_GIT" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
which_git() {
|
which_git() {
|
||||||
local which_git
|
local git_path
|
||||||
local active_developer_dir
|
local active_developer_dir
|
||||||
|
|
||||||
which_git="$(which git 2>/dev/null)"
|
if [[ -n "$HOMEBREW_GIT" ]]
|
||||||
if [[ -n "$which_git" && "/usr/bin/git" = "$which_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
|
then
|
||||||
active_developer_dir="$('/usr/bin/xcode-select' -print-path 2>/dev/null)"
|
active_developer_dir="$('/usr/bin/xcode-select' -print-path 2>/dev/null)"
|
||||||
if [[ -n "$active_developer_dir" && -x "$active_developer_dir/usr/bin/git" ]]
|
if [[ -n "$active_developer_dir" && -x "$active_developer_dir/usr/bin/git" ]]
|
||||||
then
|
then
|
||||||
which_git="$active_developer_dir/usr/bin/git"
|
git_path="$active_developer_dir/usr/bin/git"
|
||||||
else
|
else
|
||||||
which_git=""
|
git_path=""
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo "$which_git"
|
echo "$git_path"
|
||||||
}
|
}
|
||||||
|
|
||||||
git_init_if_necessary() {
|
git_init_if_necessary() {
|
||||||
@ -272,15 +293,16 @@ EOS
|
|||||||
odie "$HOMEBREW_REPOSITORY must be writable!"
|
odie "$HOMEBREW_REPOSITORY must be writable!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$(which_git)" ]]
|
HOMEBREW_GIT="$(which_git)"
|
||||||
|
if [[ -z "$HOMEBREW_GIT" ]]
|
||||||
then
|
then
|
||||||
brew install git
|
brew install git
|
||||||
if [[ -z "$(which_git)" ]]
|
HOMEBREW_GIT="$(which_git)"
|
||||||
|
if [[ -z "$HOMEBREW_GIT" ]]
|
||||||
then
|
then
|
||||||
odie "Git must be installed and in your PATH!"
|
odie "Git must be installed and in your PATH!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
hash -p "$(cd "$(dirname "$(which_git)")" && pwd -P)/git" git
|
|
||||||
|
|
||||||
if [[ -z "$HOMEBREW_VERBOSE" ]]
|
if [[ -z "$HOMEBREW_VERBOSE" ]]
|
||||||
then
|
then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user