Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor GitHelpers for consistent logging, whether cloning or updati…

…ng the repo.
  • Loading branch information...
commit 5b6c1ebb3ed0ddc399e9267c042f8dcf08295686 1 parent 05943c8
@benhoskings benhoskings authored
Showing with 19 additions and 11 deletions.
  1. +19 −11 lib/babushka/helpers/git_helpers.rb
View
30 lib/babushka/helpers/git_helpers.rb
@@ -13,18 +13,26 @@ def git uri, opts = {}, &block
def git_update uri, repo
if !repo.exists?
- repo.clone! uri
+ update_and_log uri, repo, "Cloning #{uri} into #{repo.path}" do
+ repo.clone! uri
+ end
else
- log_block "Updating #{uri}" do
- if repo.repo_shell('git fetch origin').nil?
- log_error " Couldn't fetch,", :newline => false
- elsif !repo.behind?
- log " Already up-to-date at #{repo.current_head.colorize('yellow')},", :newline => false
- true
- else
- log " #{repo.current_head.colorize('yellow')}..#{repo.repo_shell("git rev-parse --short origin/#{repo.current_branch}").colorize('yellow')} (#{repo.repo_shell("git log -1 --pretty=format:%s origin/#{repo.current_branch}").chomp('.')}),", :newline => false
- repo.reset_hard! "origin/#{repo.current_branch}"
- end
+ update_and_log uri, repo, "Updating #{repo.path} from #{uri}" do
+ repo.repo_shell('git fetch origin')
+ end
+ end
+ end
+
+ def update_and_log uri, repo, message, &block
+ log_block message do
+ if !block.call
+ # failed
+ elsif !repo.behind?
+ log " at #{repo.current_head.colorize('yellow')},", :newline => false
+ true
+ else
+ log " #{repo.current_head.colorize('yellow')}..#{repo.repo_shell("git rev-parse --short origin/#{repo.current_branch}").colorize('yellow')} (#{repo.repo_shell("git log -1 --pretty=format:%s origin/#{repo.current_branch}").chomp('.')}),", :newline => false
+ repo.reset_hard! "origin/#{repo.current_branch}"
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.