@@ -49,14 +49,10 @@ def clone(repository, name, opts = {})
49
49
50
50
arr_opts = [ ]
51
51
arr_opts << "--bare" if opts [ :bare ]
52
- if opts [ :remote ]
53
- arr_opts << "-o"
54
- arr_opts << opts [ :remote ]
55
- end
56
- if opts [ :depth ] && opts [ :depth ] . to_i > 0
57
- arr_opts << "--depth"
58
- arr_opts << opts [ :depth ] . to_i
59
- end
52
+ arr_opts << "-o" << opts [ :remote ] if opts [ :remote ]
53
+ arr_opts << "--depth" << opts [ :depth ] . to_i if opts [ :depth ] && opts [ :depth ] . to_i > 0
54
+
55
+ arr_opts << '--'
60
56
arr_opts << repository
61
57
arr_opts << clone_dir
62
58
@@ -78,10 +74,7 @@ def log_commits(opts = {})
78
74
arr_opts << "--author=#{ opts [ :author ] } " if opts [ :author ] . is_a? String
79
75
arr_opts << "#{ opts [ :between ] [ 0 ] . to_s } ..#{ opts [ :between ] [ 1 ] . to_s } " if ( opts [ :between ] && opts [ :between ] . size == 2 )
80
76
arr_opts << opts [ :object ] if opts [ :object ] . is_a? String
81
- if opts [ :path_limiter ] . is_a? String
82
- arr_opts << '--'
83
- arr_opts << opts [ :path_limiter ]
84
- end
77
+ arr_opts << '--' << opts [ :path_limiter ] if opts [ :path_limiter ] . is_a? String
85
78
86
79
command_lines ( 'log' , arr_opts , true ) . map { |l | l . split . first }
87
80
end
@@ -96,10 +89,7 @@ def full_log_commits(opts = {})
96
89
arr_opts << "--author=#{ opts [ :author ] } " if opts [ :author ] . is_a? String
97
90
arr_opts << "#{ opts [ :between ] [ 0 ] . to_s } ..#{ opts [ :between ] [ 1 ] . to_s } " if ( opts [ :between ] && opts [ :between ] . size == 2 )
98
91
arr_opts << opts [ :object ] if opts [ :object ] . is_a? String
99
- if opts [ :path_limiter ] . is_a? String
100
- arr_opts << '--'
101
- arr_opts << opts [ :path_limiter ]
102
- end
92
+ arr_opts << '--' << opts [ :path_limiter ] if opts [ :path_limiter ] . is_a? String
103
93
104
94
full_log = command_lines ( 'log' , arr_opts , true )
105
95
process_commit_data ( full_log )
@@ -192,7 +182,7 @@ def ls_tree(sha)
192
182
end
193
183
194
184
def mv ( file1 , file2 )
195
- command_lines ( 'mv' , [ file1 , file2 ] )
185
+ command_lines ( 'mv' , [ '--' , file1 , file2 ] )
196
186
end
197
187
198
188
def full_tree ( sha )
@@ -240,11 +230,7 @@ def grep(string, opts = {})
240
230
grep_opts << '-e'
241
231
grep_opts << string
242
232
grep_opts << opts [ :object ] if opts [ :object ] . is_a? ( String )
243
-
244
- if opts [ :path_limiter ] . is_a? String
245
- grep_opts << '--'
246
- grep_opts << opts [ :path_limiter ]
247
- end
233
+ grep_opts << '--' << opts [ :path_limiter ] if opts [ :path_limiter ] . is_a? String
248
234
249
235
hsh = { }
250
236
command_lines ( 'grep' , grep_opts ) . each do |line |
@@ -260,11 +246,7 @@ def diff_full(obj1 = 'HEAD', obj2 = nil, opts = {})
260
246
diff_opts = [ '-p' ]
261
247
diff_opts << obj1
262
248
diff_opts << obj2 if obj2 . is_a? ( String )
263
-
264
- if opts [ :path_limiter ] . is_a? String
265
- diff_opts << '--'
266
- diff_opts << opts [ :path_limiter ]
267
- end
249
+ diff_opts << '--' << opts [ :path_limiter ] if opts [ :path_limiter ] . is_a? String
268
250
269
251
command ( 'diff' , diff_opts )
270
252
end
@@ -273,11 +255,7 @@ def diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {})
273
255
diff_opts = [ '--numstat' ]
274
256
diff_opts << obj1
275
257
diff_opts << obj2 if obj2 . is_a? ( String )
276
-
277
- if opts [ :path_limiter ] . is_a? String
278
- diff_opts << '--'
279
- diff_opts << opts [ :path_limiter ]
280
- end
258
+ diff_opts << '--' << opts [ :path_limiter ] if opts [ :path_limiter ] . is_a? String
281
259
282
260
hsh = { :total => { :insertions => 0 , :deletions => 0 , :lines => 0 , :files => 0 } , :files => { } }
283
261
@@ -381,12 +359,19 @@ def config_set(name, value)
381
359
end
382
360
383
361
def add ( path = '.' )
384
- command ( 'add' , path )
362
+ arr_opts = [ '--' ]
363
+ if path . is_a? ( Array )
364
+ arr_opts += path
365
+ else
366
+ arr_opts << path
367
+ end
368
+ command ( 'add' , arr_opts )
385
369
end
386
370
387
371
def remove ( path = '.' , opts = { } )
388
372
arr_opts = [ '-f' ] # overrides the up-to-date check by default
389
373
arr_opts << [ '-r' ] if opts [ :recursive ]
374
+ arr_opts << '--'
390
375
if path . is_a? ( Array )
391
376
arr_opts += path
392
377
else
@@ -416,13 +401,13 @@ def reset(commit, opts = {})
416
401
417
402
def apply ( patch_file )
418
403
arr_opts = [ ]
419
- arr_opts << patch_file if patch_file
404
+ arr_opts << '--' << patch_file if patch_file
420
405
command ( 'apply' , arr_opts )
421
406
end
422
407
423
408
def apply_mail ( patch_file )
424
409
arr_opts = [ ]
425
- arr_opts << patch_file if patch_file
410
+ arr_opts << '--' << patch_file if patch_file
426
411
command ( 'am' , arr_opts )
427
412
end
428
413
@@ -439,7 +424,7 @@ def stashes_all
439
424
end
440
425
441
426
def stash_save ( message )
442
- output = command ( 'stash save' , [ message ] )
427
+ output = command ( 'stash save' , [ '--' , message ] )
443
428
output =~ /HEAD is now at/
444
429
end
445
430
@@ -467,10 +452,7 @@ def branch_delete(branch)
467
452
def checkout ( branch , opts = { } )
468
453
arr_opts = [ ]
469
454
arr_opts << '-f' if opts [ :force ]
470
- if opts [ :new_branch ]
471
- arr_opts << '-b'
472
- arr_opts << opts [ :new_branch ]
473
- end
455
+ arr_opts << '-b' << opts [ :new_branch ] if opts [ :new_branch ]
474
456
arr_opts << branch
475
457
476
458
command ( 'checkout' , arr_opts )
@@ -485,10 +467,7 @@ def checkout_file(version, file)
485
467
486
468
def merge ( branch , message = nil )
487
469
arr_opts = [ ]
488
- if message
489
- arr_opts << '-m'
490
- arr_opts << message
491
- end
470
+ arr_opts << '-m' << message if message
492
471
arr_opts += branch . to_a
493
472
command ( 'merge' , arr_opts )
494
473
end
@@ -515,6 +494,7 @@ def conflicts # :yields: file, your, their
515
494
def remote_add ( name , url , opts = { } )
516
495
arr_opts = [ 'add' ]
517
496
arr_opts << '-f' if opts [ :with_fetch ]
497
+ arr_opts << '--'
518
498
arr_opts << name
519
499
arr_opts << url
520
500
@@ -524,7 +504,7 @@ def remote_add(name, url, opts = {})
524
504
# this is documented as such, but seems broken for some reason
525
505
# i'll try to get around it some other way later
526
506
def remote_remove ( name )
527
- command ( 'remote' , [ 'rm' , name ] )
507
+ command ( 'remote' , [ 'rm' , '--' , name ] )
528
508
end
529
509
530
510
def remotes
@@ -584,10 +564,7 @@ def commit_tree(tree, opts = {})
584
564
585
565
arr_opts = [ ]
586
566
arr_opts << tree
587
- if opts [ :parent ]
588
- arr_opts << '-p'
589
- arr_opts << opts [ :parent ]
590
- end
567
+ arr_opts << '-p' << opts [ :parent ] if opts [ :parent ]
591
568
arr_opts += opts [ :parents ] . map { |p | [ '-p' , p ] } . flatten if opts [ :parents ]
592
569
command ( 'commit-tree' , arr_opts , true , "< #{ escape t . path } " )
593
570
end
@@ -601,11 +578,7 @@ def checkout_index(opts = {})
601
578
arr_opts << "--prefix=#{ opts [ :prefix ] } " if opts [ :prefix ]
602
579
arr_opts << "--force" if opts [ :force ]
603
580
arr_opts << "--all" if opts [ :all ]
604
-
605
- if opts [ :path_limiter ] . is_a? String
606
- arr_opts << '--'
607
- arr_opts << opts [ :path_limiter ]
608
- end
581
+ arr_opts << '--' << opts [ :path_limiter ] if opts [ :path_limiter ] . is_a? String
609
582
610
583
command ( 'checkout-index' , arr_opts )
611
584
end
@@ -632,7 +605,7 @@ def archive(sha, file = nil, opts = {})
632
605
arr_opts << "--prefix=#{ opts [ :prefix ] } " if opts [ :prefix ]
633
606
arr_opts << "--remote=#{ opts [ :remote ] } " if opts [ :remote ]
634
607
arr_opts << sha
635
- arr_opts << opts [ :path ] if opts [ :path ]
608
+ arr_opts << '--' << opts [ :path ] if opts [ :path ]
636
609
command ( 'archive' , arr_opts , true , ( opts [ :add_gzip ] ? '| gzip' : '' ) + " > #{ escape file } " )
637
610
return file
638
611
end
0 commit comments