From 065ab3e5f302434a189038aa46a475154c79a91d Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Mon, 22 Sep 2014 19:46:57 +0200 Subject: [PATCH] Only clone GitLab Shell on tests if necessary. --- lib/tasks/gitlab/shell.rake | 5 ++++- spec/support/test_env.rb | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/tasks/gitlab/shell.rake b/lib/tasks/gitlab/shell.rake index ece3ad58385..2834570d8f0 100644 --- a/lib/tasks/gitlab/shell.rake +++ b/lib/tasks/gitlab/shell.rake @@ -22,7 +22,10 @@ namespace :gitlab do # Make sure we're on the right tag Dir.chdir(target_dir) do - sh "git fetch origin && git reset --hard $(git describe #{args.tag} || git describe origin/#{args.tag})" + # First try to checkout without fetching + # to avoid stalling tests if the Internet is down. + reset = "git reset --hard $(git describe #{args.tag} || git describe origin/#{args.tag})" + sh "#{reset} || git fetch origin && #{reset}" redis_url = URI.parse(ENV['REDIS_URL'] || "redis://localhost:6379") diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index e67c29a6783..4b0a3856f89 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -17,7 +17,11 @@ module TestEnv tmp_test_path = Rails.root.join('tmp', 'tests') if File.directory?(tmp_test_path) - FileUtils.rm_r(tmp_test_path) + Dir.entries(tmp_test_path).each do |entry| + unless ['.', '..', 'gitlab-shell'].include?(entry) + FileUtils.rm_r(File.join(tmp_test_path, entry)) + end + end end FileUtils.mkdir_p(tmp_test_path) @@ -38,9 +42,7 @@ module TestEnv end def setup_gitlab_shell - unless File.directory?(Gitlab.config.gitlab_shell.path) - %x[rake gitlab:shell:install] - end + `rake gitlab:shell:install` end def setup_factory_repo