added Matthias and Simon to credits for the gitrb code
[rubygit.git] / tests / units / test_index_ops.rb
blobdcd84984e0ec4dfb6642ca99b69d585bffa39030
1 #!/usr/bin/env ruby
3 require File.dirname(__FILE__) + '/../test_helper'
5 class TestIndexOps < 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       g = Git.clone(@wbare, 'new')
15       Dir.chdir('new') do
16         assert_equal('100644', g.status['example.txt'].mode_index)
17         
18         new_file('test-file', 'blahblahblah')
19         assert(g.status.untracked.assoc('test-file'))
20         
21         g.add
22         assert(g.status.added.assoc('test-file'))
23         assert(!g.status.untracked.assoc('test-file'))
24         assert(!g.status.changed.assoc('example.txt'))
25         
26         new_file('example.txt', 'hahahaha')
27         assert(g.status.changed.assoc('example.txt'))
28         
29         g.add
30         assert(g.status.changed.assoc('example.txt'))
31         
32         g.commit('my message')
33         assert(!g.status.changed.assoc('example.txt'))
34         assert(!g.status.added.assoc('test-file'))
35         assert(!g.status.untracked.assoc('test-file')) 
36         assert_equal('hahahaha', g.status['example.txt'].blob.contents)
37       end
38     end
39   end
40   
41   def test_add_array
42     in_temp_dir do |path|
43       g = Git.clone(@wbare, 'new')
44       Dir.chdir('new') do
45         
46         new_file('test-file1', 'blahblahblah1')
47         new_file('test-file2', 'blahblahblah2')
48         assert(g.status.untracked.assoc('test-file1'))
49         
50         g.add(['test-file1', 'test-file2'])
51         assert(g.status.added.assoc('test-file1'))
52         assert(g.status.added.assoc('test-file1'))
53         assert(!g.status.untracked.assoc('test-file1'))
54                 
55         g.commit('my message')
56         assert(!g.status.added.assoc('test-file1'))
57         assert(!g.status.untracked.assoc('test-file1')) 
58         assert_equal('blahblahblah1', g.status['test-file1'].blob.contents)
59       end
60     end
61   end
62   
63   def test_remove
64     in_temp_dir do |path|
65       g = Git.clone(@wbare, 'remove_test')
66       Dir.chdir('remove_test') do
67         assert(g.status['example.txt'])
68         g.remove('example.txt')
69         assert(g.status.deleted.assoc('example.txt')) 
70         g.commit('deleted file')
71         assert(!g.status['example.txt'])
72       end
73     end
74   end
75   
76   def test_reset
77     in_temp_dir do |path|
78       g = Git.clone(@wbare, 'reset_test')
79       Dir.chdir('reset_test') do
80         new_file('test-file1', 'blahblahblah1')
81         new_file('test-file2', 'blahblahblah2')
82         assert(g.status.untracked.assoc('test-file1'))
83         
84         g.add(['test-file1', 'test-file2'])
85         assert(!g.status.untracked.assoc('test-file1'))
86         
87         g.reset
88         assert(g.status.untracked.assoc('test-file1'))
89         assert(!g.status.added.assoc('test-file1'))
90       end
91     end
92   end
93   
94 end