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>
This commit is contained in:
parent
fe5a225648
commit
d1b7c91787
@ -21,17 +21,26 @@ 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
|
||||||
git init -q
|
git init -q
|
||||||
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 reset --hard origin/master
|
||||||
|
SKIP_FETCH_HOMEBREW_REPOSITORY=1
|
||||||
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 &&
|
||||||
git remote set-url --delete origin ".*mxcl\/homebrew.*"
|
git remote set-url --delete origin ".*mxcl\/homebrew.*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -295,6 +304,7 @@ EOS
|
|||||||
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
|
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
|
||||||
do
|
do
|
||||||
[[ -d "$DIR/.git" ]] || continue
|
[[ -d "$DIR/.git" ]] || continue
|
||||||
|
[[ -n "$SKIP_FETCH_HOMEBREW_REPOSITORY" && "$DIR" = "$HOMEBREW_REPOSITORY" ]] && continue
|
||||||
cd "$DIR" || continue
|
cd "$DIR" || continue
|
||||||
UPSTREAM_BRANCH="$(upstream_branch)"
|
UPSTREAM_BRANCH="$(upstream_branch)"
|
||||||
# the refspec ensures that the default upstream branch gets updated
|
# the refspec ensures that the default upstream branch gets updated
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user