From d1b7c91787066d22068f65696fdd5d700fb1dde1 Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Thu, 28 Jan 2016 17:11:35 +0800 Subject: [PATCH] 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: Xu Cheng --- Library/Homebrew/cmd/update-bash.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/update-bash.sh b/Library/Homebrew/cmd/update-bash.sh index 47b811e4b2..8c0c0e3ef5 100644 --- a/Library/Homebrew/cmd/update-bash.sh +++ b/Library/Homebrew/cmd/update-bash.sh @@ -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