Skip to content

Commit 8ea488b

Browse files
author
Daniel Mendler
committed
missing -- added, code cleanup
1 parent b3089f0 commit 8ea488b

File tree

1 file changed

+28
-55
lines changed

1 file changed

+28
-55
lines changed

lib/git/lib.rb

Lines changed: 28 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,10 @@ def clone(repository, name, opts = {})
4949

5050
arr_opts = []
5151
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 << '--'
6056
arr_opts << repository
6157
arr_opts << clone_dir
6258

@@ -78,10 +74,7 @@ def log_commits(opts = {})
7874
arr_opts << "--author=#{opts[:author]}" if opts[:author].is_a? String
7975
arr_opts << "#{opts[:between][0].to_s}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2)
8076
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
8578

8679
command_lines('log', arr_opts, true).map { |l| l.split.first }
8780
end
@@ -96,10 +89,7 @@ def full_log_commits(opts = {})
9689
arr_opts << "--author=#{opts[:author]}" if opts[:author].is_a? String
9790
arr_opts << "#{opts[:between][0].to_s}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2)
9891
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
10393

10494
full_log = command_lines('log', arr_opts, true)
10595
process_commit_data(full_log)
@@ -192,7 +182,7 @@ def ls_tree(sha)
192182
end
193183

194184
def mv(file1, file2)
195-
command_lines('mv', [file1, file2])
185+
command_lines('mv', ['--', file1, file2])
196186
end
197187

198188
def full_tree(sha)
@@ -240,11 +230,7 @@ def grep(string, opts = {})
240230
grep_opts << '-e'
241231
grep_opts << string
242232
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
248234

249235
hsh = {}
250236
command_lines('grep', grep_opts).each do |line|
@@ -260,11 +246,7 @@ def diff_full(obj1 = 'HEAD', obj2 = nil, opts = {})
260246
diff_opts = ['-p']
261247
diff_opts << obj1
262248
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
268250

269251
command('diff', diff_opts)
270252
end
@@ -273,11 +255,7 @@ def diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {})
273255
diff_opts = ['--numstat']
274256
diff_opts << obj1
275257
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
281259

282260
hsh = {:total => {:insertions => 0, :deletions => 0, :lines => 0, :files => 0}, :files => {}}
283261

@@ -381,12 +359,19 @@ def config_set(name, value)
381359
end
382360

383361
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)
385369
end
386370

387371
def remove(path = '.', opts = {})
388372
arr_opts = ['-f'] # overrides the up-to-date check by default
389373
arr_opts << ['-r'] if opts[:recursive]
374+
arr_opts << '--'
390375
if path.is_a?(Array)
391376
arr_opts += path
392377
else
@@ -416,13 +401,13 @@ def reset(commit, opts = {})
416401

417402
def apply(patch_file)
418403
arr_opts = []
419-
arr_opts << patch_file if patch_file
404+
arr_opts << '--' << patch_file if patch_file
420405
command('apply', arr_opts)
421406
end
422407

423408
def apply_mail(patch_file)
424409
arr_opts = []
425-
arr_opts << patch_file if patch_file
410+
arr_opts << '--' << patch_file if patch_file
426411
command('am', arr_opts)
427412
end
428413

@@ -439,7 +424,7 @@ def stashes_all
439424
end
440425

441426
def stash_save(message)
442-
output = command('stash save', [message])
427+
output = command('stash save', ['--', message])
443428
output =~ /HEAD is now at/
444429
end
445430

@@ -467,10 +452,7 @@ def branch_delete(branch)
467452
def checkout(branch, opts = {})
468453
arr_opts = []
469454
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]
474456
arr_opts << branch
475457

476458
command('checkout', arr_opts)
@@ -485,10 +467,7 @@ def checkout_file(version, file)
485467

486468
def merge(branch, message = nil)
487469
arr_opts = []
488-
if message
489-
arr_opts << '-m'
490-
arr_opts << message
491-
end
470+
arr_opts << '-m' << message if message
492471
arr_opts += branch.to_a
493472
command('merge', arr_opts)
494473
end
@@ -515,6 +494,7 @@ def conflicts # :yields: file, your, their
515494
def remote_add(name, url, opts = {})
516495
arr_opts = ['add']
517496
arr_opts << '-f' if opts[:with_fetch]
497+
arr_opts << '--'
518498
arr_opts << name
519499
arr_opts << url
520500

@@ -524,7 +504,7 @@ def remote_add(name, url, opts = {})
524504
# this is documented as such, but seems broken for some reason
525505
# i'll try to get around it some other way later
526506
def remote_remove(name)
527-
command('remote', ['rm', name])
507+
command('remote', ['rm', '--', name])
528508
end
529509

530510
def remotes
@@ -584,10 +564,7 @@ def commit_tree(tree, opts = {})
584564

585565
arr_opts = []
586566
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]
591568
arr_opts += opts[:parents].map { |p| ['-p', p] }.flatten if opts[:parents]
592569
command('commit-tree', arr_opts, true, "< #{escape t.path}")
593570
end
@@ -601,11 +578,7 @@ def checkout_index(opts = {})
601578
arr_opts << "--prefix=#{opts[:prefix]}" if opts[:prefix]
602579
arr_opts << "--force" if opts[:force]
603580
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
609582

610583
command('checkout-index', arr_opts)
611584
end
@@ -632,7 +605,7 @@ def archive(sha, file = nil, opts = {})
632605
arr_opts << "--prefix=#{opts[:prefix]}" if opts[:prefix]
633606
arr_opts << "--remote=#{opts[:remote]}" if opts[:remote]
634607
arr_opts << sha
635-
arr_opts << opts[:path] if opts[:path]
608+
arr_opts << '--' << opts[:path] if opts[:path]
636609
command('archive', arr_opts, true, (opts[:add_gzip] ? '| gzip' : '') + " > #{escape file}")
637610
return file
638611
end

0 commit comments

Comments
 (0)