Skip to content

Commit

Permalink
Handle case when other envs are missing a cookbook.
Browse files Browse the repository at this point in the history
* Refactored to use the same method to extract version strings.
* Using 'none' as a placeholder for missing version.
  • Loading branch information
Jeremy Voorhis committed Apr 5, 2012
1 parent 04e946f commit 223cf89
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/chef/knife/env-diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ def run
from_cookbooks.each do |from_cookbook, from_data|
diff_versions = {}

unless from_data['versions'].empty?
from_version = from_data["versions"].first['version']
end
from_version = get_cookbook_version(from_data)

to_env.each do |to_env, to_cookbooks|
to_version = to_cookbooks[from_cookbook]["versions"].first['version']
to_version = get_cookbook_version(to_cookbooks[from_cookbook])

if from_version != to_version || from_version.nil?
diff_versions[to_env] = to_version
Expand All @@ -65,15 +63,20 @@ def run
end
ui.msg "\n"
end

end
end

end

def get_env_cookbooks(env)
def get_env_cookbooks(env)
rest.get_rest("environments/#{env}/cookbooks")
end
end

def get_cookbook_version(data)
if data['versions'].empty?
'none'
else
data['versions'].first['version']
end
end
end
end

0 comments on commit 223cf89

Please sign in to comment.