update: show message prompting brew tap --repair

This message is shown when a fetch fails due to a branch rename
This commit is contained in:
Rylan Polster 2021-01-28 01:51:40 -05:00
parent 4bdc11ddc9
commit f508f8dc0c
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
6 changed files with 43 additions and 5 deletions

View File

@ -144,6 +144,19 @@ module Homebrew
link_completions_manpages_and_docs
Tap.each(&:link_completions_and_manpages)
failed_fetch_dirs = ENV["HOMEBREW_FAILED_FETCH_DIRS"]&.split("\n")
if failed_fetch_dirs.present?
failed_fetch_taps = failed_fetch_dirs.map { |dir| Tap.from_path(dir) }
puts Formatter.headline "Some taps failed to update!", color: :red
puts <<~EOS
The following taps can not read their remote branches:
#{failed_fetch_taps.join("\n ")}
This may be happening because the remote branch was renamed.
Reset taps to point to the correct remote branches by running `brew tap --repair`
EOS
end
return if new_repository_version.blank?
ohai "Homebrew was updated to version #{new_repository_version}"

View File

@ -1,6 +1,6 @@
#: * `update-reset` [<repository> ...]
#:
#: Fetch and reset Homebrew and all tap repositories (or any specified <repository>) using `git`(1) to their latest `origin/master`.
#: Fetch and reset Homebrew and all tap repositories (or any specified <repository>) using `git`(1) to their latest `origin/HEAD`.
#:
#: *Note:* this will destroy all your uncommitted or committed changes.

View File

@ -483,7 +483,9 @@ EOS
trap '{ /usr/bin/pkill -P $$; wait; exit 130; }' SIGINT
local update_failed_file="$HOMEBREW_REPOSITORY/.git/UPDATE_FAILED"
local failed_fetch_dirs_file="$HOMEBREW_REPOSITORY/.git/FAILED_FETCH_DIRS"
rm -f "$update_failed_file"
rm -f "$failed_fetch_dirs_file"
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
do
@ -566,23 +568,38 @@ EOS
echo "Fetching $DIR..."
fi
local tmp_failure_file="$HOMEBREW_REPOSITORY/.git/TMP_FETCH_FAILURES"
rm -f "$tmp_failure_file"
if [[ -n "$HOMEBREW_UPDATE_PREINSTALL" ]]
then
git fetch --tags --force "${QUIET_ARGS[@]}" origin \
"refs/heads/$UPSTREAM_BRANCH_DIR:refs/remotes/origin/$UPSTREAM_BRANCH_DIR" 2>/dev/null
else
# Capture stderr to tmp_failure_file
if ! git fetch --tags --force "${QUIET_ARGS[@]}" origin \
"refs/heads/$UPSTREAM_BRANCH_DIR:refs/remotes/origin/$UPSTREAM_BRANCH_DIR"
"refs/heads/$UPSTREAM_BRANCH_DIR:refs/remotes/origin/$UPSTREAM_BRANCH_DIR" 2>>"$tmp_failure_file"
then
# Reprint fetch errors to stderr
[[ -f "$tmp_failure_file" ]] && cat "$tmp_failure_file" 1>&2
if [[ "$UPSTREAM_SHA_HTTP_CODE" = "404" ]]
then
TAP="${DIR#$HOMEBREW_LIBRARY/Taps/}"
echo "$TAP does not exist! Run \`brew untap $TAP\` to remove it." >>"$update_failed_file"
else
echo "Fetching $DIR failed!" >>"$update_failed_file"
if [[ -f "$tmp_failure_file" ]] &&
[[ "$(<"$tmp_failure_file")" = "fatal: couldn't find remote ref refs/heads/$UPSTREAM_BRANCH_DIR" ]]
then
echo "$DIR" >>"$failed_fetch_dirs_file"
fi
fi
fi
fi
rm -f "$tmp_failure_file"
) &
done
@ -596,6 +613,13 @@ EOS
export HOMEBREW_UPDATE_FAILED="1"
fi
if [[ -f "$failed_fetch_dirs_file" ]]
then
HOMEBREW_FAILED_FETCH_DIRS="$(<"$failed_fetch_dirs_file")"
rm -f "$failed_fetch_dirs_file"
export HOMEBREW_FAILED_FETCH_DIRS
fi
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
do
[[ -d "$DIR/.git" ]] || continue
@ -629,6 +653,7 @@ EOS
if [[ -n "$HOMEBREW_UPDATED" ||
-n "$HOMEBREW_UPDATE_FAILED" ||
-n "$HOMEBREW_FAILED_FETCH_DIRS" ||
-n "$HOMEBREW_UPDATE_FORCE" ||
-d "$HOMEBREW_LIBRARY/LinkedKegs" ||
! -f "$HOMEBREW_CACHE/all_commands_list.txt" ||

View File

@ -217,7 +217,7 @@ __brew_internal_commands() {
'update-license-data:Update SPDX license data in the Homebrew repository'
'update-python-resources:Update versions for PyPI resource blocks in formula'
'update-report:The Ruby implementation of `brew update`'
'update-reset:Fetch and reset Homebrew and all tap repositories (or any specified repository) using `git`(1) to their latest `origin/master`'
'update-reset:Fetch and reset Homebrew and all tap repositories (or any specified repository) using `git`(1) to their latest `origin/HEAD`'
'update-test:Run a test of `brew update` with a new repository clone'
'upgrade:Upgrade outdated casks and outdated, unpinned formulae using the same options they were originally installed with, plus any appended brew formula options'
'uses:Show formulae and casks that specify formula as a dependency; that is, show dependents of formula'

View File

@ -607,7 +607,7 @@ Fetch the newest version of Homebrew and all formulae from GitHub using `git`(1)
### `update-reset` [*`repository`* ...]
Fetch and reset Homebrew and all tap repositories (or any specified *`repository`*) using `git`(1) to their latest `origin/master`.
Fetch and reset Homebrew and all tap repositories (or any specified *`repository`*) using `git`(1) to their latest `origin/HEAD`.
*Note:* this will destroy all your uncommitted or committed changes.

View File

@ -812,7 +812,7 @@ Run on auto\-updates (e\.g\. before \fBbrew install\fR)\. Skips some slower step
Always do a slower, full update check (even if unnecessary)\.
.
.SS "\fBupdate\-reset\fR [\fIrepository\fR \.\.\.]"
Fetch and reset Homebrew and all tap repositories (or any specified \fIrepository\fR) using \fBgit\fR(1) to their latest \fBorigin/master\fR\.
Fetch and reset Homebrew and all tap repositories (or any specified \fIrepository\fR) using \fBgit\fR(1) to their latest \fBorigin/HEAD\fR\.
.
.P
\fINote:\fR this will destroy all your uncommitted or committed changes\.