Merge pull request #10423 from Rylan12/rename-branches
Handle upstream branch renames
This commit is contained in:
commit
db6f65ddc0
@ -50,6 +50,7 @@ module Homebrew
|
|||||||
|
|
||||||
if args.repair?
|
if args.repair?
|
||||||
Tap.each(&:link_completions_and_manpages)
|
Tap.each(&:link_completions_and_manpages)
|
||||||
|
Tap.each(&:fix_remote_configuration)
|
||||||
elsif args.list_pinned?
|
elsif args.list_pinned?
|
||||||
puts Tap.select(&:pinned?).map(&:name)
|
puts Tap.select(&:pinned?).map(&:name)
|
||||||
elsif args.no_named?
|
elsif args.no_named?
|
||||||
|
|||||||
@ -144,6 +144,19 @@ module Homebrew
|
|||||||
link_completions_manpages_and_docs
|
link_completions_manpages_and_docs
|
||||||
Tap.each(&:link_completions_and_manpages)
|
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 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_repository_version.blank?
|
return if new_repository_version.blank?
|
||||||
|
|
||||||
ohai "Homebrew was updated to version #{new_repository_version}"
|
ohai "Homebrew was updated to version #{new_repository_version}"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#: * `update-reset` [<repository> ...]
|
#: * `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.
|
#: *Note:* this will destroy all your uncommitted or committed changes.
|
||||||
|
|
||||||
|
|||||||
@ -483,7 +483,9 @@ EOS
|
|||||||
trap '{ /usr/bin/pkill -P $$; wait; exit 130; }' SIGINT
|
trap '{ /usr/bin/pkill -P $$; wait; exit 130; }' SIGINT
|
||||||
|
|
||||||
local update_failed_file="$HOMEBREW_REPOSITORY/.git/UPDATE_FAILED"
|
local update_failed_file="$HOMEBREW_REPOSITORY/.git/UPDATE_FAILED"
|
||||||
|
local missing_remote_ref_dirs_file="$HOMEBREW_REPOSITORY/.git/FAILED_FETCH_DIRS"
|
||||||
rm -f "$update_failed_file"
|
rm -f "$update_failed_file"
|
||||||
|
rm -f "$missing_remote_ref_dirs_file"
|
||||||
|
|
||||||
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
|
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
|
||||||
do
|
do
|
||||||
@ -566,23 +568,38 @@ EOS
|
|||||||
echo "Fetching $DIR..."
|
echo "Fetching $DIR..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local tmp_failure_file="$HOMEBREW_REPOSITORY/.git/TMP_FETCH_FAILURES"
|
||||||
|
rm -f "$tmp_failure_file"
|
||||||
|
|
||||||
if [[ -n "$HOMEBREW_UPDATE_PREINSTALL" ]]
|
if [[ -n "$HOMEBREW_UPDATE_PREINSTALL" ]]
|
||||||
then
|
then
|
||||||
git fetch --tags --force "${QUIET_ARGS[@]}" origin \
|
git fetch --tags --force "${QUIET_ARGS[@]}" origin \
|
||||||
"refs/heads/$UPSTREAM_BRANCH_DIR:refs/remotes/origin/$UPSTREAM_BRANCH_DIR" 2>/dev/null
|
"refs/heads/$UPSTREAM_BRANCH_DIR:refs/remotes/origin/$UPSTREAM_BRANCH_DIR" 2>/dev/null
|
||||||
else
|
else
|
||||||
|
# Capture stderr to tmp_failure_file
|
||||||
if ! git fetch --tags --force "${QUIET_ARGS[@]}" origin \
|
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
|
then
|
||||||
|
# Reprint fetch errors to stderr
|
||||||
|
[[ -f "$tmp_failure_file" ]] && cat "$tmp_failure_file" 1>&2
|
||||||
|
|
||||||
if [[ "$UPSTREAM_SHA_HTTP_CODE" = "404" ]]
|
if [[ "$UPSTREAM_SHA_HTTP_CODE" = "404" ]]
|
||||||
then
|
then
|
||||||
TAP="${DIR#$HOMEBREW_LIBRARY/Taps/}"
|
TAP="${DIR#$HOMEBREW_LIBRARY/Taps/}"
|
||||||
echo "$TAP does not exist! Run \`brew untap $TAP\` to remove it." >>"$update_failed_file"
|
echo "$TAP does not exist! Run \`brew untap $TAP\` to remove it." >>"$update_failed_file"
|
||||||
else
|
else
|
||||||
echo "Fetching $DIR failed!" >>"$update_failed_file"
|
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" >>"$missing_remote_ref_dirs_file"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f "$tmp_failure_file"
|
||||||
) &
|
) &
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -596,6 +613,13 @@ EOS
|
|||||||
export HOMEBREW_UPDATE_FAILED="1"
|
export HOMEBREW_UPDATE_FAILED="1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -f "$missing_remote_ref_dirs_file" ]]
|
||||||
|
then
|
||||||
|
HOMEBREW_MISSING_REMOTE_REF_DIRS="$(<"$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/*/*
|
for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
|
||||||
do
|
do
|
||||||
[[ -d "$DIR/.git" ]] || continue
|
[[ -d "$DIR/.git" ]] || continue
|
||||||
@ -629,6 +653,7 @@ EOS
|
|||||||
|
|
||||||
if [[ -n "$HOMEBREW_UPDATED" ||
|
if [[ -n "$HOMEBREW_UPDATED" ||
|
||||||
-n "$HOMEBREW_UPDATE_FAILED" ||
|
-n "$HOMEBREW_UPDATE_FAILED" ||
|
||||||
|
-n "$HOMEBREW_FAILED_FETCH_DIRS" ||
|
||||||
-n "$HOMEBREW_UPDATE_FORCE" ||
|
-n "$HOMEBREW_UPDATE_FORCE" ||
|
||||||
-d "$HOMEBREW_LIBRARY/LinkedKegs" ||
|
-d "$HOMEBREW_LIBRARY/LinkedKegs" ||
|
||||||
! -f "$HOMEBREW_CACHE/all_commands_list.txt" ||
|
! -f "$HOMEBREW_CACHE/all_commands_list.txt" ||
|
||||||
|
|||||||
@ -54,6 +54,18 @@ module GitRepositoryExtension
|
|||||||
popen_git("rev-parse", "--abbrev-ref", "HEAD", safe: safe)
|
popen_git("rev-parse", "--abbrev-ref", "HEAD", safe: safe)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Change the name of a local branch
|
||||||
|
sig { params(old: String, new: String).void }
|
||||||
|
def git_rename_branch(old:, new:)
|
||||||
|
popen_git("branch", "-m", old, new)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Set an upstream branch for a local branch to track
|
||||||
|
sig { params(local: String, origin: String).void }
|
||||||
|
def git_branch_set_upstream(local:, origin:)
|
||||||
|
popen_git("branch", "-u", "origin/#{origin}", local)
|
||||||
|
end
|
||||||
|
|
||||||
# Gets the name of the default origin HEAD branch.
|
# Gets the name of the default origin HEAD branch.
|
||||||
sig { returns(T.nilable(String)) }
|
sig { returns(T.nilable(String)) }
|
||||||
def git_origin_branch
|
def git_origin_branch
|
||||||
@ -72,6 +84,17 @@ module GitRepositoryExtension
|
|||||||
popen_git("show", "-s", "--format=%cd", "--date=short", "HEAD")
|
popen_git("show", "-s", "--format=%cd", "--date=short", "HEAD")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns true if the given branch exists on origin
|
||||||
|
sig { params(branch: String).returns(T::Boolean) }
|
||||||
|
def git_origin_has_branch?(branch)
|
||||||
|
popen_git("ls-remote", "--heads", "origin", branch).present?
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
|
def git_origin_set_head_auto
|
||||||
|
popen_git("remote", "set-head", "origin", "--auto")
|
||||||
|
end
|
||||||
|
|
||||||
# Gets the full commit message of the specified commit, or of the HEAD commit if unspecified.
|
# Gets the full commit message of the specified commit, or of the HEAD commit if unspecified.
|
||||||
sig { params(commit: String, safe: T::Boolean).returns(T.nilable(String)) }
|
sig { params(commit: String, safe: T::Boolean).returns(T.nilable(String)) }
|
||||||
def git_commit_message(commit = "HEAD", safe: false)
|
def git_commit_message(commit = "HEAD", safe: false)
|
||||||
|
|||||||
@ -362,6 +362,22 @@ class Tap
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fix_remote_configuration
|
||||||
|
return unless remote.include? "github.com"
|
||||||
|
|
||||||
|
current_upstream_head = path.git_origin_branch
|
||||||
|
return if path.git_origin_has_branch? current_upstream_head
|
||||||
|
|
||||||
|
safe_system "git", "-C", path, "fetch", "origin"
|
||||||
|
path.git_origin_set_head_auto
|
||||||
|
|
||||||
|
new_upstream_head = path.git_origin_branch
|
||||||
|
path.git_rename_branch old: current_upstream_head, new: new_upstream_head
|
||||||
|
path.git_branch_set_upstream local: new_upstream_head, origin: new_upstream_head
|
||||||
|
|
||||||
|
ohai "#{name}: changed default branch name from #{current_upstream_head} to #{new_upstream_head}!"
|
||||||
|
end
|
||||||
|
|
||||||
# Uninstall this {Tap}.
|
# Uninstall this {Tap}.
|
||||||
def uninstall(manual: false)
|
def uninstall(manual: false)
|
||||||
require "descriptions"
|
require "descriptions"
|
||||||
|
|||||||
@ -217,7 +217,7 @@ __brew_internal_commands() {
|
|||||||
'update-license-data:Update SPDX license data in the Homebrew repository'
|
'update-license-data:Update SPDX license data in the Homebrew repository'
|
||||||
'update-python-resources:Update versions for PyPI resource blocks in formula'
|
'update-python-resources:Update versions for PyPI resource blocks in formula'
|
||||||
'update-report:The Ruby implementation of `brew update`'
|
'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'
|
'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'
|
'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'
|
'uses:Show formulae and casks that specify formula as a dependency; that is, show dependents of formula'
|
||||||
|
|||||||
@ -607,7 +607,7 @@ Fetch the newest version of Homebrew and all formulae from GitHub using `git`(1)
|
|||||||
|
|
||||||
### `update-reset` [*`repository`* ...]
|
### `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.
|
*Note:* this will destroy all your uncommitted or committed changes.
|
||||||
|
|
||||||
|
|||||||
@ -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)\.
|
Always do a slower, full update check (even if unnecessary)\.
|
||||||
.
|
.
|
||||||
.SS "\fBupdate\-reset\fR [\fIrepository\fR \.\.\.]"
|
.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
|
.P
|
||||||
\fINote:\fR this will destroy all your uncommitted or committed changes\.
|
\fINote:\fR this will destroy all your uncommitted or committed changes\.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user