51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/kitchen-yansible/tools/dependencies.rb', line 51
def prepare_dependencies(dependencies)
dependencies.each do |dependency|
info("Processing '#{dependency[:name]}' dependency.")
dependency_target_path = File.join(dependencies_tmp_dir, dependency[:name])
if dependency.key?(:path)
info('Processing as path type.')
if File.exist?(dependency[:path])
copy_dirs(dependency[:path], dependency_target_path)
else
warn("Dependency path '#{dependency[:path]}' doesn't exists. Omitting copy operation.")
end
end
if dependency.key?(:repo)
if dependency[:repo].downcase == 'git'
info('Processing as Git repository.')
if command_exists('git')
if File.exist?(dependency_target_path)
if execute_local_command('git status .', opts: { :chdir => dependency_target_path })
if git_get_origin(dependency_target_path).chomp.eql?(dependency[:url])
warn("Dependency downloaded already, resetting to HEAD.")
git_clean(dependency_target_path)
else
warn("Removing directory #{dependency_target_path} due to repository origin difference.")
FileUtils.remove_entry_secure(dependency_target_path)
git_clone(dependency[:name], dependency[:url], dependency_target_path)
end
else
warn("Dependency path '#{dependency_target_path}' is not a valid Git repository. Removing then.")
FileUtils.remove_entry_secure(dependency_target_path)
git_clone(dependency[:name], dependency[:url], dependency_target_path)
end
else
git_clone(dependency[:name], dependency[:url], dependency_target_path)
end
raw_ref = dependency.key?(:ref) ? dependency[:ref] : 'master'
begin
git_check_ref(dependency_target_path, raw_ref)
rescue
message = unindent(<<-MSG)
===============================================================================
Invalid Git reference - #{raw_ref}
Please check '#{dependency[:name]}' dependency configuration.
===============================================================================
MSG
raise UserError, message
end
info("Resetting repository to '#{raw_ref}' reference.")
git_checkout(dependency_target_path, raw_ref, force: true)
else
message = unindent(<<-MSG)
===============================================================================
Couldn't find git binary.
Please make sure execution host has Git binaries installed.
===============================================================================
MSG
raise UserError, message
end
else
raise UserError, "Working with '#{dependency[:repo]}' repository is not implemented yet."
end
end
end unless dependencies.nil?
end
|