sourcecontrol 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ == 0.0.1 / 2007-02-17
2
+
3
+ * 1 major enhancement
4
+ * First release, as a requirement for RPlug
5
+ * This is as bare-bones as it gets, folks
6
+
@@ -0,0 +1,13 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/sc
6
+ lib/source_control.rb
7
+ lib/source_control/base.rb
8
+ lib/source_control/cvs.rb
9
+ lib/source_control/darcs.rb
10
+ lib/source_control/mercurial.rb
11
+ lib/source_control/subversion.rb
12
+ lib/source_control/svk.rb
13
+ test/test_source_control.rb
@@ -0,0 +1,48 @@
1
+ source_control
2
+ by Jamie Macey and Steven Baker
3
+ http://dev.tracefunc.com/source_control/
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSYS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2006 FIX
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ $: << File.expand_path('./lib')
4
+ require 'source_control'
5
+
6
+ Hoe.new('sourcecontrol', SourceControl::VERSION) do |p|
7
+ p.author = ['Jamie Macey', 'Steven Baker']
8
+ p.email = 'jamie.macey@gmail.com'
9
+ p.summary = "SourceControl is a library to provide abstract access to version control systems"
10
+
11
+ p.rubyforge_name = 'sourcecontrol'
12
+
13
+ # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
14
+ # p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
15
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
16
+ end
17
+
18
+ desc 'Run rcov coverage report'
19
+ task :rcov do
20
+ system "rm -rf coverage"
21
+ system "rcov -Ilib test/test_*.rb test/*/test_*.rb"
22
+ end
23
+
data/bin/sc ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ gem 'source_control'
4
+
@@ -0,0 +1,39 @@
1
+ require 'yaml'
2
+ require 'rubygems'
3
+ gem 'facets'
4
+ require 'facet/string/starts_with'
5
+
6
+ require 'source_control/base'
7
+ require 'source_control/cvs'
8
+ require 'source_control/darcs'
9
+ require 'source_control/mercurial'
10
+ require 'source_control/subversion'
11
+ require 'source_control/svk'
12
+
13
+ module SourceControl
14
+ VERSION = '0.0.1'
15
+
16
+ # Magic creation method. If a local repository is in an unknown
17
+ # version control system, this method uses a heuristic to determine
18
+ # which VCS a given path belongs in. If indeterminate, returns nil.
19
+ def self.new(path)
20
+ [SVK, Subversion, CVS, Mercurial, Darcs].each do |scm|
21
+ if scm.covers? path
22
+ return scm.new(:local => path)
23
+ end
24
+ end
25
+ nil
26
+ end
27
+
28
+ def self.find(name)
29
+ case name.to_s.downcase
30
+ when 'svn', 'subversion': Subversion
31
+ when 'hg', 'mercurial': Mercurial
32
+ when 'darcs': Darcs
33
+ when 'svk': SVK
34
+ when 'cvs': CVS
35
+ end
36
+ end
37
+
38
+ end
39
+
@@ -0,0 +1,27 @@
1
+ module SourceControl
2
+
3
+ # Base source control class, all concrete source controls subclass
4
+ # from it.
5
+ class Base
6
+ def initialize(options)
7
+ @sc = options
8
+ end
9
+
10
+ def get_remote_info
11
+ @remote_info ||= get_remote_info_concrete
12
+ end
13
+
14
+ # def method_missing(method, *args)
15
+ # run "#{command} #{method}"
16
+ # end
17
+
18
+ def shell(cmd)
19
+ # puts "SC: #{cmd}"
20
+ response = `#{cmd}`
21
+ # puts response
22
+ response
23
+ end
24
+ end
25
+
26
+ end
27
+
@@ -0,0 +1,12 @@
1
+ module SourceControl
2
+
3
+ class CVS < Base
4
+ def command; 'cvs' end
5
+
6
+ def self.covers?(path)
7
+ File.exist? path + '/CVS'
8
+ end
9
+ end
10
+
11
+ end
12
+
@@ -0,0 +1,16 @@
1
+ module SourceControl
2
+
3
+ class Darcs < Base
4
+ def command; 'darcs' end
5
+
6
+ def self.covers?(path)
7
+ path_parts = path.split('/')
8
+ path_parts.length.downto(1) do |n|
9
+ return true if File.exist? path_parts[0...n].join('/') + '/_darcs'
10
+ end
11
+ false
12
+ end
13
+ end
14
+
15
+ end
16
+
@@ -0,0 +1,27 @@
1
+ module SourceControl
2
+
3
+ class Mercurial < Base
4
+ def command; 'hg' end
5
+
6
+ def self.covers?(path)
7
+ path_parts = path.split('/')
8
+ path_parts.length.downto(1) do |n|
9
+ return true if File.exist? path_parts[0...n].join('/') + '/.hg'
10
+ end
11
+ false
12
+ end
13
+
14
+ def commit(options)
15
+ cmd = 'hg commit'
16
+ options.each do |key, value|
17
+ case key
18
+ when :message
19
+ cmd << " -m '#{value}'"
20
+ end
21
+ end
22
+ run "#{cmd}"
23
+ end
24
+ end
25
+
26
+ end
27
+
@@ -0,0 +1,57 @@
1
+ module SourceControl
2
+
3
+ class Subversion < Base
4
+ def command; 'svn' end
5
+
6
+ def self.covers?(path)
7
+ File.exist? path + '/.svn'
8
+ end
9
+
10
+ def add(relative_path)
11
+ shell "#{command} add #{relative_path}"
12
+ end
13
+
14
+ def export(opts)
15
+ cmd = "#{command} export #{@sc[:remote_uri]} #{opts[:dir]}"
16
+ if opts[:revision]
17
+ cmd << " -r #{opts[:revision]}"
18
+ end
19
+ shell cmd
20
+ end
21
+
22
+ def get_remote_info_concrete
23
+ remote_info = {}
24
+ server_response = shell "#{command} info #{@sc[:remote_uri]}"
25
+
26
+ server_response =~ /^Last Changed Rev: (.*)$/
27
+ remote_info[:last_changed_revision] = $1.to_i
28
+
29
+ remote_info
30
+ end
31
+
32
+ def last_changed_revision
33
+ get_remote_info
34
+ @remote_info[:last_changed_revision]
35
+ end
36
+
37
+ def remove(relative_path)
38
+ shell "#{command} rm #{relative_path}"
39
+ end
40
+
41
+ def status(path)
42
+ results = Hash.new{|h,k| h[k] = [] }
43
+ shell("#{command} st #{path}").each do |line|
44
+ case line
45
+ when /^M (.*)$/: results[:modified] << $1
46
+ when /^A (.*)$/: results[:added] << $1
47
+ when /^D (.*)$/: results[:removed] << $1
48
+ when /^\? (.*)$/: results[:unknown] << $1
49
+ when /^! (.*)$/: results[:missing] << $1
50
+ end
51
+ end
52
+ results
53
+ end
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,40 @@
1
+ module SourceControl
2
+
3
+ class SVK < Base
4
+ def command; 'svk' end
5
+
6
+ def self.covers?(path)
7
+ configfile = File.expand_path('~/.svk/config')
8
+ return false unless File.exists?(configfile)
9
+ svk_config = YAML.load(File.read(configfile))
10
+ svk_config['checkout'].value['hash'].keys.each do |checkout_path|
11
+ return true if path.starts_with? checkout_path
12
+ end
13
+ false
14
+ end
15
+
16
+ def add(relative_path)
17
+ shell "#{command} add #{relative_path}"
18
+ end
19
+
20
+ def remove(relative_path)
21
+ shell "#{command} rm #{relative_path}"
22
+ end
23
+
24
+ def status(path)
25
+ results = Hash.new{|h,k| h[k] = [] }
26
+ shell("#{command} st #{path}").each do |line|
27
+ case line
28
+ when /^M (.*)$/: results[:modified] << $1
29
+ when /^A (.*)$/: results[:added] << $1
30
+ when /^D (.*)$/: results[:removed] << $1
31
+ when /^\? (.*)$/: results[:unknown] << $1
32
+ when /^! (.*)$/: results[:missing] << $1
33
+ end
34
+ end
35
+ results
36
+ end
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,30 @@
1
+ require 'test/unit'
2
+ require 'source_control'
3
+ require 'rubygems'
4
+ require 'mocha'
5
+
6
+ class SourceControl::Base
7
+ attr_accessor :remote_info
8
+ def get_remote_info_concrete; end
9
+ end
10
+
11
+ class TestBase < Test::Unit::TestCase
12
+ def setup
13
+ @sc = SourceControl::Base.new(:remote => '/')
14
+ end
15
+
16
+ def test_get_remote_info
17
+ @sc.expects(:get_remote_info_concrete).returns(:foo)
18
+ assert_equal :foo, @sc.get_remote_info
19
+ end
20
+
21
+ def test_get_remote_info_caches_result
22
+ @sc.expects(:get_remote_info_concrete).returns(:foo).times(1)
23
+ assert_equal nil, @sc.remote_info
24
+ assert_equal :foo, @sc.get_remote_info
25
+ assert_equal :foo, @sc.get_remote_info
26
+ assert_equal :foo, @sc.get_remote_info
27
+ assert_equal :foo, @sc.remote_info
28
+ end
29
+ end
30
+
@@ -0,0 +1,83 @@
1
+ require 'test/unit'
2
+ require 'source_control'
3
+ require 'rubygems'
4
+ require 'mocha'
5
+
6
+ class TestSubversionRemote < Test::Unit::TestCase
7
+ def setup
8
+ @sc = SourceControl::Subversion.new(:remote_uri => 'svn://localhost/')
9
+ end
10
+
11
+ def test_export
12
+ @sc.expects(:shell).with("svn export svn://localhost/ foo")
13
+ @sc.export(:dir => 'foo')
14
+ end
15
+
16
+ def test_export_with_revision
17
+ @sc.expects(:shell).with("svn export svn://localhost/ foo -r 13")
18
+ @sc.export(:dir => 'foo', :revision => 13)
19
+ end
20
+
21
+ def test_get_remote_info_concrete
22
+ command = "svn info svn://localhost/"
23
+ response= <<RESPONSE
24
+ Path: arts
25
+ URL: http://thar.be/svn/projects/plugins/arts
26
+ Repository Root: http://thar.be/svn/projects
27
+ Repository UUID: fc021c06-de14-0410-8c5a-e664d767796e
28
+ Revision: 74
29
+ Node Kind: directory
30
+ Last Changed Author: kevinc
31
+ Last Changed Rev: 74
32
+ Last Changed Date: 2007-01-29 00:22:27 -0800 (Mon, 29 Jan 2007)
33
+
34
+ RESPONSE
35
+ @sc.expects(:shell).with(command).returns(response)
36
+ expected_info = {
37
+ :last_changed_revision => 74
38
+ }
39
+ assert_equal expected_info, @sc.get_remote_info_concrete
40
+ end
41
+ end
42
+
43
+ class TestSubversionLocal < Test::Unit::TestCase
44
+ def setup
45
+ @sc = SourceControl::Subversion.new(:local_path => '/home/user/dev/project')
46
+ end
47
+
48
+ def test_add
49
+ @sc.expects(:shell).with("svn add foo")
50
+ @sc.add("foo")
51
+ end
52
+
53
+ def test_remove
54
+ @sc.expects(:shell).with("svn rm foo")
55
+ @sc.remove("foo")
56
+ end
57
+
58
+ def test_status
59
+ response = <<RESPONSE
60
+ M mod1
61
+ D rem1
62
+ A add1
63
+ ! mis1
64
+ ? unk1
65
+ M dir/mod2
66
+ D dir/rem2
67
+ A dir/add2
68
+ ! dir/mis2
69
+ ? dir/unk2
70
+
71
+ RESPONSE
72
+ @sc.expects(:shell).with("svn st foo").returns(response)
73
+ status = @sc.status("foo")
74
+ assert_equal %w(mod1 dir/mod2), status[:modified]
75
+ assert_equal %w(add1 dir/add2), status[:added]
76
+ assert_equal %w(rem1 dir/rem2), status[:removed]
77
+ assert_equal %w(mis1 dir/mis2), status[:missing]
78
+ assert_equal %w(unk1 dir/unk2), status[:unknown]
79
+ end
80
+
81
+ end
82
+
83
+
@@ -0,0 +1,48 @@
1
+ require 'test/unit'
2
+ require 'source_control'
3
+ require 'rubygems'
4
+ require 'mocha'
5
+
6
+ #class TestSVKRemote < Test::Unit::TestCase
7
+ #end
8
+
9
+ class TestSVKLocal < Test::Unit::TestCase
10
+ def setup
11
+ @sc = SourceControl::SVK.new(:local_path => '/home/user/dev/project')
12
+ end
13
+
14
+ def test_add
15
+ @sc.expects(:shell).with("svk add foo")
16
+ @sc.add("foo")
17
+ end
18
+
19
+ def test_remove
20
+ @sc.expects(:shell).with("svk rm foo")
21
+ @sc.remove("foo")
22
+ end
23
+
24
+ def test_status
25
+ response = <<RESPONSE
26
+ M mod1
27
+ D rem1
28
+ A add1
29
+ ! mis1
30
+ ? unk1
31
+ M dir/mod2
32
+ D dir/rem2
33
+ A dir/add2
34
+ ! dir/mis2
35
+ ? dir/unk2
36
+
37
+ RESPONSE
38
+ @sc.expects(:shell).with("svk st foo").returns(response)
39
+ status = @sc.status("foo")
40
+ assert_equal %w(mod1 dir/mod2), status[:modified]
41
+ assert_equal %w(add1 dir/add2), status[:added]
42
+ assert_equal %w(rem1 dir/rem2), status[:removed]
43
+ assert_equal %w(mis1 dir/mis2), status[:missing]
44
+ assert_equal %w(unk1 dir/unk2), status[:unknown]
45
+ end
46
+
47
+ end
48
+
@@ -0,0 +1,78 @@
1
+ require 'test/unit'
2
+ require 'source_control'
3
+
4
+ SCM_PATH = ARGV[0]
5
+ SCM_TYPE = ARGV[1]
6
+
7
+ class SourceControlTest < Test::Unit::TestCase
8
+
9
+ def test_scm_interface
10
+ initialize_scm
11
+ create_repository
12
+ copy_in_files
13
+ check_status
14
+ add_files
15
+ commit_initial_files
16
+ check_committed_status
17
+ modify_working_copy
18
+ check_modified_status
19
+ commit_modifications
20
+ check_revision_history
21
+ check_file_history
22
+ destroy_repository
23
+ end
24
+
25
+ def initialize_scm
26
+
27
+ end
28
+
29
+ def create_repository
30
+
31
+ end
32
+
33
+ def copy_in_files
34
+
35
+ end
36
+
37
+ def check_status
38
+
39
+ end
40
+
41
+ def add_files
42
+
43
+ end
44
+
45
+ def commit_initial_files
46
+
47
+ end
48
+
49
+ def check_committed_status
50
+
51
+ end
52
+
53
+ def modify_working_copy
54
+
55
+ end
56
+
57
+ def check_modified_status
58
+
59
+ end
60
+
61
+ def commit_modifications
62
+
63
+ end
64
+
65
+ def check_revision_history
66
+
67
+ end
68
+
69
+ def check_file_history
70
+
71
+ end
72
+
73
+ def destroy_repository
74
+
75
+ end
76
+
77
+ end
78
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: sourcecontrol
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-02-20 00:00:00 -08:00
8
+ summary: SourceControl is a library to provide abstract access to version control systems
9
+ require_paths:
10
+ - lib
11
+ email: jamie.macey@gmail.com
12
+ homepage: http://www.zenspider.com/ZSS/Products/sourcecontrol/
13
+ rubyforge_project: sourcecontrol
14
+ description: The author was too lazy to write a description
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Jamie Macey
31
+ - Steven Baker
32
+ files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ - Rakefile
37
+ - bin/sc
38
+ - lib/source_control.rb
39
+ - lib/source_control/base.rb
40
+ - lib/source_control/cvs.rb
41
+ - lib/source_control/darcs.rb
42
+ - lib/source_control/mercurial.rb
43
+ - lib/source_control/subversion.rb
44
+ - lib/source_control/svk.rb
45
+ - test/test_source_control.rb
46
+ test_files:
47
+ - test/test_source_control.rb
48
+ - test/source_control/test_subversion.rb
49
+ - test/source_control/test_base.rb
50
+ - test/source_control/test_svk.rb
51
+ rdoc_options: []
52
+
53
+ extra_rdoc_files: []
54
+
55
+ executables:
56
+ - sc
57
+ extensions: []
58
+
59
+ requirements: []
60
+
61
+ dependencies:
62
+ - !ruby/object:Gem::Dependency
63
+ name: hoe
64
+ version_requirement:
65
+ version_requirements: !ruby/object:Gem::Version::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.2.0
70
+ version: