Improve handling of *_GIT_REMOTE env vars

- Output a message whenever a non-default remote is set.
- Ensure that `CoreTap.instance.install` uses the right remote.
This commit is contained in:
Mike McQuaid 2020-01-13 09:43:02 +00:00
parent 5ec4b4fda8
commit 2f39057243
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
2 changed files with 19 additions and 0 deletions

View File

@ -30,6 +30,10 @@ git_init_if_necessary() {
trap '{ rm -rf .git; exit 1; }' EXIT trap '{ rm -rf .git; exit 1; }' EXIT
git init git init
git config --bool core.autocrlf false git config --bool core.autocrlf false
if [[ "$HOMEBREW_DEFAULT_BREW_GIT_REMOTE" != "$HOMEBREW_BREW_GIT_REMOTE" ]]
then
echo "HOMEBREW_BREW_GIT_REMOTE set: using $HOMEBREW_BREW_GIT_REMOTE for Homebrew/brew Git remote URL."
fi
git config remote.origin.url "$HOMEBREW_BREW_GIT_REMOTE" git config remote.origin.url "$HOMEBREW_BREW_GIT_REMOTE"
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
latest_tag="$(git ls-remote --tags --refs -q origin | tail -n1 | cut -f2)" latest_tag="$(git ls-remote --tags --refs -q origin | tail -n1 | cut -f2)"
@ -48,6 +52,10 @@ git_init_if_necessary() {
trap '{ rm -rf .git; exit 1; }' EXIT trap '{ rm -rf .git; exit 1; }' EXIT
git init git init
git config --bool core.autocrlf false git config --bool core.autocrlf false
if [[ "$HOMEBREW_DEFAULT_CORE_GIT_REMOTE" != "$HOMEBREW_CORE_GIT_REMOTE" ]]
then
echo "HOMEBREW_CORE_GIT_REMOTE set: using $HOMEBREW_CORE_GIT_REMOTE for Homebrew/core Git remote URL."
fi
git config remote.origin.url "$HOMEBREW_CORE_GIT_REMOTE" git config remote.origin.url "$HOMEBREW_CORE_GIT_REMOTE"
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch --force --depth=1 origin refs/heads/master:refs/remotes/origin/master git fetch --force --depth=1 origin refs/heads/master:refs/remotes/origin/master
@ -397,6 +405,7 @@ EOS
if [[ "$HOMEBREW_DEFAULT_BREW_GIT_REMOTE" != "$HOMEBREW_BREW_GIT_REMOTE" ]] if [[ "$HOMEBREW_DEFAULT_BREW_GIT_REMOTE" != "$HOMEBREW_BREW_GIT_REMOTE" ]]
then then
safe_cd "$HOMEBREW_REPOSITORY" safe_cd "$HOMEBREW_REPOSITORY"
echo "HOMEBREW_BREW_GIT_REMOTE set: using $HOMEBREW_BREW_GIT_REMOTE for Homebrew/brew Git remote."
git remote set-url origin "$HOMEBREW_BREW_GIT_REMOTE" git remote set-url origin "$HOMEBREW_BREW_GIT_REMOTE"
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
latest_tag="$(git ls-remote --tags --refs -q origin | tail -n1 | cut -f2)" latest_tag="$(git ls-remote --tags --refs -q origin | tail -n1 | cut -f2)"
@ -407,6 +416,7 @@ EOS
[[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]]
then then
safe_cd "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" safe_cd "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core"
echo "HOMEBREW_CORE_GIT_REMOTE set: using $HOMEBREW_CORE_GIT_REMOTE for Homebrew/brew Git remote."
git remote set-url origin "$HOMEBREW_CORE_GIT_REMOTE" git remote set-url origin "$HOMEBREW_CORE_GIT_REMOTE"
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch --force --depth=1 origin refs/heads/master:refs/remotes/origin/master git fetch --force --depth=1 origin refs/heads/master:refs/remotes/origin/master

View File

@ -648,6 +648,15 @@ class CoreTap < Tap
safe_system HOMEBREW_BREW_FILE, "tap", instance.name safe_system HOMEBREW_BREW_FILE, "tap", instance.name
end end
def install(options = {})
if HOMEBREW_CORE_GIT_REMOTE != default_remote
puts "HOMEBREW_CORE_GIT_REMOTE set: using #{HOMEBREW_CORE_GIT_REMOTE} " \
"for Homebrew/core Git remote URL."
options[:clone_target] ||= HOMEBREW_CORE_GIT_REMOTE
end
super(options)
end
# @private # @private
def uninstall def uninstall
raise "Tap#uninstall is not available for CoreTap" raise "Tap#uninstall is not available for CoreTap"