lib/omnibus/fetchers/git_fetcher.rb in omnibus-1.3.0 vs lib/omnibus/fetchers/git_fetcher.rb in omnibus-2.0.0.rc1

- old
+ new

@@ -1,7 +1,7 @@ # -# Copyright:: Copyright (c) 2012 Opscode, Inc. +# Copyright:: Copyright (c) 2012-2014 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -14,14 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # module Omnibus - # Fetcher implementation for projects in git. class GitFetcher < Fetcher - name :git attr_reader :source attr_reader :project_dir attr_reader :version @@ -32,11 +30,11 @@ @version = software.version @project_dir = software.project_dir end def description - s=<<-E + <<-E repo URI: #{@source[:git]} local location: #{@project_dir} E end @@ -45,13 +43,13 @@ rescue end def clean if existing_git_clone? - log "cleaning existing build" - clean_cmd = "git clean -fdx" - shell = Mixlib::ShellOut.new(clean_cmd, :live_stream => STDOUT, :cwd => project_dir) + log 'cleaning existing build' + clean_cmd = 'git clean -fdx' + shell = Mixlib::ShellOut.new(clean_cmd, live_stream: STDOUT, cwd: project_dir) shell.run_command shell.error! end rescue Exception => e ErrorReporter.new(e, self).explain("Failed to clean git repository '#{@source[:git]}'") @@ -74,41 +72,41 @@ if retries >= 3 ErrorReporter.new(e, self).explain("Failed to fetch git repository '#{@source[:git]}'") raise else # Deal with github failing all the time :( - time_to_sleep = 5 * (2 ** retries) + time_to_sleep = 5 * (2**retries) retries += 1 log "git clone/fetch failed for #{@source} #{retries} time(s), retrying in #{time_to_sleep}s" sleep(time_to_sleep) retry end end private def clone - puts "cloning the source from git" + puts 'cloning the source from git' clone_cmd = "git clone #{@source[:git]} #{project_dir}" - shell = Mixlib::ShellOut.new(clone_cmd, :live_stream => STDOUT) + shell = Mixlib::ShellOut.new(clone_cmd, live_stream: STDOUT) shell.run_command shell.error! end def checkout sha_ref = target_revision checkout_cmd = "git checkout #{sha_ref}" - shell = Mixlib::ShellOut.new(checkout_cmd, :live_stream => STDOUT, :cwd => project_dir) + shell = Mixlib::ShellOut.new(checkout_cmd, live_stream: STDOUT, cwd: project_dir) shell.run_command shell.error! end def fetch_updates puts "fetching updates and resetting to revision #{target_revision}" fetch_cmd = "git fetch origin && git fetch origin --tags && git reset --hard #{target_revision}" - shell = Mixlib::ShellOut.new(fetch_cmd, :live_stream => STDOUT, :cwd => project_dir) + shell = Mixlib::ShellOut.new(fetch_cmd, live_stream: STDOUT, cwd: project_dir) shell.run_command shell.error! end def existing_git_clone? @@ -119,12 +117,12 @@ current_revision && current_revision.strip.to_i(16) == target_revision.strip.to_i(16) end def current_revision @current_rev ||= begin - rev_cmd = "git rev-parse HEAD" - shell = Mixlib::ShellOut.new(rev_cmd, :live_stream => STDOUT, :cwd => project_dir) + rev_cmd = 'git rev-parse HEAD' + shell = Mixlib::ShellOut.new(rev_cmd, live_stream: STDOUT, cwd: project_dir) shell.run_command shell.error! output = shell.stdout sha_hash?(output) ? output : nil @@ -152,24 +150,22 @@ # execute `git ls-remote` the trailing '*' does globbing. This # allows us to return the SHA of the tagged commit for annotated # tags. We take care to only return exact matches in # process_remote_list. cmd = "git ls-remote origin #{ref}*" - shell = Mixlib::ShellOut.new(cmd, :live_stream => STDOUT, :cwd => project_dir) + shell = Mixlib::ShellOut.new(cmd, live_stream: STDOUT, cwd: project_dir) shell.run_command shell.error! commit_ref = process_remote_list(shell.stdout, ref) - if !commit_ref - raise "Could not parse SHA reference" - end + fail 'Could not parse SHA reference' unless commit_ref commit_ref rescue Exception => e if retries >= 3 ErrorReporter.new(e, self).explain("Failed to find any commits for the ref '#{ref}'") raise else # Deal with github failing all the time :( - time_to_sleep = 5 * (2 ** retries) + time_to_sleep = 5 * (2**retries) retries += 1 log "git ls-remote failed for #{@source} #{retries} time(s), retrying in #{time_to_sleep}s" sleep(time_to_sleep) retry end