Skip to content
Snippets Groups Projects
Commit d1b7c917 authored by Xu Cheng's avatar Xu Cheng
Browse files

update-bash: fix git_init_if_necessary


* Make sure `.git` directory be deleted at any error. So we won't have a
  stale setup.
* Run `git fetch` and `git reset` when initialize git in the first time.
  Otherwise, we will get error and merging problem afterwards.

Closes Homebrew/homebrew#48509.

Signed-off-by: default avatarXu Cheng <xucheng@me.com>
parent fe5a2256
No related branches found
No related tags found
No related merge requests found
......@@ -21,17 +21,26 @@ which_git() {
}
git_init_if_necessary() {
set -e
trap '{ rm -rf .git; exit 1; }' EXIT
if [[ ! -d ".git" ]]
then
git init -q
git config --bool core.autocrlf false
git config remote.origin.url https://github.com/Homebrew/homebrew.git
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin
git reset --hard origin/master
SKIP_FETCH_HOMEBREW_REPOSITORY=1
fi
set +e
trap - EXIT
if [[ "$(git remote show origin -n)" = *"mxcl/homebrew"* ]]
then
git remote set-url origin https://github.com/Homebrew/homebrew.git
git remote set-url origin https://github.com/Homebrew/homebrew.git &&
git remote set-url --delete origin ".*mxcl\/homebrew.*"
fi
}
......@@ -295,6 +304,7 @@ EOS
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
do
[[ -d "$DIR/.git" ]] || continue
[[ -n "$SKIP_FETCH_HOMEBREW_REPOSITORY" && "$DIR" = "$HOMEBREW_REPOSITORY" ]] && continue
cd "$DIR" || continue
UPSTREAM_BRANCH="$(upstream_branch)"
# the refspec ensures that the default upstream branch gets updated
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment