schacon-git 1.0.7 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +7 -1
- data/lib/git/base.rb +51 -47
- data/lib/git/branch.rb +3 -5
- data/lib/git/branches.rb +4 -13
- data/lib/git/diff.rb +20 -17
- data/lib/git/lib.rb +126 -117
- data/lib/git/log.rb +20 -18
- data/lib/git/object.rb +63 -86
- data/lib/git/remote.rb +1 -3
- data/lib/git/stash.rb +2 -1
- data/lib/git/stashes.rb +5 -10
- data/lib/git/status.rb +7 -15
- data/lib/git.rb +14 -0
- metadata +6 -7
- data/tests/all_tests.rb +0 -4
- data/tests/test_helper.rb +0 -77
data/lib/git/lib.rb
CHANGED
@@ -7,14 +7,12 @@ module Git
|
|
7
7
|
|
8
8
|
class Lib
|
9
9
|
|
10
|
-
@git_dir = nil
|
11
|
-
@git_index_file = nil
|
12
|
-
@git_work_dir = nil
|
13
|
-
@path = nil
|
14
|
-
|
15
|
-
@logger = nil
|
16
|
-
|
17
10
|
def initialize(base = nil, logger = nil)
|
11
|
+
@git_dir = nil
|
12
|
+
@git_index_file = nil
|
13
|
+
@git_work_dir = nil
|
14
|
+
@path = nil
|
15
|
+
|
18
16
|
if base.is_a?(Git::Base)
|
19
17
|
@git_dir = base.repo.path
|
20
18
|
@git_index_file = base.index.path if base.index
|
@@ -24,9 +22,7 @@ module Git
|
|
24
22
|
@git_index_file = base[:index]
|
25
23
|
@git_work_dir = base[:working_directory]
|
26
24
|
end
|
27
|
-
|
28
|
-
@logger = logger
|
29
|
-
end
|
25
|
+
@logger = logger
|
30
26
|
end
|
31
27
|
|
32
28
|
def init
|
@@ -39,18 +35,22 @@ module Git
|
|
39
35
|
# {:working_directory} otherwise
|
40
36
|
#
|
41
37
|
# accepts options:
|
42
|
-
# :remote
|
43
|
-
# :bare
|
38
|
+
# :remote:: name of remote (rather than 'origin')
|
39
|
+
# :bare:: no working directory
|
40
|
+
# :depth:: the number of commits back to pull
|
44
41
|
#
|
45
42
|
# TODO - make this work with SSH password or auth_key
|
46
43
|
#
|
47
44
|
def clone(repository, name, opts = {})
|
48
45
|
@path = opts[:path] || '.'
|
49
|
-
opts[:path] ?
|
46
|
+
clone_dir = opts[:path] ? File.join(@path, name) : name
|
50
47
|
|
51
48
|
arr_opts = []
|
52
49
|
arr_opts << "--bare" if opts[:bare]
|
53
|
-
arr_opts << "-o
|
50
|
+
arr_opts << "-o" << opts[:remote] if opts[:remote]
|
51
|
+
arr_opts << "--depth" << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0
|
52
|
+
|
53
|
+
arr_opts << '--'
|
54
54
|
arr_opts << repository
|
55
55
|
arr_opts << clone_dir
|
56
56
|
|
@@ -66,46 +66,41 @@ module Git
|
|
66
66
|
def log_commits(opts = {})
|
67
67
|
arr_opts = ['--pretty=oneline']
|
68
68
|
arr_opts << "-#{opts[:count]}" if opts[:count]
|
69
|
-
arr_opts << "--since
|
70
|
-
arr_opts << "--until
|
71
|
-
arr_opts << "--grep
|
72
|
-
arr_opts << "--author
|
69
|
+
arr_opts << "--since=#{opts[:since]}" if opts[:since].is_a? String
|
70
|
+
arr_opts << "--until=#{opts[:until]}" if opts[:until].is_a? String
|
71
|
+
arr_opts << "--grep=#{opts[:grep]}" if opts[:grep].is_a? String
|
72
|
+
arr_opts << "--author=#{opts[:author]}" if opts[:author].is_a? String
|
73
73
|
arr_opts << "#{opts[:between][0].to_s}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2)
|
74
74
|
arr_opts << opts[:object] if opts[:object].is_a? String
|
75
|
-
arr_opts << '--
|
76
|
-
|
75
|
+
arr_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String
|
76
|
+
|
77
77
|
command_lines('log', arr_opts, true).map { |l| l.split.first }
|
78
78
|
end
|
79
79
|
|
80
80
|
def full_log_commits(opts = {})
|
81
81
|
arr_opts = ['--pretty=raw']
|
82
82
|
arr_opts << "-#{opts[:count]}" if opts[:count]
|
83
|
-
arr_opts << "--
|
84
|
-
arr_opts << "--
|
85
|
-
arr_opts << "--
|
86
|
-
arr_opts << "--
|
83
|
+
arr_opts << "--skip=#{opts[:skip]}" if opts[:skip]
|
84
|
+
arr_opts << "--since=#{opts[:since]}" if opts[:since].is_a? String
|
85
|
+
arr_opts << "--until=#{opts[:until]}" if opts[:until].is_a? String
|
86
|
+
arr_opts << "--grep=#{opts[:grep]}" if opts[:grep].is_a? String
|
87
|
+
arr_opts << "--author=#{opts[:author]}" if opts[:author].is_a? String
|
87
88
|
arr_opts << "#{opts[:between][0].to_s}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2)
|
88
89
|
arr_opts << opts[:object] if opts[:object].is_a? String
|
89
|
-
arr_opts << '--
|
90
|
+
arr_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String
|
90
91
|
|
91
92
|
full_log = command_lines('log', arr_opts, true)
|
92
93
|
process_commit_data(full_log)
|
93
94
|
end
|
94
95
|
|
95
96
|
def revparse(string)
|
96
|
-
if
|
97
|
-
|
97
|
+
return string if string =~ /[A-Fa-f0-9]{40}/ # passing in a sha - just no-op it
|
98
|
+
rev = ['head', 'remotes', 'tags'].map do |d|
|
99
|
+
File.join(@git_dir, 'refs', d, string)
|
100
|
+
end.find do |path|
|
101
|
+
File.file?(path)
|
98
102
|
end
|
99
|
-
|
100
|
-
head = File.join(@git_dir, 'refs', 'heads', string)
|
101
|
-
return File.read(head).chomp if File.file?(head)
|
102
|
-
|
103
|
-
head = File.join(@git_dir, 'refs', 'remotes', string)
|
104
|
-
return File.read(head).chomp if File.file?(head)
|
105
|
-
|
106
|
-
head = File.join(@git_dir, 'refs', 'tags', string)
|
107
|
-
return File.read(head).chomp if File.file?(head)
|
108
|
-
|
103
|
+
return File.read(rev).chomp if rev
|
109
104
|
command('rev-parse', string)
|
110
105
|
end
|
111
106
|
|
@@ -125,10 +120,10 @@ module Git
|
|
125
120
|
def commit_data(sha)
|
126
121
|
sha = sha.to_s
|
127
122
|
cdata = command_lines('cat-file', ['commit', sha])
|
128
|
-
process_commit_data(cdata, sha)
|
123
|
+
process_commit_data(cdata, sha, 0)
|
129
124
|
end
|
130
125
|
|
131
|
-
def process_commit_data(data, sha = nil)
|
126
|
+
def process_commit_data(data, sha = nil, indent = 4)
|
132
127
|
in_message = false
|
133
128
|
|
134
129
|
if sha
|
@@ -139,11 +134,11 @@ module Git
|
|
139
134
|
|
140
135
|
data.each do |line|
|
141
136
|
line = line.chomp
|
142
|
-
if
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
137
|
+
if line == ''
|
138
|
+
in_message = !in_message
|
139
|
+
elsif in_message
|
140
|
+
hsh['message'] << line[indent..-1] << "\n"
|
141
|
+
else
|
147
142
|
data = line.split
|
148
143
|
key = data.shift
|
149
144
|
value = data.join(' ')
|
@@ -157,10 +152,6 @@ module Git
|
|
157
152
|
else
|
158
153
|
hsh[key] = value
|
159
154
|
end
|
160
|
-
elsif in_message && line == ''
|
161
|
-
in_message = false
|
162
|
-
else
|
163
|
-
in_message = true
|
164
155
|
end
|
165
156
|
end
|
166
157
|
|
@@ -179,7 +170,7 @@ module Git
|
|
179
170
|
def ls_tree(sha)
|
180
171
|
data = {'blob' => {}, 'tree' => {}}
|
181
172
|
|
182
|
-
command_lines('ls-tree', sha
|
173
|
+
command_lines('ls-tree', sha).each do |line|
|
183
174
|
(info, filenm) = line.split("\t")
|
184
175
|
(mode, type, sha) = info.split
|
185
176
|
data[type][filenm] = {:mode => mode, :sha => sha}
|
@@ -189,11 +180,11 @@ module Git
|
|
189
180
|
end
|
190
181
|
|
191
182
|
def mv(file1, file2)
|
192
|
-
command_lines('mv', [file1, file2])
|
183
|
+
command_lines('mv', ['--', file1, file2])
|
193
184
|
end
|
194
185
|
|
195
186
|
def full_tree(sha)
|
196
|
-
command_lines('ls-tree', ['-r', sha
|
187
|
+
command_lines('ls-tree', ['-r', sha])
|
197
188
|
end
|
198
189
|
|
199
190
|
def tree_depth(sha)
|
@@ -207,8 +198,7 @@ module Git
|
|
207
198
|
def branches_all
|
208
199
|
arr = []
|
209
200
|
command_lines('branch', '-a').each do |b|
|
210
|
-
current =
|
211
|
-
current = true if b[0, 2] == '* '
|
201
|
+
current = (b[0, 2] == '* ')
|
212
202
|
arr << [b.gsub('* ', '').strip, current]
|
213
203
|
end
|
214
204
|
arr
|
@@ -230,14 +220,16 @@ module Git
|
|
230
220
|
# [tree-ish] = [[line_no, match], [line_no, match2]]
|
231
221
|
# [tree-ish] = [[line_no, match], [line_no, match2]]
|
232
222
|
def grep(string, opts = {})
|
233
|
-
opts[:object]
|
223
|
+
opts[:object] ||= 'HEAD'
|
234
224
|
|
235
225
|
grep_opts = ['-n']
|
236
226
|
grep_opts << '-i' if opts[:ignore_case]
|
237
227
|
grep_opts << '-v' if opts[:invert_match]
|
238
|
-
grep_opts <<
|
228
|
+
grep_opts << '-e'
|
229
|
+
grep_opts << string
|
239
230
|
grep_opts << opts[:object] if opts[:object].is_a?(String)
|
240
|
-
grep_opts <<
|
231
|
+
grep_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String
|
232
|
+
|
241
233
|
hsh = {}
|
242
234
|
command_lines('grep', grep_opts).each do |line|
|
243
235
|
if m = /(.*)\:(\d+)\:(.*)/.match(line)
|
@@ -252,8 +244,8 @@ module Git
|
|
252
244
|
diff_opts = ['-p']
|
253
245
|
diff_opts << obj1
|
254
246
|
diff_opts << obj2 if obj2.is_a?(String)
|
255
|
-
diff_opts <<
|
256
|
-
|
247
|
+
diff_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String
|
248
|
+
|
257
249
|
command('diff', diff_opts)
|
258
250
|
end
|
259
251
|
|
@@ -261,8 +253,8 @@ module Git
|
|
261
253
|
diff_opts = ['--numstat']
|
262
254
|
diff_opts << obj1
|
263
255
|
diff_opts << obj2 if obj2.is_a?(String)
|
264
|
-
diff_opts <<
|
265
|
-
|
256
|
+
diff_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String
|
257
|
+
|
266
258
|
hsh = {:total => {:insertions => 0, :deletions => 0, :lines => 0, :files => 0}, :files => {}}
|
267
259
|
|
268
260
|
command_lines('diff', diff_opts).each do |file|
|
@@ -306,12 +298,18 @@ module Git
|
|
306
298
|
command_lines('ls-files', '--stage').each do |line|
|
307
299
|
(info, file) = line.split("\t")
|
308
300
|
(mode, sha, stage) = info.split
|
301
|
+
file = eval(file) if file =~ /^\".*\"$/ # This takes care of quoted strings returned from git
|
309
302
|
hsh[file] = {:path => file, :mode_index => mode, :sha_index => sha, :stage => stage}
|
310
303
|
end
|
311
304
|
hsh
|
312
305
|
end
|
313
306
|
|
314
307
|
|
308
|
+
def ignored_files
|
309
|
+
command_lines('ls-files', ['--others', '-i', '--exclude-standard'])
|
310
|
+
end
|
311
|
+
|
312
|
+
|
315
313
|
def config_remote(name)
|
316
314
|
hsh = {}
|
317
315
|
config_list.each do |key, value|
|
@@ -323,8 +321,7 @@ module Git
|
|
323
321
|
end
|
324
322
|
|
325
323
|
def config_get(name)
|
326
|
-
|
327
|
-
c[name]
|
324
|
+
config_list[name]
|
328
325
|
#command('config', ['--get', name])
|
329
326
|
end
|
330
327
|
|
@@ -362,46 +359,56 @@ module Git
|
|
362
359
|
## WRITE COMMANDS ##
|
363
360
|
|
364
361
|
def config_set(name, value)
|
365
|
-
command('config', [name,
|
362
|
+
command('config', [name, value])
|
366
363
|
end
|
367
364
|
|
368
365
|
def add(path = '.')
|
369
|
-
|
370
|
-
|
366
|
+
arr_opts = ['--']
|
367
|
+
if path.is_a?(Array)
|
368
|
+
arr_opts += path
|
369
|
+
else
|
370
|
+
arr_opts << path
|
371
|
+
end
|
372
|
+
command('add', arr_opts)
|
371
373
|
end
|
372
374
|
|
373
375
|
def remove(path = '.', opts = {})
|
374
|
-
path = path.join(' ') if path.is_a?(Array)
|
375
|
-
|
376
376
|
arr_opts = ['-f'] # overrides the up-to-date check by default
|
377
377
|
arr_opts << ['-r'] if opts[:recursive]
|
378
|
-
arr_opts <<
|
378
|
+
arr_opts << '--'
|
379
|
+
if path.is_a?(Array)
|
380
|
+
arr_opts += path
|
381
|
+
else
|
382
|
+
arr_opts << path
|
383
|
+
end
|
379
384
|
|
380
385
|
command('rm', arr_opts)
|
381
386
|
end
|
382
387
|
|
383
388
|
def commit(message, opts = {})
|
384
|
-
arr_opts = [
|
389
|
+
arr_opts = ['-m', message]
|
385
390
|
arr_opts << '-a' if opts[:add_all]
|
391
|
+
arr_opts << '--allow-empty' if opts[:allow_empty]
|
392
|
+
arr_opts << "--author" << opts[:author] if opts[:author]
|
386
393
|
command('commit', arr_opts)
|
387
394
|
end
|
388
395
|
|
389
396
|
def reset(commit, opts = {})
|
390
397
|
arr_opts = []
|
391
398
|
arr_opts << '--hard' if opts[:hard]
|
392
|
-
arr_opts << commit
|
399
|
+
arr_opts << commit if commit
|
393
400
|
command('reset', arr_opts)
|
394
401
|
end
|
395
402
|
|
396
403
|
def apply(patch_file)
|
397
404
|
arr_opts = []
|
398
|
-
arr_opts << patch_file
|
405
|
+
arr_opts << '--' << patch_file if patch_file
|
399
406
|
command('apply', arr_opts)
|
400
407
|
end
|
401
408
|
|
402
409
|
def apply_mail(patch_file)
|
403
410
|
arr_opts = []
|
404
|
-
arr_opts << patch_file
|
411
|
+
arr_opts << '--' << patch_file if patch_file
|
405
412
|
command('am', arr_opts)
|
406
413
|
end
|
407
414
|
|
@@ -418,14 +425,16 @@ module Git
|
|
418
425
|
end
|
419
426
|
|
420
427
|
def stash_save(message)
|
421
|
-
output = command('stash save', [message])
|
422
|
-
|
423
|
-
return true
|
428
|
+
output = command('stash save', ['--', message])
|
429
|
+
output =~ /HEAD is now at/
|
424
430
|
end
|
425
431
|
|
426
|
-
def stash_apply(id)
|
427
|
-
|
428
|
-
|
432
|
+
def stash_apply(id = nil)
|
433
|
+
if id
|
434
|
+
command('stash apply', [id])
|
435
|
+
else
|
436
|
+
command('stash apply')
|
437
|
+
end
|
429
438
|
end
|
430
439
|
|
431
440
|
def stash_clear
|
@@ -447,23 +456,23 @@ module Git
|
|
447
456
|
def checkout(branch, opts = {})
|
448
457
|
arr_opts = []
|
449
458
|
arr_opts << '-f' if opts[:force]
|
450
|
-
arr_opts <<
|
451
|
-
arr_opts << branch
|
459
|
+
arr_opts << '-b' << opts[:new_branch] if opts[:new_branch]
|
460
|
+
arr_opts << branch
|
452
461
|
|
453
462
|
command('checkout', arr_opts)
|
454
463
|
end
|
455
464
|
|
456
465
|
def checkout_file(version, file)
|
457
466
|
arr_opts = []
|
458
|
-
arr_opts << version
|
459
|
-
arr_opts << file
|
467
|
+
arr_opts << version
|
468
|
+
arr_opts << file
|
460
469
|
command('checkout', arr_opts)
|
461
470
|
end
|
462
471
|
|
463
472
|
def merge(branch, message = nil)
|
464
473
|
arr_opts = []
|
465
|
-
arr_opts <<
|
466
|
-
arr_opts
|
474
|
+
arr_opts << '-m' << message if message
|
475
|
+
arr_opts += [branch]
|
467
476
|
command('merge', arr_opts)
|
468
477
|
end
|
469
478
|
|
@@ -475,15 +484,13 @@ module Git
|
|
475
484
|
unmerged
|
476
485
|
end
|
477
486
|
|
478
|
-
def conflicts #yields
|
487
|
+
def conflicts # :yields: file, your, their
|
479
488
|
self.unmerged.each do |f|
|
480
489
|
your = Tempfile.new("YOUR-#{File.basename(f)}").path
|
481
|
-
|
482
|
-
command('show', arr_opts)
|
490
|
+
command('show', ":2:#{f}", true, "> #{escape your}")
|
483
491
|
|
484
492
|
their = Tempfile.new("THEIR-#{File.basename(f)}").path
|
485
|
-
|
486
|
-
command('show', arr_opts)
|
493
|
+
command('show', ":3:#{f}", true, "> #{escape their}")
|
487
494
|
yield(f, your, their)
|
488
495
|
end
|
489
496
|
end
|
@@ -491,6 +498,7 @@ module Git
|
|
491
498
|
def remote_add(name, url, opts = {})
|
492
499
|
arr_opts = ['add']
|
493
500
|
arr_opts << '-f' if opts[:with_fetch]
|
501
|
+
arr_opts << '--'
|
494
502
|
arr_opts << name
|
495
503
|
arr_opts << url
|
496
504
|
|
@@ -500,7 +508,7 @@ module Git
|
|
500
508
|
# this is documented as such, but seems broken for some reason
|
501
509
|
# i'll try to get around it some other way later
|
502
510
|
def remote_remove(name)
|
503
|
-
command('remote', ['rm', name])
|
511
|
+
command('remote', ['rm', '--', name])
|
504
512
|
end
|
505
513
|
|
506
514
|
def remotes
|
@@ -517,11 +525,12 @@ module Git
|
|
517
525
|
|
518
526
|
|
519
527
|
def fetch(remote)
|
520
|
-
command('fetch', remote
|
528
|
+
command('fetch', remote)
|
521
529
|
end
|
522
530
|
|
523
|
-
def push(remote, branch = 'master')
|
524
|
-
command('push', [remote
|
531
|
+
def push(remote, branch = 'master', tags = false)
|
532
|
+
command('push', [remote, branch])
|
533
|
+
command('push', ['--tags', remote]) if tags
|
525
534
|
end
|
526
535
|
|
527
536
|
def tag_sha(tag_name)
|
@@ -543,7 +552,7 @@ module Git
|
|
543
552
|
def read_tree(treeish, opts = {})
|
544
553
|
arr_opts = []
|
545
554
|
arr_opts << "--prefix=#{opts[:prefix]}" if opts[:prefix]
|
546
|
-
arr_opts
|
555
|
+
arr_opts += [treeish]
|
547
556
|
command('read-tree', arr_opts)
|
548
557
|
end
|
549
558
|
|
@@ -552,21 +561,20 @@ module Git
|
|
552
561
|
end
|
553
562
|
|
554
563
|
def commit_tree(tree, opts = {})
|
555
|
-
opts[:message]
|
564
|
+
opts[:message] ||= "commit tree #{tree}"
|
556
565
|
t = Tempfile.new('commit-message')
|
557
566
|
t.write(opts[:message])
|
558
567
|
t.close
|
559
568
|
|
560
569
|
arr_opts = []
|
561
570
|
arr_opts << tree
|
562
|
-
arr_opts <<
|
563
|
-
opts[:parents].
|
564
|
-
arr_opts
|
565
|
-
command('commit-tree', arr_opts)
|
571
|
+
arr_opts << '-p' << opts[:parent] if opts[:parent]
|
572
|
+
arr_opts += [opts[:parents]].map { |p| ['-p', p] }.flatten if opts[:parents]
|
573
|
+
command('commit-tree', arr_opts, true, "< #{escape t.path}")
|
566
574
|
end
|
567
575
|
|
568
576
|
def update_ref(branch, commit)
|
569
|
-
command('update-ref', [branch
|
577
|
+
command('update-ref', [branch, commit])
|
570
578
|
end
|
571
579
|
|
572
580
|
def checkout_index(opts = {})
|
@@ -574,7 +582,8 @@ module Git
|
|
574
582
|
arr_opts << "--prefix=#{opts[:prefix]}" if opts[:prefix]
|
575
583
|
arr_opts << "--force" if opts[:force]
|
576
584
|
arr_opts << "--all" if opts[:all]
|
577
|
-
arr_opts <<
|
585
|
+
arr_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String
|
586
|
+
|
578
587
|
command('checkout-index', arr_opts)
|
579
588
|
end
|
580
589
|
|
@@ -586,43 +595,39 @@ module Git
|
|
586
595
|
# :remote
|
587
596
|
# :path
|
588
597
|
def archive(sha, file = nil, opts = {})
|
589
|
-
opts[:format]
|
598
|
+
opts[:format] ||= 'zip'
|
590
599
|
|
591
600
|
if opts[:format] == 'tgz'
|
592
601
|
opts[:format] = 'tar'
|
593
602
|
opts[:add_gzip] = true
|
594
603
|
end
|
595
604
|
|
596
|
-
|
597
|
-
file = Tempfile.new('archive').path
|
598
|
-
end
|
605
|
+
file ||= Tempfile.new('archive').path
|
599
606
|
|
600
607
|
arr_opts = []
|
601
608
|
arr_opts << "--format=#{opts[:format]}" if opts[:format]
|
602
609
|
arr_opts << "--prefix=#{opts[:prefix]}" if opts[:prefix]
|
603
610
|
arr_opts << "--remote=#{opts[:remote]}" if opts[:remote]
|
604
611
|
arr_opts << sha
|
605
|
-
arr_opts << opts[:path] if opts[:path]
|
606
|
-
arr_opts
|
607
|
-
arr_opts << "> #{file.to_s}"
|
608
|
-
command('archive', arr_opts)
|
612
|
+
arr_opts << '--' << opts[:path] if opts[:path]
|
613
|
+
command('archive', arr_opts, true, (opts[:add_gzip] ? '| gzip' : '') + " > #{escape file}")
|
609
614
|
return file
|
610
615
|
end
|
611
616
|
|
612
617
|
private
|
613
618
|
|
614
|
-
def command_lines(cmd, opts = [], chdir = true)
|
619
|
+
def command_lines(cmd, opts = [], chdir = true, redirect = '')
|
615
620
|
command(cmd, opts, chdir).split("\n")
|
616
621
|
end
|
617
622
|
|
618
|
-
def command(cmd, opts = [], chdir = true, &block)
|
619
|
-
ENV['GIT_DIR'] = @git_dir
|
620
|
-
ENV['GIT_INDEX_FILE'] = @git_index_file
|
621
|
-
ENV['GIT_WORK_TREE'] = @git_work_dir
|
623
|
+
def command(cmd, opts = [], chdir = true, redirect = '', &block)
|
624
|
+
ENV['GIT_DIR'] = @git_dir
|
625
|
+
ENV['GIT_INDEX_FILE'] = @git_index_file
|
626
|
+
ENV['GIT_WORK_TREE'] = @git_work_dir
|
622
627
|
path = @git_work_dir || @git_dir || @path
|
623
628
|
|
624
|
-
opts = opts.
|
625
|
-
git_cmd = "git #{cmd} #{opts} 2>&1"
|
629
|
+
opts = [opts].flatten.map {|s| escape(s) }.join(' ')
|
630
|
+
git_cmd = "git #{cmd} #{opts} #{redirect} 2>&1"
|
626
631
|
|
627
632
|
out = nil
|
628
633
|
if chdir && (Dir.getwd != path)
|
@@ -652,6 +657,10 @@ module Git
|
|
652
657
|
`#{git_cmd}`.chomp
|
653
658
|
end
|
654
659
|
end
|
655
|
-
|
660
|
+
|
661
|
+
def escape(s)
|
662
|
+
"'" + s.to_s.gsub('\'', '\'\\\'\'') + "'"
|
663
|
+
end
|
664
|
+
|
656
665
|
end
|
657
666
|
end
|
data/lib/git/log.rb
CHANGED
@@ -4,22 +4,20 @@ module Git
|
|
4
4
|
class Log
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
-
@base = nil
|
8
|
-
@commits = nil
|
9
|
-
|
10
|
-
@object = nil
|
11
|
-
@path = nil
|
12
|
-
@count = nil
|
13
|
-
@since = nil
|
14
|
-
@until = nil
|
15
|
-
@between = nil
|
16
|
-
|
17
|
-
@dirty_flag = nil
|
18
|
-
|
19
7
|
def initialize(base, count = 30)
|
20
8
|
dirty_log
|
21
9
|
@base = base
|
22
10
|
@count = count
|
11
|
+
|
12
|
+
@commits = nil
|
13
|
+
@author = nil
|
14
|
+
@grep = nil
|
15
|
+
@object = nil
|
16
|
+
@path = nil
|
17
|
+
@since = nil
|
18
|
+
@skip = nil
|
19
|
+
@until = nil
|
20
|
+
@between = nil
|
23
21
|
end
|
24
22
|
|
25
23
|
def object(objectish)
|
@@ -46,6 +44,12 @@ module Git
|
|
46
44
|
return self
|
47
45
|
end
|
48
46
|
|
47
|
+
def skip(num)
|
48
|
+
dirty_log
|
49
|
+
@skip = num
|
50
|
+
return self
|
51
|
+
end
|
52
|
+
|
49
53
|
def since(date)
|
50
54
|
dirty_log
|
51
55
|
@since = date
|
@@ -76,11 +80,9 @@ module Git
|
|
76
80
|
@commits.size rescue nil
|
77
81
|
end
|
78
82
|
|
79
|
-
def each
|
83
|
+
def each(&block)
|
80
84
|
check_log
|
81
|
-
@commits.each
|
82
|
-
yield c
|
83
|
-
end
|
85
|
+
@commits.each(&block)
|
84
86
|
end
|
85
87
|
|
86
88
|
def first
|
@@ -105,11 +107,11 @@ module Git
|
|
105
107
|
def run_log
|
106
108
|
log = @base.lib.full_log_commits(:count => @count, :object => @object,
|
107
109
|
:path_limiter => @path, :since => @since,
|
108
|
-
:author => @author, :grep => @grep,
|
110
|
+
:author => @author, :grep => @grep, :skip => @skip,
|
109
111
|
:until => @until, :between => @between)
|
110
112
|
@commits = log.map { |c| Git::Object::Commit.new(@base, c['sha'], c) }
|
111
113
|
end
|
112
114
|
|
113
115
|
end
|
114
116
|
|
115
|
-
end
|
117
|
+
end
|