From baf75af908e7eff2c02d4e673e90bf0d1ec281d3 Mon Sep 17 00:00:00 2001 From: EricFromCanada Date: Wed, 24 Oct 2018 18:20:17 -0400 Subject: [PATCH 1/5] brew: prepend shims to PATH used by _system Ensures `system` and `safe_system` use brewed git if available. --- Library/Homebrew/brew.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index ba8e445c8d..fcc78728d7 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -37,8 +37,8 @@ begin homebrew_path = PATH.new(ENV["HOMEBREW_PATH"]) # Add SCM wrappers. - path.append(HOMEBREW_SHIMS_PATH/"scm") - homebrew_path.append(HOMEBREW_SHIMS_PATH/"scm") + path.prepend(HOMEBREW_SHIMS_PATH/"scm") + homebrew_path.prepend(HOMEBREW_SHIMS_PATH/"scm") ENV["PATH"] = path From 9e4fb40f92ed2acadc82909cc3bc4b2d66467c2d Mon Sep 17 00:00:00 2001 From: EricFromCanada Date: Thu, 25 Oct 2018 09:24:00 -0400 Subject: [PATCH 2/5] docs: update descriptions of git- and curl-related vars Note that the `HOMEBREW_FORCE_BREWED_` vars are automatically set if the system `git` and `curl` are too old. Drop mention of `HOMEBREW_GIT` which isn't user-settable. --- Library/Homebrew/manpages/brew.1.md.erb | 17 ++++++----------- Library/Homebrew/shims/scm/git | 2 +- docs/Manpage.md | 17 ++++++----------- manpages/brew.1 | 11 ++--------- 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/Library/Homebrew/manpages/brew.1.md.erb b/Library/Homebrew/manpages/brew.1.md.erb index b17b10a47a..3488c08878 100644 --- a/Library/Homebrew/manpages/brew.1.md.erb +++ b/Library/Homebrew/manpages/brew.1.md.erb @@ -10,7 +10,7 @@ # When done, regenerate the man page and its HTML version by running `brew man`. %> brew(1) -- The missing package manager for macOS -=============================================== +================================================ ## SYNOPSIS @@ -105,6 +105,7 @@ can take several different forms: The formula file will be cached for later use. ## ENVIRONMENT + Note that environment variables must have a value set to be detected. For example, `export HOMEBREW_NO_INSECURE_REDIRECT=1` rather than just `export HOMEBREW_NO_INSECURE_REDIRECT`. * `HOMEBREW_ARTIFACT_DOMAIN`: @@ -180,22 +181,16 @@ Note that environment variables must have a value set to be detected. For exampl editors will do strange things in this case. * `HOMEBREW_FORCE_BREWED_CURL`: - If set, Homebrew will use a Homebrew-installed `curl` rather than the - system version. + If set, Homebrew will always use a Homebrew-installed `curl` rather than the + system version. Automatically set if the system version of `curl` is too old. * `HOMEBREW_FORCE_VENDOR_RUBY`: If set, Homebrew will always use its vendored, relocatable Ruby version even if the system version of Ruby is new enough. - * `HOMEBREW_GIT`: - When using Git, Homebrew will use `GIT` if set, - a Homebrew-built Git if installed, or the system-provided binary. - - Set this to force Homebrew to use a particular git binary. - * `HOMEBREW_FORCE_BREWED_GIT`: - If set, Homebrew will use a Homebrew-installed `git` rather than the - system version. + If set, Homebrew will always use a Homebrew-installed `git` rather than the + system version. Automatically set if the system version of `git` is too old. * `HOMEBREW_GITHUB_API_TOKEN`: A personal access token for the GitHub API, which you can create at diff --git a/Library/Homebrew/shims/scm/git b/Library/Homebrew/shims/scm/git index 0930c0adc3..c4e7ec5134 100755 --- a/Library/Homebrew/shims/scm/git +++ b/Library/Homebrew/shims/scm/git @@ -1,6 +1,6 @@ #!/bin/bash -# This script because we support $GIT, $HOMEBREW_SVN, etc., Xcode-only and +# This script because we support $HOMEBREW_GIT, $HOMEBREW_SVN, etc., Xcode-only and # no Xcode/CLT configurations. Order is careful to be what the user would want. set +o posix diff --git a/docs/Manpage.md b/docs/Manpage.md index 0dad55baa5..b7c0754964 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1,5 +1,5 @@ brew(1) -- The missing package manager for macOS -=============================================== +================================================ ## SYNOPSIS @@ -1100,6 +1100,7 @@ can take several different forms: The formula file will be cached for later use. ## ENVIRONMENT + Note that environment variables must have a value set to be detected. For example, `export HOMEBREW_NO_INSECURE_REDIRECT=1` rather than just `export HOMEBREW_NO_INSECURE_REDIRECT`. * `HOMEBREW_ARTIFACT_DOMAIN`: @@ -1175,22 +1176,16 @@ Note that environment variables must have a value set to be detected. For exampl editors will do strange things in this case. * `HOMEBREW_FORCE_BREWED_CURL`: - If set, Homebrew will use a Homebrew-installed `curl` rather than the - system version. + If set, Homebrew will always use a Homebrew-installed `curl` rather than the + system version. Automatically set if the system version of `curl` is too old. * `HOMEBREW_FORCE_VENDOR_RUBY`: If set, Homebrew will always use its vendored, relocatable Ruby version even if the system version of Ruby is new enough. - * `HOMEBREW_GIT`: - When using Git, Homebrew will use `GIT` if set, - a Homebrew-built Git if installed, or the system-provided binary. - - Set this to force Homebrew to use a particular git binary. - * `HOMEBREW_FORCE_BREWED_GIT`: - If set, Homebrew will use a Homebrew-installed `git` rather than the - system version. + If set, Homebrew will always use a Homebrew-installed `git` rather than the + system version. Automatically set if the system version of `git` is too old. * `HOMEBREW_GITHUB_API_TOKEN`: A personal access token for the GitHub API, which you can create at diff --git a/manpages/brew.1 b/manpages/brew.1 index 4480c25ecd..95cccd299a 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1297,22 +1297,15 @@ If set, Homebrew will use this editor when editing a single formula, or several . .TP \fBHOMEBREW_FORCE_BREWED_CURL\fR -If set, Homebrew will use a Homebrew\-installed \fBcurl\fR rather than the system version\. +If set, Homebrew will always use a Homebrew\-installed \fBcurl\fR rather than the system version\. Automatically set if the system version of \fBcurl\fR is too old\. . .TP \fBHOMEBREW_FORCE_VENDOR_RUBY\fR If set, Homebrew will always use its vendored, relocatable Ruby version even if the system version of Ruby is new enough\. . .TP -\fBHOMEBREW_GIT\fR -When using Git, Homebrew will use \fBGIT\fR if set, a Homebrew\-built Git if installed, or the system\-provided binary\. -. -.IP -Set this to force Homebrew to use a particular git binary\. -. -.TP \fBHOMEBREW_FORCE_BREWED_GIT\fR -If set, Homebrew will use a Homebrew\-installed \fBgit\fR rather than the system version\. +If set, Homebrew will always use a Homebrew\-installed \fBgit\fR rather than the system version\. Automatically set if the system version of \fBgit\fR is too old\. . .TP \fBHOMEBREW_GITHUB_API_TOKEN\fR From 7c9bea27037d31cb903bdcd1acb0e58b31d7fa2f Mon Sep 17 00:00:00 2001 From: EricFromCanada Date: Thu, 25 Oct 2018 01:17:22 -0400 Subject: [PATCH 3/5] system_config: skip HOMEBREW_GIT as its final path is shown further down --- Library/Homebrew/system_config.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Library/Homebrew/system_config.rb b/Library/Homebrew/system_config.rb index 23cdbffcef..e6a387cdbd 100644 --- a/Library/Homebrew/system_config.rb +++ b/Library/Homebrew/system_config.rb @@ -123,7 +123,6 @@ class SystemConfig HOMEBREW_CACHE: "#{ENV["HOME"]}/Library/Caches/Homebrew", HOMEBREW_TEMP: ENV["HOMEBREW_SYSTEM_TEMP"], HOMEBREW_RUBY_WARNINGS: "-W0", - HOMEBREW_GIT: "git", }.freeze boring_keys = %w[ HOMEBREW_BROWSER @@ -137,6 +136,7 @@ class SystemConfig HOMEBREW_BREW_FILE HOMEBREW_COMMAND_DEPTH HOMEBREW_CURL + HOMEBREW_GIT HOMEBREW_GIT_CONFIG_FILE HOMEBREW_LIBRARY HOMEBREW_MACOS_VERSION @@ -168,9 +168,6 @@ class SystemConfig if defaults_hash[:HOMEBREW_RUBY_WARNINGS] != ENV["HOMEBREW_RUBY_WARNINGS"].to_s f.puts "HOMEBREW_RUBY_WARNINGS: #{ENV["HOMEBREW_RUBY_WARNINGS"]}" end - if defaults_hash[:HOMEBREW_GIT] != ENV["HOMEBREW_GIT"].to_s - f.puts "HOMEBREW_GIT: #{ENV["HOMEBREW_GIT"]}" - end unless ENV["HOMEBREW_ENV"] ENV.sort.each do |key, value| next unless key.start_with?("HOMEBREW_") From 7aa995693479992a76e19a15132843d6fdf765f5 Mon Sep 17 00:00:00 2001 From: EricFromCanada Date: Fri, 26 Oct 2018 17:08:59 -0400 Subject: [PATCH 4/5] brew: check system-provided curl and git on Linux Set HOMEBREW_FORCE_BREWED_CURL or HOMEBREW_FORCE_BREWED_GIT if the system-provided versions are missing or outdated, causing either to be installed on the next `brew update`. --- Library/Homebrew/brew.sh | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 135c77ded8..2f729b733e 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -55,6 +55,12 @@ git() { "$HOMEBREW_LIBRARY/Homebrew/shims/scm/git" "$@" } +numeric() { + # Condense the exploded argument into a single return value. + # shellcheck disable=SC2086,SC2183 + printf "%01d%02d%02d%02d" ${1//./ } +} + HOMEBREW_VERSION="$(git -C "$HOMEBREW_REPOSITORY" describe --tags --dirty --abbrev=7 2>/dev/null)" HOMEBREW_USER_AGENT_VERSION="$HOMEBREW_VERSION" if [[ -z "$HOMEBREW_VERSION" ]] @@ -114,6 +120,25 @@ else : "${HOMEBREW_OS_VERSION:=$(uname -r)}" HOMEBREW_OS_USER_AGENT_VERSION="$HOMEBREW_OS_VERSION" + # Ensure the system Curl is a version that supports modern HTTPS certificates. + HOMEBREW_MINIMUM_CURL_VERSION="7.41.0" + system_curl_version_output="$($(command -v curl) --version 2>/dev/null)" + system_curl_name_and_version="${system_curl_version_output%% (*}" + if [[ $(numeric "${system_curl_name_and_version##* }") -lt $(numeric "$HOMEBREW_MINIMUM_CURL_VERSION") ]] + then + HOMEBREW_SYSTEM_CURL_TOO_OLD="1" + HOMEBREW_FORCE_BREWED_CURL="1" + fi + + # Ensure the system Git is at or newer than the minimum required version. + # Git 2.7.4 is the version of git on Ubuntu 16.04 LTS (Xenial Xerus). + HOMEBREW_MINIMUM_GIT_VERSION="2.7.0" + system_git_version_output="$($(command -v git) --version 2>/dev/null)" + if [[ $(numeric "${system_git_version_output##* }") -lt $(numeric "$HOMEBREW_MINIMUM_GIT_VERSION") ]] + then + HOMEBREW_FORCE_BREWED_GIT="1" + fi + CACHE_HOME="${XDG_CACHE_HOME:-${HOME}/.cache}" HOMEBREW_CACHE="${HOMEBREW_CACHE:-${CACHE_HOME}/Homebrew}" HOMEBREW_SYSTEM_TEMP="/tmp" @@ -153,8 +178,9 @@ else fi HOMEBREW_USER_AGENT="$HOMEBREW_PRODUCT/$HOMEBREW_USER_AGENT_VERSION ($HOMEBREW_SYSTEM; $HOMEBREW_PROCESSOR $HOMEBREW_OS_USER_AGENT_VERSION)" -HOMEBREW_CURL_VERSION="$("$HOMEBREW_CURL" --version 2>/dev/null | head -n1 | awk '{print $1"/"$2}')" -HOMEBREW_USER_AGENT_CURL="$HOMEBREW_USER_AGENT $HOMEBREW_CURL_VERSION" +curl_version_output="$("$HOMEBREW_CURL" --version 2>/dev/null)" +curl_name_and_version="${curl_version_output%% (*}" +HOMEBREW_USER_AGENT_CURL="$HOMEBREW_USER_AGENT ${curl_name_and_version// //}" # Declared in bin/brew export HOMEBREW_BREW_FILE From 0362e66a2620cf18eeff68b3f53e84051fdadebf Mon Sep 17 00:00:00 2001 From: EricFromCanada Date: Sat, 27 Oct 2018 20:44:13 -0400 Subject: [PATCH 5/5] doctor: use minimum Git version set in brew.sh --- Library/Homebrew/brew.sh | 4 +++- Library/Homebrew/diagnostic.rb | 3 +-- Library/Homebrew/system_config.rb | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 2f729b733e..003e19a32d 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -105,7 +105,8 @@ then HOMEBREW_FORCE_BREWED_CURL="1" fi - # The system Git is too old for some Homebrew functionality we rely on. + # The system Git on macOS versions before Sierra is too old for some Homebrew functionality we rely on. + HOMEBREW_MINIMUM_GIT_VERSION="2.14.3" if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -lt "101200" ]] then HOMEBREW_FORCE_BREWED_GIT="1" @@ -198,6 +199,7 @@ export HOMEBREW_SYSTEM export HOMEBREW_CURL export HOMEBREW_SYSTEM_CURL_TOO_OLD export HOMEBREW_GIT +export HOMEBREW_MINIMUM_GIT_VERSION export HOMEBREW_PROCESSOR export HOMEBREW_PRODUCT export HOMEBREW_OS_VERSION diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 7f84168060..55df9aca8c 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -489,8 +489,7 @@ module Homebrew end def check_git_version - # System Git version on macOS Sierra. - minimum_version = "2.14.3".freeze + minimum_version = ENV["HOMEBREW_MINIMUM_GIT_VERSION"].freeze return unless Utils.git_available? return if Version.create(Utils.git_version) >= Version.create(minimum_version) diff --git a/Library/Homebrew/system_config.rb b/Library/Homebrew/system_config.rb index e6a387cdbd..f5ed7bd37c 100644 --- a/Library/Homebrew/system_config.rb +++ b/Library/Homebrew/system_config.rb @@ -141,6 +141,7 @@ class SystemConfig HOMEBREW_LIBRARY HOMEBREW_MACOS_VERSION HOMEBREW_MACOS_VERSION_NUMERIC + HOMEBREW_MINIMUM_GIT_VERSION HOMEBREW_RUBY_PATH HOMEBREW_SYSTEM HOMEBREW_SYSTEM_TEMP