code_cache 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b35ba34266cc6f725541d547606b0bda66347ff
4
- data.tar.gz: 7b9e153b63507075879e93025035381296f86a55
3
+ metadata.gz: cf939dd1b7522417b33a50aefe64cc8e50f5fd7a
4
+ data.tar.gz: ced2daf270974cd3f988d829abd271e6ebe4af6e
5
5
  SHA512:
6
- metadata.gz: a0f4c2d7416cd4c446c3662cd307d3a712ea9957a505ad200b04f23f7e05416fa631f23ce48e483607749231fa03d7f0f4f86517a51adc3b6aa1f0e0d8db9e1f
7
- data.tar.gz: fef3d5e9b7294679c4ef00497dcb4c83167968872a5f180821a8226b2adfd00d15b4cd9cdd5d7577af6f861d3c5655f1c425b9880b4f3c6de262d233dd0f240e
6
+ metadata.gz: af3dd36dc40e347b417e1730dfa6898b96f6d92947395e94c640f6e79f7301171be0a57524c79d6d46640bd9447ae2bab57b424aba9591285c2a61d6876f4869
7
+ data.tar.gz: c2e5151d8ebece993df6247468abd028801c73cb0ff65ebb2fa7388428ec469ba195e978320931a705f2e6aeee8c95eaff8e795570dcfea62c82b337992758c5
data/README.md CHANGED
@@ -5,7 +5,8 @@ Version control checkout abstraction and cache.
5
5
 
6
6
  repo = CodeCache.repo( repo_url )
7
7
  begin
8
- repo.checkout( :head, 'path/to/checkout' )
8
+ repo.checkout( :head, 'path/to/checkout' ) # checkout master
9
+ repo.checkout( :head, 'path/to/checkout', 'branch_name' ) # checkout specific branch
9
10
  rescue => e
10
11
  puts "Checkout failed"
11
12
  end
@@ -11,11 +11,11 @@ module CodeCache
11
11
  end
12
12
  end
13
13
 
14
- def self.repo(url)
14
+ def self.repo(url, options = {})
15
15
  if self.identify(url) == :git
16
- Repo::Git.new(url)
16
+ Repo::Git.new(url, options)
17
17
  else
18
- Repo::SVN.new(url)
18
+ Repo::SVN.new(url, options)
19
19
  end
20
20
  end
21
21
 
@@ -1,13 +1,16 @@
1
1
  require 'fileutils'
2
+ require 'rbconfig'
3
+ require 'tmpdir'
2
4
 
3
5
  module CodeCache
4
6
 
5
7
  class Repo
6
-
8
+
7
9
  attr_accessor :url, :cache
8
-
10
+
9
11
  def initialize(url, options = {})
10
- @cache = options[:cache] || '/tmp/code_cache'
12
+ cache_dir = Dir.tmpdir() if RbConfig::CONFIG['host_os'].include? "ming"
13
+ @cache = options[:cache] || cache_dir || '/tmp/code_cache'
11
14
  @url = url
12
15
 
13
16
  check_repo(url)
@@ -52,5 +55,8 @@ module CodeCache
52
55
 
53
56
  class CopyError < StandardError
54
57
  end
58
+
59
+ class BranchNotFound < StandardError
60
+ end
55
61
 
56
62
  end
@@ -10,7 +10,7 @@ module CodeCache
10
10
  # Split the url into a unique array for the cache path
11
11
  def split_url
12
12
  match = /(?:(?:git|ssh)@(.*):|(?:https?:\/\/(.*?)\/))(.*).git/.match(url)
13
- match.captures.compact
13
+ match.captures.compact if match
14
14
  end
15
15
 
16
16
  # Check access to the repo in question
@@ -23,11 +23,10 @@ module CodeCache
23
23
 
24
24
  # Checkout a particular revision from the repo into the destination
25
25
  # Caches the checkout in the process
26
- def checkout( revision, destination )
26
+ def checkout( revision, destination , branch=nil)
27
27
 
28
- if revision != :head
29
- raise "Checking out anything other than the head of the default branch not supported"
30
- end
28
+ raise "Checking out anything other than the head of the default branch not supported" if revision != :head
29
+ raise "Not checking out, as #{destination} directory has another git repository" if !Dir["#{destination}/.git"].empty?
31
30
 
32
31
  cache_destination = location_in_cache()
33
32
 
@@ -36,9 +35,8 @@ module CodeCache
36
35
 
37
36
  puts "Cache: #{cache_destination}"
38
37
  puts "Destination: #{destination}"
39
-
40
- checkout_from_cache_to_destination(cache_destination, destination, revision)
41
-
38
+ output = checkout_from_cache_to_destination(cache_destination, destination, revision, branch)
39
+
42
40
  true
43
41
  end
44
42
 
@@ -63,11 +61,18 @@ module CodeCache
63
61
  { :output => output, :status => status }
64
62
  end
65
63
 
66
- def checkout_from_cache_to_destination(cache_destination, destination, revision)
67
- output = `git clone --single-branch #{cache_destination} #{destination} 2>&1`
64
+ def checkout_from_cache_to_destination(cache_destination, destination, revision, branch)
65
+ if branch
66
+ output = `git clone --single-branch #{cache_destination} #{destination} -b #{branch} 2>&1`
67
+ else
68
+ output = `git clone --single-branch #{cache_destination} #{destination} 2>&1`
69
+ end
68
70
  status = $? == 0
71
+
72
+ raise CodeCache::BranchNotFound if output.include? 'Could not find remote branch'
73
+
69
74
  { :output => output, :status => status }
70
75
  end
71
76
 
72
77
  end
73
- end
78
+ end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Buckhurst
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2016-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mixlib-shellout
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.7
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.7
27
41
  description: Provides a simple api for checking out svn and git repositories. Caches
28
42
  checkouts locally so that subsequent checkouts are optimised.
29
43
  email: david.buckhurst@bbc.co.uk
@@ -31,11 +45,11 @@ executables: []
31
45
  extensions: []
32
46
  extra_rdoc_files: []
33
47
  files:
34
- - README.md
35
48
  - lib/code_cache.rb
36
49
  - lib/code_cache/repo.rb
37
50
  - lib/code_cache/repo/git.rb
38
51
  - lib/code_cache/repo/svn.rb
52
+ - README.md
39
53
  homepage: https://github.com/bbc/code_cache
40
54
  licenses:
41
55
  - MIT
@@ -46,17 +60,17 @@ require_paths:
46
60
  - lib
47
61
  required_ruby_version: !ruby/object:Gem::Requirement
48
62
  requirements:
49
- - - ">="
63
+ - - '>='
50
64
  - !ruby/object:Gem::Version
51
65
  version: '0'
52
66
  required_rubygems_version: !ruby/object:Gem::Requirement
53
67
  requirements:
54
- - - ">="
68
+ - - '>='
55
69
  - !ruby/object:Gem::Version
56
70
  version: '0'
57
71
  requirements: []
58
72
  rubyforge_project:
59
- rubygems_version: 2.4.8
73
+ rubygems_version: 2.0.14
60
74
  signing_key:
61
75
  specification_version: 4
62
76
  summary: Abstracts & caches svn & git operations