2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-11-18 19:34:13 -05:00
|
|
|
require 'rubygems/test_case'
|
|
|
|
require 'rubygems/source'
|
|
|
|
|
|
|
|
class TestGemSourceGit < Gem::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@name, @version, @repository, @head = git_gem
|
|
|
|
|
|
|
|
@hash = Digest::SHA1.hexdigest @repository
|
|
|
|
|
|
|
|
@source = Gem::Source::Git.new @name, @repository, 'master', false
|
|
|
|
end
|
|
|
|
|
2013-11-30 18:27:52 -05:00
|
|
|
def test_base_dir
|
|
|
|
assert_equal File.join(Gem.dir, 'bundler'), @source.base_dir
|
|
|
|
|
|
|
|
@source.root_dir = "#{@gemhome}2"
|
|
|
|
|
|
|
|
assert_equal File.join("#{@gemhome}2", 'bundler'), @source.base_dir
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def test_checkout
|
|
|
|
@source.checkout
|
|
|
|
|
|
|
|
assert_path_exists File.join @source.install_dir, 'a.gemspec'
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_checkout_master
|
|
|
|
Dir.chdir @repository do
|
|
|
|
system @git, 'checkout', '-q', '-b', 'other'
|
|
|
|
system @git, 'mv', 'a.gemspec', 'b.gemspec'
|
|
|
|
system @git, 'commit', '-q', '-a', '-m', 'rename gemspec'
|
|
|
|
system @git, 'checkout', '-q', 'master'
|
|
|
|
end
|
|
|
|
|
|
|
|
@source = Gem::Source::Git.new @name, @repository, 'other', false
|
|
|
|
|
|
|
|
@source.checkout
|
|
|
|
|
|
|
|
assert_path_exists File.join @source.install_dir, 'b.gemspec'
|
|
|
|
end
|
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
def test_checkout_local
|
|
|
|
@source.remote = false
|
|
|
|
|
|
|
|
@source.checkout
|
|
|
|
|
|
|
|
install_dir = File.join Gem.dir, 'bundler', 'gems', "a-#{@head[0..11]}"
|
|
|
|
|
|
|
|
refute_path_exists File.join install_dir, 'a.gemspec'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_checkout_local_cached
|
|
|
|
@source.cache
|
|
|
|
|
|
|
|
@source.remote = false
|
|
|
|
|
|
|
|
@source.checkout
|
|
|
|
|
|
|
|
assert_path_exists File.join @source.install_dir, 'a.gemspec'
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def test_checkout_submodules
|
|
|
|
source = Gem::Source::Git.new @name, @repository, 'master', true
|
|
|
|
|
|
|
|
git_gem 'b'
|
|
|
|
|
|
|
|
Dir.chdir 'git/a' do
|
2013-11-25 14:14:49 -05:00
|
|
|
Gem::Util.silent_system @git, 'submodule', '--quiet',
|
|
|
|
'add', File.expand_path('../b'), 'b'
|
2013-11-18 19:34:13 -05:00
|
|
|
system @git, 'commit', '--quiet', '-m', 'add submodule b'
|
|
|
|
end
|
|
|
|
|
|
|
|
source.checkout
|
|
|
|
|
|
|
|
assert_path_exists File.join source.install_dir, 'a.gemspec'
|
|
|
|
assert_path_exists File.join source.install_dir, 'b/b.gemspec'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cache
|
|
|
|
assert @source.cache
|
|
|
|
|
|
|
|
assert_path_exists @source.repo_cache_dir
|
|
|
|
|
|
|
|
Dir.chdir @source.repo_cache_dir do
|
|
|
|
assert_equal @head, Gem::Util.popen(@git, 'rev-parse', 'master').strip
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
def test_cache_local
|
|
|
|
@source.remote = false
|
|
|
|
|
|
|
|
@source.cache
|
|
|
|
|
|
|
|
refute_path_exists @source.repo_cache_dir
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def test_dir_shortref
|
|
|
|
@source.cache
|
|
|
|
|
|
|
|
assert_equal @head[0..11], @source.dir_shortref
|
|
|
|
end
|
|
|
|
|
2013-11-22 13:53:21 -05:00
|
|
|
def test_download
|
|
|
|
refute @source.download nil, nil
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def test_equals2
|
|
|
|
assert_equal @source, @source
|
|
|
|
|
|
|
|
assert_equal @source, @source.dup
|
|
|
|
|
|
|
|
source =
|
|
|
|
Gem::Source::Git.new @source.name, @source.repository, 'other', false
|
|
|
|
|
|
|
|
refute_equal @source, source
|
|
|
|
|
|
|
|
source =
|
|
|
|
Gem::Source::Git.new @source.name, 'repo/other', @source.reference, false
|
|
|
|
|
|
|
|
refute_equal @source, source
|
|
|
|
|
|
|
|
source =
|
|
|
|
Gem::Source::Git.new 'b', @source.repository, @source.reference, false
|
|
|
|
|
|
|
|
refute_equal @source, source
|
|
|
|
|
|
|
|
source =
|
|
|
|
Gem::Source::Git.new @source.name, @source.repository, @source.reference,
|
|
|
|
true
|
|
|
|
|
|
|
|
refute_equal @source, source
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_install_dir
|
|
|
|
@source.cache
|
|
|
|
|
|
|
|
expected = File.join Gem.dir, 'bundler', 'gems', "a-#{@head[0..11]}"
|
|
|
|
|
|
|
|
assert_equal expected, @source.install_dir
|
|
|
|
end
|
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
def test_install_dir_local
|
|
|
|
@source.remote = false
|
|
|
|
|
|
|
|
assert_nil @source.install_dir
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def test_repo_cache_dir
|
|
|
|
expected =
|
|
|
|
File.join Gem.dir, 'cache', 'bundler', 'git', "a-#{@hash}"
|
|
|
|
|
|
|
|
assert_equal expected, @source.repo_cache_dir
|
2013-11-30 18:27:52 -05:00
|
|
|
|
|
|
|
@source.root_dir = "#{@gemhome}2"
|
|
|
|
|
|
|
|
expected =
|
|
|
|
File.join "#{@gemhome}2", 'cache', 'bundler', 'git', "a-#{@hash}"
|
|
|
|
|
|
|
|
assert_equal expected, @source.repo_cache_dir
|
2013-11-18 19:34:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rev_parse
|
|
|
|
@source.cache
|
|
|
|
|
|
|
|
assert_equal @head, @source.rev_parse
|
|
|
|
|
|
|
|
Dir.chdir @repository do
|
|
|
|
system @git, 'checkout', '--quiet', '-b', 'other'
|
|
|
|
end
|
|
|
|
|
|
|
|
master_head = @head
|
|
|
|
|
|
|
|
git_gem 'a', 2
|
|
|
|
|
|
|
|
source = Gem::Source::Git.new @name, @repository, 'other', false
|
|
|
|
|
|
|
|
source.cache
|
|
|
|
|
|
|
|
refute_equal master_head, source.rev_parse
|
2014-10-01 04:30:21 -04:00
|
|
|
|
|
|
|
source = Gem::Source::Git.new @name, @repository, 'nonexistent', false
|
|
|
|
|
|
|
|
source.cache
|
|
|
|
|
|
|
|
e = assert_raises Gem::Exception do
|
2014-10-04 08:31:34 -04:00
|
|
|
capture_subprocess_io {source.rev_parse}
|
2014-10-01 04:30:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "unable to find reference nonexistent in #{@repository}",
|
|
|
|
e.message
|
2013-11-18 19:34:13 -05:00
|
|
|
end
|
|
|
|
|
2013-11-30 18:27:52 -05:00
|
|
|
def test_root_dir
|
|
|
|
assert_equal Gem.dir, @source.root_dir
|
|
|
|
|
|
|
|
@source.root_dir = "#{@gemhome}2"
|
|
|
|
|
|
|
|
assert_equal "#{@gemhome}2", @source.root_dir
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def test_spaceship
|
|
|
|
git = Gem::Source::Git.new 'a', 'git/a', 'master', false
|
|
|
|
remote = Gem::Source.new @gem_repo
|
|
|
|
installed = Gem::Source::Installed.new
|
2014-09-13 23:30:02 -04:00
|
|
|
vendor = Gem::Source::Vendor.new 'vendor/foo'
|
2013-11-18 19:34:13 -05:00
|
|
|
|
|
|
|
assert_equal( 0, git. <=>(git), 'git <=> git')
|
|
|
|
|
|
|
|
assert_equal( 1, git. <=>(remote), 'git <=> remote')
|
|
|
|
assert_equal(-1, remote. <=>(git), 'remote <=> git')
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
assert_equal( 1, git. <=>(installed), 'git <=> installed')
|
|
|
|
assert_equal(-1, installed.<=>(git), 'installed <=> git')
|
|
|
|
|
|
|
|
assert_equal(-1, git. <=>(vendor), 'git <=> vendor')
|
|
|
|
assert_equal( 1, vendor. <=>(git), 'vendor <=> git')
|
2013-11-18 19:34:13 -05:00
|
|
|
end
|
|
|
|
|
2013-11-21 18:27:30 -05:00
|
|
|
def test_specs
|
|
|
|
source = Gem::Source::Git.new @name, @repository, 'master', true
|
|
|
|
|
|
|
|
Dir.chdir 'git/a' do
|
|
|
|
FileUtils.mkdir 'b'
|
|
|
|
|
|
|
|
Dir.chdir 'b' do
|
|
|
|
b = Gem::Specification.new 'b', 1
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open 'b.gemspec', 'w' do |io|
|
2013-11-21 18:27:30 -05:00
|
|
|
io.write b.to_ruby
|
|
|
|
end
|
|
|
|
|
|
|
|
system @git, 'add', 'b.gemspec'
|
|
|
|
system @git, 'commit', '--quiet', '-m', 'add b/b.gemspec'
|
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.touch 'c.gemspec'
|
|
|
|
|
|
|
|
system @git, 'add', 'c.gemspec'
|
|
|
|
system @git, 'commit', '--quiet', '-m', 'add c.gemspec'
|
|
|
|
end
|
|
|
|
|
|
|
|
specs = nil
|
|
|
|
|
|
|
|
capture_io do
|
|
|
|
specs = source.specs
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal %w[a-1 b-1], specs.map { |spec| spec.full_name }
|
2013-11-25 14:14:49 -05:00
|
|
|
|
|
|
|
a_spec = specs.shift
|
|
|
|
|
2013-11-30 18:27:52 -05:00
|
|
|
base_dir = File.dirname File.dirname source.install_dir
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
assert_equal source.install_dir, a_spec.full_gem_path
|
2013-11-30 18:27:52 -05:00
|
|
|
assert_equal File.join(source.install_dir, 'a.gemspec'), a_spec.loaded_from
|
|
|
|
assert_equal base_dir, a_spec.base_dir
|
|
|
|
|
2013-12-10 14:54:19 -05:00
|
|
|
extension_dir =
|
2013-11-30 18:27:52 -05:00
|
|
|
File.join Gem.dir, 'bundler', 'extensions',
|
|
|
|
Gem::Platform.local.to_s, Gem.extension_api_version,
|
|
|
|
"a-#{source.dir_shortref}"
|
|
|
|
|
2013-12-10 14:54:19 -05:00
|
|
|
assert_equal extension_dir, a_spec.extension_dir
|
2013-11-25 14:14:49 -05:00
|
|
|
|
|
|
|
b_spec = specs.shift
|
|
|
|
|
|
|
|
assert_equal File.join(source.install_dir, 'b'), b_spec.full_gem_path
|
2013-11-30 18:27:52 -05:00
|
|
|
assert_equal File.join(source.install_dir, 'b', 'b.gemspec'),
|
|
|
|
b_spec.loaded_from
|
|
|
|
assert_equal base_dir, b_spec.base_dir
|
|
|
|
|
2013-12-10 14:54:19 -05:00
|
|
|
assert_equal extension_dir, b_spec.extension_dir
|
2013-11-21 18:27:30 -05:00
|
|
|
end
|
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
def test_specs_local
|
|
|
|
source = Gem::Source::Git.new @name, @repository, 'master', true
|
|
|
|
source.remote = false
|
|
|
|
|
|
|
|
capture_io do
|
|
|
|
assert_empty source.specs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_uri
|
|
|
|
assert_equal URI(@repository), @source.uri
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def test_uri_hash
|
|
|
|
assert_equal @hash, @source.uri_hash
|
|
|
|
|
|
|
|
source =
|
|
|
|
Gem::Source::Git.new 'a', 'http://git@example/repo.git', 'master', false
|
|
|
|
|
|
|
|
assert_equal '291c4caac7feba8bb64c297987028acb3dde6cfe',
|
|
|
|
source.uri_hash
|
|
|
|
|
|
|
|
source =
|
|
|
|
Gem::Source::Git.new 'a', 'HTTP://git@EXAMPLE/repo.git', 'master', false
|
|
|
|
|
|
|
|
assert_equal '291c4caac7feba8bb64c297987028acb3dde6cfe',
|
|
|
|
source.uri_hash
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|