Skip to content

Commit

Permalink
update: repair tap on missing remote ref
Browse files Browse the repository at this point in the history
- automatically run `brew tap --repair` when we detect it's needed
- don't pass list of taps to repair taps to update-report; no longer
  since update repairs them
  • Loading branch information
rrotter committed Feb 6, 2025
1 parent b9aed97 commit 88629f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
13 changes: 0 additions & 13 deletions Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,6 @@ def output_update_report
link_completions_manpages_and_docs
Tap.installed.each(&:link_completions_and_manpages)

failed_fetch_dirs = ENV["HOMEBREW_MISSING_REMOTE_REF_DIRS"]&.split("\n")
if failed_fetch_dirs.present?
failed_fetch_taps = failed_fetch_dirs.map { |dir| Tap.from_path(dir) }

ofail <<~EOS
Some taps failed to update!
The following taps can not read their remote branches:
#{failed_fetch_taps.join("\n ")}
This is happening because the remote branch was renamed or deleted.
Reset taps to point to the correct remote branches by running `brew tap --repair`
EOS
end

return if new_tag.blank? || new_tag == old_tag || args.quiet?

puts
Expand Down
17 changes: 14 additions & 3 deletions Library/Homebrew/cmd/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ EOS
}

fetch_tags() {
local retry=$1
local fail_silently="${HOMEBREW_UPDATE_AUTO}"

if [[ -n "${HOMEBREW_VERBOSE}" ]]
Expand All @@ -347,6 +348,7 @@ fetch_tags() {
then
# Looks like upstream HEAD branch has been renamed.
echo "${DIR}" >>"${missing_remote_ref_dirs_file}"
[[ -z "${retry}" ]] && fail_silently=1
fi

if [[ -z "${fail_silently}" ]]
Expand Down Expand Up @@ -764,9 +766,19 @@ EOS

if [[ -f "${missing_remote_ref_dirs_file}" ]]
then
HOMEBREW_MISSING_REMOTE_REF_DIRS="$(cat "${missing_remote_ref_dirs_file}")"
while IFS='' read -r DIR
do
brew tap --repair ${HOMEBREW_VERBOSE+--verbose} "${DIR#"${HOMEBREW_LIBRARY}"/Taps/}"

cd "${DIR}"
TAP_VAR="$(repository_var_suffix "${DIR}")"
UPSTREAM_BRANCH_DIR="$(upstream_branch)"
declare UPSTREAM_BRANCH"${TAP_VAR}"="${UPSTREAM_BRANCH_DIR}"

fetch_tags retry
done <"${missing_remote_ref_dirs_file}"

rm -f "${missing_remote_ref_dirs_file}"
export HOMEBREW_MISSING_REMOTE_REF_DIRS
fi

for DIR in "${HOMEBREW_REPOSITORY}" "${HOMEBREW_LIBRARY}"/Taps/*/*
Expand Down Expand Up @@ -914,7 +926,6 @@ EOS
# shellcheck disable=SC2031
if [[ -n "${HOMEBREW_UPDATED}" ]] ||
[[ -n "${HOMEBREW_UPDATE_FAILED}" ]] ||
[[ -n "${HOMEBREW_MISSING_REMOTE_REF_DIRS}" ]] ||
[[ -n "${HOMEBREW_UPDATE_FORCE}" ]] ||
[[ -n "${HOMEBREW_MIGRATE_LINUXBREW_FORMULAE}" ]] ||
[[ -d "${HOMEBREW_LIBRARY}/LinkedKegs" ]] ||
Expand Down

0 comments on commit 88629f9

Please sign in to comment.