3 require File.dirname(__FILE__) + '/../lib/git'
5 class Test::Unit::TestCase
9 if File.directory?(File.join(cwd, 'files'))
10 @test_dir = File.join(cwd, 'files')
11 elsif File.directory?(File.join(cwd, '..', 'files'))
12 @test_dir = File.join(cwd, '..', 'files')
13 elsif File.directory?(File.join(cwd, 'tests', 'files'))
14 @test_dir = File.join(cwd, 'tests', 'files')
17 @wdir_dot = File.expand_path(File.join(@test_dir, 'working'))
18 @wbare = File.expand_path(File.join(@test_dir, 'working.git'))
19 @index = File.expand_path(File.join(@test_dir, 'index'))
21 @wdir = create_temp_repo(@wdir_dot)
26 #puts "teardown #{@tmp_path}"
27 FileUtils.rm_r(@tmp_path)
31 def create_temp_repo(clone_path)
32 filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
33 @tmp_path = File.join("/tmp/", filename)
34 FileUtils.mkdir_p(@tmp_path)
35 FileUtils.cp_r(clone_path, @tmp_path)
36 tmp_path = File.join(@tmp_path, 'working')
37 Dir.chdir(tmp_path) do
38 FileUtils.mv('dot_git', '.git')
43 def in_temp_dir(remove_after = true)
44 filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
45 tmp_path = File.join("/tmp/", filename)
46 FileUtils.mkdir(tmp_path)
50 FileUtils.rm_r(tmp_path) if remove_after
54 def new_file(name, contents)
55 File.open(name, 'w') do |f|
60 def append_file(name, contents)
61 File.open(name, 'a') do |f|