@@ -9,34 +9,34 @@ def setup
9
9
@git = Git . open ( @wdir )
10
10
end
11
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
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
40
41
41
def test_revert
42
42
in_temp_dir do |path |
@@ -60,57 +60,81 @@ def test_revert
60
60
end
61
61
end
62
62
63
- # def test_add_array
64
- # in_temp_dir do |path|
65
- # g = Git.clone(@wbare, 'new')
66
- # Dir.chdir('new') do
67
-
68
- # new_file('test-file1', 'blahblahblah1')
69
- # new_file('test-file2', 'blahblahblah2')
70
- # assert(g.status.untracked.assoc('test-file1'))
71
-
72
- # g.add(['test-file1', 'test-file2'])
73
- # assert(g.status.added.assoc('test-file1'))
74
- # assert(g.status.added.assoc('test-file1'))
75
- # assert(!g.status.untracked.assoc('test-file1'))
76
-
77
- # g.commit('my message')
78
- # assert(!g.status.added.assoc('test-file1'))
79
- # assert(!g.status.untracked.assoc('test-file1'))
80
- # assert_equal('blahblahblah1', g.status['test-file1'].blob.contents)
81
- # end
82
- # end
83
- # end
84
-
85
- # def test_remove
86
- # in_temp_dir do |path|
87
- # g = Git.clone(@wbare, 'remove_test')
88
- # Dir.chdir('remove_test') do
89
- # assert(g.status['example.txt'])
90
- # g.remove('example.txt')
91
- # assert(g.status.deleted.assoc('example.txt'))
92
- # g.commit('deleted file')
93
- # assert(!g.status['example.txt'])
94
- # end
95
- # end
96
- # end
97
-
98
- # def test_reset
99
- # in_temp_dir do |path|
100
- # g = Git.clone(@wbare, 'reset_test')
101
- # Dir.chdir('reset_test') do
102
- # new_file('test-file1', 'blahblahblah1')
103
- # new_file('test-file2', 'blahblahblah2')
104
- # assert(g.status.untracked.assoc('test-file1'))
105
-
106
- # g.add(['test-file1', 'test-file2'])
107
- # assert(!g.status.untracked.assoc('test-file1'))
108
-
109
- # g.reset
110
- # assert(g.status.untracked.assoc('test-file1'))
111
- # assert(!g.status.added.assoc('test-file1'))
112
- # end
113
- # end
114
- # end
63
+ def test_clean
64
+ in_temp_dir do |path |
65
+ g = Git . clone ( @wbare , 'clean_me' )
66
+ Dir . chdir ( 'clean_me' ) do
67
+ new_file ( 'test-file' , 'blahblahbal' )
68
+ g . add
69
+ g . commit ( "first commit" )
70
+
71
+ new_file ( 'file-to-clean' , 'blablahbla' )
72
+ FileUtils . mkdir_p ( "dir_to_clean" )
73
+
74
+ Dir . chdir ( 'dir_to_clean' ) do
75
+ new_file ( 'clean-me-too' , 'blablahbla' )
76
+ end
77
+
78
+ assert ( File . exists? ( 'file-to-clean' ) )
79
+ assert ( File . exists? ( 'dir_to_clean' ) )
80
+ g . clean
81
+ assert ( !File . exists? ( 'file-to-clean' ) )
82
+ assert ( !File . exists? ( 'dir_to_clean' ) )
83
+ end
84
+ end
85
+ end
86
+
87
+ def test_add_array
88
+ in_temp_dir do |path |
89
+ g = Git . clone ( @wbare , 'new' )
90
+ Dir . chdir ( 'new' ) do
91
+
92
+ new_file ( 'test-file1' , 'blahblahblah1' )
93
+ new_file ( 'test-file2' , 'blahblahblah2' )
94
+ assert ( g . status . untracked . assoc ( 'test-file1' ) )
95
+
96
+ g . add ( [ 'test-file1' , 'test-file2' ] )
97
+ assert ( g . status . added . assoc ( 'test-file1' ) )
98
+ assert ( g . status . added . assoc ( 'test-file1' ) )
99
+ assert ( !g . status . untracked . assoc ( 'test-file1' ) )
100
+
101
+ g . commit ( 'my message' )
102
+ assert ( !g . status . added . assoc ( 'test-file1' ) )
103
+ assert ( !g . status . untracked . assoc ( 'test-file1' ) )
104
+ assert_equal ( 'blahblahblah1' , g . status [ 'test-file1' ] . blob . contents )
105
+ end
106
+ end
107
+ end
108
+
109
+ def test_remove
110
+ in_temp_dir do |path |
111
+ g = Git . clone ( @wbare , 'remove_test' )
112
+ Dir . chdir ( 'remove_test' ) do
113
+ assert ( g . status [ 'example.txt' ] )
114
+ g . remove ( 'example.txt' )
115
+ assert ( g . status . deleted . assoc ( 'example.txt' ) )
116
+ g . commit ( 'deleted file' )
117
+ assert ( !g . status [ 'example.txt' ] )
118
+ end
119
+ end
120
+ end
121
+
122
+ def test_reset
123
+ in_temp_dir do |path |
124
+ g = Git . clone ( @wbare , 'reset_test' )
125
+ Dir . chdir ( 'reset_test' ) do
126
+ new_file ( 'test-file1' , 'blahblahblah1' )
127
+ new_file ( 'test-file2' , 'blahblahblah2' )
128
+ assert ( g . status . untracked . assoc ( 'test-file1' ) )
129
+
130
+ g . add ( [ 'test-file1' , 'test-file2' ] )
131
+ assert ( !g . status . untracked . assoc ( 'test-file1' ) )
132
+
133
+ g . reset
134
+ assert ( g . status . untracked . assoc ( 'test-file1' ) )
135
+ assert ( !g . status . added . assoc ( 'test-file1' ) )
136
+ end
137
+ end
138
+ end
115
139
116
140
end
0 commit comments