git_wrapper 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.md +74 -0
- data/Rakefile +1 -0
- data/git_wrapper.gemspec +21 -0
- data/lib/git_wrapper/commands/add.rb +21 -0
- data/lib/git_wrapper/commands/branch.rb +73 -0
- data/lib/git_wrapper/commands/checkout.rb +21 -0
- data/lib/git_wrapper/commands/commit.rb +21 -0
- data/lib/git_wrapper/commands/config.rb +26 -0
- data/lib/git_wrapper/commands/diff.rb +27 -0
- data/lib/git_wrapper/commands/fetch.rb +21 -0
- data/lib/git_wrapper/commands/git.rb +44 -0
- data/lib/git_wrapper/commands/init.rb +16 -0
- data/lib/git_wrapper/commands/log.rb +82 -0
- data/lib/git_wrapper/commands/merge.rb +16 -0
- data/lib/git_wrapper/commands/pull.rb +21 -0
- data/lib/git_wrapper/commands/push.rb +27 -0
- data/lib/git_wrapper/commands/remote.rb +49 -0
- data/lib/git_wrapper/commands/remove.rb +16 -0
- data/lib/git_wrapper/commands/reset.rb +36 -0
- data/lib/git_wrapper/commands/revert.rb +23 -0
- data/lib/git_wrapper/commands/shell.rb +67 -0
- data/lib/git_wrapper/commands/show.rb +40 -0
- data/lib/git_wrapper/commands/status.rb +17 -0
- data/lib/git_wrapper/commands/tag.rb +54 -0
- data/lib/git_wrapper/repository.rb +208 -0
- data/lib/git_wrapper/results/diff_name_status.rb +28 -0
- data/lib/git_wrapper/results/file_status.rb +21 -0
- data/lib/git_wrapper/results/log_info.rb +23 -0
- data/lib/git_wrapper/results/status_porcelain.rb +40 -0
- data/lib/git_wrapper/version.rb +3 -0
- data/lib/git_wrapper.rb +45 -0
- data/spec/repository_spec.rb +886 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/status_porcelain_parser_spec.rb +78 -0
- data/spec/support/helpers/file_helper.rb +37 -0
- data/spec/support/matchers/git_status_matchers.rb +40 -0
- metadata +105 -0
@@ -0,0 +1,886 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GitWrapper, '-> Repository' do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@file_helper = FileHelper.new
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:each) do
|
10
|
+
@file_helper.remove_temp_folders
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'Init repo' do
|
14
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
15
|
+
repo.init.should be_true
|
16
|
+
repo.log_output.last.should eq("Initialized empty Git repository in #{repo.location}/.git/\n")
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'Init bare repo' do
|
20
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
21
|
+
repo.init_bare.should be_true
|
22
|
+
repo.log_output.last.should eq("Initialized empty Git repository in #{repo.location}/\n")
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Init repo in new folder' do
|
26
|
+
folder_name = @file_helper.create_temp_folder
|
27
|
+
repo = Repository.new(folder_name)
|
28
|
+
repo.init.should be_true
|
29
|
+
repo.location.should eq(folder_name)
|
30
|
+
Dir.exists?(repo.location).should be_true
|
31
|
+
FileUtils.rm_rf repo.location
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'Is initialized repo' do
|
35
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
36
|
+
repo.initialized?.should be_false
|
37
|
+
repo.init
|
38
|
+
repo.initialized?.should be_true
|
39
|
+
repo.bare?.should be_false
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'Is initialized bare repo' do
|
43
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
44
|
+
repo.initialized?.should be_false
|
45
|
+
repo.init_bare
|
46
|
+
repo.initialized?.should be_true
|
47
|
+
repo.bare?.should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'Status into new repo' do
|
51
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
52
|
+
repo.init
|
53
|
+
repo.status.should be_empty
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'Add one file into repo' do
|
57
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
58
|
+
repo.init
|
59
|
+
|
60
|
+
file1 = @file_helper.create_temp_file(repo.location, 'test')
|
61
|
+
file2 = @file_helper.create_temp_file(repo.location, 'test')
|
62
|
+
|
63
|
+
initial_status = repo.status
|
64
|
+
initial_status.should have(2).items
|
65
|
+
initial_status[0].should be_git_untracked(File.basename(file1))
|
66
|
+
initial_status[1].should be_git_untracked(File.basename(file2))
|
67
|
+
|
68
|
+
repo.add(file1).should be_true
|
69
|
+
repo.add('0123456.789').should be_false
|
70
|
+
|
71
|
+
final_status = repo.status
|
72
|
+
final_status.should have(2).items
|
73
|
+
final_status[0].should be_git_new_file(File.basename(file1))
|
74
|
+
final_status[1].should be_git_untracked(File.basename(file2))
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'Add all files into repo' do
|
78
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
79
|
+
repo.init
|
80
|
+
|
81
|
+
file1 = @file_helper.create_temp_file(repo.location, 'test')
|
82
|
+
file2 = @file_helper.create_temp_file(repo.location, 'test')
|
83
|
+
|
84
|
+
initial_status = repo.status
|
85
|
+
initial_status.should have(2).items
|
86
|
+
initial_status[0].should be_git_untracked(File.basename(file1))
|
87
|
+
initial_status[1].should be_git_untracked(File.basename(file2))
|
88
|
+
|
89
|
+
repo.add_all.should be_true
|
90
|
+
|
91
|
+
final_status = repo.status
|
92
|
+
final_status.should have(2).items
|
93
|
+
final_status[0].should be_git_new_file(File.basename(file1))
|
94
|
+
final_status[1].should be_git_new_file(File.basename(file2))
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'Commit repo' do
|
98
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
99
|
+
repo.init
|
100
|
+
|
101
|
+
file = @file_helper.create_temp_file(repo.location, 'test')
|
102
|
+
|
103
|
+
repo.status.first.should be_git_untracked(File.basename(file))
|
104
|
+
repo.add_all
|
105
|
+
repo.status.first.should be_git_new_file(File.basename(file))
|
106
|
+
|
107
|
+
repo.commit('comment').should be_true
|
108
|
+
repo.commit('comment').should be_false
|
109
|
+
|
110
|
+
repo.status.should be_empty
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'Commit clean directory' do
|
114
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
115
|
+
repo.init
|
116
|
+
|
117
|
+
repo.commit('comment').should be_false
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'Commt in name of another user' do
|
121
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
122
|
+
repo.init
|
123
|
+
@file_helper.create_temp_file(repo.location, 'test')
|
124
|
+
repo.add_all
|
125
|
+
repo.commit('first_commit', :author_name => 'another_author', :author_email => 'another_author@mail.com').should be_true
|
126
|
+
|
127
|
+
log = repo.log.first
|
128
|
+
log.author_name.should eq 'another_author'
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'Delete file' do
|
132
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
133
|
+
repo.init
|
134
|
+
|
135
|
+
file = @file_helper.create_temp_file(repo.location, 'test')
|
136
|
+
|
137
|
+
repo.add_all
|
138
|
+
repo.commit('comments')
|
139
|
+
repo.status.should be_empty
|
140
|
+
|
141
|
+
repo.remove(File.basename(file)).should be_true
|
142
|
+
repo.status.first.should be_git_deleted(File.basename(file))
|
143
|
+
|
144
|
+
repo.remove('0123456.789').should be_false
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'Add remote to repo' do
|
148
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
149
|
+
repo.init
|
150
|
+
|
151
|
+
repo.remotes.should be_empty
|
152
|
+
|
153
|
+
repo.add_remote('origin', @file_helper.create_temp_folder).should be_true
|
154
|
+
repo.add_remote('origin', '0123456789').should be_false
|
155
|
+
|
156
|
+
repo.remotes.should have(1).items
|
157
|
+
repo.remotes.first.should eq('origin')
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'Remove remote from repo' do
|
161
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
162
|
+
repo.init
|
163
|
+
|
164
|
+
repo.remotes.should be_empty
|
165
|
+
|
166
|
+
repo.add_remote('origin', @file_helper.create_temp_folder)
|
167
|
+
|
168
|
+
repo.remotes.first.should eq('origin')
|
169
|
+
|
170
|
+
repo.remove_remote('origin').should be_true
|
171
|
+
repo.remove_remote('origin').should be_false
|
172
|
+
|
173
|
+
repo.remotes.should be_empty
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'Pull from another repo' do
|
177
|
+
repo1 = Repository.new(@file_helper.create_temp_folder)
|
178
|
+
file_name1 = @file_helper.create_temp_file(repo1.location, 'test')
|
179
|
+
repo1.init
|
180
|
+
repo1.add_all
|
181
|
+
repo1.commit('...')
|
182
|
+
|
183
|
+
repo2 = Repository.new(@file_helper.create_temp_folder)
|
184
|
+
repo2.init
|
185
|
+
repo2.add_remote('origin', repo1.location)
|
186
|
+
|
187
|
+
file_name2 = "#{repo2.location}/#{File.basename(file_name1)}"
|
188
|
+
|
189
|
+
File.exist?(file_name2).should be_false
|
190
|
+
|
191
|
+
repo2.pull('origin').should be_true
|
192
|
+
repo2.pull('origin_2').should be_false
|
193
|
+
|
194
|
+
File.exist?(file_name2).should be_true
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'Push into bare repo' do
|
198
|
+
repo1 = Repository.new(@file_helper.create_temp_folder)
|
199
|
+
repo1.init_bare
|
200
|
+
|
201
|
+
repo2 = Repository.new(@file_helper.create_temp_folder)
|
202
|
+
repo2.init
|
203
|
+
file_name1 = @file_helper.create_temp_file(repo2.location, 'test')
|
204
|
+
|
205
|
+
repo2.add_remote('origin', repo1.location)
|
206
|
+
repo2.add_all
|
207
|
+
repo2.commit('...')
|
208
|
+
repo2.push('origin').should be_true
|
209
|
+
repo2.push('origin_2').should be_false
|
210
|
+
|
211
|
+
repo3 = Repository.new(@file_helper.create_temp_folder)
|
212
|
+
repo3.init
|
213
|
+
repo3.add_remote('origin', repo1.location)
|
214
|
+
|
215
|
+
file_name2 = "#{repo3.location}/#{File.basename(file_name1)}"
|
216
|
+
|
217
|
+
File.exist?(file_name2).should be_false
|
218
|
+
|
219
|
+
repo3.pull('origin')
|
220
|
+
|
221
|
+
File.exist?(file_name2).should be_true
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'Show base, mine and theirs version of a file' do
|
225
|
+
master_repo = Repository.new(@file_helper.create_temp_folder)
|
226
|
+
master_repo.init_bare
|
227
|
+
|
228
|
+
my_repo = Repository.new(@file_helper.create_temp_folder)
|
229
|
+
my_repo.init
|
230
|
+
my_repo.add_remote('origin', master_repo.location)
|
231
|
+
my_file = @file_helper.create_temp_file(my_repo.location, 'version base')
|
232
|
+
my_repo.add_all
|
233
|
+
my_repo.commit('base commit')
|
234
|
+
my_repo.push
|
235
|
+
|
236
|
+
their_repo = Repository.new(@file_helper.create_temp_folder)
|
237
|
+
their_repo.init
|
238
|
+
their_repo.add_remote('origin', master_repo.location)
|
239
|
+
their_repo.pull
|
240
|
+
their_file = "#{their_repo.location}/#{File.basename(my_file)}"
|
241
|
+
File.open(their_file, 'w') { |f| f.puts 'version theirs' }
|
242
|
+
their_repo.add_all
|
243
|
+
their_repo.commit('theris commit')
|
244
|
+
their_repo.push
|
245
|
+
|
246
|
+
File.open(my_file, 'w') { |f| f.puts 'version mine' }
|
247
|
+
my_repo.add_all
|
248
|
+
my_repo.commit('mine commit')
|
249
|
+
|
250
|
+
my_repo.pull.should be_false
|
251
|
+
my_repo.status.first.should be_git_merge_conflict(File.basename(my_file))
|
252
|
+
|
253
|
+
my_repo.show_base(File.basename(my_file)).should eq("version base\n")
|
254
|
+
my_repo.show_mine(File.basename(my_file)).should eq("version mine\n")
|
255
|
+
my_repo.show_theirs(File.basename(my_file)).should eq("version theirs\n")
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'Show file from differente versions' do
|
259
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
260
|
+
repo.init
|
261
|
+
|
262
|
+
file_name = @file_helper.create_temp_file(repo.location, 'version 1')
|
263
|
+
repo.add_all
|
264
|
+
repo.commit 'first commit'
|
265
|
+
|
266
|
+
repo.checkout 'master', 'test'
|
267
|
+
|
268
|
+
File.open(file_name, 'w') { |f| f.puts 'version 2' }
|
269
|
+
repo.add_all
|
270
|
+
repo.commit 'seccond_commit'
|
271
|
+
|
272
|
+
repo.checkout 'master'
|
273
|
+
|
274
|
+
repo.show(File.basename(file_name)).should eq "version 1\n"
|
275
|
+
repo.show(File.basename(file_name), 'test').should eq "version 2\n"
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'Show commit logs' do
|
279
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
280
|
+
repo.init
|
281
|
+
|
282
|
+
file_name1 = @file_helper.create_temp_file(repo.location, 'test')
|
283
|
+
file_name2 = @file_helper.create_temp_file(repo.location, 'test')
|
284
|
+
|
285
|
+
repo.add_all
|
286
|
+
|
287
|
+
repo.commit('first commit')
|
288
|
+
|
289
|
+
log = repo.log
|
290
|
+
|
291
|
+
log.should have(1).items
|
292
|
+
log.first.subject.should eq('first commit')
|
293
|
+
log.first.parents.should be_empty
|
294
|
+
log.first.merge?.should be_false
|
295
|
+
|
296
|
+
File.open(file_name1, 'w') { |f| f.puts 'test 2' }
|
297
|
+
|
298
|
+
repo.add_all
|
299
|
+
repo.commit('second commit')
|
300
|
+
|
301
|
+
repo.log(:file_name => File.basename(file_name1)).should have(2).items
|
302
|
+
repo.log(:file_name => File.basename(file_name2)).should have(1).items
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'Show merge logs' do
|
306
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
307
|
+
repo.init
|
308
|
+
|
309
|
+
@file_helper.create_temp_file(repo.location, 'file1')
|
310
|
+
repo.add_all
|
311
|
+
repo.commit 'first commit'
|
312
|
+
|
313
|
+
repo.checkout 'master', 'test'
|
314
|
+
|
315
|
+
@file_helper.create_temp_file(repo.location, 'file2')
|
316
|
+
repo.add_all
|
317
|
+
repo.commit 'second commit'
|
318
|
+
second_commit = repo.log.first
|
319
|
+
|
320
|
+
repo.checkout 'master'
|
321
|
+
|
322
|
+
@file_helper.create_temp_file(repo.location, 'file2')
|
323
|
+
repo.add_all
|
324
|
+
repo.commit 'third commit'
|
325
|
+
third_commit = repo.log.first
|
326
|
+
|
327
|
+
repo.merge 'test'
|
328
|
+
|
329
|
+
log = repo.log.first
|
330
|
+
log.subject.should eq "Merge branch 'test'"
|
331
|
+
log.merge?.should be_true
|
332
|
+
log.parents.first.should eq third_commit.commit_hash
|
333
|
+
log.parents.last.should eq second_commit.commit_hash
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'Show existent branches' do
|
337
|
+
origin = Repository.new(@file_helper.create_temp_folder)
|
338
|
+
origin.init_bare
|
339
|
+
|
340
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
341
|
+
repo.init
|
342
|
+
repo.add_remote 'origin', origin.location
|
343
|
+
@file_helper.create_temp_file(repo.location, 'test')
|
344
|
+
|
345
|
+
repo.branches.should be_empty
|
346
|
+
|
347
|
+
repo.add_all
|
348
|
+
repo.commit('first commit')
|
349
|
+
repo.push
|
350
|
+
|
351
|
+
branches = repo.branches
|
352
|
+
branches.should have(2).items
|
353
|
+
branches.should include('master')
|
354
|
+
branches.should include('remotes/origin/master')
|
355
|
+
end
|
356
|
+
|
357
|
+
it 'Create a new branch' do
|
358
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
359
|
+
repo.init
|
360
|
+
@file_helper.create_temp_file(repo.location, 'test')
|
361
|
+
repo.add_all
|
362
|
+
repo.commit('first commit')
|
363
|
+
|
364
|
+
repo.branch("branch1").should be_true
|
365
|
+
|
366
|
+
repo.branches.should include('branch1')
|
367
|
+
end
|
368
|
+
|
369
|
+
it 'Remove an existing branch' do
|
370
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
371
|
+
repo.init
|
372
|
+
@file_helper.create_temp_file(repo.location, 'test')
|
373
|
+
repo.add_all
|
374
|
+
repo.commit('first commit')
|
375
|
+
|
376
|
+
repo.branch("branch1")
|
377
|
+
|
378
|
+
repo.branches.should include('branch1')
|
379
|
+
|
380
|
+
repo.remove_branch('branch1').should be_true
|
381
|
+
repo.remove_branch('branch1').should be_false
|
382
|
+
|
383
|
+
repo.branches.should_not include('branch1')
|
384
|
+
end
|
385
|
+
|
386
|
+
it 'Get a current branch' do
|
387
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
388
|
+
repo.init
|
389
|
+
@file_helper.create_temp_file(repo.location, 'test')
|
390
|
+
repo.add_all
|
391
|
+
repo.commit('first commit')
|
392
|
+
|
393
|
+
repo.current_branch.should eq('master')
|
394
|
+
|
395
|
+
repo.branch("branch1")
|
396
|
+
|
397
|
+
repo.current_branch.should eq('master')
|
398
|
+
|
399
|
+
repo.checkout('branch1')
|
400
|
+
|
401
|
+
repo.current_branch.should eq('branch1')
|
402
|
+
end
|
403
|
+
|
404
|
+
it 'Branch an existing commit' do
|
405
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
406
|
+
repo.init
|
407
|
+
file_name = @file_helper.create_temp_file(repo.location, 'version master')
|
408
|
+
repo.add_all
|
409
|
+
repo.commit('first commit')
|
410
|
+
|
411
|
+
repo.checkout("master", "branch1");
|
412
|
+
|
413
|
+
File.open(file_name, 'w') { |f| f.puts 'version branch1' }
|
414
|
+
|
415
|
+
repo.add_all
|
416
|
+
repo.commit('version branch1')
|
417
|
+
|
418
|
+
repo.checkout('master')
|
419
|
+
|
420
|
+
File.open(file_name, 'r') do |f|
|
421
|
+
f.gets.should eq("version master\n")
|
422
|
+
end
|
423
|
+
|
424
|
+
repo.branch('branch2', 'branch1')
|
425
|
+
repo.checkout('branch2')
|
426
|
+
|
427
|
+
File.open(file_name, 'r') do |f|
|
428
|
+
f.gets.should eq("version branch1\n")
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
it 'Checkout an existing branch' do
|
433
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
434
|
+
repo.init
|
435
|
+
file_name = @file_helper.create_temp_file(repo.location, 'version master')
|
436
|
+
repo.add_all
|
437
|
+
repo.commit('commit master')
|
438
|
+
|
439
|
+
repo.current_branch.should eq('master')
|
440
|
+
|
441
|
+
repo.branch('branch1')
|
442
|
+
repo.checkout('branch1').should be_true
|
443
|
+
repo.checkout('0123456789').should be_false
|
444
|
+
|
445
|
+
repo.current_branch.should eq('branch1')
|
446
|
+
File.open(file_name, 'r') do |f|
|
447
|
+
f.gets.should eq("version master\n")
|
448
|
+
end
|
449
|
+
|
450
|
+
File.open(file_name, 'w') { |f| f.puts 'version branch1' }
|
451
|
+
repo.add_all
|
452
|
+
repo.commit('commit branch1')
|
453
|
+
|
454
|
+
repo.checkout('master')
|
455
|
+
repo.current_branch.should eq('master')
|
456
|
+
File.open(file_name, 'r') do |f|
|
457
|
+
f.gets.should eq("version master\n")
|
458
|
+
end
|
459
|
+
|
460
|
+
repo.checkout('branch1')
|
461
|
+
repo.current_branch.should eq('branch1')
|
462
|
+
File.open(file_name, 'r') do |f|
|
463
|
+
f.gets.should eq("version branch1\n")
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
it 'Checkout into a new branch' do
|
468
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
469
|
+
repo.init
|
470
|
+
@file_helper.create_temp_file(repo.location, 'version master')
|
471
|
+
repo.add_all
|
472
|
+
repo.commit('commit master')
|
473
|
+
|
474
|
+
repo.checkout('master', 'branch1').should be_true
|
475
|
+
|
476
|
+
repo.current_branch.should eq('branch1')
|
477
|
+
end
|
478
|
+
|
479
|
+
it 'Create a new tag' do
|
480
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
481
|
+
repo.init
|
482
|
+
@file_helper.create_temp_file(repo.location, 'test')
|
483
|
+
repo.add_all
|
484
|
+
repo.commit('first commit')
|
485
|
+
|
486
|
+
repo.tag('tag1').should be_true
|
487
|
+
|
488
|
+
repo.tags.should include('tag1')
|
489
|
+
end
|
490
|
+
|
491
|
+
it 'Remove an existing tag' do
|
492
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
493
|
+
repo.init
|
494
|
+
@file_helper.create_temp_file(repo.location, 'test')
|
495
|
+
repo.add_all
|
496
|
+
repo.commit('first commit')
|
497
|
+
|
498
|
+
repo.tag('tag1')
|
499
|
+
|
500
|
+
repo.tags.should include('tag1')
|
501
|
+
|
502
|
+
repo.remove_tag('tag1').should be_true
|
503
|
+
repo.remove_tag('tag1').should be_false
|
504
|
+
|
505
|
+
repo.tags.should_not include('tag1')
|
506
|
+
end
|
507
|
+
|
508
|
+
it 'Create a new tag from existing commit' do
|
509
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
510
|
+
repo.init
|
511
|
+
file_name = @file_helper.create_temp_file(repo.location, 'version master')
|
512
|
+
repo.add_all
|
513
|
+
repo.commit('commit master')
|
514
|
+
|
515
|
+
repo.checkout('master', 'branch1')
|
516
|
+
|
517
|
+
File.open(file_name, 'w') { |f| f.puts 'version branch1' }
|
518
|
+
|
519
|
+
repo.add_all
|
520
|
+
repo.commit('version branch1')
|
521
|
+
|
522
|
+
repo.tag('tag1', 'master').should be_true
|
523
|
+
|
524
|
+
repo.checkout('tag1', 'branch2')
|
525
|
+
|
526
|
+
File.open(file_name, 'r') do |f|
|
527
|
+
f.gets.should eq("version master\n")
|
528
|
+
end
|
529
|
+
|
530
|
+
repo.checkout('branch1')
|
531
|
+
|
532
|
+
File.open(file_name, 'r') do |f|
|
533
|
+
f.gets.should eq("version branch1\n")
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
it 'Merge two branches' do
|
538
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
539
|
+
repo.init
|
540
|
+
file_name1 = @file_helper.create_temp_file(repo.location, 'version master')
|
541
|
+
repo.add_all
|
542
|
+
repo.commit('commit master')
|
543
|
+
|
544
|
+
repo.checkout('master', 'branch1')
|
545
|
+
|
546
|
+
file_name2 = @file_helper.create_temp_file(repo.location, 'version branch1')
|
547
|
+
|
548
|
+
repo.add_all
|
549
|
+
repo.commit("commit branch 1")
|
550
|
+
|
551
|
+
repo.checkout("master")
|
552
|
+
|
553
|
+
File.exists?(file_name1).should be_true
|
554
|
+
File.exists?(file_name2).should be_false
|
555
|
+
|
556
|
+
repo.merge('branch1').should be_true
|
557
|
+
|
558
|
+
File.exists?(file_name1).should be_true
|
559
|
+
File.exists?(file_name2).should be_true
|
560
|
+
end
|
561
|
+
|
562
|
+
it 'Merge with conflicts' do
|
563
|
+
master_repo = Repository.new(@file_helper.create_temp_folder)
|
564
|
+
master_repo.init_bare
|
565
|
+
|
566
|
+
my_repo = Repository.new(@file_helper.create_temp_folder)
|
567
|
+
my_repo.init
|
568
|
+
my_repo.add_remote('origin', master_repo.location)
|
569
|
+
my_file = @file_helper.create_temp_file(my_repo.location, 'version base')
|
570
|
+
my_repo.add_all
|
571
|
+
my_repo.commit('base commit')
|
572
|
+
my_repo.push
|
573
|
+
|
574
|
+
their_repo = Repository.new(@file_helper.create_temp_folder)
|
575
|
+
their_repo.init
|
576
|
+
their_repo.add_remote('origin', master_repo.location)
|
577
|
+
their_repo.pull
|
578
|
+
their_file = "#{their_repo.location}/#{File.basename(my_file)}"
|
579
|
+
File.open(their_file, 'w') { |f| f.puts 'version theirs' }
|
580
|
+
their_repo.add_all
|
581
|
+
their_repo.commit('theris commit')
|
582
|
+
their_repo.push
|
583
|
+
|
584
|
+
File.open(my_file, 'w') { |f| f.puts 'version mine' }
|
585
|
+
my_repo.add_all
|
586
|
+
my_repo.commit('mine commit')
|
587
|
+
|
588
|
+
my_repo.fetch
|
589
|
+
my_repo.merge('origin/master').should be_false
|
590
|
+
my_repo.status.first.should be_git_merge_conflict(File.basename(my_file))
|
591
|
+
|
592
|
+
my_repo.show_base(File.basename(my_file)).should eq("version base\n")
|
593
|
+
my_repo.show_mine(File.basename(my_file)).should eq("version mine\n")
|
594
|
+
my_repo.show_theirs(File.basename(my_file)).should eq("version theirs\n")
|
595
|
+
end
|
596
|
+
|
597
|
+
it 'Fetch from remote' do
|
598
|
+
remote_repo = Repository.new(@file_helper.create_temp_folder)
|
599
|
+
remote_repo.init_bare
|
600
|
+
|
601
|
+
repo1 = Repository.new(@file_helper.create_temp_folder)
|
602
|
+
repo1.init
|
603
|
+
repo1.add_remote('origin', remote_repo.location)
|
604
|
+
@file_helper.create_temp_file(repo1.location, 'file 1')
|
605
|
+
repo1.add_all
|
606
|
+
repo1.commit('first commit')
|
607
|
+
repo1.push
|
608
|
+
|
609
|
+
repo2 = Repository.new(@file_helper.create_temp_folder)
|
610
|
+
repo2.init
|
611
|
+
repo2.add_remote('origin', remote_repo.location)
|
612
|
+
repo2.branches.should be_empty
|
613
|
+
|
614
|
+
repo2.fetch.should be_true
|
615
|
+
|
616
|
+
repo2.branches.should have(1).items
|
617
|
+
repo2.branches.should include('remotes/origin/master')
|
618
|
+
end
|
619
|
+
|
620
|
+
it 'Show diff file status between working tree and remote branch' do
|
621
|
+
remote_repo = Repository.new(@file_helper.create_temp_folder)
|
622
|
+
remote_repo.init_bare
|
623
|
+
|
624
|
+
repo1 = Repository.new(@file_helper.create_temp_folder)
|
625
|
+
repo1.init
|
626
|
+
repo1.add_remote('origin', remote_repo.location)
|
627
|
+
file1 = @file_helper.create_temp_file(repo1.location, 'file 1')
|
628
|
+
file2 = @file_helper.create_temp_file(repo1.location, 'file 2')
|
629
|
+
file3 = @file_helper.create_temp_file(repo1.location, 'file 3')
|
630
|
+
repo1.add_all
|
631
|
+
repo1.commit('first commit')
|
632
|
+
repo1.push
|
633
|
+
|
634
|
+
repo2 = Repository.new(@file_helper.create_temp_folder)
|
635
|
+
repo2.init
|
636
|
+
repo2.add_remote('origin', remote_repo.location)
|
637
|
+
repo2.pull
|
638
|
+
|
639
|
+
repo1.remove file1
|
640
|
+
File.open(file2, 'w') { |f| f.puts 'file 2 v.2' }
|
641
|
+
file4 = @file_helper.create_temp_file(repo1.location, 'file 3')
|
642
|
+
repo1.add_all
|
643
|
+
repo1.commit('second commit')
|
644
|
+
repo1.push
|
645
|
+
|
646
|
+
repo2.fetch.should be_true
|
647
|
+
|
648
|
+
diff = repo2.diff('origin/master')
|
649
|
+
diff.should have(3).items
|
650
|
+
diff.select { |d| d.file_name == File.basename(file1) }.first.status.should be(:new_file)
|
651
|
+
diff.select { |d| d.file_name == File.basename(file2) }.first.status.should be(:modified)
|
652
|
+
diff.select { |d| d.file_name == File.basename(file3) }.should be_empty
|
653
|
+
diff.select { |d| d.file_name == File.basename(file4) }.first.status.should be(:deleted)
|
654
|
+
|
655
|
+
diff_reverse = repo2.diff_reverse('origin/master')
|
656
|
+
diff_reverse.should have(3).items
|
657
|
+
diff_reverse.select { |d| d.file_name == File.basename(file1) }.first.status.should be(:deleted)
|
658
|
+
diff_reverse.select { |d| d.file_name == File.basename(file2) }.first.status.should be(:modified)
|
659
|
+
diff_reverse.select { |d| d.file_name == File.basename(file3) }.should be_empty
|
660
|
+
diff_reverse.select { |d| d.file_name == File.basename(file4) }.first.status.should be(:new_file)
|
661
|
+
end
|
662
|
+
|
663
|
+
it 'Revert a specific commit' do
|
664
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
665
|
+
repo.init
|
666
|
+
|
667
|
+
file1 = @file_helper.create_temp_file(repo.location, 'file_1')
|
668
|
+
file2 = @file_helper.create_temp_file(repo.location, 'file_2')
|
669
|
+
|
670
|
+
repo.add_all
|
671
|
+
repo.commit 'first commit'
|
672
|
+
|
673
|
+
file3 = @file_helper.create_temp_file(repo.location, 'file_3')
|
674
|
+
repo.remove file2
|
675
|
+
|
676
|
+
repo.add_all
|
677
|
+
repo.commit 'second commit'
|
678
|
+
|
679
|
+
File.exist?(file1).should be_true
|
680
|
+
File.exist?(file2).should be_false
|
681
|
+
File.exist?(file3).should be_true
|
682
|
+
|
683
|
+
last_log = repo.log.first
|
684
|
+
last_log.subject.should eq 'second commit'
|
685
|
+
|
686
|
+
repo.revert(last_log.commit_hash).should be_true
|
687
|
+
|
688
|
+
File.exist?(file1).should be_true
|
689
|
+
File.exist?(file2).should be_true
|
690
|
+
File.exist?(file3).should be_false
|
691
|
+
end
|
692
|
+
|
693
|
+
it 'Revert a specific merge' do
|
694
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
695
|
+
repo.init
|
696
|
+
|
697
|
+
file1 = @file_helper.create_temp_file(repo.location, 'file_1')
|
698
|
+
repo.add_all
|
699
|
+
repo.commit 'first commit'
|
700
|
+
|
701
|
+
repo.branch 'test'
|
702
|
+
|
703
|
+
file2 = @file_helper.create_temp_file(repo.location, 'file_2')
|
704
|
+
repo.add_all
|
705
|
+
repo.commit 'second commit'
|
706
|
+
|
707
|
+
repo.checkout 'test'
|
708
|
+
|
709
|
+
file3 = @file_helper.create_temp_file(repo.location, 'file_3')
|
710
|
+
repo.add_all
|
711
|
+
repo.commit 'third commit'
|
712
|
+
|
713
|
+
File.exist?(file1).should be_true
|
714
|
+
File.exist?(file2).should be_false
|
715
|
+
File.exist?(file3).should be_true
|
716
|
+
|
717
|
+
repo.checkout 'master'
|
718
|
+
|
719
|
+
File.exist?(file1).should be_true
|
720
|
+
File.exist?(file2).should be_true
|
721
|
+
File.exist?(file3).should be_false
|
722
|
+
|
723
|
+
repo.merge 'test'
|
724
|
+
|
725
|
+
File.exist?(file1).should be_true
|
726
|
+
File.exist?(file2).should be_true
|
727
|
+
File.exist?(file3).should be_true
|
728
|
+
|
729
|
+
last_log = repo.log.first
|
730
|
+
last_log.subject.should eq "Merge branch 'test'"
|
731
|
+
|
732
|
+
repo.revert(last_log.commit_hash).should be_true
|
733
|
+
|
734
|
+
File.exist?(file1).should be_true
|
735
|
+
File.exist?(file2).should be_true
|
736
|
+
File.exist?(file3).should be_false
|
737
|
+
end
|
738
|
+
|
739
|
+
it 'Reset index only' do
|
740
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
741
|
+
repo.init
|
742
|
+
|
743
|
+
file1 = @file_helper.create_temp_file(repo.location, 'file_1')
|
744
|
+
repo.add_all
|
745
|
+
repo.commit 'first commit'
|
746
|
+
|
747
|
+
file2 = @file_helper.create_temp_file(repo.location, 'file_2')
|
748
|
+
repo.add_all
|
749
|
+
|
750
|
+
File.exist?(file1).should be_true
|
751
|
+
File.exist?(file2).should be_true
|
752
|
+
repo.status.should have(1).items
|
753
|
+
repo.status.first.should be_git_new_file(File.basename(file2))
|
754
|
+
|
755
|
+
repo.reset.should be_true
|
756
|
+
|
757
|
+
File.exist?(file1).should be_true
|
758
|
+
File.exist?(file2).should be_true
|
759
|
+
repo.status.should have(1).items
|
760
|
+
repo.status.first.should be_git_untracked(File.basename(file2))
|
761
|
+
end
|
762
|
+
|
763
|
+
it 'Reset index and working tree (hard)' do
|
764
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
765
|
+
repo.init
|
766
|
+
|
767
|
+
file1 = @file_helper.create_temp_file(repo.location, 'file_1')
|
768
|
+
repo.add_all
|
769
|
+
repo.commit 'first commit'
|
770
|
+
|
771
|
+
file2 = @file_helper.create_temp_file(repo.location, 'file_2')
|
772
|
+
repo.add_all
|
773
|
+
|
774
|
+
File.exist?(file1).should be_true
|
775
|
+
File.exist?(file2).should be_true
|
776
|
+
repo.status.should have(1).items
|
777
|
+
repo.status.first.should be_git_new_file(File.basename(file2))
|
778
|
+
|
779
|
+
repo.reset(:mode => :hard).should be_true
|
780
|
+
|
781
|
+
File.exist?(file1).should be_true
|
782
|
+
File.exist?(file2).should be_false
|
783
|
+
repo.status.should be_empty
|
784
|
+
end
|
785
|
+
|
786
|
+
it 'Reset index only to specific commit' do
|
787
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
788
|
+
repo.init
|
789
|
+
|
790
|
+
file1 = @file_helper.create_temp_file(repo.location, 'file_1')
|
791
|
+
repo.add_all
|
792
|
+
repo.commit 'first commit'
|
793
|
+
|
794
|
+
file2 = @file_helper.create_temp_file(repo.location, 'file_2')
|
795
|
+
repo.add_all
|
796
|
+
repo.commit 'second commit'
|
797
|
+
|
798
|
+
file3 = @file_helper.create_temp_file(repo.location, 'file_2')
|
799
|
+
repo.add_all
|
800
|
+
|
801
|
+
File.exist?(file1).should be_true
|
802
|
+
File.exist?(file2).should be_true
|
803
|
+
File.exist?(file3).should be_true
|
804
|
+
|
805
|
+
repo.status.should have(1).items
|
806
|
+
repo.status.first.should be_git_new_file(File.basename(file3))
|
807
|
+
|
808
|
+
repo.log.should have(2).items
|
809
|
+
repo.log.first.subject.should eq 'second commit'
|
810
|
+
|
811
|
+
repo.reset(:commit => repo.log.last.commit_hash).should be_true
|
812
|
+
|
813
|
+
File.exist?(file1).should be_true
|
814
|
+
File.exist?(file2).should be_true
|
815
|
+
File.exist?(file3).should be_true
|
816
|
+
|
817
|
+
repo.status.should have(2).items
|
818
|
+
repo.status.first.should be_git_untracked(File.basename(file2))
|
819
|
+
repo.status.last.should be_git_untracked(File.basename(file3))
|
820
|
+
|
821
|
+
repo.log.should have(1).items
|
822
|
+
repo.log.first.subject.should eq 'first commit'
|
823
|
+
end
|
824
|
+
|
825
|
+
it 'Reset index and working tree (hard) to specific commit' do
|
826
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
827
|
+
repo.init
|
828
|
+
|
829
|
+
file1 = @file_helper.create_temp_file(repo.location, 'file_1')
|
830
|
+
repo.add_all
|
831
|
+
repo.commit 'first commit'
|
832
|
+
|
833
|
+
file2 = @file_helper.create_temp_file(repo.location, 'file_2')
|
834
|
+
repo.add_all
|
835
|
+
repo.commit 'second commit'
|
836
|
+
|
837
|
+
file3 = @file_helper.create_temp_file(repo.location, 'file_2')
|
838
|
+
repo.add_all
|
839
|
+
|
840
|
+
File.exist?(file1).should be_true
|
841
|
+
File.exist?(file2).should be_true
|
842
|
+
File.exist?(file3).should be_true
|
843
|
+
|
844
|
+
repo.status.should have(1).items
|
845
|
+
repo.status.first.should be_git_new_file(File.basename(file3))
|
846
|
+
|
847
|
+
repo.log.should have(2).items
|
848
|
+
repo.log.first.subject.should eq 'second commit'
|
849
|
+
|
850
|
+
repo.reset(:mode => :hard, :commit => repo.log.last.commit_hash).should be_true
|
851
|
+
|
852
|
+
File.exist?(file1).should be_true
|
853
|
+
File.exist?(file2).should be_false
|
854
|
+
File.exist?(file3).should be_false
|
855
|
+
|
856
|
+
repo.status.should be_empty
|
857
|
+
|
858
|
+
repo.log.should have(1).items
|
859
|
+
repo.log.first.subject.should eq 'first commit'
|
860
|
+
end
|
861
|
+
|
862
|
+
it 'Config user and email' do
|
863
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
864
|
+
repo.init
|
865
|
+
|
866
|
+
repo.config('user.name', 'user_test').should be_true
|
867
|
+
repo.config('user.email', 'user_test@mail.com').should be_true
|
868
|
+
|
869
|
+
repo.config('user.name').should eq 'user_test'
|
870
|
+
repo.config('user.email').should eq 'user_test@mail.com'
|
871
|
+
end
|
872
|
+
|
873
|
+
it 'Log specific user on commit' do
|
874
|
+
repo = Repository.new(@file_helper.create_temp_folder)
|
875
|
+
repo.init
|
876
|
+
|
877
|
+
repo.config('user.name', 'user_test').should be_true
|
878
|
+
|
879
|
+
@file_helper.create_temp_file(repo.location, 'file')
|
880
|
+
repo.add_all
|
881
|
+
repo.commit 'test'
|
882
|
+
|
883
|
+
repo.log.first.commiter_name.should eq 'user_test'
|
884
|
+
end
|
885
|
+
|
886
|
+
end
|