xtrn 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ Externals
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format nested --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ xtrn (0.1.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ ZenTest (4.6.2)
10
+ autotest (4.4.6)
11
+ ZenTest (>= 4.4.1)
12
+ diff-lcs (1.1.3)
13
+ rspec (2.8.0)
14
+ rspec-core (~> 2.8.0)
15
+ rspec-expectations (~> 2.8.0)
16
+ rspec-mocks (~> 2.8.0)
17
+ rspec-core (2.8.0)
18
+ rspec-expectations (2.8.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.8.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ autotest (~> 4.4)
27
+ rspec (~> 2.8)
28
+ xtrn!
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # A brain-dead replacement for svn:externals (and soon Git submodules)
2
+
3
+ Mainly, <tt>xtrn</tt> doesn't depend on the revision control system. This means that you can pull in code from heterogeneous systems with a single command.
4
+
5
+ Just create an <tt>Externals</tt> file in the root of your project, require the <tt>xtrn</tt> gem and run <tt>xtrn</tt> (again, in the root of
6
+ your project).
7
+
8
+ The format of the <tt>Externals</tt> file is as follows:
9
+
10
+ ---
11
+ - url: svn://svnhost/dir/to/external/codebase
12
+ path: checkout/to/here
13
+ type: svn
14
+ - url: svn://svnhost2/another/thing
15
+ path: this/one/goes/here
16
+ type: svn
data/bin/xtrn ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'xtrn'
3
+ require 'yaml'
4
+
5
+ dir = Xtrn::Directory.new(YAML.load(File.open('Externals', 'rb', &:read)), Xtrn::Executor.new)
6
+ dir.update!
7
+
8
+ GITIGNORE = '.gitignore'
9
+
10
+ gitignore_contents = File.file?(GITIGNORE) ? File.open(GITIGNORE, 'rb', &:read) : ''
11
+ updated_gitignore_contents = dir.updated_gitignore(gitignore_contents)
12
+
13
+ File.open(GITIGNORE, 'wb') {|f|f.write(updated_gitignore_contents)} unless updated_gitignore_contents == gitignore_contents
@@ -0,0 +1,35 @@
1
+ module Xtrn
2
+ class Directory
3
+
4
+ def initialize(config, executor)
5
+ @config = config
6
+ @executor = executor
7
+ end
8
+
9
+ def update!
10
+ @config.each do |entry|
11
+
12
+ x = @executor.exec("svn info #{entry['url']}")
13
+ rev = YAML.load(x)["Last Changed Rev"]
14
+ cmd = if File.directory?(entry['path'])
15
+ 'update'
16
+ else
17
+ 'checkout'
18
+ end
19
+
20
+ @executor.exec("svn #{cmd} -r#{rev} #{entry['url']} #{entry['path']}")
21
+ end
22
+
23
+ def updated_gitignore(original_gitignore)
24
+ to_add = @config.map{|i|i['path']}
25
+
26
+ original_gitignore.each_line do |line|
27
+ line.strip!
28
+ to_add.delete(line)
29
+ end
30
+ return original_gitignore if to_add.empty?
31
+ [*original_gitignore.lines.map(&:"strip!"), *to_add].join("\n")
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,8 @@
1
+ module Xtrn
2
+ class Executor
3
+ def exec(cmd)
4
+ `#{cmd}`
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,3 @@
1
+ module Xtrn
2
+ VERSION = '0.1.0'
3
+ end
data/lib/xtrn.rb ADDED
@@ -0,0 +1,3 @@
1
+ %w(directory executor).each do |i|
2
+ require File.dirname(__FILE__) + "/xtrn/#{i}"
3
+ end
data/spec/xtrn_spec.rb ADDED
@@ -0,0 +1,74 @@
1
+ require 'rspec'
2
+ require 'xtrn'
3
+ describe Xtrn::Directory do
4
+
5
+ let(:config) do
6
+ [
7
+ {
8
+ 'path' => 'foo',
9
+ 'type' => 'svn',
10
+ 'url' => 'svn://svnhost/path/to/project'
11
+ }
12
+ ]
13
+ end
14
+
15
+ let(:executor) {mock('executor')}
16
+
17
+ subject { Xtrn::Directory.new(config, executor) }
18
+
19
+ context 'updating' do
20
+ before do
21
+ executor.should_receive(:exec).with("svn info #{config[0]['url']}") {
22
+ <<EOF
23
+ Ignore this one: Some value
24
+ Last Changed Rev: 12345
25
+ Some other stuff: Bobby
26
+ EOF
27
+ }
28
+ end
29
+
30
+ context 'when checkout path does not exist' do
31
+
32
+ it 'should check out the given svn directory path' do
33
+ File.should_receive(:"directory?").with(config[0]['path']).and_return(false)
34
+ executor.should_receive(:exec).with("svn checkout -r12345 #{config[0]['url']} #{config[0]['path']}")
35
+
36
+ subject.update!
37
+ end
38
+
39
+ end
40
+
41
+ context 'when checkout path already exists' do
42
+
43
+ it 'should update the given svn directory path' do
44
+ File.should_receive(:"directory?").with(config[0]['path']).and_return(true)
45
+ executor.should_receive(:exec).with("svn update -r12345 #{config[0]['url']} #{config[0]['path']}")
46
+
47
+ subject.update!
48
+ end
49
+ end
50
+ end
51
+
52
+ context "gitignore" do
53
+ it 'should add missing entry to gitignore' do
54
+ original_gitignore =<<EOF
55
+ Some_entry
56
+ # A comment
57
+ Another_entry
58
+ EOF
59
+ subject.updated_gitignore(original_gitignore).should == original_gitignore + config[0]['path']
60
+ end
61
+
62
+
63
+ it 'should not add duplicate entries to gitignore' do
64
+ original_gitignore =<<EOF
65
+ Some_entry
66
+ #{config[0]['path']}
67
+ # A comment
68
+ Another_entry
69
+ EOF
70
+ subject.updated_gitignore(original_gitignore).should == original_gitignore
71
+ end
72
+ end
73
+
74
+ end
data/xtrn.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/lib/xtrn/version'
2
+ Gem::Specification.new do |s|
3
+ s.name = 'xtrn'
4
+ s.summary = 'Manage your externals without locking yourself into a single source control system.'
5
+ s.authors = ['James Fairbairn', 'Gavin Sandie']
6
+ s.email = %w(james@mediamolecule.com gavin@mediamolecule.com)
7
+ s.version = Xtrn::VERSION
8
+
9
+ s.files = `git ls-files`.split("\n")
10
+ s.executables = `git ls-files bin`.split("\n").map{|i|i.sub(/^bin\//, '')}
11
+
12
+ s.add_development_dependency 'rspec', '~> 2.8'
13
+ s.add_development_dependency 'autotest', '~> 4.4'
14
+
15
+ end
16
+
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xtrn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James Fairbairn
9
+ - Gavin Sandie
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-01-18 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &20265220 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '2.8'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *20265220
26
+ - !ruby/object:Gem::Dependency
27
+ name: autotest
28
+ requirement: &20264720 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '4.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *20264720
37
+ description:
38
+ email:
39
+ - james@mediamolecule.com
40
+ - gavin@mediamolecule.com
41
+ executables:
42
+ - xtrn
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gitignore
47
+ - .rspec
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - README.md
51
+ - bin/xtrn
52
+ - lib/xtrn.rb
53
+ - lib/xtrn/directory.rb
54
+ - lib/xtrn/executor.rb
55
+ - lib/xtrn/version.rb
56
+ - spec/xtrn_spec.rb
57
+ - xtrn.gemspec
58
+ homepage:
59
+ licenses: []
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.11
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Manage your externals without locking yourself into a single source control
82
+ system.
83
+ test_files: []