scm 0.1.0.pre1 → 0.1.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +3 -0
- data/lib/scm/commits/commit.rb +30 -4
- data/lib/scm/commits/git.rb +6 -6
- data/lib/scm/commits/hg.rb +3 -3
- data/lib/scm/git.rb +61 -13
- data/lib/scm/hg.rb +39 -6
- data/lib/scm/repository.rb +27 -0
- data/lib/scm/svn.rb +37 -14
- data/lib/scm/util.rb +30 -0
- data/lib/scm/version.rb +1 -1
- data/spec/hg_spec.rb +24 -0
- metadata +12 -9
data/ChangeLog.md
CHANGED
data/lib/scm/commits/commit.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
1
3
|
module SCM
|
2
4
|
module Commits
|
3
5
|
#
|
@@ -17,6 +19,12 @@ module SCM
|
|
17
19
|
# The summary of the commit
|
18
20
|
attr_reader :summary
|
19
21
|
|
22
|
+
# The full commit message of the commit
|
23
|
+
attr_reader :message
|
24
|
+
|
25
|
+
# The files changed by the commit
|
26
|
+
attr_reader :files
|
27
|
+
|
20
28
|
#
|
21
29
|
# Creates a new commit object.
|
22
30
|
#
|
@@ -32,11 +40,29 @@ module SCM
|
|
32
40
|
# @param [String] summary
|
33
41
|
# The summary of the commit.
|
34
42
|
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
43
|
+
# @param [String] message
|
44
|
+
# The full commit message of the commit.
|
45
|
+
#
|
46
|
+
# @param [String] files
|
47
|
+
# The files changed in the commit.
|
48
|
+
#
|
49
|
+
def initialize(commit,date,author,summary,message,files=[])
|
50
|
+
@commit = commit
|
51
|
+
@date = date
|
52
|
+
@author = author
|
39
53
|
@summary = summary
|
54
|
+
@message = message
|
55
|
+
@files = files
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Inspects the commit.
|
60
|
+
#
|
61
|
+
# @return [String]
|
62
|
+
# The inspected commit.
|
63
|
+
#
|
64
|
+
def inspect
|
65
|
+
"#<#{self.class}: #{@commit}>"
|
40
66
|
end
|
41
67
|
|
42
68
|
#
|
data/lib/scm/commits/git.rb
CHANGED
@@ -37,12 +37,12 @@ module SCM
|
|
37
37
|
# @param [String] summary
|
38
38
|
# The summary of the commit.
|
39
39
|
#
|
40
|
-
def initialize(commit,parent,tree,date,author,email,summary)
|
41
|
-
super(commit,date,author,summary)
|
40
|
+
def initialize(commit,parent,tree,date,author,email,summary,message,files)
|
41
|
+
super(commit,date,author,summary,message,files)
|
42
42
|
|
43
43
|
@parent = parent
|
44
|
-
@tree
|
45
|
-
@email
|
44
|
+
@tree = tree
|
45
|
+
@email = email
|
46
46
|
end
|
47
47
|
|
48
48
|
alias sha1 commit
|
@@ -50,11 +50,11 @@ module SCM
|
|
50
50
|
#
|
51
51
|
# Coerces the Git commit into an Array.
|
52
52
|
#
|
53
|
-
# @return [Array<commit, parent, tree, date, author, email, summary>]
|
53
|
+
# @return [Array<commit, parent, tree, date, author, email, summary, message, files>]
|
54
54
|
# The commit components.
|
55
55
|
#
|
56
56
|
def to_ary
|
57
|
-
[@commit, @parent, @tree, @date, @author, @email, @summary]
|
57
|
+
[@commit, @parent, @tree, @date, @author, @email, @summary, @message, @files]
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
data/lib/scm/commits/hg.rb
CHANGED
@@ -34,10 +34,10 @@ module SCM
|
|
34
34
|
# @param [String] summary
|
35
35
|
# The summary of the commit.
|
36
36
|
#
|
37
|
-
def initialize(revision,hash,branch,user,date,summary)
|
38
|
-
super(revision,date,user,summary)
|
37
|
+
def initialize(revision,hash,branch,user,date,summary,message,files)
|
38
|
+
super(revision,date,user,summary,message,files)
|
39
39
|
|
40
|
-
@hash
|
40
|
+
@hash = hash
|
41
41
|
@branch = branch
|
42
42
|
end
|
43
43
|
|
data/lib/scm/git.rb
CHANGED
@@ -249,11 +249,19 @@ module SCM
|
|
249
249
|
# @param [String, Symbol] name
|
250
250
|
# The name of the branch to switch to.
|
251
251
|
#
|
252
|
+
# @param [Hash] options
|
253
|
+
# Additional options.
|
254
|
+
#
|
255
|
+
# @option options [Boolean] :quiet
|
256
|
+
# Switch branch quietly.
|
257
|
+
#
|
252
258
|
# @return [Boolean]
|
253
259
|
# Specifies whether the branch was successfully switched.
|
254
260
|
#
|
255
|
-
def switch_branch(name)
|
256
|
-
|
261
|
+
def switch_branch(name, options={})
|
262
|
+
arguments = ""
|
263
|
+
arguments << '-q' if options[:quiet]
|
264
|
+
git(:checkout, arguments, name)
|
257
265
|
end
|
258
266
|
|
259
267
|
#
|
@@ -441,7 +449,10 @@ module SCM
|
|
441
449
|
def commits(options={})
|
442
450
|
return enum_for(:commits,options) unless block_given?
|
443
451
|
|
444
|
-
arguments = [
|
452
|
+
arguments = [
|
453
|
+
'--name-only',
|
454
|
+
'--pretty=format:%H~|~%P~|~%T~|~%at~|~%an~|~%ae~|~%s~|~%b~|~'
|
455
|
+
]
|
445
456
|
|
446
457
|
if options[:limit]
|
447
458
|
arguments << "-#{options[:limit]}"
|
@@ -455,16 +466,23 @@ module SCM
|
|
455
466
|
arguments += ['--', *options[:paths]]
|
456
467
|
end
|
457
468
|
|
458
|
-
commit
|
459
|
-
parent
|
460
|
-
tree
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
469
|
+
commit = nil
|
470
|
+
parent = nil
|
471
|
+
tree = nil
|
472
|
+
date = nil
|
473
|
+
author = nil
|
474
|
+
email = nil
|
475
|
+
summary = nil
|
476
|
+
|
477
|
+
io = popen('git log',*arguments)
|
465
478
|
|
466
|
-
|
467
|
-
|
479
|
+
until io.eof?
|
480
|
+
line = io.readline.chomp
|
481
|
+
|
482
|
+
commit, parent, tree, date, author, email, summary, body, files = line.split('~|~',9)
|
483
|
+
|
484
|
+
message = [summary, '', body].join($/)
|
485
|
+
files = readlines_until(io)
|
468
486
|
|
469
487
|
yield Commits::Git.new(
|
470
488
|
commit,
|
@@ -473,11 +491,41 @@ module SCM
|
|
473
491
|
Time.at(date.to_i),
|
474
492
|
author,
|
475
493
|
email,
|
476
|
-
summary
|
494
|
+
summary,
|
495
|
+
message,
|
496
|
+
files
|
477
497
|
)
|
478
498
|
end
|
479
499
|
end
|
480
500
|
|
501
|
+
#
|
502
|
+
# Lists the files of the Git repository.
|
503
|
+
#
|
504
|
+
# @param [String] pattern
|
505
|
+
# Optional glob pattern to filter the files by.
|
506
|
+
#
|
507
|
+
# @yield [file]
|
508
|
+
# The given block will be passed each file.
|
509
|
+
#
|
510
|
+
# @yieldparam [String] file
|
511
|
+
# A path of a file tracked by Git.
|
512
|
+
#
|
513
|
+
# @return [Enumerator]
|
514
|
+
# If no block is given, an Enumerator will be returned.
|
515
|
+
#
|
516
|
+
def files(pattern=nil,&block)
|
517
|
+
return enum_for(:files,pattern) unless block
|
518
|
+
|
519
|
+
arguments = []
|
520
|
+
|
521
|
+
if pattern
|
522
|
+
arguments << '--' << pattern
|
523
|
+
end
|
524
|
+
|
525
|
+
popen('git','ls-files',*arguments,&block)
|
526
|
+
return nil
|
527
|
+
end
|
528
|
+
|
481
529
|
protected
|
482
530
|
|
483
531
|
#
|
data/lib/scm/hg.rb
CHANGED
@@ -35,6 +35,10 @@ module SCM
|
|
35
35
|
# Could not initialize the Hg repository.
|
36
36
|
#
|
37
37
|
def self.create(path,options={})
|
38
|
+
if options[:bare]
|
39
|
+
raise("Hg does not support creating bare repositories")
|
40
|
+
end
|
41
|
+
|
38
42
|
unless path.start_with?('ssh://')
|
39
43
|
FileUtils.mkdir_p(path)
|
40
44
|
end
|
@@ -398,7 +402,7 @@ module SCM
|
|
398
402
|
def commits(options={})
|
399
403
|
return enum_for(:commits,options) unless block_given?
|
400
404
|
|
401
|
-
arguments = []
|
405
|
+
arguments = ['-v']
|
402
406
|
|
403
407
|
if options[:commit]
|
404
408
|
arguments << '--rev' << options[:commit]
|
@@ -422,12 +426,18 @@ module SCM
|
|
422
426
|
user = nil
|
423
427
|
date = nil
|
424
428
|
summary = nil
|
429
|
+
message = nil
|
430
|
+
files = nil
|
431
|
+
|
432
|
+
io = popen('hg log',*arguments)
|
433
|
+
|
434
|
+
until io.eof?
|
435
|
+
line = io.readline.chomp
|
425
436
|
|
426
|
-
popen('hg log',*arguments) do |line|
|
427
437
|
if line.empty?
|
428
|
-
yield Commits::Hg.new(revision,hash,branch,user,date,summary)
|
438
|
+
yield Commits::Hg.new(revision,hash,branch,user,date,summary,message,files)
|
429
439
|
|
430
|
-
revision = hash = branch = user = date = summary = nil
|
440
|
+
revision = hash = branch = user = date = summary = message = files = nil
|
431
441
|
else
|
432
442
|
key, value = line.split(' ',2)
|
433
443
|
|
@@ -440,13 +450,36 @@ module SCM
|
|
440
450
|
user = value
|
441
451
|
when 'date:'
|
442
452
|
date = Time.parse(value)
|
443
|
-
when '
|
444
|
-
|
453
|
+
when 'description:'
|
454
|
+
description = readlines_until(io)
|
455
|
+
summary = description[0]
|
456
|
+
message = description.join($/)
|
457
|
+
when 'files:'
|
458
|
+
files = value.split(' ')
|
445
459
|
end
|
446
460
|
end
|
447
461
|
end
|
448
462
|
end
|
449
463
|
|
464
|
+
#
|
465
|
+
# Lists the files of the Hg repository.
|
466
|
+
#
|
467
|
+
# @yield [file]
|
468
|
+
# The given block will be passed each file.
|
469
|
+
#
|
470
|
+
# @yieldparam [String] file
|
471
|
+
# A path of a file tracked by Hg.
|
472
|
+
#
|
473
|
+
# @return [Enumerator]
|
474
|
+
# If no block is given, an Enumerator will be returned.
|
475
|
+
#
|
476
|
+
def files(&block)
|
477
|
+
return enum_for(:files) unless block
|
478
|
+
|
479
|
+
popen('hg','manifest',&block)
|
480
|
+
return nil
|
481
|
+
end
|
482
|
+
|
450
483
|
protected
|
451
484
|
|
452
485
|
#
|
data/lib/scm/repository.rb
CHANGED
@@ -311,6 +311,33 @@ module SCM
|
|
311
311
|
@path.to_s
|
312
312
|
end
|
313
313
|
|
314
|
+
#
|
315
|
+
# Inspects the Repository.
|
316
|
+
#
|
317
|
+
# @return [String]
|
318
|
+
# The repository class name and path.
|
319
|
+
#
|
320
|
+
def inspect
|
321
|
+
"#<#{self.class}: #{@path}>"
|
322
|
+
end
|
323
|
+
|
324
|
+
#
|
325
|
+
# Lists the files of the repository.
|
326
|
+
#
|
327
|
+
# @yield [file]
|
328
|
+
# The given block will be passed each file.
|
329
|
+
#
|
330
|
+
# @yieldparam [String] file
|
331
|
+
# A path of a file within the repository.
|
332
|
+
#
|
333
|
+
# @return [Enumerator]
|
334
|
+
# If no block is given, an Enumerator will be returned.
|
335
|
+
#
|
336
|
+
# @abstract
|
337
|
+
#
|
338
|
+
def files(&block)
|
339
|
+
end
|
340
|
+
|
314
341
|
protected
|
315
342
|
|
316
343
|
#
|
data/lib/scm/svn.rb
CHANGED
@@ -426,7 +426,7 @@ module SCM
|
|
426
426
|
def commits(options={})
|
427
427
|
return enum_for(:commits,options) unless block_given?
|
428
428
|
|
429
|
-
arguments = []
|
429
|
+
arguments = ['-v']
|
430
430
|
|
431
431
|
if options[:commit]
|
432
432
|
arguments << '--revision' << options[:commit]
|
@@ -443,7 +443,8 @@ module SCM
|
|
443
443
|
revision = nil
|
444
444
|
date = nil
|
445
445
|
author = nil
|
446
|
-
|
446
|
+
message = ''
|
447
|
+
files = []
|
447
448
|
|
448
449
|
io = popen('svn log',*arguments)
|
449
450
|
|
@@ -451,28 +452,50 @@ module SCM
|
|
451
452
|
io.readline
|
452
453
|
|
453
454
|
until io.eof?
|
454
|
-
line = io.readline
|
455
|
-
line.chomp!
|
455
|
+
line = io.readline.chomp
|
456
456
|
|
457
457
|
revision, author, date, changes = line.split(' | ',4)
|
458
458
|
revision = revision[1..-1].to_i
|
459
|
-
date
|
460
|
-
|
461
|
-
# eat the empty line separating the metadata from the summary
|
462
|
-
line.readline
|
459
|
+
date = Time.parse(date)
|
463
460
|
|
464
|
-
|
465
|
-
|
466
|
-
break if line == LOG_SEPARATOR
|
461
|
+
# eat the next line separating the metadata from the summary
|
462
|
+
line = io.readline.chomp
|
467
463
|
|
468
|
-
|
464
|
+
if line == 'Changed paths:'
|
465
|
+
files = readlines_until(io)
|
469
466
|
end
|
470
467
|
|
471
|
-
|
468
|
+
description = readlines_until(io,LOG_SEPARATOR)
|
469
|
+
summary = description[0]
|
470
|
+
message = description.join($/)
|
471
|
+
|
472
|
+
yield Commits::SVN.new(revision,date,author,summary,message,files)
|
472
473
|
|
473
474
|
revision = date = author = nil
|
474
|
-
|
475
|
+
message = ''
|
476
|
+
files = []
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
#
|
481
|
+
# Lists the files of the SVN repository.
|
482
|
+
#
|
483
|
+
# @yield [file]
|
484
|
+
# The given block will be passed each file.
|
485
|
+
#
|
486
|
+
# @yieldparam [String] file
|
487
|
+
# A path of a file tracked by SVN.
|
488
|
+
#
|
489
|
+
# @return [Enumerator]
|
490
|
+
# If no block is given, an Enumerator will be returned.
|
491
|
+
#
|
492
|
+
def files
|
493
|
+
return enum_for(:files) unless block_given?
|
494
|
+
|
495
|
+
popen('svn','ls','-R') do |file|
|
496
|
+
yield file if File.file?(File.join(@path,file))
|
475
497
|
end
|
498
|
+
return nil
|
476
499
|
end
|
477
500
|
|
478
501
|
protected
|
data/lib/scm/util.rb
CHANGED
@@ -20,6 +20,9 @@ module SCM
|
|
20
20
|
def run(program,*arguments)
|
21
21
|
arguments = arguments.map { |arg| arg.to_s }
|
22
22
|
|
23
|
+
# filter out empty Strings
|
24
|
+
arguments.reject! { |arg| arg.empty? }
|
25
|
+
|
23
26
|
system(program.to_s,*arguments)
|
24
27
|
end
|
25
28
|
|
@@ -61,5 +64,32 @@ module SCM
|
|
61
64
|
|
62
65
|
return io
|
63
66
|
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Read lines until a separator line is encountered.
|
70
|
+
#
|
71
|
+
# @param [IO] io
|
72
|
+
# The IO stream to read from.
|
73
|
+
#
|
74
|
+
# @param [String] separator
|
75
|
+
# The separator line to stop at.
|
76
|
+
#
|
77
|
+
# @return [Array<String>]
|
78
|
+
# The read lines.
|
79
|
+
#
|
80
|
+
def readlines_until(io,separator='')
|
81
|
+
lines = []
|
82
|
+
|
83
|
+
until io.eof?
|
84
|
+
line = io.readline
|
85
|
+
line.chomp!
|
86
|
+
|
87
|
+
break if line == separator
|
88
|
+
|
89
|
+
lines << line
|
90
|
+
end
|
91
|
+
|
92
|
+
return lines
|
93
|
+
end
|
64
94
|
end
|
65
95
|
end
|
data/lib/scm/version.rb
CHANGED
data/spec/hg_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'scm/hg'
|
3
|
+
|
4
|
+
describe Hg do
|
5
|
+
describe "create" do
|
6
|
+
it "should create the directory, if it does not exist" do
|
7
|
+
repo = Hg.create(directory('create_new_hg_repo'))
|
8
|
+
|
9
|
+
repo.path.should be_directory
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should create a hg repository" do
|
13
|
+
repo = Hg.create(mkdir('init_hg_repo'))
|
14
|
+
|
15
|
+
repo.path.join('.hg').should be_directory
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should raise an exception when :base is specified" do
|
19
|
+
lambda {
|
20
|
+
Hg.create(mkdir('init_bare_hg_repo'), :bare => true)
|
21
|
+
}.should raise_error
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.pre2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ore-tasks
|
16
|
-
requirement: &
|
16
|
+
requirement: &12756120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.4'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *12756120
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &12755360 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '2.4'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *12755360
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: yard
|
38
|
-
requirement: &
|
38
|
+
requirement: &12754740 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 0.7.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *12754740
|
47
47
|
description: SCM is a simple Ruby library for interacting with common SCMs, such as
|
48
48
|
Git, Mercurial (Hg) and SubVersion (SVN).
|
49
49
|
email: postmodern.mod3@gmail.com
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- scm.gemspec
|
76
76
|
- spec/git_spec.rb
|
77
77
|
- spec/helpers/scm.rb
|
78
|
+
- spec/hg_spec.rb
|
78
79
|
- spec/scm_spec.rb
|
79
80
|
- spec/spec_helper.rb
|
80
81
|
homepage: http://github.com/postmodern/scm
|
@@ -98,10 +99,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
99
|
version: '0'
|
99
100
|
requirements: []
|
100
101
|
rubyforge_project:
|
101
|
-
rubygems_version: 1.8.
|
102
|
+
rubygems_version: 1.8.10
|
102
103
|
signing_key:
|
103
104
|
specification_version: 3
|
104
105
|
summary: Ruby interface to common SCMs
|
105
106
|
test_files:
|
106
107
|
- spec/git_spec.rb
|
108
|
+
- spec/hg_spec.rb
|
107
109
|
- spec/scm_spec.rb
|
110
|
+
has_rdoc:
|