pullr 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ doc
2
+ pkg
3
+ tmp/*
4
+ .DS_Store
5
+ .yardoc
6
+ *.db
7
+ *.log
8
+ *.swp
9
+ *~
data/.specopts ADDED
@@ -0,0 +1 @@
1
+ --colour --format specdoc
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title 'Pullr Documentation' --protected --files ChangeLog.md,LICENSE.txt
data/ChangeLog.md ADDED
@@ -0,0 +1,9 @@
1
+ ### 0.1.1 / 2010-03-14
2
+
3
+ * Initial release.
4
+ * Currently supports pulling from:
5
+ * Mercurial (Hg)
6
+ * Git
7
+ * SubVersion (SVN)
8
+ * Rsync
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+
2
+ Copyright (c) 2010 Hal Brodigan
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ 'Software'), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Pullr
2
+
3
+ * [pullr.rubyforge.org](http://pullr.rubyforge.org/)
4
+ * [github.com/postmodern/pullr](http://github.com/postmodern/pullr/)
5
+ * Postmodern (postmodern.mod3 at gmail.com)
6
+
7
+ ## Description
8
+
9
+ Pullr is a Ruby library for quickly pulling down or updating any Repository.
10
+ Currently, Pullr supports Git, Mercurial (Hg), SubVersion (SVN) and Rsync.
11
+ Pullr provides a command-line utility and an API which can be used by
12
+ other frameworks.
13
+
14
+ ## Features
15
+
16
+ * Currently supports pulling from:
17
+ * Mercurial (Hg)
18
+ * Git
19
+ * SubVersion (SVN)
20
+ * Rsync
21
+
22
+ ## Synopsis
23
+
24
+ Pull down a repository:
25
+
26
+ $ pullr git://github.com/evanphx/rubinius.git
27
+
28
+ Pull down a repository into a specific directory:
29
+
30
+ $ pullr git://github.com/datamapper/dm-rails.git /home/deploy/dm-rails
31
+
32
+ Pull down a repository from a generic HTTP URL:
33
+
34
+ $ pullr http://www.tortall.net/svn/yasm/trunk/yasm -S svn
35
+
36
+ Update an existing repository:
37
+
38
+ $ cd yasm
39
+ $ pullr -u
40
+
41
+ ## Examples
42
+
43
+ Pull down a repository:
44
+
45
+ remote = Pullr::RemoteRepository.new(:uri => 'git://github.com/evanphx/rubinius.git')
46
+ remote.pull
47
+ # => #<Pullr::LocalRepository: ...>
48
+
49
+ Pull down a repository into a specific directory:
50
+
51
+ remote = Pullr::RemoteRepository.new(:uri => 'git://github.com/datamapper/dm-rails.git /home/deploy/dm-rails')
52
+ remote.pull('/home/deploy/dm-rails')
53
+ # => #<Pullr::LocalRepository: ...>
54
+
55
+ Pull down a repository from a generic HTTP URL:
56
+
57
+ remote = Pullr::RemoteRepository.new(:uri => 'http://www.tortall.net/svn/yasm/trunk/yasm', :scm => :svn)
58
+ remote.pull
59
+
60
+ Update an existing repository:
61
+
62
+ local = Pullr::LocalRepository.new(:path => 'yasm')
63
+ local.update
64
+
65
+ ## Requirements
66
+
67
+ * [addressable](http://addressable.rubyforge.org/) >= 0.2.1
68
+
69
+ ## Install
70
+
71
+ $ sudo gem install pullr
72
+
73
+ ## License
74
+
75
+ See {file:LICENSE.txt} for license information.
76
+
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require './lib/pullr/version.rb'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = 'pullr'
9
+ gem.version = Pullr::VERSION
10
+ gem.summary = %Q{A Ruby library for quickly pulling down or updating any Repository.}
11
+ gem.description = %Q{Pullr is a Ruby library for quickly pulling down or updating any Repository. Pullr currently supports Git, Mercurial (Hg), SubVersion (SVN) and Rsync. Pullr provides a command-line utility and an API which can be used by other frameworks.}
12
+ gem.email = 'postmodern.mod3@gmail.com'
13
+ gem.homepage = 'http://github.com/postmodern/pullr'
14
+ gem.authors = ['Postmodern']
15
+ gem.add_dependency 'addressable', '>= 2.1.1'
16
+ gem.add_development_dependency 'rspec', '>= 1.3.0'
17
+ gem.add_development_dependency 'yard', '>= 0.5.3'
18
+ gem.has_rdoc = 'yard'
19
+ end
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs += ['lib', 'spec']
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ spec.spec_opts = ['--options', '.specopts']
29
+ end
30
+
31
+ task :spec => :check_dependencies
32
+ task :default => :spec
33
+
34
+ begin
35
+ require 'yard'
36
+
37
+ YARD::Rake::YardocTask.new
38
+ rescue LoadError
39
+ task :yard do
40
+ abort "YARD is not available. In order to run yard, you must: gem install yard"
41
+ end
42
+ end
data/bin/pullr ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
4
+ unless $LOAD_PATH.include?(lib_dir)
5
+ $LOAD_PATH << lib_dir
6
+ end
7
+
8
+ require 'pullr/cli'
9
+
10
+ Pullr::CLI.run
data/lib/pullr.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'pullr/remote_repository'
2
+ require 'pullr/local_repository'
3
+ require 'pullr/version'
data/lib/pullr/cli.rb ADDED
@@ -0,0 +1,98 @@
1
+ require 'pullr/local_repository'
2
+ require 'pullr/remote_repository'
3
+
4
+ require 'optparse'
5
+
6
+ module Pullr
7
+ class CLI
8
+
9
+ #
10
+ # Initializes the Command Line Interface (CLI).
11
+ #
12
+ def initialize
13
+ @scm = nil
14
+ @uri = nil
15
+ @path = nil
16
+ @mode = :clone
17
+ @args = []
18
+ end
19
+
20
+ #
21
+ # Runs the Command Line Interface (CLI).
22
+ #
23
+ def CLI.run
24
+ self.new.run(*ARGV)
25
+ end
26
+
27
+ #
28
+ # Runs the Command Line Interface (CLI) with the given arguments.
29
+ #
30
+ # @param [Array<String>] args
31
+ # Arguments to run the CLI with.
32
+ #
33
+ def run(*args)
34
+ optparse(*args)
35
+
36
+ case @mode
37
+ when :clone
38
+ @uri ||= @args[0]
39
+
40
+ unless @uri
41
+ STDERR.puts "pullr: missing the URI argument"
42
+ exit -1
43
+ end
44
+
45
+ repo = RemoteRepository.new(
46
+ :uri => @uri,
47
+ :scm => @scm
48
+ )
49
+
50
+ repo.pull(@path || @args[1])
51
+ when :update
52
+ repo = LocalRepository.new(
53
+ :uri => @uri,
54
+ :path => @path,
55
+ :scm => @scm
56
+ )
57
+
58
+ repo.update
59
+ end
60
+ end
61
+
62
+ protected
63
+
64
+ #
65
+ # Parses the given arguments.
66
+ #
67
+ # @param [Array<String>] args
68
+ # The command-line arguments.
69
+ #
70
+ def optparse(*args)
71
+ opts = OptionParser.new
72
+
73
+ opts.banner = 'usage: pullr URI [PATH]'
74
+
75
+ opts.on('-S','--scm NAME','Source Code Management to use') do |scm|
76
+ @scm = scm
77
+ end
78
+
79
+ opts.on('-U','--uri URI','The URI of the repository') do |uri|
80
+ @uri = uri
81
+ end
82
+
83
+ opts.on('-u','--update [PATH]','Update the repository') do |path|
84
+ @mode = :update
85
+ @path = (path || Dir.pwd)
86
+ end
87
+
88
+ begin
89
+ @args = opts.parse!(args)
90
+ rescue OptionParser::InvalidOption => e
91
+ STDERR.puts e.message
92
+ STDERR.puts opts
93
+ exit -1
94
+ end
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,39 @@
1
+ module Pullr
2
+ module CommandLine
3
+ #
4
+ # Changes directories.
5
+ #
6
+ # @param [String] path
7
+ # Path to the new directory.
8
+ #
9
+ # @yield []
10
+ # If a block is given, then the directory will only be changed
11
+ # temporarily, then changed back after the block has finished.
12
+ #
13
+ def cd(path,&block)
14
+ if block
15
+ pwd = Dir.pwd
16
+ Dir.chdir(path)
17
+
18
+ block.call()
19
+
20
+ Dir.chdir(pwd)
21
+ else
22
+ Dir.chdir(path)
23
+ end
24
+ end
25
+
26
+ #
27
+ # Runs a command.
28
+ #
29
+ # @param [String] program
30
+ # The name or path of the program to run.
31
+ #
32
+ # @param [Array<String>] args
33
+ # The additional arguments to run with the program.
34
+ #
35
+ def sh(program,*args)
36
+ system(program,*args)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ require 'pullr/exceptions/ambigious_repository'
2
+ require 'pullr/exceptions/ambigious_uri'
3
+ require 'pullr/exceptions/unknown_scm'
@@ -0,0 +1,4 @@
1
+ module Pullr
2
+ class AmbigiousRepository < RuntimeError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pullr
2
+ class AmbigiousURI < RuntimeError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Pullr
2
+ class UnknownSCM < StandardError
3
+ end
4
+ end
@@ -0,0 +1,72 @@
1
+ require 'pullr/exceptions/ambigious_repository'
2
+ require 'pullr/repository'
3
+
4
+ module Pullr
5
+ class LocalRepository
6
+
7
+ include Repository
8
+
9
+ # The path of the repository
10
+ attr_reader :path
11
+
12
+ # The SCM used for the repository
13
+ attr_reader :scm
14
+
15
+ # Optional URI for the remote repository
16
+ attr_accessor :uri
17
+
18
+ #
19
+ # Initializes the repository.
20
+ #
21
+ # @param [Hash] options
22
+ # Options for the repository.
23
+ #
24
+ # @option options [String] :path
25
+ # Path to the repository.
26
+ #
27
+ # @option options [Symbol, String] :scm
28
+ # The SCM used to manage the repository.
29
+ #
30
+ # @option options [URI::Generic] :uri
31
+ # Optional URI for the remote repository.
32
+ #
33
+ def initialize(options={})
34
+ super(options)
35
+
36
+ @path = options[:path]
37
+
38
+ unless @scm
39
+ infer_scm_from_dir && infer_scm_from_uri
40
+ end
41
+
42
+ unless @scm
43
+ raise(AmbigiousRepository,"could not infer the SCM from the directory #{@path.dump}",caller)
44
+ end
45
+
46
+ extend SCM.lookup(@scm)
47
+ end
48
+
49
+ #
50
+ # The control directory used by the SCM.
51
+ #
52
+ # @return [String]
53
+ # The name of the control directory.
54
+ #
55
+ def scm_dir
56
+ dir, scm = SCM::DIRS.find { |dir,scm| scm == @scm }
57
+
58
+ return dir
59
+ end
60
+
61
+ #
62
+ # Pulls any new updates for the repository down.
63
+ #
64
+ # @param [URI::Generic] uri
65
+ # Optional URI to pull from.
66
+ #
67
+ def update(uri=self.uri)
68
+ scm_update(@path,uri)
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,56 @@
1
+ require 'pullr/exceptions/ambigious_uri'
2
+ require 'pullr/repository'
3
+ require 'pullr/local_repository'
4
+
5
+ module Pullr
6
+ class RemoteRepository
7
+
8
+ include Repository
9
+
10
+ # The SCM that manages the remote repository
11
+ attr_reader :scm
12
+
13
+ # The URI of the remote repository
14
+ attr_reader :uri
15
+
16
+ #
17
+ # Initializes the remote repository.
18
+ #
19
+ # @param [Hash] options
20
+ # Options for the remote repository.
21
+ #
22
+ # @option options [URI::Generic] :uri
23
+ # The URI of the remote repository.
24
+ #
25
+ # @option options [Symbol, String] :scm
26
+ # The SCM used for the remote repository.
27
+ #
28
+ def initialize(options={})
29
+ super(options)
30
+
31
+ infer_scm_from_uri unless @scm
32
+
33
+ unless @scm
34
+ raise(AmbigiousURI,"could not infer the SCM used for the URI #{@uri}",caller)
35
+ end
36
+
37
+ extend SCM.lookup(@scm)
38
+ end
39
+
40
+ #
41
+ # Clones the remote repository into the given destination.
42
+ #
43
+ # @param [String] dest
44
+ # The destination directory to clone the repository into.
45
+ #
46
+ # @return [Repository]
47
+ # The cloned repository.
48
+ #
49
+ def pull(dest=nil)
50
+ scm_pull(@uri,dest)
51
+
52
+ return LocalRepository.new(:path => dest, :scm => @scm)
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,67 @@
1
+ require 'pullr/scm/scm'
2
+
3
+ require 'addressable/uri'
4
+
5
+ module Pullr
6
+ module Repository
7
+ #
8
+ # Initializes the repository.
9
+ #
10
+ # @param [Hash] options
11
+ # Options for the repository.
12
+ #
13
+ # @option options [Symbol, String] :scm
14
+ # The SCM used to manage the repository.
15
+ #
16
+ # @option options [URI::Generic] :uri
17
+ # Optional URI for the remote repository.
18
+ #
19
+ def initialize(options={})
20
+ @scm = options[:scm]
21
+ @uri = nil
22
+
23
+ case options[:uri]
24
+ when Addressable::URI
25
+ @uri = options[:uri]
26
+ when Hash
27
+ @uri = Addressable::URI.new(options[:uri])
28
+ when URI::Generic, String
29
+ @uri = Addressable::URI.parse(options[:uri])
30
+ end
31
+ end
32
+
33
+ protected
34
+
35
+ #
36
+ # Attempts to infer the SCM used for the remote repository.
37
+ #
38
+ # @return [Boolean]
39
+ # Specifies whether the SCM was infered from the repository's URI.
40
+ #
41
+ def infer_scm_from_uri
42
+ if @uri
43
+ if (@scm = SCM.infer_from_uri(@uri))
44
+ return true
45
+ end
46
+ end
47
+
48
+ return false
49
+ end
50
+
51
+ #
52
+ # Attempts to infer the SCM used for the repository.
53
+ #
54
+ # @return [Boolean]
55
+ # Specifies whether the SCM was successfully infered.
56
+ #
57
+ def infer_scm_from_dir
58
+ if @path
59
+ if (@scm = SCM.infer_from_dir(@path))
60
+ return true
61
+ end
62
+ end
63
+
64
+ return false
65
+ end
66
+ end
67
+ end
data/lib/pullr/scm.rb ADDED
@@ -0,0 +1 @@
1
+ require 'pullr/scm/scm'
@@ -0,0 +1,42 @@
1
+ require 'pullr/command_line'
2
+
3
+ module Pullr
4
+ module SCM
5
+ module Git
6
+ include CommandLine
7
+
8
+ #
9
+ # Pulls down a copy of a Git source repository.
10
+ #
11
+ # @param [Addressable::URI] uri
12
+ # The URI of the Git repository.
13
+ #
14
+ # @param [String] dest
15
+ # Optional destination to pull the repository down into.
16
+ #
17
+ def scm_pull(uri,dest=nil)
18
+ if dest
19
+ sh 'git', 'clone', uri, dest
20
+ else
21
+ sh 'git', 'clone', uri
22
+ end
23
+ end
24
+
25
+ #
26
+ # Updates a local Git repository.
27
+ #
28
+ # @param [String] path
29
+ # Path to the local repository to update.
30
+ #
31
+ # @param [Addressable::URI] uri
32
+ # Optional URI of the remote Git repository to update from.
33
+ #
34
+ def scm_update(path,uri=nil)
35
+ cd(path) do
36
+ sh 'git', 'reset', '-q', '--hard', 'HEAD'
37
+ sh 'git', 'pull'
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ require 'pullr/command_line'
2
+
3
+ module Pullr
4
+ module SCM
5
+ module Mercurial
6
+ include CommandLine
7
+
8
+ #
9
+ # Pulls down a copy of a Mercurial repository.
10
+ #
11
+ # @param [Addressable::URI] uri
12
+ # The URI of the Mercurial repository.
13
+ #
14
+ # @param [String] dest
15
+ # Optional destination to pull the repository down into.
16
+ #
17
+ def scm_pull(uri,dest=nil)
18
+ if dest
19
+ sh 'hg', 'clone', uri, dest
20
+ else
21
+ sh 'hg', 'clone', uri
22
+ end
23
+ end
24
+
25
+ #
26
+ # Updates a local Mercurial repository.
27
+ #
28
+ # @param [String] path
29
+ # Path to the local repository to update.
30
+ #
31
+ # @param [Addressable::URI] uri
32
+ # Optional URI of the remote Mercurial repository to update from.
33
+ #
34
+ def scm_update(path,uri=nil)
35
+ cd(path) do
36
+ sh 'hg', 'pull'
37
+ sh 'hg', 'update', '-C'
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,61 @@
1
+ require 'pullr/command_line'
2
+
3
+ module Pullr
4
+ module SCM
5
+ module Rsync
6
+ include CommandLine
7
+
8
+ #
9
+ # Pulls down a copy of a Rsync source repository.
10
+ #
11
+ # @param [Addressable::URI] uri
12
+ # The URI of the Rsync repository.
13
+ #
14
+ # @param [String] dest
15
+ # Optional destination to pull the repository down into.
16
+ #
17
+ def scm_pull(uri,dest=nil)
18
+ unless dest
19
+ raise(ArgumentError,"the destination argument for clone is missing",caller)
20
+ end
21
+
22
+ sh 'rsync', '-a', rsync_uri(uri), dest
23
+ end
24
+
25
+ #
26
+ # Updates a local Rsync repository.
27
+ #
28
+ # @param [String] path
29
+ # Path to the local repository to update.
30
+ #
31
+ # @param [Addressable::URI] uri
32
+ # Optional URI of the remote Rsync repository to update from.
33
+ #
34
+ def scm_update(path,uri=nil)
35
+ unless uri
36
+ raise(ArgumentError,"must specify the 'uri' argument to pull from",caller)
37
+ end
38
+
39
+ sh 'rsync', '-v', '-a', '--delete-after', rsync_uri(uri), path
40
+ end
41
+
42
+ #
43
+ # Converts a given URI to one compatible with `rsync`.
44
+ #
45
+ # @param [URI::Generic] uri
46
+ # The URI to convert.
47
+ #
48
+ # @return [String]
49
+ # The `rsync` compatible URI.
50
+ #
51
+ def rsync_uri(uri)
52
+ new_uri = uri.host
53
+
54
+ new_uri = "#{uri.user}@#{new_uri}" if uri.user
55
+ new_uri = "#{new_uri}:#{uri.path}" unless uri.path.empty?
56
+
57
+ return new_uri
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,107 @@
1
+ require 'pullr/exceptions/unknown_scm'
2
+ require 'pullr/scm/git'
3
+ require 'pullr/scm/mercurial'
4
+ require 'pullr/scm/sub_version'
5
+ require 'pullr/scm/rsync'
6
+
7
+ module Pullr
8
+ module SCM
9
+ # Mapping of known SCM names and their respective mixins
10
+ NAMES = {
11
+ :git => Git,
12
+ :mercurial => Mercurial,
13
+ :hg => Mercurial,
14
+ :sub_version => SubVersion,
15
+ :subversion => SubVersion,
16
+ :svn => SubVersion,
17
+ :rsync => Rsync
18
+ }
19
+
20
+ # Mapping of known URI schemes and their respective SCM names
21
+ SCHEMES = {
22
+ 'git' => :git,
23
+ 'hg' => :mercurial,
24
+ 'svn' => :sub_version,
25
+ 'svn+ssh' => :sub_version,
26
+ 'rsync' => :rsync
27
+ }
28
+
29
+ # Mapping of URI path extensions and their respective SCM names
30
+ EXTS = {
31
+ '.git' => :git
32
+ }
33
+
34
+ # Mapping of directories and the SCMs that use them
35
+ DIRS = {
36
+ '.git' => :git,
37
+ '.hg' => :mercurial,
38
+ '.svn' => :sub_version
39
+ }
40
+
41
+ #
42
+ # Attempts to infer the SCM used for the remote repository.
43
+ #
44
+ # @param [Addressable::URI] uri
45
+ # The URI to infer the SCM from.
46
+ #
47
+ # @return [Symbol]
48
+ # The name of the infered SCM.
49
+ #
50
+ def SCM.infer_from_uri(uri)
51
+ uri_scheme = uri.scheme
52
+
53
+ if (scm = SCM::SCHEMES[uri_scheme])
54
+ return scm
55
+ end
56
+
57
+ uri_ext = File.extname(uri.path)
58
+
59
+ if (scm = SCM::EXTS[uri_ext])
60
+ return scm
61
+ end
62
+
63
+ return nil
64
+ end
65
+
66
+ #
67
+ # Attempts to infer the SCM used to manage a given directory.
68
+ #
69
+ # @param [String] path
70
+ # The path to the directory.
71
+ #
72
+ # @return [Symbol]
73
+ # The name of the infered SCM.
74
+ #
75
+ def SCM.infer_from_dir(path)
76
+ SCM::DIRS.each do |name,scm|
77
+ if File.directory?(File.join(path,name))
78
+ return scm
79
+ end
80
+ end
81
+
82
+ return nil
83
+ end
84
+
85
+ #
86
+ # Finds the SCM mixin for a given SCM name.
87
+ #
88
+ # @param [Symbol, String] name
89
+ # The name of the SCM.
90
+ #
91
+ # @return [Module]
92
+ # The SCM mixin.
93
+ #
94
+ # @raise [UnknownSCM]
95
+ # The SCM name did not map to a known SCM mixin.
96
+ #
97
+ def SCM.lookup(name)
98
+ name = name.to_sym
99
+
100
+ unless NAMES.has_key?(name)
101
+ raise(UnknownSCM,"unknown SCM #{name}",caller)
102
+ end
103
+
104
+ return NAMES[name]
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,39 @@
1
+ require 'pullr/command_line'
2
+
3
+ module Pullr
4
+ module SCM
5
+ module SubVersion
6
+ include CommandLine
7
+
8
+ #
9
+ # Pulls down a copy of a SubVersion source repository.
10
+ #
11
+ # @param [Addressable::URI] uri
12
+ # The URI of the SubVersion repository.
13
+ #
14
+ # @param [String] dest
15
+ # Optional destination to pull the repository down into.
16
+ #
17
+ def scm_pull(uri,dest=nil)
18
+ if dest
19
+ sh 'svn', 'checkout', uri, dest
20
+ else
21
+ sh 'svn', 'checkout', uri
22
+ end
23
+ end
24
+
25
+ #
26
+ # Updates a local SubVersion repository.
27
+ #
28
+ # @param [String] path
29
+ # Path to the local repository to update.
30
+ #
31
+ # @param [Addressable::URI] uri
32
+ # Optional URI of the remote SubVersion repository to update from.
33
+ #
34
+ def scm_update(path,uri=nil)
35
+ cd(path) { sh 'svn', 'update' }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ module Pullr
2
+ # pullr version
3
+ VERSION = '0.1.1'
4
+ end
data/pullr.gemspec ADDED
@@ -0,0 +1,84 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{pullr}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Postmodern"]
12
+ s.date = %q{2010-03-14}
13
+ s.default_executable = %q{pullr}
14
+ s.description = %q{Pullr is a Ruby library for quickly pulling down or updating any Repository. Pullr currently supports Git, Mercurial (Hg), SubVersion (SVN) and Rsync. Pullr provides a command-line utility and an API which can be used by other frameworks.}
15
+ s.email = %q{postmodern.mod3@gmail.com}
16
+ s.executables = ["pullr"]
17
+ s.extra_rdoc_files = [
18
+ "ChangeLog.md",
19
+ "LICENSE.txt",
20
+ "README.md"
21
+ ]
22
+ s.files = [
23
+ ".gitignore",
24
+ ".specopts",
25
+ ".yardopts",
26
+ "ChangeLog.md",
27
+ "LICENSE.txt",
28
+ "README.md",
29
+ "Rakefile",
30
+ "bin/pullr",
31
+ "lib/pullr.rb",
32
+ "lib/pullr/cli.rb",
33
+ "lib/pullr/command_line.rb",
34
+ "lib/pullr/exceptions.rb",
35
+ "lib/pullr/exceptions/ambigious_repository.rb",
36
+ "lib/pullr/exceptions/ambigious_uri.rb",
37
+ "lib/pullr/exceptions/unknown_scm.rb",
38
+ "lib/pullr/local_repository.rb",
39
+ "lib/pullr/remote_repository.rb",
40
+ "lib/pullr/repository.rb",
41
+ "lib/pullr/scm.rb",
42
+ "lib/pullr/scm/git.rb",
43
+ "lib/pullr/scm/mercurial.rb",
44
+ "lib/pullr/scm/rsync.rb",
45
+ "lib/pullr/scm/scm.rb",
46
+ "lib/pullr/scm/sub_version.rb",
47
+ "lib/pullr/version.rb",
48
+ "pullr.gemspec",
49
+ "spec/pullr_spec.rb",
50
+ "spec/scm_spec.rb",
51
+ "spec/spec_helper.rb"
52
+ ]
53
+ s.has_rdoc = %q{yard}
54
+ s.homepage = %q{http://github.com/postmodern/pullr}
55
+ s.rdoc_options = ["--charset=UTF-8"]
56
+ s.require_paths = ["lib"]
57
+ s.rubygems_version = %q{1.3.6}
58
+ s.summary = %q{A Ruby library for quickly pulling down or updating any Repository.}
59
+ s.test_files = [
60
+ "spec/spec_helper.rb",
61
+ "spec/pullr_spec.rb",
62
+ "spec/scm_spec.rb"
63
+ ]
64
+
65
+ if s.respond_to? :specification_version then
66
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
67
+ s.specification_version = 3
68
+
69
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
70
+ s.add_runtime_dependency(%q<addressable>, [">= 2.1.1"])
71
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
72
+ s.add_development_dependency(%q<yard>, [">= 0.5.3"])
73
+ else
74
+ s.add_dependency(%q<addressable>, [">= 2.1.1"])
75
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
76
+ s.add_dependency(%q<yard>, [">= 0.5.3"])
77
+ end
78
+ else
79
+ s.add_dependency(%q<addressable>, [">= 2.1.1"])
80
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
81
+ s.add_dependency(%q<yard>, [">= 0.5.3"])
82
+ end
83
+ end
84
+
@@ -0,0 +1,9 @@
1
+ require 'pullr/version'
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Pullr do
6
+ it "should define a VERSION constant" do
7
+ Pullr.should be_const_defined('VERSION')
8
+ end
9
+ end
data/spec/scm_spec.rb ADDED
@@ -0,0 +1,115 @@
1
+ require 'pullr/scm/scm'
2
+
3
+ require 'spec_helper'
4
+ require 'addressable/uri'
5
+ require 'fileutils'
6
+ require 'tmpdir'
7
+
8
+ describe SCM do
9
+ it "should lookup an SCM with a String name" do
10
+ SCM.lookup('git').should == SCM::Git
11
+ end
12
+
13
+ it "should lookup an SCM with a Symbol name" do
14
+ SCM.lookup(:git).should == SCM::Git
15
+ end
16
+
17
+ it "should raise UnknownSCM when looking up unknown SCM names" do
18
+ lambda {
19
+ SCM.lookup(:bla)
20
+ }.should raise_error(UnknownSCM)
21
+ end
22
+
23
+ describe "Git" do
24
+ it "should be known as 'git'" do
25
+ SCM.lookup(:git).should == SCM::Git
26
+ end
27
+
28
+ it "should be inferable from the scheme of a URI" do
29
+ uri = Addressable::URI.parse('git://sourceforge.net')
30
+
31
+ SCM.infer_from_uri(uri).should == :git
32
+ end
33
+
34
+ it "should be inferable from the extension of a URI" do
35
+ uri = Addressable::URI.parse('git@github.com/user/project.git')
36
+
37
+ SCM.infer_from_uri(uri).should == :git
38
+ end
39
+
40
+ it "should be inferable from the SCM control directory" do
41
+ repo = Dir.mktmpdir('repo')
42
+ FileUtils.mkdir(File.join(repo,'.git'))
43
+
44
+ SCM.infer_from_dir(repo).should == :git
45
+ end
46
+ end
47
+
48
+ describe "Mercurial" do
49
+ it "should be known as 'mercurial'" do
50
+ SCM.lookup(:mercurial).should == SCM::Mercurial
51
+ end
52
+
53
+ it "should also be known as 'hg'" do
54
+ SCM.lookup(:hg).should == SCM::Mercurial
55
+ end
56
+
57
+ it "should be inferable from the scheme of a URI" do
58
+ uri = Addressable::URI.parse('hg://sourceforge.net')
59
+
60
+ SCM.infer_from_uri(uri).should == :mercurial
61
+ end
62
+
63
+ it "should be inferable from the SCM control directory" do
64
+ repo = Dir.mktmpdir('repo')
65
+ FileUtils.mkdir(File.join(repo,'.hg'))
66
+
67
+ SCM.infer_from_dir(repo).should == :mercurial
68
+ end
69
+ end
70
+
71
+ describe "SubVersion" do
72
+ it "should be known as 'sub_version'" do
73
+ SCM.lookup(:sub_version).should == SCM::SubVersion
74
+ end
75
+
76
+ it "should also be known as 'subversion'" do
77
+ SCM.lookup(:subversion).should == SCM::SubVersion
78
+ end
79
+
80
+ it "should also be known as 'svn'" do
81
+ SCM.lookup(:svn).should == SCM::SubVersion
82
+ end
83
+
84
+ it "should be inferable from the scheme of a URI" do
85
+ uri = Addressable::URI.parse('svn://sourceforge.net')
86
+
87
+ SCM.infer_from_uri(uri).should == :sub_version
88
+ end
89
+
90
+ it "should be inferable from the 'svn+ssh' URI scheme " do
91
+ uri = Addressable::URI.parse('svn+ssh://sourceforge.net')
92
+
93
+ SCM.infer_from_uri(uri).should == :sub_version
94
+ end
95
+
96
+ it "should be inferable from the SCM control directory" do
97
+ repo = Dir.mktmpdir('repo')
98
+ FileUtils.mkdir(File.join(repo,'.svn'))
99
+
100
+ SCM.infer_from_dir(repo).should == :sub_version
101
+ end
102
+ end
103
+
104
+ describe "Rsync" do
105
+ it "should be known as 'rsync'" do
106
+ SCM.lookup(:rsync).should == SCM::Rsync
107
+ end
108
+
109
+ it "should be inferable from the scheme of a URI" do
110
+ uri = Addressable::URI.parse('rsync://sourceforge.net')
111
+
112
+ SCM.infer_from_uri(uri).should == :rsync
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ gem 'rspec', '>=1.3.0'
3
+ require 'spec'
4
+
5
+ require 'pullr/version'
6
+
7
+ include Pullr
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pullr
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Postmodern
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-14 00:00:00 -08:00
18
+ default_executable: pullr
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: addressable
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 1
30
+ - 1
31
+ version: 2.1.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 3
44
+ - 0
45
+ version: 1.3.0
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: yard
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 5
58
+ - 3
59
+ version: 0.5.3
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: Pullr is a Ruby library for quickly pulling down or updating any Repository. Pullr currently supports Git, Mercurial (Hg), SubVersion (SVN) and Rsync. Pullr provides a command-line utility and an API which can be used by other frameworks.
63
+ email: postmodern.mod3@gmail.com
64
+ executables:
65
+ - pullr
66
+ extensions: []
67
+
68
+ extra_rdoc_files:
69
+ - ChangeLog.md
70
+ - LICENSE.txt
71
+ - README.md
72
+ files:
73
+ - .gitignore
74
+ - .specopts
75
+ - .yardopts
76
+ - ChangeLog.md
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - bin/pullr
81
+ - lib/pullr.rb
82
+ - lib/pullr/cli.rb
83
+ - lib/pullr/command_line.rb
84
+ - lib/pullr/exceptions.rb
85
+ - lib/pullr/exceptions/ambigious_repository.rb
86
+ - lib/pullr/exceptions/ambigious_uri.rb
87
+ - lib/pullr/exceptions/unknown_scm.rb
88
+ - lib/pullr/local_repository.rb
89
+ - lib/pullr/remote_repository.rb
90
+ - lib/pullr/repository.rb
91
+ - lib/pullr/scm.rb
92
+ - lib/pullr/scm/git.rb
93
+ - lib/pullr/scm/mercurial.rb
94
+ - lib/pullr/scm/rsync.rb
95
+ - lib/pullr/scm/scm.rb
96
+ - lib/pullr/scm/sub_version.rb
97
+ - lib/pullr/version.rb
98
+ - pullr.gemspec
99
+ - spec/pullr_spec.rb
100
+ - spec/scm_spec.rb
101
+ - spec/spec_helper.rb
102
+ has_rdoc: yard
103
+ homepage: http://github.com/postmodern/pullr
104
+ licenses: []
105
+
106
+ post_install_message:
107
+ rdoc_options:
108
+ - --charset=UTF-8
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ requirements: []
126
+
127
+ rubyforge_project:
128
+ rubygems_version: 1.3.6
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: A Ruby library for quickly pulling down or updating any Repository.
132
+ test_files:
133
+ - spec/spec_helper.rb
134
+ - spec/pullr_spec.rb
135
+ - spec/scm_spec.rb