update: shallow fetch for git_init_if_necessary

Users shouldn't need to fetch all of git history.

Closes Homebrew/homebrew#49903.

Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
Xu Cheng 2016-03-09 17:09:38 +08:00
parent e8caa48cc2
commit 0f6def90b7

View File

@ -42,23 +42,22 @@ which_git() {
} }
git_init_if_necessary() { git_init_if_necessary() {
set -e
trap '{ rm -rf .git; exit 1; }' EXIT
if [[ ! -d ".git" ]] if [[ ! -d ".git" ]]
then then
set -e
trap '{ rm -rf .git; exit 1; }' EXIT
git init git init
git config --bool core.autocrlf false git config --bool core.autocrlf false
git config remote.origin.url https://github.com/Homebrew/homebrew.git git config remote.origin.url https://github.com/Homebrew/homebrew.git
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin git fetch --force --depth=1 origin refs/heads/master:refs/remotes/origin/master
git reset --hard origin/master git reset --hard origin/master
SKIP_FETCH_HOMEBREW_REPOSITORY=1 SKIP_FETCH_HOMEBREW_REPOSITORY=1
set +e
trap - EXIT
return
fi fi
set +e
trap - EXIT
if [[ "$(git remote show origin -n)" = *"mxcl/homebrew"* ]] if [[ "$(git remote show origin -n)" = *"mxcl/homebrew"* ]]
then then
git remote set-url origin https://github.com/Homebrew/homebrew.git && git remote set-url origin https://github.com/Homebrew/homebrew.git &&