Tap#install: better TapRemoteMismatchError check

* remote check requires `git` installed.
* Do not perform check if user does not passing remote explicitly.

Fixes #108
This commit is contained in:
Xu Cheng 2016-04-19 15:18:54 +08:00
parent 9b79f45e94
commit 71b6e0aa18
2 changed files with 6 additions and 2 deletions

View File

@ -188,7 +188,6 @@ class Tap
requested_remote = options[:clone_target] || "https://github.com/#{user}/homebrew-#{repo}" requested_remote = options[:clone_target] || "https://github.com/#{user}/homebrew-#{repo}"
if installed? if installed?
raise TapRemoteMismatchError.new(name, @remote, requested_remote) unless remote == requested_remote
raise TapAlreadyTappedError, name unless full_clone raise TapAlreadyTappedError, name unless full_clone
raise TapAlreadyUnshallowError, name unless shallow? raise TapAlreadyUnshallowError, name unless shallow?
end end
@ -197,6 +196,10 @@ class Tap
Utils.ensure_git_installed! Utils.ensure_git_installed!
if installed? if installed?
if options[:clone_target] && requested_remote != remote
raise TapRemoteMismatchError.new(name, @remote, requested_remote)
end
ohai "Unshallowing #{name}" unless quiet ohai "Unshallowing #{name}" unless quiet
args = %W[fetch --unshallow] args = %W[fetch --unshallow]
args << "-q" if quiet args << "-q" if quiet

View File

@ -181,9 +181,10 @@ class TapTest < Homebrew::TestCase
def test_install_tap_remote_mismatch_error def test_install_tap_remote_mismatch_error
setup_git_repo setup_git_repo
already_tapped_tap = Tap.new("Homebrew", "foo") already_tapped_tap = Tap.new("Homebrew", "foo")
touch @tap.path/".git/shallow"
assert_equal true, already_tapped_tap.installed? assert_equal true, already_tapped_tap.installed?
wrong_remote = "#{@tap.remote}-oops" wrong_remote = "#{@tap.remote}-oops"
assert_raises(TapRemoteMismatchError) { already_tapped_tap.install :clone_target => wrong_remote } assert_raises(TapRemoteMismatchError) { already_tapped_tap.install :clone_target => wrong_remote, :full_clone => true }
end end
def test_install_tap_already_unshallow_error def test_install_tap_already_unshallow_error