3
3
require File . dirname ( __FILE__ ) + '/../test_helper'
4
4
5
5
class TestIndexOps < Test ::Unit ::TestCase
6
-
6
+
7
7
def setup
8
8
set_file_paths
9
9
@git = Git . open ( @wdir )
10
10
end
11
-
11
+
12
12
def test_add
13
13
in_temp_dir do |path |
14
14
g = Git . clone ( @wbare , 'new' )
15
15
Dir . chdir ( 'new' ) do
16
16
assert_equal ( '100644' , g . status [ 'example.txt' ] . mode_index )
17
-
17
+
18
18
new_file ( 'test-file' , 'blahblahblah' )
19
19
assert ( g . status . untracked . assoc ( 'test-file' ) )
20
-
20
+
21
21
g . add
22
22
assert ( g . status . added . assoc ( 'test-file' ) )
23
23
assert ( !g . status . untracked . assoc ( 'test-file' ) )
24
24
assert ( !g . status . changed . assoc ( 'example.txt' ) )
25
-
25
+
26
26
new_file ( 'example.txt' , 'hahahaha' )
27
27
assert ( g . status . changed . assoc ( 'example.txt' ) )
28
-
28
+
29
29
g . add
30
30
assert ( g . status . changed . assoc ( 'example.txt' ) )
31
-
31
+
32
32
g . commit ( 'my message' )
33
33
assert ( !g . status . changed . assoc ( 'example.txt' ) )
34
34
assert ( !g . status . added . assoc ( 'test-file' ) )
35
- assert ( !g . status . untracked . assoc ( 'test-file' ) )
35
+ assert ( !g . status . untracked . assoc ( 'test-file' ) )
36
36
assert_equal ( 'hahahaha' , g . status [ 'example.txt' ] . blob . contents )
37
37
end
38
38
end
@@ -66,13 +66,13 @@ def test_clean
66
66
assert ( File . exist? ( 'ignored_file' ) )
67
67
68
68
g . clean ( :force => true )
69
-
69
+
70
70
assert ( !File . exist? ( 'file-to-clean' ) )
71
71
assert ( File . exist? ( 'dir_to_clean' ) )
72
72
assert ( File . exist? ( 'ignored_file' ) )
73
73
74
74
new_file ( 'file-to-clean' , 'blablahbla' )
75
-
75
+
76
76
g . clean ( :force => true , :d => true )
77
77
78
78
assert ( !File . exist? ( 'file-to-clean' ) )
@@ -89,23 +89,47 @@ def test_clean
89
89
end
90
90
end
91
91
end
92
-
92
+
93
93
def test_revert
94
94
in_temp_dir do |path |
95
95
g = Git . clone ( @wbare , 'new' )
96
96
Dir . chdir ( 'new' ) do
97
+ puts "Log before any commits"
98
+ puts '-' * 80
99
+ puts `git log`
100
+ puts '-' * 80
101
+
97
102
new_file ( 'test-file' , 'blahblahbal' )
98
103
g . add
99
104
g . commit ( "first commit" )
100
105
first_commit = g . gcommit ( 'HEAD' )
101
106
107
+ puts "Log after one commit:"
108
+ puts '-' * 80
109
+ puts `git log`
110
+ puts '-' * 80
111
+
102
112
new_file ( 'test-file2' , 'blablahbla' )
103
113
g . add
104
114
g . commit ( "second-commit" )
105
115
g . gcommit ( 'HEAD' )
106
116
117
+ puts "Log after two commits:"
118
+ puts '-' * 80
119
+ puts `git log`
120
+ puts '-' * 80
121
+
122
+ puts "first commit: #{ first_commit . sha } "
123
+ puts "second commit: #{ second_commit . sha } "
124
+
107
125
commits = g . log ( 10000 ) . count
108
126
g . revert ( first_commit . sha )
127
+
128
+ puts "Log after revert:"
129
+ puts '-' * 80
130
+ puts `git log`
131
+ puts '-' * 80
132
+
109
133
assert_equal ( commits + 1 , g . log ( 10000 ) . count )
110
134
assert ( !File . exist? ( 'test-file2' ) )
111
135
end
@@ -116,53 +140,53 @@ def test_add_array
116
140
in_temp_dir do |path |
117
141
g = Git . clone ( @wbare , 'new' )
118
142
Dir . chdir ( 'new' ) do
119
-
143
+
120
144
new_file ( 'test-file1' , 'blahblahblah1' )
121
145
new_file ( 'test-file2' , 'blahblahblah2' )
122
146
assert ( g . status . untracked . assoc ( 'test-file1' ) )
123
-
147
+
124
148
g . add ( [ 'test-file1' , 'test-file2' ] )
125
149
assert ( g . status . added . assoc ( 'test-file1' ) )
126
150
assert ( g . status . added . assoc ( 'test-file1' ) )
127
151
assert ( !g . status . untracked . assoc ( 'test-file1' ) )
128
-
152
+
129
153
g . commit ( 'my message' )
130
154
assert ( !g . status . added . assoc ( 'test-file1' ) )
131
- assert ( !g . status . untracked . assoc ( 'test-file1' ) )
155
+ assert ( !g . status . untracked . assoc ( 'test-file1' ) )
132
156
assert_equal ( 'blahblahblah1' , g . status [ 'test-file1' ] . blob . contents )
133
157
end
134
158
end
135
159
end
136
-
160
+
137
161
def test_remove
138
162
in_temp_dir do |path |
139
163
g = Git . clone ( @wbare , 'remove_test' )
140
164
Dir . chdir ( 'remove_test' ) do
141
165
assert ( g . status [ 'example.txt' ] )
142
166
g . remove ( 'example.txt' )
143
- assert ( g . status . deleted . assoc ( 'example.txt' ) )
167
+ assert ( g . status . deleted . assoc ( 'example.txt' ) )
144
168
g . commit ( 'deleted file' )
145
169
assert ( !g . status [ 'example.txt' ] )
146
170
end
147
171
end
148
172
end
149
-
173
+
150
174
def test_reset
151
175
in_temp_dir do |path |
152
176
g = Git . clone ( @wbare , 'reset_test' )
153
177
Dir . chdir ( 'reset_test' ) do
154
178
new_file ( 'test-file1' , 'blahblahblah1' )
155
179
new_file ( 'test-file2' , 'blahblahblah2' )
156
180
assert ( g . status . untracked . assoc ( 'test-file1' ) )
157
-
181
+
158
182
g . add ( [ 'test-file1' , 'test-file2' ] )
159
183
assert ( !g . status . untracked . assoc ( 'test-file1' ) )
160
-
184
+
161
185
g . reset
162
186
assert ( g . status . untracked . assoc ( 'test-file1' ) )
163
187
assert ( !g . status . added . assoc ( 'test-file1' ) )
164
188
end
165
189
end
166
190
end
167
-
191
+
168
192
end
0 commit comments