diff options
| author | Xu Cheng | 2016-01-28 17:11:35 +0800 |
|---|---|---|
| committer | Xu Cheng | 2016-01-28 19:03:24 +0800 |
| commit | d1b7c91787066d22068f65696fdd5d700fb1dde1 (patch) | |
| tree | ecc7a233ede399ece289d85837b7c32ad165e6b4 /Library/Homebrew/cmd | |
| parent | fe5a225648dc2aecf0080c4d501e192f12f26674 (diff) | |
| download | brew-d1b7c91787066d22068f65696fdd5d700fb1dde1.tar.bz2 | |
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 <xucheng@me.com>
Diffstat (limited to 'Library/Homebrew/cmd')
| -rw-r--r-- | Library/Homebrew/cmd/update-bash.sh | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Library/Homebrew/cmd/update-bash.sh b/Library/Homebrew/cmd/update-bash.sh index 47b811e4b..8c0c0e3ef 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 |
