class Gem::TestCase

def git_gem name = 'a', version = 1

def git_gem name = 'a', version = 1
  have_git?
  directory = File.join 'git', name
  directory = File.expand_path directory
  git_spec = Gem::Specification.new name, version do |specification|
    yield specification if block_given?
  end
  FileUtils.mkdir_p directory
  gemspec = "#{name}.gemspec"
  open File.join(directory, gemspec), 'w' do |io|
    io.write git_spec.to_ruby
  end
  head = nil
  Dir.chdir directory do
    unless File.exist? '.git' then
      system @git, 'init', '--quiet'
      system @git, 'config', 'user.name',  'RubyGems Tests'
      system @git, 'config', 'user.email', 'rubygems@example'
    end
    system @git, 'add', gemspec
    system @git, 'commit', '-a', '-m', 'a non-empty commit message', '--quiet'
    head = Gem::Util.popen('git', 'rev-parse', 'master').strip
  end
  return name, git_spec.version, directory, head
end