1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../test_helper'
require 'stringio'
require 'logger'
class TestInit < Test::Unit::TestCase
def setup
set_file_paths
end
def test_open_simple
g = Git.open(@wdir)
assert_match(/^C?:?#{@wdir}$/, g.dir.path)
assert_match(/^C?:?#{File.join(@wdir, '.git')}$/, g.repo.path)
assert_match(/^C?:?#{File.join(@wdir, '.git', 'index')}$/, g.index.path)
end
def test_open_opts
g = Git.open @wdir, :repository => @wbare, :index => @index
assert_equal(g.repo.path, @wbare)
assert_equal(g.index.path, @index)
end
def test_git_bare
g = Git.bare @wbare
assert_equal(g.repo.path, @wbare)
end
#g = Git.init
# Git.init('project')
# Git.init('/home/schacon/proj',
# { :git_dir => '/opt/git/proj.git',
# :index_file => '/tmp/index'} )
def test_git_init
in_temp_dir do |path|
repo = Git.init(path)
assert(File.directory?(File.join(path, '.git')))
assert(File.exist?(File.join(path, '.git', 'config')))
assert_equal('false', repo.config('core.bare'))
branch = `git config --get init.defaultBranch`.strip
branch = 'master' if branch.empty?
assert_equal("ref: refs/heads/#{branch}\n", File.read("#{path}/.git/HEAD"))
end
end
def test_git_init_bare
in_temp_dir do |path|
repo = Git.init(path, :bare => true)
assert(File.exist?(File.join(path, 'config')))
assert_equal('true', repo.config('core.bare'))
end
end
def test_git_init_remote_git
in_temp_dir do |dir|
assert(!File.exist?(File.join(dir, 'config')))
in_temp_dir do |path|
Git.init(path, :repository => dir)
assert(File.exist?(File.join(dir, 'config')))
end
end
end
def test_git_init_initial_branch
in_temp_dir do |path|
repo = Git.init(path, initial_branch: 'main')
assert(File.directory?(File.join(path, '.git')))
assert(File.exist?(File.join(path, '.git', 'config')))
assert_equal('false', repo.config('core.bare'))
assert_equal("ref: refs/heads/main\n", File.read("#{path}/.git/HEAD"))
end
end
def test_git_clone
in_temp_dir do |path|
g = Git.clone(@wbare, 'bare-co')
assert(File.exist?(File.join(g.repo.path, 'config')))
assert(g.dir)
end
end
def test_git_clone_with_branch
in_temp_dir do |path|
g = Git.clone(@wbare, 'clone-branch', :branch => 'test')
assert_equal(g.current_branch, 'test')
end
end
def test_git_clone_bare
in_temp_dir do |path|
g = Git.clone(@wbare, 'bare.git', :bare => true)
assert(File.exist?(File.join(g.repo.path, 'config')))
assert_nil(g.dir)
end
end
def test_git_clone_mirror
in_temp_dir do |path|
g = Git.clone(@wbare, 'bare.git', :mirror => true)
assert(File.exist?(File.join(g.repo.path, 'config')))
assert_nil(g.dir)
end
end
def test_git_clone_config
in_temp_dir do |path|
g = Git.clone(@wbare, 'config.git', :config => "receive.denyCurrentBranch=ignore")
assert_equal('ignore', g.config['receive.denycurrentbranch'])
assert(File.exist?(File.join(g.repo.path, 'config')))
assert(g.dir)
end
end
# If the :log option is not passed to Git.clone, the result should not
# have a logger
#
def test_git_clone_without_log
in_temp_dir do |path|
g = Git.clone(@wbare, 'bare-co')
actual_logger = g.instance_variable_get(:@logger)
assert_equal(nil, actual_logger)
end
end
# If the :log option is passed to Git.clone, the result should have
# a logger set to the value of :log
#
def test_git_clone_log
log_io = StringIO.new
expected_logger = Logger.new(log_io)
in_temp_dir do |path|
g = Git.clone(@wbare, 'bare-co', { log: expected_logger })
actual_logger = g.instance_variable_get(:@logger)
assert_equal(expected_logger.object_id, actual_logger.object_id)
# Ensure that both the clone and Git::Base creation are logged to the logger
#
assert_includes(log_io.string, "Cloning into 'bare-co'...")
assert_includes(log_io.string, 'Starting Git')
end
end
# trying to open a git project using a bare repo - rather than using Git.repo
def test_git_open_error
assert_raise ArgumentError do
Git.open @wbare
end
end
end
|