Skip to content

Commit

Permalink
tap: allow to change tap remote with brew tap --force
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan committed Oct 11, 2021
1 parent f12346e commit 7be2a95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Library/Homebrew/cmd/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def tap_args
switch "--force-auto-update",
description: "Auto-update tap even if it is not hosted on GitHub. By default, only taps "\
"hosted on GitHub are auto-updated (for performance reasons)."
switch "--force",
description: "Force tap even if it is already tapped. Useful for retapping with a new Git remote."
switch "--custom-remote",
description: "Force tap even if it is already installed. Useful for retapping with a new custom Git remote."
switch "--repair",
description: "Migrate tapped formulae from symlink-based to directory-based structure."
switch "--list-pinned",
Expand Down Expand Up @@ -66,7 +66,7 @@ def tap
begin
tap.install clone_target: args.named.second,
force_auto_update: force_auto_update?(args: args),
force: args.force?,
custom_remote: args.custom_remote?,
quiet: args.quiet?
rescue TapRemoteMismatchError => e
odie e
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def core_tap?
# @param force_auto_update [Boolean, nil] If present, whether to override the
# logic that skips non-GitHub repositories during auto-updates.
# @param quiet [Boolean] If set, suppress all output.
# @param force [Boolean] If set, reset the tap's remote if already installed.
def install(quiet: false, clone_target: nil, force_auto_update: nil, force: false)
# @param custom_remote [Boolean] If set, reset the tap's remote if already installed.
def install(quiet: false, clone_target: nil, force_auto_update: nil, custom_remote: false)
require "descriptions"
require "readall"

Expand All @@ -260,7 +260,7 @@ def install(quiet: false, clone_target: nil, force_auto_update: nil, force: fals

requested_remote = clone_target || default_remote

if installed? && !force
if installed? && !custom_remote
raise TapRemoteMismatchError.new(name, @remote, requested_remote) if clone_target && requested_remote != remote
raise TapAlreadyTappedError, name if force_auto_update.nil? && !shallow?
end
Expand All @@ -269,7 +269,7 @@ def install(quiet: false, clone_target: nil, force_auto_update: nil, force: fals
Utils::Git.ensure_installed!

if installed?
if clone_target && requested_remote != remote # we are sure that `force: true` here
if clone_target && requested_remote != remote # we are sure that `custom_remote: true` here
path.cd do
safe_system "git", "remote", "set-url", "origin", requested_remote
safe_system "git", "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"
Expand Down

0 comments on commit 7be2a95

Please sign in to comment.