4 require File.dirname(__FILE__) + '/../lib/git'
6 class Test::Unit::TestCase
10 if File.directory?(File.join(cwd, 'files'))
11 @test_dir = File.join(cwd, 'files')
12 elsif File.directory?(File.join(cwd, '..', 'files'))
13 @test_dir = File.join(cwd, '..', 'files')
14 elsif File.directory?(File.join(cwd, 'tests', 'files'))
15 @test_dir = File.join(cwd, 'tests', 'files')
18 @wdir_dot = File.expand_path(File.join(@test_dir, 'working'))
19 @wbare = File.expand_path(File.join(@test_dir, 'working.git'))
20 @index = File.expand_path(File.join(@test_dir, 'index'))
22 @wdir = create_temp_repo(@wdir_dot)
27 #puts "teardown #{@tmp_path}"
28 FileUtils.rm_r(@tmp_path)
35 g = Git.clone(@wbare, 'new')
42 def create_temp_repo(clone_path)
43 filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
44 @tmp_path = File.join("/tmp/", filename)
45 FileUtils.mkdir_p(@tmp_path)
46 FileUtils.cp_r(clone_path, @tmp_path)
47 tmp_path = File.join(@tmp_path, 'working')
48 Dir.chdir(tmp_path) do
49 FileUtils.mv('dot_git', '.git')
54 def in_temp_dir(remove_after = true)
55 filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
56 tmp_path = File.join("/tmp/", filename)
57 FileUtils.mkdir(tmp_path)
61 FileUtils.rm_r(tmp_path) if remove_after
65 def new_file(name, contents)
66 File.open(name, 'w') do |f|
71 def append_file(name, contents)
72 File.open(name, 'a') do |f|