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

Commit

Permalink
update-bash: fix git_init_if_necessary
Browse files Browse the repository at this point in the history
* 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 #48509.

Signed-off-by: Xu Cheng <xucheng@me.com>
  • Loading branch information
xu-cheng committed Jan 28, 2016
1 parent 5bcc7b1 commit 2774b98
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Library/Homebrew/cmd/update-bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2774b98

Please sign in to comment.