git add working, git status object working
[rubygit.git] / tests / units / test_index.rb
blobcf20eafe87dc9e2c5bf95c75a52a00798d4c530f
1 #!/usr/bin/env ruby
3 require File.dirname(__FILE__) + '/../test_helper'
5 class TestIndex< Test::Unit::TestCase
6   
7   def setup
8     set_file_paths
9     @git = Git.open(@wdir)
10   end
11   
12   def test_add
13     in_temp_dir do |path|
14       #puts path
15       g = Git.clone(@wbare, 'new')
16       Dir.chdir('new') do
17         assert_equal('100644', g.status['example.txt'].mode_index)
18         new_file('test-file', 'blahblahblah')
19         assert(g.status.untracked.assoc('test-file'))
20         g.add
21         assert(g.status.added.assoc('test-file'))
22         assert(!g.status.untracked.assoc('test-file'))
23         assert(!g.status.changed.assoc('example.txt'))
24         append_file('example.txt', 'hahahaha')
25         assert(g.status.changed.assoc('example.txt'))
26         g.add
27         assert(g.status.changed.assoc('example.txt'))
28         g.commit('my message')
29         assert(!g.status.changed.assoc('example.txt'))
30         assert(!g.status.added.assoc('test-file'))
31         assert(!g.status.untracked.assoc('test-file'))        
32       end
33     end
34   end
35   
36   def new_file(name, contents)
37     File.open(name, 'w') do |f|
38       f.puts contents
39     end
40   end
42   def append_file(name, contents)
43     File.open(name, 'a') do |f|
44       f.puts contents
45     end
46   end
47   
48 end