r10k 1.2.0rc1 → 1.2.0rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDUwMzg3OTY2MGUxZjA3MmFkMmQyNTAxOTUyMTc2YmJjNDU3ZWIyMg==
4
+ ZDA2OGNkZDI0MjI2M2UxODU5NmFjYTcxMTFiZmRlMWYxNjdmNTZiNw==
5
5
  data.tar.gz: !binary |-
6
- ODkwYWNjOGRjNzcyMGEwYTJiOTM5ZmE0ZDcwYjdlYzdkYjkwMmE2YQ==
6
+ YWJmZjEyYzdjMTQ3YzA3MDYzNzY3NWQzYTUzNTZlNmI1ZmQwMTg1OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmRmZmJiMjRkMGM3MjcwZGRlODk2YTAzZDM4ZTYwNTFhZTNhYjA0ZTg4Yzg5
10
- M2M3OTI2YjgxYjdjZTE3NjQ5MWU1MmY3ZTcxYTg0ZTA1MDQ0MmI0ODI0NTI3
11
- NWJmMDk0M2NhODczNjllNzA4MDU4ODJiNjRmOWQ4NzNjMmQ3YmU=
9
+ ZjY5NmRiYTc1ZDkwN2JhOWFkN2Y3NjFkZWY0OGM2MjJjMzNkOTk4ZTVjYTI4
10
+ YmIxYjFhMmRjNmIyYjYzMmU4ZmEyYWIxMDQwZjhhZjAxNWUxOGZmMmRkMmZk
11
+ ZmIwZTAzMTMxZjY5MzJhMzM4ZGJmOTZhMWU4NGE5ZDFkYTgwOTA=
12
12
  data.tar.gz: !binary |-
13
- MzExZTMyY2VjZTI4N2E3M2M2NjQ3Yzg4YTZmYzZjMjUwMmE0ZmQ4MjNmMWJk
14
- MmY3NTEwNmJlNDVkNWI5MGEyN2MwMjZjMmQ0NjYyYmJmZTQ0ZGNkYTU2MzZi
15
- NWRmZTViMTBjZGEzYTAwOTdiMmYzYmNkMmM2NThkM2U1MGQyMjk=
13
+ ODYwY2YwZmIyMTA3ZDQwNWUzMzlmOWNmYTBiMmU3YzE1M2YyMDU3ZTdhNmRk
14
+ MzA2NDMyNTRhOTI0M2NjYTk1NjEzYzY5MjdmNWZhYTE1NmVlODA0NDU3YjBl
15
+ NjVlMDc0ZGI1YmZiYWY2NDYxMGYyNDNhYmQ1MWEzMGU5ODUyMzQ=
data/CHANGELOG CHANGED
@@ -4,7 +4,7 @@ CHANGELOG
4
4
  1.2.0
5
5
  -----
6
6
 
7
- 2014/02/08
7
+ Unreleased
8
8
 
9
9
  ### User Notes
10
10
 
@@ -27,6 +27,47 @@ Modules can swap out sources. When an existing module is changed from Forge to
27
27
  Git, for instance, the existing module will be removed before the new module is
28
28
  installed. (GH-30)
29
29
 
30
+ 1.2.0rc2
31
+ --------
32
+
33
+ 2014/02/27
34
+
35
+ ### Notes
36
+
37
+ Git repositories were not tracking their upstream remotes, repos should now
38
+ properly update upstream changes.
39
+
40
+ Git reference clones now fetch their cache remotes immediately after the
41
+ initial clone.
42
+
43
+ 1.2.0rc1
44
+ --------
45
+
46
+ 2014/02/08
47
+
48
+ Release Candidate 1 for 1.2.0
49
+
50
+ 1.1.4
51
+ -----
52
+
53
+ 2014-02-24
54
+
55
+ This is a backwards compatible bugfix release.
56
+
57
+ ### Notes
58
+
59
+ * (GH-90) Multiple environments with the same name but with different sources
60
+ were previously colliding and some environments were being ignored. This has
61
+ been fixed and all environments should be deployed when updates are run.
62
+
63
+ ### Thanks
64
+
65
+ Thanks to the following contributors for their their extraordinary patience and
66
+ help in for chasing down GH-90:
67
+
68
+ * Andreas Ntaflos (antaflos)
69
+ * Igor Galić (igalic)
70
+
30
71
  1.1.3
31
72
  -----
32
73
 
@@ -5,6 +5,7 @@ module R10K
5
5
  require 'r10k/git/ref'
6
6
  require 'r10k/git/tag'
7
7
  require 'r10k/git/head'
8
+ require 'r10k/git/remote_head'
8
9
  require 'r10k/git/commit'
9
10
 
10
11
  require 'r10k/git/repository'
@@ -73,7 +73,7 @@ class R10K::Git::Cache < R10K::Git::Repository
73
73
  # @return [Array<String>] A list the branches for the git repository
74
74
  def branches
75
75
  output = git %w[for-each-ref refs/heads --format %(refname)], :git_dir => git_dir
76
- output.scan(%r[refs/heads/(.*)$]).flatten
76
+ output.stdout.scan(%r[refs/heads/(.*)$]).flatten
77
77
  end
78
78
 
79
79
  # @return [true, false] If the repository has been locally cached
@@ -0,0 +1,13 @@
1
+ require 'r10k/git'
2
+
3
+ # @api private
4
+ class R10K::Git::RemoteHead < R10K::Git::Head
5
+
6
+ def sha1
7
+ if @repository.nil?
8
+ raise ArgumentError, "Cannot resolve #{self.inspect}: no associated git repository"
9
+ else
10
+ @repository.resolve_head("refs/remotes/cache/#{@head}")
11
+ end
12
+ end
13
+ end
@@ -30,19 +30,10 @@ class R10K::Git::Repository
30
30
  #
31
31
  # @return [String] The dereferenced hash of `pattern`
32
32
  def resolve_ref(pattern)
33
- commit = nil
34
- begin
35
- all_commits = git ['show-ref', '-s', pattern], :git_dir => git_dir
36
- commit = all_commits.lines.first
37
- rescue R10K::Util::Subprocess::SubprocessError
38
- end
39
-
40
- if commit.nil?
41
- begin
42
- commit = git ['rev-parse', "#{ref}^{commit}"], :git_dir => git_dir
43
- rescue R10K::Util::Subprocess::SubprocessError
44
- end
45
- end
33
+ commit = resolve_tag(pattern)
34
+ commit ||= resolve_remote_head(pattern)
35
+ commit ||= resolve_head(pattern)
36
+ commit ||= resolve_commit(pattern)
46
37
 
47
38
  if commit
48
39
  commit.chomp
@@ -52,6 +43,55 @@ class R10K::Git::Repository
52
43
  end
53
44
  alias rev_parse resolve_ref
54
45
 
46
+ def resolve_tag(pattern)
47
+ output = git ['show-ref', '--tags', '-s', pattern], :git_dir => git_dir, :raise_on_fail => false
48
+
49
+ if output.success?
50
+ output.stdout.lines.first
51
+ end
52
+ end
53
+
54
+ def resolve_head(pattern)
55
+ output = git ['show-ref', '--heads', '-s', pattern], :git_dir => git_dir, :raise_on_fail => false
56
+
57
+ if output.success?
58
+ output.stdout.lines.first
59
+ end
60
+ end
61
+
62
+ def resolve_remote_head(pattern, remote = 'origin')
63
+ pattern = "refs/remotes/#{remote}/#{pattern}"
64
+ output = git ['show-ref', '-s', pattern], :git_dir => git_dir, :raise_on_fail => false
65
+
66
+ if output.success?
67
+ output.stdout.lines.first
68
+ end
69
+ end
70
+
71
+ # Define the same interface for resolving refs.
72
+ def resolve_commit(pattern)
73
+ output = git ['rev-parse', "#{pattern}^{commit}"], :git_dir => git_dir, :raise_on_fail => false
74
+
75
+ if output.success?
76
+ output.stdout.chomp
77
+ end
78
+ end
79
+
80
+ # @return [Hash<String, String>] A hash of remote names and fetch URLs
81
+ # @api private
82
+ def remotes
83
+ output = git ['remote', '-v'], :git_dir => git_dir
84
+
85
+ ret = {}
86
+ output.stdout.each_line do |line|
87
+ next if line.match /\(push\)/
88
+ name, url, _ = line.split(/\s+/)
89
+ ret[name] = url
90
+ end
91
+
92
+ ret
93
+ end
94
+
55
95
  private
56
96
 
57
97
  # Fetch objects and refs from the given git remote
@@ -69,12 +109,15 @@ class R10K::Git::Repository
69
109
  # @option opts [String] :path
70
110
  # @option opts [String] :git_dir
71
111
  # @option opts [String] :work_tree
112
+ # @option opts [String] :raise_on_fail
72
113
  #
73
114
  # @raise [R10K::ExecutionFailure] If the executed command exited with a
74
115
  # nonzero exit code.
75
116
  #
76
117
  # @return [String] The git command output
77
118
  def git(cmd, opts = {})
119
+ raise_on_fail = opts.fetch(:raise_on_fail, true)
120
+
78
121
  argv = %w{git}
79
122
 
80
123
  if opts[:path]
@@ -92,12 +135,11 @@ class R10K::Git::Repository
92
135
  argv.concat(cmd)
93
136
 
94
137
  subproc = R10K::Util::Subprocess.new(argv)
95
- subproc.raise_on_fail = true
138
+ subproc.raise_on_fail = raise_on_fail
96
139
  subproc.logger = self.logger
97
140
 
98
141
  result = subproc.execute
99
142
 
100
- # todo ensure that logging always occurs even if the command fails to run
101
- result.stdout
143
+ result
102
144
  end
103
145
  end
@@ -55,11 +55,8 @@ class R10K::Git::WorkingDir < R10K::Git::Repository
55
55
  def sync
56
56
  if not cloned?
57
57
  clone
58
- elsif fetch?
59
- fetch_from_cache
60
- checkout(@ref)
61
- elsif needs_checkout?
62
- checkout(@ref)
58
+ else
59
+ update
63
60
  end
64
61
  end
65
62
 
@@ -110,6 +107,11 @@ class R10K::Git::WorkingDir < R10K::Git::Repository
110
107
  @ref.fetch? or needs_checkout?
111
108
  end
112
109
 
110
+ # Prefer remote heads from the 'cache' remote over the real remote
111
+ def resolve_remote_head(pattern, remote = 'cache')
112
+ super(pattern, remote)
113
+ end
114
+
113
115
  private
114
116
 
115
117
  def fetch?
@@ -136,6 +138,7 @@ class R10K::Git::WorkingDir < R10K::Git::Repository
136
138
  # that doing a normal `git pull` on a directory will work.
137
139
  git ["clone", "--reference", @cache.git_dir, @remote, @full_path]
138
140
  git ["remote", "add", "cache", @cache.git_dir], :path => @full_path
141
+ git ['fetch', 'cache'], :path => @full_path
139
142
  checkout(@ref)
140
143
  end
141
144
 
@@ -11,33 +11,40 @@ module Deployment
11
11
 
12
12
  private
13
13
 
14
- def load_environments!
15
- @environments = @deployment.environments.inject({}) do |hash, env|
16
- hash[env.dirname] = env
17
- hash
18
- end
19
- end
14
+ def active_environments(names)
20
15
 
21
- # @param [Array<String>] names The list of environments to deploy.
22
- #
23
- def with_environments(names = [], &block)
24
- load_environments!
16
+ active = []
25
17
 
26
- # If an explicit list of environments were not given, deploy everything
27
- if names.size > 0
28
- to_deploy = names
18
+ all_environments = @deployment.environments
19
+ if names.empty?
20
+ active = all_environments
29
21
  else
30
- to_deploy = @environments.keys
31
- end
22
+ # This has average case O(N^2) but N should remain relatively small, so
23
+ # while this should be optimized that optimization can wait a while.
24
+ names.each do |env_name|
25
+
26
+ matching = all_environments.select do |env|
27
+ env.dirname == env_name
28
+ end
32
29
 
33
- to_deploy.reverse.each do |env_name|
34
- if (env = @environments[env_name])
35
- yield env
36
- else
37
- logger.warn "Environment #{env_name} not found in any source"
38
- task_runner.succeeded = false
30
+ if matching.empty?
31
+ logger.warn "Environment #{env_name} not found in any source"
32
+ task_runner.succeeded = false
33
+ else
34
+ active.concat(matching)
35
+ end
39
36
  end
40
37
  end
38
+
39
+ active.reverse
40
+ end
41
+
42
+ # @param [Array<String>] names The list of environments to deploy.
43
+ #
44
+ def with_environments(names = [])
45
+ active_environments(names).each do |env|
46
+ yield env
47
+ end
41
48
  end
42
49
  end
43
50
 
@@ -21,7 +21,6 @@ class R10K::Util::Subprocess::Result
21
21
  # @return [Integer]
22
22
  attr_reader :exit_code
23
23
 
24
-
25
24
  def initialize(argv, stdout, stderr, exit_code)
26
25
  @argv = argv
27
26
  @cmd = argv.join(' ')
@@ -33,4 +32,12 @@ class R10K::Util::Subprocess::Result
33
32
  def [](field)
34
33
  send(field)
35
34
  end
35
+
36
+ def failed?
37
+ exit_code != 0
38
+ end
39
+
40
+ def success?
41
+ exit_code == 0
42
+ end
36
43
  end
@@ -1,3 +1,3 @@
1
1
  module R10K
2
- VERSION = '1.2.0rc1'
2
+ VERSION = '1.2.0rc2'
3
3
  end
@@ -29,7 +29,7 @@ describe R10K::Git::Cache do
29
29
  end
30
30
 
31
31
  it "lists local branches using git for-each-ref" do
32
- expect(cache).to receive(:git).with(%w[for-each-ref refs/heads --format %(refname)], anything).and_return refs
32
+ expect(cache).to receive(:git).with(%w[for-each-ref refs/heads --format %(refname)], anything).and_return(double(:stdout => refs))
33
33
 
34
34
  expect(cache.branches).to eq %w[master next next-fetch-errors next-update-forge-modules]
35
35
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'r10k/git'
3
+
4
+ describe R10K::Git::Repository do
5
+ include_context "fail on execution"
6
+
7
+ describe "remotes" do
8
+ let(:output) do
9
+ "cache /home/user/.r10k/git/git@github.com-org-org-modules (fetch)\n" +
10
+ "cache /home/user/.r10k/git/git@github.com-org-org-modules (push)\n" +
11
+ "origin git@github.com:org/org-modules (fetch)\n" +
12
+ "origin git@github.com:org/org-modules (push)\n"
13
+ end
14
+
15
+ it "generates a hash of remote names and remote URLs" do
16
+ expect(subject).to receive(:git).with(%w[remote -v], anything).and_return(double(:stdout => output))
17
+
18
+ expect(subject.remotes).to eq(
19
+ 'cache' => '/home/user/.r10k/git/git@github.com-org-org-modules',
20
+ 'origin' => 'git@github.com:org/org-modules',
21
+ )
22
+ end
23
+ end
24
+ end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'r10k/git'
2
3
 
3
4
  describe R10K::Git::WorkingDir do
4
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r10k
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0rc1
4
+ version: 1.2.0rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Thebo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-09 00:00:00.000000000 Z
11
+ date: 2014-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -227,6 +227,7 @@ files:
227
227
  - lib/r10k/git/errors.rb
228
228
  - lib/r10k/git/head.rb
229
229
  - lib/r10k/git/ref.rb
230
+ - lib/r10k/git/remote_head.rb
230
231
  - lib/r10k/git/repository.rb
231
232
  - lib/r10k/git/tag.rb
232
233
  - lib/r10k/git/working_dir.rb
@@ -287,6 +288,7 @@ files:
287
288
  - spec/unit/git/commit_spec.rb
288
289
  - spec/unit/git/head_spec.rb
289
290
  - spec/unit/git/ref_spec.rb
291
+ - spec/unit/git/repository_spec.rb
290
292
  - spec/unit/git/tag_spec.rb
291
293
  - spec/unit/git/working_dir_spec.rb
292
294
  - spec/unit/module/forge_spec.rb
@@ -368,6 +370,7 @@ test_files:
368
370
  - spec/unit/git/working_dir_spec.rb
369
371
  - spec/unit/git/cache_spec.rb
370
372
  - spec/unit/git/commit_spec.rb
373
+ - spec/unit/git/repository_spec.rb
371
374
  - spec/unit/git/head_spec.rb
372
375
  - spec/unit/git/tag_spec.rb
373
376
  - spec/unit/deployment/environment_spec.rb