# Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide. # # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use, # reproduction, modification, or disclosure of this program is # strictly prohibited. Any use of this program by an authorized # licensee is strictly subject to the terms and conditions, # including confidentiality obligations, set forth in the applicable # License Agreement between RightScale.com, Inc. and # the licensee module RightConf class GitRepoConfigurator include Configurator register :git_repo description 'Clone git repository and build if needed' settings :repo => 'git repo URL', :path => 'Path where git repo should be cloned to', :tag => 'git tag or branch or sha that should be checked out ("master" by default)' validate_has_settings :repo, :path # Clone git repo and run build commands if given # # === Return # true:: Always return true def run if File.exist?(path) unless File.exist?(File.join(path, '.git')) FileUtils.mv(path, "#{path}_old") post_note "Had to move #{path} to #{path}_old" end end unless File.exist?(path) report_check("Cloning #{repo} into #{path}") Command.execute('git', 'clone', repo, path, :abort_on_failure => "Failed to clone #{repo} into #{path}") report_success if tag report_check("Checking out #{tag}") Dir.chdir(path) do Command.execute('git', 'checkout', tag, :abort_on_failure => "Failed to checkout #{tag}") end report_success end end true end end end