# Copyright (C) 2011-2012 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 # Check whether repo was already cloned # # === Return # true:: If repo was already cloned # false:: Otherwise def check_linux File.exist?(path) && File.exist?(File.join(path, '.git')) end alias :check_darwin :check_linux alias :check_windows :check_linux # Clone git repo and run build commands if given # # === Return # true:: Always return true def run_linux if File.exist?(path) FileUtils.mv(path, "#{path}_old") post_note "Had to move #{path} to #{path}_old" end 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 true end alias :run_darwin :run_linux # Clone git repo and run build commands if given on Windows # # === Return # true:: Always return true def run_windows true # TBD end end end